From 3eea42fd49ee828479eef368d8c93ea0d3eedc82 Mon Sep 17 00:00:00 2001 From: "pulse-triage[bot]" <249995291+pulse-triage[bot]@users.noreply.github.com> Date: Sun, 6 Sep 2026 14:01:05 +0100 Subject: [PATCH] test(alerts): reject stale healthy evidence after queue refresh failure A pre-action health read can finish after retry or dismissal succeeds but its follow-up read fails. Exercise this combined race for both actions so old healthy evidence cannot erase delivery uncertainty. Change-source: pulse-maintainer --- .../useNotificationDeliveryHealth.test.tsx | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/frontend-modern/src/features/alerts/__tests__/useNotificationDeliveryHealth.test.tsx b/frontend-modern/src/features/alerts/__tests__/useNotificationDeliveryHealth.test.tsx index d30e03af6..66ac42540 100644 --- a/frontend-modern/src/features/alerts/__tests__/useNotificationDeliveryHealth.test.tsx +++ b/frontend-modern/src/features/alerts/__tests__/useNotificationDeliveryHealth.test.tsx @@ -171,24 +171,34 @@ describe('useNotificationDeliveryHealth', () => { ); describe.each(['dismissTerminalFailures', 'retryTerminalFailures'] as const)('%s', (action) => { - it('reports unavailable rather than healthy when the post-action refresh fails', () => + it('keeps uncertainty after a failed post-action refresh even when older healthy evidence arrives', () => createRoot(async (dispose) => { const confirmSpy = vi.spyOn(window, 'confirm').mockReturnValue(true); const onAfterQueueAction = vi.fn().mockResolvedValue(undefined); + let finishOld!: (health: Awaited>) => void; try { vi.mocked(NotificationsAPI.getHealth) .mockResolvedValueOnce({ queue: { status: 'degraded', attentionRequired: 2 }, } as never) + .mockReturnValueOnce( + new Promise((resolve) => { + finishOld = resolve; + }), + ) .mockRejectedValueOnce(new Error('post-action connection lost')); vi.mocked(NotificationsAPI[action]).mockResolvedValueOnce({ affected: 2 } as never); const state = useNotificationDeliveryHealth({ onAfterQueueAction }); await state.loadDeliveryHealth(); + const oldRequest = state.loadDeliveryHealth(); await state[action](); + expect(state.deliveryHealthUnavailable()).toBe(true); + finishOld(healthWith('healthy')); + await oldRequest; expect(NotificationsAPI[action]).toHaveBeenCalledOnce(); - expect(NotificationsAPI.getHealth).toHaveBeenCalledTimes(2); + expect(NotificationsAPI.getHealth).toHaveBeenCalledTimes(3); expect(onAfterQueueAction).toHaveBeenCalledOnce(); expect(state.deliveryHealth()).toBeNull(); expect(state.deliveryHealthUnavailable()).toBe(true);