From 225514011366f568a91fa31166d73d9d51ba1326 Mon Sep 17 00:00:00 2001 From: Shakker Date: Mon, 11 May 2026 02:03:28 +0100 Subject: [PATCH] test: tighten copilot token cache assertion --- src/agents/github-copilot-token.test.ts | 44 ++++++++++++++----------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/src/agents/github-copilot-token.test.ts b/src/agents/github-copilot-token.test.ts index 7d50685f98b..01c5e003562 100644 --- a/src/agents/github-copilot-token.test.ts +++ b/src/agents/github-copilot-token.test.ts @@ -77,6 +77,8 @@ describe("resolveCopilotApiToken", () => { }); it("refreshes legacy cached tokens without the vscode-chat integration identity", async () => { + vi.useFakeTimers(); + vi.setSystemTime(new Date("2026-01-02T03:04:05.000Z")); const fetchImpl = vi.fn(async () => ({ ok: true, json: async () => ({ @@ -86,25 +88,29 @@ describe("resolveCopilotApiToken", () => { })); const saveJsonFileImpl = vi.fn(); - const result = await resolveCopilotApiToken({ - githubToken: "github-token", - cachePath: "/tmp/github-copilot-token-test.json", - loadJsonFileImpl: () => ({ - token: "legacy-copilot-token", - expiresAt: Date.now() + 60 * 60 * 1000, - updatedAt: Date.now(), - }), - saveJsonFileImpl, - fetchImpl: fetchImpl as unknown as typeof fetch, - }); + try { + const result = await resolveCopilotApiToken({ + githubToken: "github-token", + cachePath: "/tmp/github-copilot-token-test.json", + loadJsonFileImpl: () => ({ + token: "legacy-copilot-token", + expiresAt: Date.now() + 60 * 60 * 1000, + updatedAt: Date.now(), + }), + saveJsonFileImpl, + fetchImpl: fetchImpl as unknown as typeof fetch, + }); - expect(result.token).toBe("fresh-copilot-token"); - expect(fetchImpl).toHaveBeenCalledTimes(1); - expect(saveJsonFileImpl).toHaveBeenCalledWith("/tmp/github-copilot-token-test.json", { - token: "fresh-copilot-token", - expiresAt: expect.any(Number), - updatedAt: expect.any(Number), - integrationId: COPILOT_INTEGRATION_ID, - }); + expect(result.token).toBe("fresh-copilot-token"); + expect(fetchImpl).toHaveBeenCalledTimes(1); + expect(saveJsonFileImpl).toHaveBeenCalledWith("/tmp/github-copilot-token-test.json", { + token: "fresh-copilot-token", + expiresAt: 1_767_326_645_000, + updatedAt: 1_767_323_045_000, + integrationId: COPILOT_INTEGRATION_ID, + }); + } finally { + vi.useRealTimers(); + } }); });