Skip to content

Commit e9b2a0a

Browse files
committed
fix(antigravity): send a bare ide_version, not the whole User-Agent
Onboarding was filling metadata.ide_version with antigravityUserAgent(), which returns the entire header - antigravity/ide/2.5.5 (aidev_client; os_type=...; arch=...) - where the real client sends 2.5.5. Nothing failed, and that is the point. The request still succeeds; it just does not look like Antigravity. A fingerprint is only worth having if it matches, and this one had a parenthesized UA string sitting in a version field on every onboarding call. ANTIGRAVITY_IDE_VERSION already existed one import away. The regression pins the field and asserts the shape it must not have, so the next person reaching for the UA helper here gets a failure instead of a silently wrong fingerprint. Driven red: restoring antigravityUserAgent() fails the new test.
1 parent 97a9241 commit e9b2a0a

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎src/oauth/google-antigravity.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import { OAuthCallbackFlow, type OAuthCallbackFlowOptions } from "./callback-server";
1313
import { generatePKCE } from "./pkce";
1414
import type { OAuthController, OAuthCredentials } from "./types";
15-
import { antigravityUserAgent, ANTIGRAVITY_GOOG_API_CLIENT_UA } from "../adapters/client-fingerprint";
15+
import { antigravityUserAgent, ANTIGRAVITY_GOOG_API_CLIENT_UA, ANTIGRAVITY_IDE_VERSION } from "../adapters/client-fingerprint";
1616

1717
const CLIENT_ID = process.env.GOOGLE_ANTIGRAVITY_CLIENT_ID
1818
|| "1071006060591-tmhssin2h21lcre235vtolojh4g403ep.apps.googleusercontent.com";
@@ -111,7 +111,12 @@ async function onboardProject(accessToken: string, signal?: AbortSignal): Promis
111111
const response = await fetch(`${DAILY_API}/${API_VERSION}:onboardUser`, {
112112
method: "POST",
113113
headers: { Authorization: `Bearer ${accessToken}`, Accept: "*/*", "Content-Type": "application/json", "User-Agent": antigravityUserAgent(), "x-goog-api-client": ANTIGRAVITY_GOOG_API_CLIENT_UA },
114-
body: JSON.stringify({ tier_id: "free-tier", metadata: { ide_type: "ANTIGRAVITY", ide_name: "antigravity", ide_version: antigravityUserAgent() } }),
114+
// `ide_version` is a version, not a User-Agent. `antigravityUserAgent()` returns the whole
115+
// header — `antigravity/ide/2.5.5 (aidev_client; os_type=...; arch=...)` — so onboarding was
116+
// sending a parenthesized UA string in a field the real client fills with `2.5.5`. It is a
117+
// fingerprint mismatch rather than a crash, which is why nothing failed: the request still
118+
// succeeds, it just does not look like Antigravity.
119+
body: JSON.stringify({ tier_id: "free-tier", metadata: { ide_type: "ANTIGRAVITY", ide_name: "antigravity", ide_version: ANTIGRAVITY_IDE_VERSION } }),
115120
signal: requestSignal(signal),
116121
});
117122
if (!response.ok) {

‎tests/google-antigravity-oauth.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { mkdirSync, rmSync } from "node:fs";
44
import { tmpdir } from "node:os";
55
import { join } from "node:path";
66
import { getCredential, saveCredential } from "../src/oauth/store";
7+
import { ANTIGRAVITY_IDE_VERSION } from "../src/adapters/client-fingerprint";
78

89
const realFetch = globalThis.fetch;
910
afterEach(() => { globalThis.fetch = realFetch; });
@@ -50,6 +51,29 @@ describe("antigravity project discovery", () => {
5051
expect(onboardCalls).toBe(2);
5152
});
5253

54+
// `ide_version` was sending `antigravityUserAgent()` — the whole header, parentheses and all —
55+
// where the real client sends a bare version. Nothing failed, because the request still
56+
// succeeds; it just does not look like Antigravity. A fingerprint is only worth having if it
57+
// matches, so pin the field rather than trusting that nobody re-reaches for the UA helper.
58+
test("onboardUser sends a bare ide_version, not the User-Agent string", async () => {
59+
let onboardBody: string | undefined;
60+
routeFetch((url, init) => {
61+
if (url.includes(":loadCodeAssist")) return new Response(JSON.stringify({}), { status: 200 });
62+
if (url.includes(":onboardUser")) {
63+
onboardBody = typeof init?.body === "string" ? init.body : undefined;
64+
return new Response(JSON.stringify({ done: true, response: { cloudaicompanionProject: "p" } }), { status: 200 });
65+
}
66+
return new Response("no", { status: 404 });
67+
});
68+
69+
await discoverAntigravityProject("tok");
70+
71+
const metadata = JSON.parse(onboardBody ?? "{}").metadata as { ide_version?: string };
72+
expect(metadata.ide_version).toBe(ANTIGRAVITY_IDE_VERSION);
73+
expect(metadata.ide_version).not.toContain("antigravity/ide/");
74+
expect(metadata.ide_version).not.toContain("(");
75+
});
76+
5377
test("returns undefined when onboardUser aborts with a hard 4xx", async () => {
5478
routeFetch((url) => {
5579
if (url.includes(":loadCodeAssist")) return new Response(JSON.stringify({}), { status: 200 });

0 commit comments

Comments
 (0)