TypeScript
fix(server): Antigravity installs on Intel Macs (#30189)
Ale 🐶c55db3e9c72f
diff --git a/apps/server/src/provider/AntigravityInstallation.test.ts b/apps/server/src/provider/AntigravityInstallation.test.tsindex fb142d41dec..60361fe94fa 100644--- a/apps/server/src/provider/AntigravityInstallation.test.ts+++ b/apps/server/src/provider/AntigravityInstallation.test.ts@@ -18,6 +18,8 @@ import * as Scope from "effect/Scope";import * as Sink from "effect/Sink";import * as Stream from "effect/Stream";import { HttpClient, HttpClientResponse } from "effect/http";+import * as ChildProcess from "effect/process/ChildProcess";+import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";import * as AntigravityInstallation from "./AntigravityInstallation.ts";import { type AntigravityReleaseAsset } from "./antigravityRelease.ts";@@ -121,6 +123,7 @@ interface HarnessOptions {readonly path?: string;readonly previous?: boolean;readonly fileSystem?: FileSystem.FileSystem;+ readonly spawner?: ChildProcessSpawner.ChildProcessSpawner["Service"];readonly validate?: AntigravityInstallation.AntigravityInstallationOptions["validate"];readonly useDefaultValidation?: boolean;}@@ -175,6 +178,9 @@ const makeHarness = Effect.fn("test.makeAntigravityInstallation")(function* (),}),}).pipe(+ options.spawner+ ? Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, options.spawner)+ : (effect) => effect,Effect.provideService(FileSystem.FileSystem, trackedFs),Effect.provideService(HostProcess.Platform, platform),Effect.provideService(HostProcess.Architecture, arch),@@ -571,6 +577,58 @@ it.layer(Layer.mergeAll(NodeServices.layer, NodeCrypto.layer))("Antigravity inst}),);+ it.effect("re-signs the Intel Mac runtime ad hoc and records the signed sizes", () =>+ Effect.gen(function* () {+ const fs = yield* FileSystem.FileSystem;+ const signed: Array<ReadonlyArray<string>> = [];+ const spawner = ChildProcessSpawner.make((command) =>+ Effect.gen(function* () {+ if (!ChildProcess.isStandardCommand(command))+ return yield* Effect.die("Unexpected spawn.");+ const args = command.args.map(String);+ signed.push([String(command.command), ...args]);+ // codesign rewrites the signature, which changes each file's size.+ for (const file of args.slice(3)) {+ yield* fs.writeFileString(file, "signature", { flag: "a" });+ }+ return ChildProcessSpawner.makeHandle({+ pid: ChildProcessSpawner.ProcessId(900_000_301),+ exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),+ isRunning: Effect.succeed(false),+ kill: () => Effect.void,+ unref: Effect.succeed(Effect.void),+ stdin: Sink.drain,+ stdout: Stream.empty,+ stderr: Stream.empty,+ all: Stream.empty,+ getInputFd: () => Sink.drain,+ getOutputFd: () => Stream.empty,+ });+ }).pipe(Effect.orDie),+ );+ const { installation, validations } = yield* makeHarness({+ platform: "darwin",+ arch: "x64",+ spawner,+ });+ yield* installation.start;+ expect((yield* terminalState(installation)).phase).toBe("succeeded");+ const validated = validations[0]?.executable;+ expect(signed).toEqual([+ [+ "/usr/bin/codesign",+ "--force",+ "--sign",+ "-",+ validated?.executablePath,+ validated?.harnessPath,+ ],+ ]);+ const selected = yield* installation.resolve();+ expect(yield* fs.readFileString(selected.executablePath)).toBe(`${serverContents}signature`);+ }),+ );+// The mocked Linux PATH walk needs POSIX paths; Windows temp paths contain colons.it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")("honors explicit paths and reports invalid overrides without falling back",diff --git a/apps/server/src/provider/AntigravityInstallation.ts b/apps/server/src/provider/AntigravityInstallation.tsindex 707cb0b4469..f03a7874f87 100644--- a/apps/server/src/provider/AntigravityInstallation.ts+++ b/apps/server/src/provider/AntigravityInstallation.ts@@ -21,6 +21,7 @@ import * as Semaphore from "effect/Semaphore";import * as Stream from "effect/Stream";import * as SubscriptionRef from "effect/SubscriptionRef";import { HttpClient, HttpClientRequest, HttpClientResponse } from "effect/http";+import * as ChildProcess from "effect/process/ChildProcess";import * as ChildProcessSpawner from "effect/process/ChildProcessSpawner";import * as NodeCrypto from "node:crypto";import * as NodeFSP from "node:fs/promises";@@ -642,15 +643,39 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.ma}}).pipe(Effect.scoped);yield* fs.remove(archivePath);+ const executablePath = path.join(pairDirectory, asset.executable.name);+ const harnessPath = path.join(pairDirectory, asset.harness.name);if (platform !== "win32") {- yield* fs.chmod(path.join(pairDirectory, asset.executable.name), 0o755);- yield* fs.chmod(path.join(pairDirectory, asset.harness.name), 0o755);+ yield* fs.chmod(executablePath, 0o755);+ yield* fs.chmod(harnessPath, 0o755);+ }+ if (platform === "darwin" && arch === "x64") {+ // Google signs the Intel build with the hardened runtime but no JIT entitlement, so+ // libffi's writable+executable trampolines spin forever. Re-sign ad hoc after the hash check.+ const exitCode = yield* spawner+ .spawn(+ ChildProcess.make(+ "/usr/bin/codesign",+ ["--force", "--sign", "-", executablePath, harnessPath],+ { stdout: "ignore", stderr: "ignore" },+ ),+ )+ .pipe(+ Effect.flatMap((child) => child.exitCode),+ Effect.scoped,+ );+ if (exitCode !== 0) {+ return yield* installationError(+ "extract",+ "Could not prepare the Antigravity runtime for this Mac. Check that codesign is available.",+ );+ }}yield* report("verifying", "Checking the downloaded runtime.");yield* validate({- executablePath: path.join(pairDirectory, asset.executable.name),- harnessPath: path.join(pairDirectory, asset.harness.name),+ executablePath,+ harnessPath,source: "managed",version: asset.version,managedVersionDirectory: pairDirectory,@@ -660,8 +685,11 @@ export const makeAntigravityInstallation = Effect.fn("AntigravityInstallation.maconst record: InstalledRelease = {releaseId: asset.sha256,version: asset.version,- executable: asset.executable,- harness: asset.harness,+ executable: {+ name: asset.executable.name,+ bytes: Number((yield* fs.stat(executablePath)).size),+ },+ harness: { name: asset.harness.name, bytes: Number((yield* fs.stat(harnessPath)).size) },};yield* fs.writeFileString(path.join(pairDirectory, RELEASE_RECORD),