test(FN-4295): complete Step 2 — add 1.5x stale threshold coverage

Fusion-Task-Id: FN-4295
Fusion-Task-Lineage: e2a47487-33f5-4077-8031-c7bb14882121
This commit is contained in:
Fusion
2026-05-13 08:41:28 -07:00
committed by gsxdsm
parent 2437aae418
commit d93aeaa1c0

View File

@@ -292,6 +292,62 @@ describe("executeHeartbeat", () => {
expect(section).toContain("**stale**");
});
it.each([
{
name: "60-minute interval stays healthy at 45 minutes",
heartbeatIntervalMs: 60 * 60_000,
ageMinutes: 45,
shouldBeStale: false,
},
{
name: "60-minute interval is stale at 100 minutes",
heartbeatIntervalMs: 60 * 60_000,
ageMinutes: 100,
shouldBeStale: true,
},
{
name: "180-minute interval stays healthy at 240 minutes",
heartbeatIntervalMs: 180 * 60_000,
ageMinutes: 240,
shouldBeStale: false,
},
{
name: "180-minute interval is stale at 280 minutes",
heartbeatIntervalMs: 180 * 60_000,
ageMinutes: 280,
shouldBeStale: true,
},
])("buildReportsHealthSection applies 1.5× heartbeatIntervalMs stale threshold (FN-4295): $name", async ({
heartbeatIntervalMs,
ageMinutes,
shouldBeStale,
}) => {
const now = Date.now();
const store = createStoreWithAgentForExec();
vi.mocked(store.getCachedAgent).mockImplementation((id: string) => ({
id,
runtimeConfig: { heartbeatIntervalMs },
}) as unknown as Agent);
vi.mocked(store.getAgentsByReportsTo).mockResolvedValue([
{
id: "agent-threshold-check",
name: "Threshold Check",
state: "active",
taskId: "FN-4295",
lastHeartbeatAt: new Date(now - ageMinutes * 60_000).toISOString(),
updatedAt: new Date(now - ageMinutes * 60_000).toISOString(),
} as Agent,
]);
const monitor = new HeartbeatMonitor({ store, taskStore: mockTaskStore, rootDir: "/tmp" });
const section = await (monitor as any).buildReportsHealthSection("agent-001", store);
if (shouldBeStale) {
expect(section).toContain("**stale**");
} else {
expect(section).not.toContain("**stale**");
}
});
it("buildReportsHealthSection applies interval-specific stale thresholds in mixed report tables", async () => {
const now = Date.now();
const store = createStoreWithAgentForExec();