Repository navigation
fix(server): Antigravity limits read the 1.5.x CLI's stored sign-in #38957
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
73c8841
af001ab
1e33c2b
5af91cc
cb6cd65
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import * as NodeCrypto from "@effect/platform-node/NodeCrypto"; | ||
| import * as NodeServices from "@effect/platform-node/NodeServices"; | ||
| import * as HostProcess from "@t3tools/shared/HostProcess"; | ||
| import * as Layer from "effect/Layer"; | ||
| import { describe, expect, it } from "@effect/vitest"; | ||
| import * as Context from "effect/Context"; | ||
|
|
@@ -10,7 +11,11 @@ import * as Path from "effect/Path"; | |
| import * as TestClock from "effect/testing/TestClock"; | ||
| import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http"; | ||
|
|
||
| import { makeAntigravityUsageProbe } from "./antigravityUsageLimits.ts"; | ||
| import { | ||
| decodeGoKeyringSecret, | ||
| makeAntigravityUsageProbe, | ||
| readWindowsCliCredential, | ||
| } from "./antigravityUsageLimits.ts"; | ||
|
|
||
| const summary = { | ||
| groups: [ | ||
|
|
@@ -66,6 +71,9 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( | |
| userInfoAt?: number; | ||
| missingToken?: boolean; | ||
| authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key"; | ||
| keyringSecret?: string; | ||
| /** Reads the OS keyring instead of `keyringSecret`. */ | ||
| nativeKeyring?: boolean; | ||
| } = {}, | ||
| ) { | ||
| const fs = yield* FileSystem.FileSystem; | ||
|
|
@@ -111,7 +119,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( | |
| : Response.json({}, { status: 403 }), | ||
| ); | ||
| } | ||
| expect(JSON.parse(body)).toEqual({ project: "project-id" }); | ||
| expect(JSON.parse(body)).toEqual(options.missingToken ? {} : { project: "project-id" }); | ||
| expect(request.headers["user-agent"]).toMatch(/^antigravity\/hub\/2\.24\.0 /); | ||
| return HttpClientResponse.fromWeb( | ||
| request, | ||
|
|
@@ -132,6 +140,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* ( | |
| const usage = yield* makeAntigravityUsageProbe({ | ||
| profileDirectory, | ||
| authMethod: options.authMethod ?? "oauth-personal", | ||
| ...(options.nativeKeyring ? {} : { readKeyringSecret: Effect.succeed(options.keyringSecret) }), | ||
| }).pipe(Effect.provideService(HttpClient.HttpClient, http)); | ||
| return { ...usage, requests, writeToken, tokenPath }; | ||
| }); | ||
|
|
@@ -654,6 +663,101 @@ describe("Antigravity subscription limits", () => { | |
| }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), | ||
| ); | ||
|
|
||
| it.effect("reads the native CLI's stored sign-in when acp_token.json is absent", () => | ||
| Effect.gen(function* () { | ||
| const fs = yield* FileSystem.FileSystem; | ||
| const path = yield* Path.Path; | ||
| const { probe, tokenPath } = yield* fixture({ missingToken: true }); | ||
| // The 1.5.x CLI never writes acp_token.json; without a keyring it stores this file instead. | ||
| yield* fs.writeFileString( | ||
| path.join(path.dirname(tokenPath), "antigravity-oauth-token"), | ||
| JSON.stringify({ | ||
| token: { | ||
| access_token: "access-token", | ||
| token_type: "Bearer", | ||
| refresh_token: "refresh-a", | ||
| expiry: "2099-01-01T00:00:00Z", | ||
| expires_in: 3600, | ||
| }, | ||
| auth_method: "consumer", | ||
| id_token_email: "someone@example.com", | ||
| }), | ||
| ); | ||
| const limits = yield* probe; | ||
| expect(limits.unavailable?.message).not.toBe( | ||
| "Sign in with Google to see Antigravity limits.", | ||
| ); | ||
| expect(limits.unavailable?.reason).not.toBe("unsupported"); | ||
| }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), | ||
| ); | ||
|
|
||
| it.effect("reads the native CLI's keyring sign-in and reports when it has expired", () => | ||
| Effect.gen(function* () { | ||
| yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-09T12:00:00Z"))); | ||
| const keyringSecret = (expiry: string) => | ||
| JSON.stringify({ token: { access_token: "access-token", refresh_token: "r", expiry } }); | ||
| const signedIn = yield* fixture({ | ||
| missingToken: true, | ||
| userId: "google-user-1", | ||
| keyringSecret: keyringSecret("2026-10-09T14:00:00.123456789+01:00"), | ||
| }); | ||
| const limits = yield* signedIn.probe; | ||
| expect(limits.unavailable).toBeUndefined(); | ||
| expect(limits.windows).toHaveLength(4); | ||
| expect(signedIn.requests.some((request) => request.url.endsWith("/token"))).toBe(false); | ||
|
|
||
| const expired = yield* fixture({ | ||
| missingToken: true, | ||
| keyringSecret: keyringSecret("2026-10-09T12:00:30Z"), | ||
| }); | ||
| expect((yield* expired.probe).unavailable?.reason).toBe("probeFailed"); | ||
| expect(expired.requests).toEqual([]); | ||
| }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), | ||
| ); | ||
|
|
||
| it.effect.runIf(HostProcess.Platform.defaultValue() === "win32")( | ||
| "reads go-keyring's Windows credential target without changing it", | ||
| (ctx) => | ||
| Effect.gen(function* () { | ||
| // Never overwrite a real sign-in on a developer's machine. | ||
| if (readWindowsCliCredential(HostProcess.Architecture.defaultValue())) return ctx.skip(); | ||
| yield* TestClock.setTime( | ||
| DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-09T12:00:00Z")), | ||
| ); | ||
| const { AsyncEntry } = yield* Effect.promise(() => import("@napi-rs/keyring")); | ||
| // go-keyring writes the UTF-8 JSON at `<service>:<user>`. | ||
| const target = AsyncEntry.withTarget("gemini:antigravity", "gemini", "antigravity"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Register cleanup before creating the Windows credential.
Register conditional cleanup before
|
||
| const stored = new TextEncoder().encode( | ||
| JSON.stringify({ | ||
| token: { access_token: "access-token", expiry: "2026-10-09T14:00:00Z" }, | ||
| }), | ||
| ); | ||
| yield* Effect.acquireRelease( | ||
| Effect.promise(() => target.setSecret(stored)), | ||
| () => Effect.promise(() => target.deleteCredential()), | ||
| ); | ||
| const { probe } = yield* fixture({ missingToken: true, nativeKeyring: true }); | ||
| const limits = yield* probe; | ||
| expect(limits.unavailable).toBeUndefined(); | ||
| expect(limits.windows).toHaveLength(4); | ||
| expect(readWindowsCliCredential(HostProcess.Architecture.defaultValue())).toEqual( | ||
| Buffer.from(stored), | ||
| ); | ||
| }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), | ||
| ); | ||
|
|
||
| it("decodes go-keyring's macOS encodings", () => { | ||
| const value = '{"token":{}}'; | ||
| const bytes = (text: string) => new TextEncoder().encode(text); | ||
| expect(decodeGoKeyringSecret(bytes(value))).toBe(value); | ||
| expect( | ||
| decodeGoKeyringSecret(bytes(`go-keyring-base64:${Buffer.from(value).toString("base64")}`)), | ||
| ).toBe(value); | ||
| expect( | ||
| decodeGoKeyringSecret(bytes(`go-keyring-encoded:${Buffer.from(value).toString("hex")}`)), | ||
| ).toBe(value); | ||
| }); | ||
|
|
||
| it.effect("does not make network requests for API keys or missing sign-ins", () => | ||
| Effect.gen(function* () { | ||
| for (const options of [{ authMethod: "gemini-api-key" as const }, { missingToken: true }]) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assert successful quota retrieval in the CLI-file test.
These assertions also accept
probeFailedwith the generic retry message. A regression that rejects every CLI token file would therefore pass this test.Assert that
limits.unavailableis undefined and that the expected quota windows are present. As per coding guidelines, “Test behavior that can break.”Source: Coding guidelines