From e2930422d0b0fb3f31559385f4da9f36c8b30969 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 19 Jul 2026 03:26:50 -0700 Subject: [PATCH] fix(ci): make pr-ci-sweeper clock injectable so lookback fixtures cannot rot --- scripts/github/pr-ci-sweeper.mjs | 12 ++++++++++-- test/scripts/pr-ci-sweeper.test.ts | 2 ++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/github/pr-ci-sweeper.mjs b/scripts/github/pr-ci-sweeper.mjs index 4c414a28002f..94515d979542 100644 --- a/scripts/github/pr-ci-sweeper.mjs +++ b/scripts/github/pr-ci-sweeper.mjs @@ -131,13 +131,21 @@ async function reopenWithRetry({ github, core, owner, repo, pullNumber }) { return false; } -export async function runPrCiSweeper({ github, context, core, dryRun = false, appSlug = "" }) { +export async function runPrCiSweeper({ + github, + context, + core, + dryRun = false, + appSlug = "", + // Injectable clock: fixture-based tests pin a fixed instant so lookback + // classification cannot rot as wall-clock time passes the fixture dates. + now = Date.now(), +}) { const sweeperLogins = new Set(KNOWN_SWEEPER_LOGINS); if (appSlug) { sweeperLogins.add(`${appSlug}[bot]`); } const { owner, repo } = context.repo; - const now = Date.now(); const results = []; let refires = 0; const openPrs = await github.paginate(github.rest.pulls.list, { diff --git a/test/scripts/pr-ci-sweeper.test.ts b/test/scripts/pr-ci-sweeper.test.ts index 777b8fe4d76d..b160c7fe69c7 100644 --- a/test/scripts/pr-ci-sweeper.test.ts +++ b/test/scripts/pr-ci-sweeper.test.ts @@ -210,6 +210,7 @@ describe("runPrCiSweeper", () => { core: core as never, dryRun: true, appSlug: "openclaw-barnacle", + now: NOW, }); expect(results).toEqual([ { number: 7, sha: "a".repeat(12), action: "refire", reason: "ci-startup-failure" }, @@ -230,6 +231,7 @@ describe("runPrCiSweeper", () => { context: context as never, core: core as never, appSlug: "openclaw-barnacle", + now: NOW, }); expect(results).toEqual([ { number: 9, sha: "c".repeat(12), action: "refire", reason: "ci-run-missing" },