TypeScript
fix(server): Antigravity can reach Google on NixOS (#20551)
Felix Laga88a779defe85
diff --git a/apps/server/src/provider/antigravityAuthSupport.test.ts b/apps/server/src/provider/antigravityAuthSupport.test.tsindex dad00aa7603..16a7df96337 100644--- a/apps/server/src/provider/antigravityAuthSupport.test.ts+++ b/apps/server/src/provider/antigravityAuthSupport.test.ts@@ -556,6 +556,82 @@ describe("Antigravity stderr compatibility", () => {});it.layer(NodeServices.layer)("Antigravity profile preparation", (it) => {+ const prepareSpawn = Effect.fn(function* (+ bundles: ReadonlyArray<string>,+ baseEnv: NodeJS.ProcessEnv = {},+ platform: NodeJS.Platform = "linux",+ ) {+ const fs = yield* FileSystem.FileSystem;+ const path = yield* Path.Path;+ const directory = yield* fs.makeTempDirectoryScoped();+ const profile = yield* prepareAntigravityProfile({+ profileDirectory: path.join(directory, "profile"),+ userHome: path.join(directory, "home"),+ runtimeExecutablePath: process.execPath,+ platform,+ baseEnv,+ }).pipe(+ Effect.provideService(FileSystem.FileSystem, {+ ...fs,+ exists: (candidate) => Effect.succeed(bundles.includes(candidate)),+ }),+ );+ return buildAntigravityAcpSpawnInput({+ installation: { executablePath: "/release/acp", harnessPath: "/release/harness" },+ profile,+ cwd: directory,+ baseEnv,+ }).env;+ });++ // A Windows Node path cannot preflight the browser helper as a POSIX host.+ const caTest = it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32");++ caTest(+ "launches Linux agents with the first available CA bundle, preferring absolute Nix paths",+ () =>+ Effect.gen(function* () {+ const systemBundles = ["/etc/pki/tls/certs/ca-bundle.crt", "/etc/ssl/cert.pem"];+ const nixBundle = "/nix/store/nss-cacert/etc/ssl/certs/ca-bundle.crt";+ expect((yield* prepareSpawn(systemBundles))?.SSL_CERT_FILE).toBe(systemBundles[0]);+ expect(+ (yield* prepareSpawn([nixBundle, ...systemBundles], { NIX_SSL_CERT_FILE: nixBundle }))+ ?.SSL_CERT_FILE,+ ).toBe(nixBundle);+ expect(+ (yield* prepareSpawn(systemBundles, { NIX_SSL_CERT_FILE: nixBundle }))?.SSL_CERT_FILE,+ ).toBe(systemBundles[0]);+ expect(+ (yield* prepareSpawn(["certs/local.pem", ...systemBundles], {+ NIX_SSL_CERT_FILE: "certs/local.pem",+ }))?.SSL_CERT_FILE,+ ).toBe(systemBundles[0]);+ expect((yield* prepareSpawn([]))?.SSL_CERT_FILE).toBeUndefined();+ }),+ );++ caTest("preserves explicit certificate files and directories in Linux launches", () =>+ Effect.gen(function* () {+ const bundles = ["/etc/ssl/certs/ca-certificates.crt"];+ expect(+ (yield* prepareSpawn(bundles, { SSL_CERT_FILE: "/custom/ca.pem" }))?.SSL_CERT_FILE,+ ).toBe("/custom/ca.pem");+ const directoryEnv = yield* prepareSpawn(bundles, { SSL_CERT_DIR: "/custom/certs" });+ expect(directoryEnv?.SSL_CERT_DIR).toBe("/custom/certs");+ expect(directoryEnv?.SSL_CERT_FILE).toBeUndefined();+ }),+ );++ caTest("leaves non-Linux certificate defaults unchanged even when a bundle exists", () =>+ Effect.gen(function* () {+ const bundle = "/etc/ssl/certs/ca-certificates.crt";+ for (const platform of ["darwin", "win32"] as const) {+ const env = yield* prepareSpawn([bundle], { NIX_SSL_CERT_FILE: bundle }, platform);+ expect(env?.SSL_CERT_FILE).toBeUndefined();+ }+ }),+ );+it.effect("runs the browser helper with installed Node in standalone builds", () =>Effect.gen(function* () {const fs = yield* FileSystem.FileSystem;diff --git a/apps/server/src/provider/antigravityAuthSupport.ts b/apps/server/src/provider/antigravityAuthSupport.tsindex 216dbc7aa85..c32975dc706 100644--- a/apps/server/src/provider/antigravityAuthSupport.ts+++ b/apps/server/src/provider/antigravityAuthSupport.ts@@ -87,6 +87,7 @@ export interface AntigravityProfile {readonly tokenPath: string;readonly tempDirectory: string;readonly browserCommand: string;+ readonly caBundlePath?: string;}export interface AntigravityAuthConfig {@@ -221,6 +222,11 @@ function antigravityEnvironment(return {...environment,...credential,+ ...(profile.caBundlePath !== undefined &&+ baseEnv.SSL_CERT_FILE === undefined &&+ baseEnv.SSL_CERT_DIR === undefined+ ? { SSL_CERT_FILE: profile.caBundlePath }+ : {}),GEMINI_HOME: profile.geminiHome,AGY_ACP_FORCE_FILE_STORAGE: "1",BROWSER: profile.browserCommand,@@ -327,6 +333,27 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(const geminiHome = path.resolve(input.profileDirectory);const acpDirectory = path.join(geminiHome, "antigravity-acp");const tempDirectory = input.tempDirectory ?? path.join(acpDirectory, "tmp");+ let caBundlePath: string | undefined;+ if (platform === "linux") {+ // Bundled Python may look for certificates at paths absent on this distribution.+ // Relative paths would resolve differently when the agent runs in the project directory.+ for (const candidate of [+ (input.baseEnv ?? process.env).NIX_SSL_CERT_FILE,+ "/etc/ssl/certs/ca-bundle.crt",+ "/etc/ssl/certs/ca-certificates.crt",+ "/etc/pki/tls/certs/ca-bundle.crt",+ "/etc/ssl/cert.pem",+ ]) {+ if (+ candidate &&+ path.isAbsolute(candidate) &&+ (yield* fs.exists(candidate).pipe(Effect.orElseSucceed(() => false)))+ ) {+ caBundlePath = candidate;+ break;+ }+ }+ }const profile: AntigravityProfile = {platform,geminiHome,@@ -334,6 +361,7 @@ export const prepareAntigravityProfile = Effect.fn("prepareAntigravityProfile")(tokenPath: path.join(acpDirectory, "acp_token.json"),tempDirectory,browserCommand,+ ...(caBundlePath === undefined ? {} : { caBundlePath }),};const environment = antigravityEnvironment(profile, input.baseEnv ?? process.env, auth);yield* Effect.gen(function* () {