unbridled-41 opened a new pull request, #4603:
URL: https://github.com/apache/rocketmq-dashboard/pull/4603
Fixes #4599.
## Problem
When `GET /api/audit-logs/summary` fails, the audit page rendered the
summary cards from zero defaults, i.e. it claimed that no audit record matched
the current filters while the record table and the risk-insights panel on the
same screen listed and counted the matching records.
## Evidence
Regression test added with this PR
(`web/src/pages/ops/__tests__/AuditPage.test.tsx` → `reports a failed summary
instead of rendering it as empty statistics`), run against the pre-fix code
(baseline `origin/master` = d50ffecc):
```
AssertionError: failed summary must not be shown as zero matched records:
expected '匹配记录0' not to be '匹配记录0'
⎯ a second run with the source restored from master:
TestingLibraryElementError: Unable to find an element with the text: 审计概览加载失败
```
## Root cause and fix
The summary effect only raised a toast and left `summary` as `null`:
```ts
.catch(() => {
if (!cancelled) message.error('审计概览加载失败,请稍后重试');
})
```
and `AuditSummaryCards` substitutes a zero aggregate for `null`, so the
cards rendered `匹配记录 0`, `成功率 0%`, `失败 / 部分成功 0 / 0`, `操作人数 0` and two empty
bucket panels. The fix keeps the failure in state and replaces the cards with
an explicit failure notice, so zero is never published for a failed aggregate.
## Priority and scoring
PRIORITY 72 = impact 28 + scope 10 + reproducibility 18 + maintenance value
16.
- Impact 28: a failed aggregate is published as a factual "these filters
match nothing" result, including a 0% success rate, on an audit page whose
purpose is exactly that count.
- Scope 10: the summary endpoint failing (server error/timeout) while the
page stays usable.
- Reproducibility 18: deterministic, covered by the added test.
- Maintenance value 16: the failure path was the only untested branch of the
page's summary effect.
FIX_CONFIDENCE 95: an error flag plus a rendering branch, no API or contract
change, module suite green.
## Tests
- Red (baseline source + new test): `expected '匹配记录0' not to be '匹配记录0'`;
with the component reverted: `Unable to find an element with the text:
审计概览加载失败`.
- Green: `npx vitest run --maxWorkers=2
src/pages/ops/__tests__/AuditPage.test.tsx` → **11 passed (11)** (10
pre-existing + 1 new).
- Full web suite: see the verification comment below.
- `npx tsc -b` clean; `npx eslint` on the three changed files → no output.
## Risk
Low. Only the failed-summary branch changed; a successful summary renders
exactly as before, and the record list, insights panel and table are untouched.
The two `setSummary`/`setSummaryFailed` writes are both guarded by the effect's
`cancelled` flag, so a response for a superseded filter cannot flip the state.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]