Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 53 additions & 32 deletions apps/server/src/provider/antigravityUsageLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")(
Expand Down
12 changes: 8 additions & 4 deletions apps/server/src/provider/antigravityUsageLimits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading