diff --git a/apps/server/src/provider/antigravity/AntigravityAuth.test.ts b/apps/server/src/provider/antigravity/AntigravityAuth.test.ts index 4a298a162..129b5703b 100644 --- a/apps/server/src/provider/antigravity/AntigravityAuth.test.ts +++ b/apps/server/src/provider/antigravity/AntigravityAuth.test.ts @@ -127,7 +127,7 @@ for await (const line of lines) { process.exit(1); } mkdirSync(join(profile, "antigravity-acp"), { recursive: true }); - writeFileSync(join(profile, "antigravity-acp", "antigravity-oauth-token"), JSON.stringify({ token: { access_token: "ya29.test" } })); + if (process.env.STANDIN_KEEPS_SIGN_IN_ELSEWHERE !== "1") writeFileSync(join(profile, "antigravity-acp", "antigravity-oauth-token"), JSON.stringify({ token: { access_token: "ya29.test" } })); console.log("Signed in."); process.exit(0); } @@ -252,6 +252,17 @@ describe.skipIf(process.platform === "win32")("Antigravity Google sign-in", () = }).pipe(Effect.scoped, Effect.provide(services)), ); + it.live("fails when the CLI keeps the sign-in outside the profile", () => + Effect.gen(function* () { + const flows = yield* makeFlows([CODE], { STANDIN_KEEPS_SIGN_IN_ELSEWHERE: "1" }); + const failure = yield* Effect.flip(flows.run("login")); + expect(failure.message).toContain("didn't keep the sign-in in this account's own folder"); + assert.notInclude(flows.lines, "Signed in."); + const signedIn = yield* readAntigravityGoogleSignIn(flows.profileDir); + assert.isUndefined(signedIn.method); + }).pipe(Effect.scoped, Effect.provide(services)), + ); + it.live("stays signed out when Google refuses a session on the new sign-in", () => Effect.gen(function* () { const flows = yield* makeFlows([CODE], { T3_ACP_AUTH_REQUIRED: "1" }); diff --git a/apps/server/src/provider/antigravity/AntigravityAuth.ts b/apps/server/src/provider/antigravity/AntigravityAuth.ts index b7b46d29d..8b7334102 100644 --- a/apps/server/src/provider/antigravity/AntigravityAuth.ts +++ b/apps/server/src/provider/antigravity/AntigravityAuth.ts @@ -57,6 +57,7 @@ import { writeAntigravityProfileSettings, writeAntigravitySignInCheck, } from "./AntigravitySignInMethod.ts"; +import { readAntigravitySavedSignIn } from "./AntigravityProfile.ts"; import { ProviderSetupError } from "../Errors.ts"; /** How long the CLI may take to print its link: Windows cold starts unpack first. */ @@ -378,6 +379,18 @@ export function makeAntigravityAuthFlows(input: { signInFailed(antigravitySignInErrorMessage(login.output.join("\n"))), ); } + // The sign-in has to be in the profile's own file: that is what the + // status reads and what keeps accounts apart. A CLI that kept it + // somewhere else (the OS keyring) would pass the session check below + // on a sign-in this account doesn't own, and the row would still say + // signed out. + if (!(yield* readAntigravitySavedSignIn(input.profileDir)).cli) { + return yield* Effect.fail( + signInFailed( + "Antigravity signed in but didn't keep the sign-in in this account's own folder, so Threadlines can't use it. This Antigravity version may be newer than this Threadlines supports.", + ), + ); + } // A session opening on the new sign-in is the proof, and lists the // account's models for the status. Only then is it recorded as this // method's sign-in: one Google refuses a session (no plan, unverified) diff --git a/apps/server/src/provider/antigravity/AntigravityProfile.ts b/apps/server/src/provider/antigravity/AntigravityProfile.ts index 1de7bd182..d5b57a038 100644 --- a/apps/server/src/provider/antigravity/AntigravityProfile.ts +++ b/apps/server/src/provider/antigravity/AntigravityProfile.ts @@ -85,13 +85,25 @@ function resolveLinuxSslCertFile( } /** - * What the CLI takes for a session over SSH. It then keeps a Google sign-in - * in the profile's own file instead of the one OS keyring entry every - * profile (and the user's own terminal `agy`) shares, and signs in with - * `agy acp --login`, which prints a link and reads back a code. + * What the CLI takes for a session over SSH. It then signs in with + * `agy acp --login`, which prints a link and reads back a code, and (1.5.14 + * and 1.5.15 only) keeps a Google sign-in in the profile's own file. */ const SSH_CONNECTION_STAND_IN = "127.0.0.1 0 127.0.0.1 0"; +/** + * Keeps a Google sign-in in the profile's own file (`antigravityTokenPath`) + * instead of the one OS keyring entry every profile (and the user's own + * terminal `agy`) shares. 1.5.16 goes by `AGY_CLI_FORCE_FILE_TOKEN_STORAGE`: + * the SSH stand-in alone leaves it on the keyring. 1.5.15 and earlier go by + * `SSH_CONNECTION`, and Google's old ACP server by + * `AGY_ACP_FORCE_FILE_STORAGE`. + */ +const FILE_SIGN_IN_STORAGE_ENV = { + AGY_CLI_FORCE_FILE_TOKEN_STORAGE: "1", + AGY_ACP_FORCE_FILE_STORAGE: "1", +} as const; + /** * A `BROWSER` that opens nothing: the agent prints its sign-in URL, and the * Threadlines client (which may be another machine) opens it. Python splits @@ -124,7 +136,7 @@ export function antigravityEnvironment(input: { } Object.assign(env, input.credentials); env.GEMINI_HOME = input.profileDir; - env.AGY_ACP_FORCE_FILE_STORAGE = "1"; + Object.assign(env, FILE_SIGN_IN_STORAGE_ENV); env.AGY_CLI_DISABLE_AUTO_UPDATE = "1"; env.SSH_CONNECTION = input.base.SSH_CONNECTION?.trim() || SSH_CONNECTION_STAND_IN; env.BROWSER = noopBrowser(input.platform, input.base); diff --git a/apps/server/src/provider/antigravity/AntigravitySignInMethod.test.ts b/apps/server/src/provider/antigravity/AntigravitySignInMethod.test.ts index 44570f526..409def0f8 100644 --- a/apps/server/src/provider/antigravity/AntigravitySignInMethod.test.ts +++ b/apps/server/src/provider/antigravity/AntigravitySignInMethod.test.ts @@ -95,8 +95,10 @@ describe("antigravity process environment", () => { it("keeps the sign-in in the profile's own file and stops the CLI updating itself", () => { const value = env(config({})); - // What the CLI takes for SSH: a Google sign-in then lives in the - // profile, never in the OS keyring the user's own `agy` shares. + // A Google sign-in lives in the profile, never in the OS keyring the + // user's own `agy` shares: 1.5.16 goes by its own switch, earlier + // versions by what they take for SSH. + assert.equal(value.AGY_CLI_FORCE_FILE_TOKEN_STORAGE, "1"); assert.equal(value.SSH_CONNECTION, "127.0.0.1 0 127.0.0.1 0"); assert.equal(value.AGY_CLI_DISABLE_AUTO_UPDATE, "1"); assert.equal(value.GEMINI_HOME, "/state/profile");