GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): Antigravity limits read the 1.5.x CLI's stored sign-in (… · HNRow/r3code@5283f33

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/provider
    • antigravityUsageLimits.test.ts
    • antigravityUsageLimits.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/provider/antigravityUsageLimits.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/provider/antigravityUsageLimits.test.ts
+106-2Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as NodeCrypto from "@effect/platform-node/NodeCrypto";
22
import * as NodeServices from "@effect/platform-node/NodeServices";
3+
import * as HostProcess from "@t3tools/shared/HostProcess";
34
import * as Layer from "effect/Layer";
45
import { describe, expect, it } from "@effect/vitest";
56
import * as Context from "effect/Context";
@@ -10,7 +11,11 @@ import * as Path from "effect/Path";
1011
import * as TestClock from "effect/testing/TestClock";
1112
import { FetchHttpClient, HttpClient, HttpClientResponse } from "effect/http";
1213

13-
import { makeAntigravityUsageProbe } from "./antigravityUsageLimits.ts";
14+
import {
15+
decodeGoKeyringSecret,
16+
makeAntigravityUsageProbe,
17+
readWindowsCliCredential,
18+
} from "./antigravityUsageLimits.ts";
1419

1520
const summary = {
1621
groups: [
@@ -66,6 +71,9 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
6671
userInfoAt?: number;
6772
missingToken?: boolean;
6873
authMethod?: "oauth-personal" | "oauth-business" | "gemini-api-key";
74+
keyringSecret?: string;
75+
/** Reads the OS keyring instead of `keyringSecret`. */
76+
nativeKeyring?: boolean;
6977
} = {},
7078
) {
7179
const fs = yield* FileSystem.FileSystem;
@@ -111,7 +119,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
111119
: Response.json({}, { status: 403 }),
112120
);
113121
}
114-
expect(JSON.parse(body)).toEqual({ project: "project-id" });
122+
expect(JSON.parse(body)).toEqual(options.missingToken ? {} : { project: "project-id" });
115123
expect(request.headers["user-agent"]).toMatch(/^antigravity\/hub\/2\.24\.0 /);
116124
return HttpClientResponse.fromWeb(
117125
request,
@@ -132,6 +140,7 @@ const fixture = Effect.fn("AntigravityUsageTest.fixture")(function* (
132140
const usage = yield* makeAntigravityUsageProbe({
133141
profileDirectory,
134142
authMethod: options.authMethod ?? "oauth-personal",
143+
...(options.nativeKeyring ? {} : { readKeyringSecret: Effect.succeed(options.keyringSecret) }),
135144
}).pipe(Effect.provideService(HttpClient.HttpClient, http));
136145
return { ...usage, requests, writeToken, tokenPath };
137146
});
@@ -654,6 +663,101 @@ describe("Antigravity subscription limits", () => {
654663
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
655664
);
656665

666+
it.effect("reads the native CLI's stored sign-in when acp_token.json is absent", () =>
667+
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+
id_token_email: "[email protected]",
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");
691+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
692+
);
693+
694+
it.effect("reads the native CLI's keyring sign-in and reports when it has expired", () =>
695+
Effect.gen(function* () {
696+
yield* TestClock.setTime(DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-09T12:00:00Z")));
697+
const keyringSecret = (expiry: string) =>
698+
JSON.stringify({ token: { access_token: "access-token", refresh_token: "r", expiry } });
699+
const signedIn = yield* fixture({
700+
missingToken: true,
701+
userId: "google-user-1",
702+
keyringSecret: keyringSecret("2026-10-09T14:00:00.123456789+01:00"),
703+
});
704+
const limits = yield* signedIn.probe;
705+
expect(limits.unavailable).toBeUndefined();
706+
expect(limits.windows).toHaveLength(4);
707+
expect(signedIn.requests.some((request) => request.url.endsWith("/token"))).toBe(false);
708+
709+
const expired = yield* fixture({
710+
missingToken: true,
711+
keyringSecret: keyringSecret("2026-10-09T12:00:30Z"),
712+
});
713+
expect((yield* expired.probe).unavailable?.reason).toBe("probeFailed");
714+
expect(expired.requests).toEqual([]);
715+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
716+
);
717+
718+
it.effect.runIf(HostProcess.Platform.defaultValue() === "win32")(
719+
"reads go-keyring's Windows credential target without changing it",
720+
(ctx) =>
721+
Effect.gen(function* () {
722+
// Never overwrite a real sign-in on a developer's machine.
723+
if (readWindowsCliCredential(HostProcess.Architecture.defaultValue())) return ctx.skip();
724+
yield* TestClock.setTime(
725+
DateTime.toEpochMillis(DateTime.makeUnsafe("2026-10-09T12:00:00Z")),
726+
);
727+
const { AsyncEntry } = yield* Effect.promise(() => import("@napi-rs/keyring"));
728+
// go-keyring writes the UTF-8 JSON at `<service>:<user>`.
729+
const target = AsyncEntry.withTarget("gemini:antigravity", "gemini", "antigravity");
730+
const stored = new TextEncoder().encode(
731+
JSON.stringify({
732+
token: { access_token: "access-token", expiry: "2026-10-09T14:00:00Z" },
733+
}),
734+
);
735+
yield* Effect.acquireRelease(
736+
Effect.promise(() => target.setSecret(stored)),
737+
() => Effect.promise(() => target.deleteCredential()),
738+
);
739+
const { probe } = yield* fixture({ missingToken: true, nativeKeyring: true });
740+
const limits = yield* probe;
741+
expect(limits.unavailable).toBeUndefined();
742+
expect(limits.windows).toHaveLength(4);
743+
expect(readWindowsCliCredential(HostProcess.Architecture.defaultValue())).toEqual(
744+
Buffer.from(stored),
745+
);
746+
}).pipe(Effect.scoped, Effect.provide(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))),
747+
);
748+
749+
it("decodes go-keyring's macOS encodings", () => {
750+
const value = '{"token":{}}';
751+
const bytes = (text: string) => new TextEncoder().encode(text);
752+
expect(decodeGoKeyringSecret(bytes(value))).toBe(value);
753+
expect(
754+
decodeGoKeyringSecret(bytes(`go-keyring-base64:${Buffer.from(value).toString("base64")}`)),
755+
).toBe(value);
756+
expect(
757+
decodeGoKeyringSecret(bytes(`go-keyring-encoded:${Buffer.from(value).toString("hex")}`)),
758+
).toBe(value);
759+
});
760+
657761
it.effect("does not make network requests for API keys or missing sign-ins", () =>
658762
Effect.gen(function* () {
659763
for (const options of [{ authMethod: "gemini-api-key" as const }, { missingToken: true }]) {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.