|
1 | | -import { afterEach, describe, expect, test } from "bun:test"; |
| 1 | +import { afterEach, describe, expect, spyOn, test } from "bun:test"; |
2 | 2 | import { discoverAntigravityProject, refreshAntigravityToken } from "../src/oauth/google-antigravity"; |
3 | 3 | import { mkdirSync, rmSync } from "node:fs"; |
4 | 4 | import { tmpdir } from "node:os"; |
@@ -84,15 +84,21 @@ describe("antigravity refresh", () => { |
84 | 84 | if (url.includes(":loadCodeAssist")) return new Response(JSON.stringify({ cloudaicompanionProject: "proj-R" }), { status: 200 }); |
85 | 85 | return new Response("no", { status: 404 }); |
86 | 86 | }); |
87 | | - const issuedAt = Date.now(); |
88 | | - const cred = await refreshAntigravityToken("refresh-tok"); |
| 87 | + const issuedAt = 1_900_000_000_000; |
| 88 | + const nowSpy = spyOn(Date, "now").mockReturnValue(issuedAt); |
| 89 | + const cred = await (async () => { |
| 90 | + try { |
| 91 | + return await refreshAntigravityToken("refresh-tok"); |
| 92 | + } finally { |
| 93 | + nowSpy.mockRestore(); |
| 94 | + } |
| 95 | + })(); |
89 | 96 | expect(cred.access).toBe("fresh-access"); |
90 | 97 | expect(cred.refresh).toBe("refresh-tok"); |
91 | 98 | expect(cred.projectId).toBe("proj-R"); |
92 | 99 | // A one-hour Google token must retain roughly 55 minutes after the provider margin. The |
93 | 100 | // previous 50-minute margin stored only ten minutes and caused repeated refreshes in use. |
94 | | - expect(cred.expires - issuedAt).toBeGreaterThanOrEqual(54 * 60 * 1000); |
95 | | - expect(cred.expires - issuedAt).toBeLessThanOrEqual(60 * 60 * 1000); |
| 101 | + expect(cred.expires - issuedAt).toBe(55 * 60 * 1000); |
96 | 102 | }); |
97 | 103 |
|
98 | 104 | test("refresh failure carries status only, not the response body", async () => { |
|
0 commit comments