unbridled-41 opened a new pull request, #4584:
URL: https://github.com/apache/rocketmq-dashboard/pull/4584
Fixes #4583.
## Problem / Evidence
The alert rule editor renders its dry-run samples from page state
(`testResult`). Every entry point resets that state except **编辑**:
`openCreateModal:417`, `openDuplicateModal:504`, the modal `onCancel:1041` and
the footer cancel button `:1059` all call `setTestResult(null)`;
`openEditModal:486` does not, and the save path (`handleSubmit`) closes the
dialog while leaving the samples in state.
So: edit rule A → 试运行 → 确定 → 编辑 rule B, and B's editor shows A's samples
under 规则试运行结果, including A's labels and current values
(`web/src/pages/ops/alerts.tsx:1275`). The panel is the only evidence an
operator has about whether the rule matches live data, and it is attributed to
the wrong rule.
Regression test added in this PR:
`web/src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx`.
## Root cause / Fix
Stale view state surviving an editor session: the samples are cleared on
*every* path out of the editor except the one that reopens it. One line in
`openEditModal` makes 编辑 behave like 新建/复制:
```diff
const openEditModal = (rule: AlertRule) => {
setEditingRule(rule);
+ setTestResult(null);
form.setFieldsValue({
```
No other behaviour changes: the panel is still produced on demand by 试运行,
and every other reset point stays as it is.
## Priority & scoring
- PRIORITY **72** = impact 28 + blast radius 8 + reproducibility 20 +
maintenance value 16
- impact 28 — the operator reads another rule's dry-run evidence as if it
belonged to the rule being edited, which can lead to a wrong "the rule matches"
conclusion; no data mutation.
- blast radius 8 — the same component serves `/ops/alerts` and
`/ops/business-alerts`; only the editor panel is affected.
- reproducibility 20 — deterministic; one regression test captures it.
- maintenance value 16 — one line, aligned with the four sibling reset
points; removes an omission that would otherwise be copied into future entry
points.
- FIX_CONFIDENCE **95** — the sibling entry points define the intended
contract unambiguously, and the fix cannot regress the tested flow.
## Tests
Environment: Node 24.20.0, `web/` as checked out at the PR head.
Red — test on the base commit (`d50ffecc`, source unmodified) with
`SPRING`-free frontend suite:
```
$ git checkout origin/master -- web/src/pages/ops/alerts.tsx
$ npx vitest run src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx
FAIL src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx > AlertsPage
rule test results > shows no test samples for a rule the user never tested
AssertionError: expected <div class="ant-table-title"></div> to be null
- Expected:
null
+ Received:
<div class="ant-table-title">
规则试运行结果
</div>
❯ src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx:172:53
Test Files 1 failed (1)
Tests 1 failed (1)
```
Green — same command with the fix, plus the page suite:
```
$ npx vitest run src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx
src/pages/ops/__tests__/AlertsPage.test.tsx
Test Files 2 passed (2)
Tests 27 passed (27) (1 new + 26 existing)
```
Full suite — `npx vitest run` in `web/`:
```
Test Files 4 failed | 119 passed (123)
Tests 9 failed | 1026 passed (1035)
```
1035 = the pristine `origin/master` count 1034 + 1 new test (cross-checked:
the same suite reported 1038 while three other in-progress regression files
were still present in the tree). All 9 failures are in files this PR does not
touch — MetricsExplorer 1, ClusterPage 1, ConsumerPage 6, TopicPage 1 — the
load-fragile set that also fails intermittently on pristine `master` under a
full parallel run. Isolation run of exactly those four files:
```
$ npx vitest run src/components/__tests__/MetricsExplorer.test.tsx
src/pages/cluster/__tests__/ClusterPage.test.tsx
src/pages/instance/__tests__/ConsumerPage.test.tsx
src/pages/instance/__tests__/TopicPage.test.tsx
Test Files 4 passed (4)
Tests 111 passed (111)
```
Static checks:
```
$ npx tsc -b # clean, exit 0
$ npx eslint src/pages/ops/alerts.tsx
src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx
✖ 5 problems (0 errors, 5 warnings) # identical to origin/master's copy of
alerts.tsx (re-run to confirm)
$ npm run build # ✓ built in 11.04s
```
Diff: `web/src/pages/ops/alerts.tsx` +1/−0,
`web/src/pages/ops/__tests__/AlertsTestResultResidue.test.tsx` +175/−0 (`git
show --numstat`).
## Risk
- The only behaviour removed is the reuse of a previous session's samples;
试运行 still fills the panel in the current session.
- Rule dry-run is a read-only server call, so no mutation risk.
- No API, contract or translation changes; the panel title and table are
unchanged.
--
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]