From 7ed19ae63511163fca8d7ecc9cf0ea7495dff4ca Mon Sep 17 00:00:00 2001 From: pelikhan Date: Wed, 4 Nov 2026 11:27:08 -0800 Subject: [PATCH] test: make checkpoint-history abort deadline deterministic Replace the 1 ms real-time timeout with Vitest fake timers and the default one-second budget. Assert lookup starts, remains un-aborted at 999 ms, and aborts exactly once at 1000 ms, restoring real timers in finally. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../setup/js/finish_work_queue_claim.test.cjs | 47 ++++++++++++------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/actions/setup/js/finish_work_queue_claim.test.cjs b/actions/setup/js/finish_work_queue_claim.test.cjs index 56f1f990bd7..4f6da8ed5bc 100644 --- a/actions/setup/js/finish_work_queue_claim.test.cjs +++ b/actions/setup/js/finish_work_queue_claim.test.cjs @@ -139,31 +139,44 @@ describe("independent trusted Claim finalization", () => { }); it("aborts checkpoint-history lookup at its one-second deadline", async () => { - const controller = vi.fn(); - const client = { - rest: { - git: { - getCommit: vi.fn(({ request }) => { - request.signal.addEventListener("abort", controller, { once: true }); - return new Promise(() => {}); - }), + vi.useFakeTimers(); + try { + const controller = vi.fn(); + const client = { + rest: { + git: { + getCommit: vi.fn(({ request }) => { + request.signal.addEventListener("abort", controller, { once: true }); + return new Promise(() => {}); + }), + }, }, - }, - }; - const latest = { sha: "c".repeat(40), eventLocations: { checkpoint_prior_git_sha: "b".repeat(40) } }; + }; + const latest = { sha: "c".repeat(40), eventLocations: { checkpoint_prior_git_sha: "b".repeat(40) } }; - await expect( - workQueueStore.resolveWorkQueueEventLocations({ + const lookup = workQueueStore.resolveWorkQueueEventLocations({ githubClient: client, owner: "owner", repo: "repo", latest, work_id: "work-1", claim_id: "claim-1", - timeoutMs: 1, - }) - ).resolves.toBeUndefined(); - expect(controller).toHaveBeenCalledTimes(1); + }); + expect(client.rest.git.getCommit).toHaveBeenCalledTimes(1); + const { signal } = client.rest.git.getCommit.mock.calls[0][0].request; + expect(signal.aborted).toBe(false); + + await vi.advanceTimersByTimeAsync(999); + expect(controller).not.toHaveBeenCalled(); + expect(signal.aborted).toBe(false); + + await vi.advanceTimersByTimeAsync(1); + await expect(lookup).resolves.toBeUndefined(); + expect(controller).toHaveBeenCalledTimes(1); + expect(signal.aborted).toBe(true); + } finally { + vi.useRealTimers(); + } }); it("reuses only repository-scoped footer links from the reconciliation output after trusted authorization", async () => {