@@ -70,6 +70,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( |
70 | 70 | userId?: string; |
71 | 71 | userInfoAt?: number; |
72 | 72 | missingToken?: boolean; |
| 73 | + cliToken?: string; |
73 | 74 | authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key"; |
74 | 75 | keyringSecret?: string; |
75 | 76 | /** Reads the OS keyring instead of `keyringSecret`. */ |
@@ -92,6 +93,12 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( |
92 | 93 | }), |
93 | 94 | ); |
94 | 95 | if (!options.missingToken) yield* writeToken(options.refreshToken ?? "refresh-a"); |
| 96 | + if (options.cliToken !== undefined) { |
| 97 | + yield* fs.writeFileString( |
| 98 | + path.join(profileDirectory, "antigravity-acp", "antigravity-oauth-token"), |
| 99 | + options.cliToken, |
| 100 | + ); |
| 101 | + } |
95 | 102 | const requests: Array<{ url: string; body: string }> = []; |
96 | 103 | const http = HttpClient.make((request, url, _signal, fiber) => |
97 | 104 | Effect.sync(() => { |
@@ -119,7 +126,9 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( |
119 | 126 | : Response.json({}, { status: 403 }), |
120 | 127 | ); |
121 | 128 | } |
122 | | - expect(JSON.parse(body)).toEqual(options.missingToken ? {} : { project: "project-id" }); |
| 129 | + expect(JSON.parse(body)).toEqual( |
| 130 | + options.missingToken || options.cliToken !== undefined ? {} : { project: "project-id" }, |
| 131 | + ); |
123 | 132 | expect(request.headers["user-agent"]).toMatch(/^antigravity\/hub\/2\.24\.0 /); |
124 | 133 | return HttpClientResponse.fromWeb( |
125 | 134 | request, |
@@ -663,31 +672,29 @@ describe("Antigravity subscription limits", () => { |
663 | 672 | }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), |
664 | 673 | ); |
665 | 674 |
|
666 | | - it.effect("reads the native CLI's stored sign-in when acp_token.json is absent", () => |
| 675 | + it.effect("prefers the native CLI's stored sign-in over a leftover legacy token", () => |
667 | 676 | Effect.gen(function* () { |
668 | | - const fs = yield* FileSystem.FileSystem; |
669 | | - const path = yield* Path.Path; |
670 | | - const { probe, tokenPath } = yield* fixture({ missingToken: true }); |
671 | | - // The 1.5.x CLI never writes acp_token.json; without a keyring it stores this file instead. |
672 | | - yield* fs.writeFileString( |
673 | | - path.join(path.dirname(tokenPath), "antigravity-oauth-token"), |
674 | | - JSON.stringify({ |
675 | | - token: { |
676 | | - access_token: "access-token", |
677 | | - token_type: "Bearer", |
678 | | - refresh_token: "refresh-a", |
679 | | - expiry: "2099-01-01T00:00:00Z", |
680 | | - expires_in: 3600, |
681 | | - }, |
682 | | - auth_method: "consumer", |
683 | | - |
684 | | - }), |
685 | | - ); |
686 | | - const limits = yield* probe; |
687 | | - expect(limits.unavailable?.message).not.toBe( |
688 | | - "Sign in with Google to see Antigravity limits.", |
689 | | - ); |
690 | | - expect(limits.unavailable?.reason).not.toBe("unsupported"); |
| 677 | + for (const missingToken of [true, false]) { |
| 678 | + const { probe, requests } = yield* fixture({ |
| 679 | + missingToken, |
| 680 | + tokenStatus: 401, |
| 681 | + cliToken: JSON.stringify({ |
| 682 | + token: { |
| 683 | + access_token: "access-token", |
| 684 | + token_type: "Bearer", |
| 685 | + refresh_token: "refresh-a", |
| 686 | + expiry: "2099-01-01T00:00:00Z", |
| 687 | + expires_in: 3600, |
| 688 | + }, |
| 689 | + auth_method: "consumer", |
| 690 | + |
| 691 | + }), |
| 692 | + }); |
| 693 | + const limits = yield* probe; |
| 694 | + expect(limits.unavailable).toBeUndefined(); |
| 695 | + expect(limits.windows).toHaveLength(4); |
| 696 | + expect(requests.some((request) => request.url.endsWith("/token"))).toBe(false); |
| 697 | + } |
691 | 698 | }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), |
692 | 699 | ); |
693 | 700 |
|
@@ -724,6 +731,12 @@ describe("Antigravity subscription limits", () => { |
724 | 731 | }); |
725 | 732 | expect((yield* expired.probe).unavailable?.reason).toBe("probeFailed"); |
726 | 733 | expect(expired.requests).toEqual([]); |
| 734 | + |
| 735 | + const expiredFile = yield* fixture({ |
| 736 | + cliToken: keyringSecret("2026-10-09T12:00:30Z"), |
| 737 | + }); |
| 738 | + expect((yield* expiredFile.probe).unavailable?.reason).toBe("probeFailed"); |
| 739 | + expect(expiredFile.requests).toEqual([]); |
727 | 740 | }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), |
728 | 741 | ); |
729 | 742 |
|
|