Skip to content

Commit 1acc6b3

Browse files
committed
test(oauth): pin Antigravity expiry clock
1 parent f497c05 commit 1acc6b3

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

tests/google-antigravity-oauth.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, describe, expect, test } from "bun:test";
1+
import { afterEach, describe, expect, spyOn, test } from "bun:test";
22
import { discoverAntigravityProject, refreshAntigravityToken } from "../src/oauth/google-antigravity";
33
import { mkdirSync, rmSync } from "node:fs";
44
import { tmpdir } from "node:os";
@@ -84,15 +84,21 @@ describe("antigravity refresh", () => {
8484
if (url.includes(":loadCodeAssist")) return new Response(JSON.stringify({ cloudaicompanionProject: "proj-R" }), { status: 200 });
8585
return new Response("no", { status: 404 });
8686
});
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+
})();
8996
expect(cred.access).toBe("fresh-access");
9097
expect(cred.refresh).toBe("refresh-tok");
9198
expect(cred.projectId).toBe("proj-R");
9299
// A one-hour Google token must retain roughly 55 minutes after the provider margin. The
93100
// 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);
96102
});
97103

98104
test("refresh failure carries status only, not the response body", async () => {

0 commit comments

Comments
 (0)