Skip to content
Merged
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
13 changes: 12 additions & 1 deletion apps/server/src/provider/antigravity/AntigravityAuth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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" });
Expand Down
13 changes: 13 additions & 0 deletions apps/server/src/provider/antigravity/AntigravityAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down Expand Up @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions apps/server/src/provider/antigravity/AntigravityProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
Loading