From daa7c0cdca3b724cfbb07da321d750dd35bdc2ab Mon Sep 17 00:00:00 2001 From: Dotta Date: Fri, 30 Oct 2026 23:00:01 -0500 Subject: [PATCH] test: measure evidence retry backoff from inspection time Freeze the two evidence retry fixtures and record the actual busy or failed directory inspection instant. Retain a controlled 50ms assertion lag and the full one-hour backoff requirement, expiry, reactivation, and idle checks. Co-Authored-By: Paperclip --- .../native-harness-backup-expiration.test.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/server/src/__tests__/native-harness-backup-expiration.test.ts b/server/src/__tests__/native-harness-backup-expiration.test.ts index 25827def7b5..272687f4881 100644 --- a/server/src/__tests__/native-harness-backup-expiration.test.ts +++ b/server/src/__tests__/native-harness-backup-expiration.test.ts @@ -1090,8 +1090,12 @@ describeEmbeddedPostgres("native harness backup expiration", () => { it("retries a busy evidence obligation and disarms after the session releases it", async () => { const session = await seedSession({ issueStatus: "in_progress" }); const archive = await seedArchive(session.root); let busy = true; - await startEvidence({ isSessionBusy: () => busy }); - const retryAt = coordinator!.nextWakeAt()!; expect(retryAt - Date.now()).toBeGreaterThanOrEqual(60 * 60_000); + vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] }); vi.setSystemTime(now); + let inspectedAt: number | undefined; + await startEvidence({ isSessionBusy: () => { inspectedAt = Date.now(); return busy; } }); + await vi.advanceTimersByTimeAsync(50); + const retryAt = coordinator!.nextWakeAt()!; expect(inspectedAt).toBeDefined(); + expect(retryAt - inspectedAt!).toBeGreaterThanOrEqual(60 * 60_000); await quiet(5000); busy = false; await vi.advanceTimersByTimeAsync(retryAt - Date.now()); await settled(); expect(await exists(archive)).toBe(false); await quiet(); @@ -1119,11 +1123,18 @@ describeEmbeddedPostgres("native harness backup expiration", () => { it("backs off a failed state-base inspection and lets publication reactivate it", async () => { const session = await seedSession({ issueStatus: "in_progress" }); const archive = await seedArchive(session.root), read = fs.readdir; + vi.useFakeTimers({ toFake: ["Date", "setTimeout", "clearTimeout"] }); vi.setSystemTime(now); + let inspectedAt: number | undefined; const denied = vi.spyOn(fs, "readdir").mockImplementation(async (...args) => { - if (args[0] === stateBase) throw Object.assign(new Error("state base unavailable"), { code: "EACCES" }); + if (args[0] === stateBase) { + inspectedAt = Date.now(); + throw Object.assign(new Error("state base unavailable"), { code: "EACCES" }); + } return read(...args); }); - await startEvidence(); expect(coordinator!.nextWakeAt()! - Date.now()).toBeGreaterThanOrEqual(60 * 60_000); + await startEvidence(); await vi.advanceTimersByTimeAsync(50); + expect(inspectedAt).toBeDefined(); + expect(coordinator!.nextWakeAt()! - inspectedAt!).toBeGreaterThanOrEqual(60 * 60_000); denied.mockRestore(); await quiet(5 * 60_000); expect(await exists(archive)).toBe(true); noteNativeRunnerEvidence(now.getTime() - 10 * DAY_MS); await settled(); expect(await exists(archive)).toBe(false); await quiet();