test: tighten copilot token cache assertion

This commit is contained in:
Shakker
2026-05-11 02:03:28 +01:00
parent c8d52e36d5
commit 2255140113

View File

@@ -77,6 +77,8 @@ describe("resolveCopilotApiToken", () => {
}); });
it("refreshes legacy cached tokens without the vscode-chat integration identity", async () => { 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 () => ({ const fetchImpl = vi.fn(async () => ({
ok: true, ok: true,
json: async () => ({ json: async () => ({
@@ -86,25 +88,29 @@ describe("resolveCopilotApiToken", () => {
})); }));
const saveJsonFileImpl = vi.fn(); const saveJsonFileImpl = vi.fn();
const result = await resolveCopilotApiToken({ try {
githubToken: "github-token", const result = await resolveCopilotApiToken({
cachePath: "/tmp/github-copilot-token-test.json", githubToken: "github-token",
loadJsonFileImpl: () => ({ cachePath: "/tmp/github-copilot-token-test.json",
token: "legacy-copilot-token", loadJsonFileImpl: () => ({
expiresAt: Date.now() + 60 * 60 * 1000, token: "legacy-copilot-token",
updatedAt: Date.now(), expiresAt: Date.now() + 60 * 60 * 1000,
}), updatedAt: Date.now(),
saveJsonFileImpl, }),
fetchImpl: fetchImpl as unknown as typeof fetch, saveJsonFileImpl,
}); fetchImpl: fetchImpl as unknown as typeof fetch,
});
expect(result.token).toBe("fresh-copilot-token"); expect(result.token).toBe("fresh-copilot-token");
expect(fetchImpl).toHaveBeenCalledTimes(1); expect(fetchImpl).toHaveBeenCalledTimes(1);
expect(saveJsonFileImpl).toHaveBeenCalledWith("/tmp/github-copilot-token-test.json", { expect(saveJsonFileImpl).toHaveBeenCalledWith("/tmp/github-copilot-token-test.json", {
token: "fresh-copilot-token", token: "fresh-copilot-token",
expiresAt: expect.any(Number), expiresAt: 1_767_326_645_000,
updatedAt: expect.any(Number), updatedAt: 1_767_323_045_000,
integrationId: COPILOT_INTEGRATION_ID, integrationId: COPILOT_INTEGRATION_ID,
}); });
} finally {
vi.useRealTimers();
}
}); });
}); });