Merge pull request 'fix(web): ignore stale aggregate health snapshots' (#53)

This commit is contained in:
vince 2026-06-20 15:54:33 +02:00
commit 29077923e8
4 changed files with 150 additions and 2 deletions

View file

@ -161,6 +161,68 @@ describe("React app dashboard state view", () => {
}); });
}); });
test("does not restore aggregate health snapshots over the fresh shell", () => {
const restored = restoreDashboardTileSnapshots(
{
state: "ready",
document: dimensionLabDashboardFixture,
schemaVersion: "dashboard.v1",
currentRevisionId: "revision-a",
},
[
{
ageMs: 60_000,
response: {
state: "ready",
tile: { kind: "status", stripId: "footer-status", id: "system-status" },
item: {
id: "system-status",
label: "System Status",
value: "20 services down",
severity: "stale",
},
},
},
{
ageMs: 60_000,
response: {
state: "ready",
tile: { kind: "module", id: "runtime-health-summary" },
item: {
id: "runtime-health-summary",
kind: "summary",
title: "Runtime Health",
value: "20 services down",
detail: "0 warnings - 8 services ok - stale 60s",
severity: "stale",
},
},
},
],
);
expect(restored.restoredItemIds).toEqual(new Set());
if (restored.dashboard.state !== "ready") {
throw new Error("Expected dashboard to be ready");
}
expect(
restored.dashboard.document.statusStrips[0].items.find((item) =>
item.id === "system-status"
),
).toMatchObject({
id: "system-status",
value: "Fallback operational",
});
expect(
restored.dashboard.document.modules?.find((module) =>
module.id === "runtime-health-summary"
),
).toMatchObject({
id: "runtime-health-summary",
value: "fallback",
});
});
test("uses structured tile match keys for delimiter-bearing ids", () => { test("uses structured tile match keys for delimiter-bearing ids", () => {
expect( expect(
dashboardTileMatchKey({ kind: "service", groupId: "a:b", id: "c" }), dashboardTileMatchKey({ kind: "service", groupId: "a:b", id: "c" }),

View file

@ -15,6 +15,7 @@ import {
createDashboardTileSnapshotStore, createDashboardTileSnapshotStore,
createDashboardTileBackoff, createDashboardTileBackoff,
createDashboardRequestAborter, createDashboardRequestAborter,
isPersistableDashboardTileSnapshot,
runViewportAwareDashboardHydrationQueue, runViewportAwareDashboardHydrationQueue,
shouldPauseDashboardRefresh, shouldPauseDashboardRefresh,
subscribeToDashboardTileEvents, subscribeToDashboardTileEvents,
@ -690,7 +691,9 @@ export function restoreDashboardTileSnapshots(
}; };
} }
return snapshots.reduce( return snapshots.filter((snapshot) =>
isPersistableDashboardTileSnapshot(snapshot.response.tile)
).reduce(
(current, snapshot) => ({ (current, snapshot) => ({
dashboard: { dashboard: {
...current.dashboard, ...current.dashboard,

View file

@ -518,6 +518,77 @@ describe("dashboard refresh lifecycle", () => {
}, },
]); ]);
}); });
test("ignores restored aggregate health snapshots", () => {
const storage = createMemoryStorage();
storage.setItem(
"dimensionlab.dashboard.tiles.v1",
JSON.stringify({
currentRevisionId: "revision-a",
schemaVersion: "dashboard.v1",
tiles: [
{
item: {
id: "system-status",
label: "System Status",
value: "20 services down",
severity: "danger",
},
savedAt: 1_000,
tile: { kind: "status", stripId: "footer-status", id: "system-status" },
},
{
item: {
id: "runtime-health-summary",
kind: "summary",
title: "Runtime Health",
value: "20 services down",
detail: "0 warnings - 8 services ok",
severity: "danger",
},
savedAt: 1_000,
tile: { kind: "module", id: "runtime-health-summary" },
},
{
item: {
id: "infra-ram",
label: "Infra RAM",
value: { kind: "percent", value: 42 },
detail: "live",
severity: "ok",
},
savedAt: 1_000,
tile: { kind: "telemetry", id: "infra-ram" },
},
],
version: 1,
}),
);
const store = createDashboardTileSnapshotStore(storage, {
now: () => 16_000,
});
expect(store.restore({
currentRevisionId: "revision-a",
schemaVersion: "dashboard.v1",
})).toEqual([
{
ageMs: 15_000,
response: {
state: "ready",
tile: { kind: "telemetry", id: "infra-ram" },
item: {
id: "infra-ram",
label: "Infra RAM",
value: { kind: "percent", value: 42 },
detail: "live - stale 15s",
severity: "stale",
},
},
},
]);
});
}); });
async function waitFor(predicate: () => boolean) { async function waitFor(predicate: () => boolean) {

View file

@ -617,7 +617,9 @@ export function createDashboardTileSnapshotStore(
return { return {
currentRevisionId: payload.currentRevisionId, currentRevisionId: payload.currentRevisionId,
schemaVersion: payload.schemaVersion, schemaVersion: payload.schemaVersion,
tiles: payload.tiles.filter(isDashboardTileSnapshotRecord), tiles: payload.tiles
.filter(isDashboardTileSnapshotRecord)
.filter((record) => isPersistableDashboardTileSnapshot(record.tile)),
version: 1, version: 1,
}; };
} catch { } catch {
@ -660,6 +662,8 @@ export function createDashboardTileSnapshotStore(
response: Extract<DashboardTileSnapshotResponse, { state: "ready" }>; response: Extract<DashboardTileSnapshotResponse, { state: "ready" }>;
}, },
): void { ): void {
if (!isPersistableDashboardTileSnapshot(input.response.tile)) return;
const payload = matchingPayload(input); const payload = matchingPayload(input);
const key = dashboardTileSnapshotKey(input.response.tile); const key = dashboardTileSnapshotKey(input.response.tile);
const nextRecord: DashboardTileSnapshotRecord = { const nextRecord: DashboardTileSnapshotRecord = {
@ -720,6 +724,14 @@ function dashboardTileSnapshotKey(tile: DashboardTileReference): string {
return JSON.stringify(tile); return JSON.stringify(tile);
} }
export function isPersistableDashboardTileSnapshot(
tile: DashboardTileReference,
): boolean {
if (tile.kind === "status" && tile.id === "system-status") return false;
if (tile.kind === "module" && tile.id === "runtime-health-summary") return false;
return true;
}
function isDashboardTileSnapshotRecord( function isDashboardTileSnapshotRecord(
value: unknown, value: unknown,
): value is DashboardTileSnapshotRecord { ): value is DashboardTileSnapshotRecord {