This is an automated email from the ASF dual-hosted git repository.
lizhimins pushed a commit to branch rocketmq-studio
in repository https://gitbox.apache.org/repos/asf/rocketmq-dashboard.git
The following commit(s) were added to refs/heads/rocketmq-studio by this push:
new c5e921707 fix(mock): reject acknowledging an alert the mock inventory
does not have (#6516)
c5e921707 is described below
commit c5e921707c161ba49513057657b74d7895faeef6
Author: Apulupie <[email protected]>
AuthorDate: Thu Oct 15 18:13:47 2026 +0800
fix(mock): reject acknowledging an alert the mock inventory does not have
(#6516)
The mock branch of `acknowledgeAlert` looked the id up and returned without
a word when the store did
not have it, so the demo data source answered a missing alert with success.
The endpoint it stands in
for answers 404: `AlertService.acknowledgeAlert` throws
`BusinessException(404, "System alert not found: " + id)` when
`findAlertById` is empty.
`SystemAlertsPage`'s `handleAck` runs `acknowledgeAlert(id)` and then marks
the row acknowledged and
toasts `sysAlerts.acknowledged`, so a click on a row the store no longer
has (the list was refreshed
or the row was cleared behind the operator) reported an acknowledgement
that never happened instead of
taking the page's existing `sysAlerts.acknowledgeFailed` branch.
The lookup now throws the endpoint's message for a missing id. This is the
same shape the ACL rule and
user deletes already use, and the sibling `clusterService` certificate
paths already throw for a missing
record. The delete family in `opsService` is deliberately left to the
separate change that covers it.
---
web/src/services/opsService.test.ts | 26 ++++++++++++++++++++++++++
web/src/services/opsService.ts | 7 ++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/web/src/services/opsService.test.ts
b/web/src/services/opsService.test.ts
index ce8de492d..157c4ae9c 100644
--- a/web/src/services/opsService.test.ts
+++ b/web/src/services/opsService.test.ts
@@ -19,6 +19,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest';
import type { AuditRecord } from '../api/ops';
import { mockAuditRecords } from '../mock/audit';
import {
+ acknowledgeAlert,
createAlertRule,
deleteAlertRule,
exportAlertRulesTransfer,
@@ -200,6 +201,31 @@ describe('ops service mock data', () => {
expect(result.items[0]).not.toBe(full[0]);
});
+ it('rejects acknowledging an alert the mock inventory does not have', async
() => {
+ const alerts = await listSystemAlerts();
+ const missingId = Math.max(...alerts.map((alert) => alert.id)) + 1;
+
+ // The endpoint answers 404 "System alert not found: <id>"; the mock used
to report success
+ // for an id its store does not have, so the page kept a phantom
acknowledged row.
+ await expect(acknowledgeAlert(missingId)).rejects.toThrow(
+ `System alert not found: ${missingId}`,
+ );
+ expect((await listSystemAlerts()).map((alert) => alert.id)).toEqual(
+ alerts.map((alert) => alert.id),
+ );
+ });
+
+ it('still acknowledges an alert the mock inventory has', async () => {
+ const target = (await listSystemAlerts()).find((alert) =>
!alert.acknowledged);
+ expect(target).toBeDefined();
+
+ await acknowledgeAlert(target!.id);
+
+ expect((await listSystemAlerts()).find((alert) => alert.id ===
target!.id)?.acknowledged).toBe(
+ true,
+ );
+ });
+
it('returns copied audit records', async () => {
const first = await listAuditRecords({ page: 1, pageSize: 1 });
const originalOperator = first.items[0].operator;
diff --git a/web/src/services/opsService.ts b/web/src/services/opsService.ts
index 43e2b9a24..69da52f64 100644
--- a/web/src/services/opsService.ts
+++ b/web/src/services/opsService.ts
@@ -408,7 +408,12 @@ export async function getCollectorStatus():
Promise<CollectorStatus> {
export async function acknowledgeAlert(id: number): Promise<void> {
if (isMockMode()) {
const a = mockSystemAlerts.find((a: Record<string, unknown>) => a.id ===
id);
- if (a) (a as Record<string, unknown>).acknowledged = true;
+ if (!a) {
+ // The endpoint answers 404 "System alert not found: <id>"
(AlertService.acknowledgeAlert);
+ // acknowledging nothing must not read as a success.
+ throw new Error(`System alert not found: ${id}`);
+ }
+ (a as Record<string, unknown>).acknowledged = true;
return;
}
return opsApi.acknowledgeAlert(id);