Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.
Go aialertsdashboarddockerdocker-monitoringgohomelabinfrastructure-monitoringkubernetesmonitoringmspproxmoxproxmox-backup-serverproxmox-mail-gatewayproxmox-veself-hostedtruenastypescriptvspherewebhooks
test(alerts): retain known incident request lifecycle failures
pulse-triage[bot]20d2892d7d0a
diff --git a/frontend-modern/src/features/alerts/__tests__/useAlertResourceIncidentsState.test.tsx b/frontend-modern/src/features/alerts/__tests__/useAlertResourceIncidentsState.test.tsxnew file mode 100644index 0000000000..202dd071f0--- /dev/null+++ b/frontend-modern/src/features/alerts/__tests__/useAlertResourceIncidentsState.test.tsx@@ -0,0 +1,122 @@+import { renderHook } from '@solidjs/testing-library';+import { beforeEach, describe, expect, it, vi } from 'vitest';++import { AlertsAPI } from '@/api/alerts';+import { notificationStore } from '@/stores/notifications';+import { useAlertResourceIncidentsState } from '../useAlertResourceIncidentsState';++vi.mock('@/api/alerts', () => ({ AlertsAPI: { getIncidentsForResource: vi.fn() } }));+vi.mock('@/stores/notifications', () => ({ notificationStore: { error: vi.fn() } }));+vi.mock('@/utils/logger', () => ({ logger: { error: vi.fn() } }));++type Incidents = Awaited<ReturnType<typeof AlertsAPI.getIncidentsForResource>>;+function deferred() {+ let resolve!: (value: Incidents) => void;+ let reject!: (reason: Error) => void;+ const promise = new Promise<Incidents>((yes, no) => {+ resolve = yes;+ reject = no;+ });+ return { promise, resolve, reject };+}++// Known lifecycle defects, reproduced against the supplied main source.+// it.fails is intentional: these are unresolved bugs, NOT passing acceptance.+// Convert each to ordinary it when repairing request ownership; a fixed behaviour+// makes an expected-failure test fail until its marker is removed. PR1973 also+// needs a stale resourceIncidentError regression when that accessor lands.+describe('resource incident request ownership', () => {+ beforeEach(() => vi.resetAllMocks());++ it.fails('does not repopulate cleared history after reset', async () => {+ const pending = deferred();+ vi.mocked(AlertsAPI.getIncidentsForResource).mockReturnValueOnce(pending.promise);+ const { result } = renderHook(useAlertResourceIncidentsState);+ const load = result.openResourceIncidentPanel('host', 'Host', 'row');+ result.resetResourceIncidentsState();+ pending.resolve([]);+ await load;+ expect(result.resourceIncidents()).toEqual({});+ expect(result.resourceIncidentLoading()).toEqual({});+ expect(result.resourceIncidentPanel()).toBeNull();+ });++ it.fails('keeps the newer same-resource result when requests finish backwards', async () => {+ const old = deferred();+ const latest = [{ id: 'latest' }] as Incidents;+ vi.mocked(AlertsAPI.getIncidentsForResource)+ .mockReturnValueOnce(old.promise)+ .mockResolvedValueOnce(latest);+ const { result } = renderHook(useAlertResourceIncidentsState);+ const load = result.openResourceIncidentPanel('host', 'Host', 'row');+ await result.refreshResourceIncidentPanel();+ old.resolve([]);+ await load;+ expect(result.resourceIncidents().host).toEqual(latest);+ });++ it.fails('does not clear newer loading state or report a superseded failure', async () => {+ const old = deferred();+ const current = deferred();+ vi.mocked(AlertsAPI.getIncidentsForResource)+ .mockReturnValueOnce(old.promise)+ .mockReturnValueOnce(current.promise);+ const { result } = renderHook(useAlertResourceIncidentsState);+ const load = result.openResourceIncidentPanel('host', 'Host', 'row');+ const refresh = result.refreshResourceIncidentPanel();+ old.reject(new Error('obsolete read'));+ await load;+ const loadingAfterOldFailure = result.resourceIncidentLoading().host;+ const obsoleteNotifications = vi.mocked(notificationStore.error).mock.calls.length;+ current.resolve([]);+ await refresh;+ expect(loadingAfterOldFailure).toBe(true);+ expect(obsoleteNotifications).toBe(0);+ expect(result.resourceIncidentLoading().host).toBe(false);+ });++ it.fails('ignores failed reads after disposal', async () => {+ const pending = deferred();+ vi.mocked(AlertsAPI.getIncidentsForResource).mockReturnValueOnce(pending.promise);+ const { result, cleanup } = renderHook(useAlertResourceIncidentsState);+ const load = result.openResourceIncidentPanel('host', 'Host', 'row');+ cleanup();+ pending.reject(new Error('disposed read'));+ await load;+ expect(notificationStore.error).not.toHaveBeenCalled();+ });++ it('retains independent resource results and reports current failures', async () => {+ const first = deferred();+ vi.mocked(AlertsAPI.getIncidentsForResource)+ .mockReturnValueOnce(first.promise)+ .mockRejectedValueOnce(new Error('current read'));+ const { result } = renderHook(useAlertResourceIncidentsState);+ const load = result.openResourceIncidentPanel('first', 'First', 'row-1');+ await result.openResourceIncidentPanel('second', 'Second', 'row-2');+ expect(notificationStore.error).toHaveBeenCalledTimes(1);+ first.resolve([]);+ await load;+ expect(result.resourceIncidents().first).toEqual([]);+ expect(result.resourceIncidentLoading()).toEqual({ first: false, second: false });+ });+ it('toggles the opening row and reuses loaded history for another row', async () => {+ vi.mocked(AlertsAPI.getIncidentsForResource).mockResolvedValue([]);+ const { result } = renderHook(useAlertResourceIncidentsState);+ await result.openResourceIncidentPanel('host', 'Host', 'row-1');+ await result.openResourceIncidentPanel('host', 'Host', 'row-1');+ expect(result.resourceIncidentPanel()).toBeNull();+ await result.openResourceIncidentPanel('host', 'Host', 'row-2');+ expect(result.resourceIncidentPanel()?.rowKey).toBe('row-2');+ expect(AlertsAPI.getIncidentsForResource).toHaveBeenCalledTimes(1);+ await result.refreshResourceIncidentPanel();+ expect(AlertsAPI.getIncidentsForResource).toHaveBeenCalledTimes(2);+ });++ it('does not request history without a resource or selection', async () => {+ const { result } = renderHook(useAlertResourceIncidentsState);+ await result.openResourceIncidentPanel('', 'Missing', 'row');+ await result.refreshResourceIncidentPanel();+ expect(AlertsAPI.getIncidentsForResource).not.toHaveBeenCalled();+ });+});