From 0d3f2eebb737aa9a034dfd9d055e025aa9c05a63 Mon Sep 17 00:00:00 2001 From: Harold Kim Date: Thu, 9 Jul 2026 09:25:59 +0000 Subject: [PATCH] fix(codex): isolate fake timers to Date only in refresh-token test - Change vi.useFakeTimers() to vi.useFakeTimers({ toFake: ["Date"] }) for both the quota-failure and refresh-token-auth tests so process timers remain real and execute() does not deadlock waiting for fake setTimeout - Isolate PAPERCLIP_HOME, PAPERCLIP_INSTANCE_ID, PAPERCLIP_IN_WORKTREE, CODEX_HOME env vars in the refresh-token test to prevent the agent runner's ambient Codex home from leaking into the fixture snapshot read - Add refresh_token field to the outer auth.json fixture so the snapshot reader finds last_refresh and classifies the age bucket correctly Co-Authored-By: Paperclip --- .../src/__tests__/codex-local-execute.test.ts | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/server/src/__tests__/codex-local-execute.test.ts b/server/src/__tests__/codex-local-execute.test.ts index 99a8687e8d1..474fd8d7250 100644 --- a/server/src/__tests__/codex-local-execute.test.ts +++ b/server/src/__tests__/codex-local-execute.test.ts @@ -588,7 +588,7 @@ describe("codex execute", () => { const previousHome = process.env.HOME; process.env.HOME = root; await seedSharedCodexAuth(root); - vi.useFakeTimers(); + vi.useFakeTimers({ toFake: ["Date"] }); vi.setSystemTime(new Date(2026, 3, 22, 22, 29, 0)); try { @@ -652,6 +652,7 @@ describe("codex execute", () => { await fs.writeFile( path.join(sharedCodexHome, "auth.json"), JSON.stringify({ + refresh_token: "refresh-token-fixture-secret", tokens: { access_token: "access-token-fixture-secret", refresh_token: "refresh-token-fixture-secret", @@ -664,8 +665,16 @@ describe("codex execute", () => { ); const previousHome = process.env.HOME; + const previousPaperclipHome = process.env.PAPERCLIP_HOME; + const previousPaperclipInstanceId = process.env.PAPERCLIP_INSTANCE_ID; + const previousPaperclipInWorktree = process.env.PAPERCLIP_IN_WORKTREE; + const previousCodexHome = process.env.CODEX_HOME; process.env.HOME = root; - vi.useFakeTimers(); + process.env.PAPERCLIP_HOME = path.join(root, "paperclip-home"); + delete process.env.PAPERCLIP_INSTANCE_ID; + delete process.env.PAPERCLIP_IN_WORKTREE; + process.env.CODEX_HOME = sharedCodexHome; + vi.useFakeTimers({ toFake: ["Date"] }); vi.setSystemTime(new Date("2026-07-09T12:00:00.000Z")); try { @@ -716,6 +725,14 @@ describe("codex execute", () => { vi.useRealTimers(); if (previousHome === undefined) delete process.env.HOME; else process.env.HOME = previousHome; + if (previousPaperclipHome === undefined) delete process.env.PAPERCLIP_HOME; + else process.env.PAPERCLIP_HOME = previousPaperclipHome; + if (previousPaperclipInstanceId === undefined) delete process.env.PAPERCLIP_INSTANCE_ID; + else process.env.PAPERCLIP_INSTANCE_ID = previousPaperclipInstanceId; + if (previousPaperclipInWorktree === undefined) delete process.env.PAPERCLIP_IN_WORKTREE; + else process.env.PAPERCLIP_IN_WORKTREE = previousPaperclipInWorktree; + if (previousCodexHome === undefined) delete process.env.CODEX_HOME; + else process.env.CODEX_HOME = previousCodexHome; await fs.rm(root, { recursive: true, force: true }); } });