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 <noreply@paperclip.ing>
This commit is contained in:
Harold KimandPaperclip committed 2026-07-09 09:25:59 +00:00
1 parent e3c0e3d430
commit 0d3f2eebb7
1 file changed
+19 -2
@@ -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 });
}
});