diff --git a/apps/server/src/provider/antigravityUsageLimits.test.ts b/apps/server/src/provider/antigravityUsageLimits.test.ts index eec70e2e44fce..9fc4ebe145160 100644 --- a/apps/server/src/provider/antigravityUsageLimits.test.ts +++ b/apps/server/src/provider/antigravityUsageLimits.test.ts @@ -691,40 +691,61 @@ describe("Antigravity subscription limits", () => { }).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))), ); - it.effect("reads a Gemini Enterprise 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 } }); - // Google account instances keep their own sign-in; the shared entry belongs to another app. - const personal = yield* fixture({ - missingToken: true, - keyringSecret: keyringSecret("2026-10-09T14:00:00Z"), - }); - expect((yield* personal.probe).unavailable?.message).toBe( - "Sign in with Google to see Antigravity limits.", - ); - expect(personal.requests).toEqual([]); + it.effect( + "reads a keyring sign-in when the profile file is absent 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({ - authMethod: "oauth-business", - 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); + // Google account instances fall back to the OS keyring when no profile file exists, + // matching the 1.5 CLI's ChainedAuth behavior. + const personal = yield* fixture({ + missingToken: true, + userId: "google-user-personal", + keyringSecret: keyringSecret("2026-10-09T14:00:00Z"), + }); + const personalLimits = yield* personal.probe; + expect(personalLimits.unavailable).toBeUndefined(); + expect(personalLimits.windows).toHaveLength(4); + expect(personal.requests.some((request) => request.url.endsWith("/token"))).toBe(false); - const expired = yield* fixture({ - authMethod: "oauth-business", - 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))), + // A profile token file still takes precedence over the shared keyring entry. + const fs = yield* FileSystem.FileSystem; + const path = yield* Path.Path; + const isolated = yield* fixture({ + missingToken: true, + keyringSecret: keyringSecret("2026-10-09T14:00:00Z"), + }); + yield* fs.writeFileString( + path.join(path.dirname(isolated.tokenPath), "antigravity-oauth-token"), + keyringSecret("2026-10-09T12:00:30Z"), + ); + expect((yield* isolated.probe).unavailable?.reason).toBe("probeFailed"); + expect(isolated.requests).toEqual([]); + + const signedIn = yield* fixture({ + authMethod: "oauth-business", + 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({ + authMethod: "oauth-business", + 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")( diff --git a/apps/server/src/provider/antigravityUsageLimits.ts b/apps/server/src/provider/antigravityUsageLimits.ts index fadf2207c31f2..da1a71503137d 100644 --- a/apps/server/src/provider/antigravityUsageLimits.ts +++ b/apps/server/src/provider/antigravityUsageLimits.ts @@ -359,12 +359,16 @@ export const makeAntigravityUsageProbe = Effect.fn("makeAntigravityUsageProbe")( let projectId: string | undefined; if (!(yield* fs.exists(tokenPath))) { cached = undefined; - // Google account instances bypass the keyring, whose one entry every profile shares. + // The 1.5 CLI's ChainedAuth still falls back to the OS keyring when the profile has no + // file token, even with SSH_CONNECTION set; keep the profile file first when present. const stored = (yield* fs.exists(cliTokenPath)) ? yield* fs.readFileString(cliTokenPath) - : input.authMethod === "oauth-business" - ? yield* readKeyringSecret - : undefined; + : yield* readKeyringSecret.pipe( + Effect.catchTags({ + AntigravityKeyringError: (error) => + input.authMethod === "oauth-personal" ? Effect.undefined : Effect.fail(error), + }), + ); if (stored === undefined) { return makeUnavailableUsageLimits({ checkedAt,