Skip to content

Build your personal knowledge base with Trilium Notes

fix(llm): probe the Windows build of Antigravity's ACP server correctly

Elian Dorand7389328e377
diff --git a/apps/server/src/services/llm/providers/antigravity_binary.spec.ts b/apps/server/src/services/llm/providers/antigravity_binary.spec.ts
new file mode 100644
index 0000000000..88a32f5fe9
--- /dev/null
+++ b/apps/server/src/services/llm/providers/antigravity_binary.spec.ts
@@ -0,0 +1,79 @@
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+// The probe drives the real execFile through util.promisify's callback
+// fallback, so the mock receives (binary, args, options, callback).
+type ExecFileCallback = (err: Error | null, result?: { stdout: string; stderr: string }) => void;
+const execFileMock = vi.hoisted(() => vi.fn<(binary: string, args: string[], options: { timeout?: number }, cb: ExecFileCallback) => void>());
+vi.mock("child_process", () => ({ execFile: execFileMock }));
+
+const existsSyncMock = vi.hoisted(() => vi.fn((_path: string) => true));
+vi.mock("fs", () => ({ existsSync: existsSyncMock }));
+
+const logInfoMock = vi.hoisted(() => vi.fn());
+vi.mock("@triliumnext/core", () => ({ getLog: () => ({ info: logInfoMock, error: vi.fn() }) }));
+
+const { parseBuildLabel, resetAntigravityBinaryCache, resolveAntigravityBinaryPath } = await import("./antigravity_binary.js");
+
+describe("resolveAntigravityBinaryPath", () => {
+ const BINARY = "C:\\agy\\agy_acp_server.exe";
+ const originalOverride = process.env.TRILIUM_ANTIGRAVITY_ACP_PATH;
+
+ beforeEach(() => {
+ resetAntigravityBinaryCache();
+ execFileMock.mockReset();
+ logInfoMock.mockReset();
+ process.env.TRILIUM_ANTIGRAVITY_ACP_PATH = BINARY;
+ });
+
+ afterEach(() => {
+ if (originalOverride === undefined) {
+ delete process.env.TRILIUM_ANTIGRAVITY_ACP_PATH;
+ } else {
+ process.env.TRILIUM_ANTIGRAVITY_ACP_PATH = originalOverride;
+ }
+ });
+
+ function probeReturns(stdout: string) {
+ execFileMock.mockImplementation((_binary, _args, _options, cb) => cb(null, { stdout, stderr: "" }));
+ }
+
+ it("probes with flags every build accepts, and logs the build label where there is one", async () => {
+ probeReturns("Build label: agy_acp_server_1.1.1\nBuild target: x\n");
+
+ await expect(resolveAntigravityBinaryPath()).resolves.toBe(BINARY);
+
+ // The Windows build defines no --version: --undefok lets it through, and
+ // --only_check_args exits after parsing instead of starting the server.
+ const [ binary, args, options ] = execFileMock.mock.calls[0];
+ expect(binary).toBe(BINARY);
+ expect(args).toEqual([ "--undefok=version", "--version", "--only_check_args" ]);
+ // A Windows start unpacks the bundled Python first, about 15 s.
+ expect(options.timeout).toBe(60_000);
+ expect(logInfoMock).toHaveBeenCalledWith(expect.stringContaining("(agy_acp_server_1.1.1)"));
+ });
+
+ it("accepts a build that prints no version", async () => {
+ probeReturns("");
+
+ await expect(resolveAntigravityBinaryPath()).resolves.toBe(BINARY);
+ expect(logInfoMock).toHaveBeenCalledWith(expect.stringContaining("(version not reported)"));
+ });
+
+ it("rejects with the setup hint on a broken binary and re-probes on the next call", async () => {
+ execFileMock.mockImplementationOnce((_binary, _args, _options, cb) => cb(new Error("spawn ENOENT")));
+
+ await expect(resolveAntigravityBinaryPath()).rejects.toThrow(/failed to run \(spawn ENOENT\).*Google Antigravity/s);
+
+ probeReturns("");
+ await expect(resolveAntigravityBinaryPath()).resolves.toBe(BINARY);
+ expect(execFileMock).toHaveBeenCalledTimes(2);
+ });
+});
+
+describe("parseBuildLabel", () => {
+ it("reads the build label, falling back to the first line", () => {
+ expect(parseBuildLabel("Built on: today\nBuild label: agy_acp_server_1.2.1 \n")).toBe("agy_acp_server_1.2.1");
+ expect(parseBuildLabel("1.2.1\nmore")).toBe("1.2.1");
+ expect(parseBuildLabel("")).toBe("");
+ });
+});
diff --git a/apps/server/src/services/llm/providers/antigravity_binary.ts b/apps/server/src/services/llm/providers/antigravity_binary.ts
index 0674903d7a..55dc561f6f 100644
--- a/apps/server/src/services/llm/providers/antigravity_binary.ts
+++ b/apps/server/src/services/llm/providers/antigravity_binary.ts
@@ -10,7 +10,7 @@
*
* Resolution order: the TRILIUM_ANTIGRAVITY_ACP_PATH override, then the
* executable on PATH (see `findOnPath`, which also asks the login shell). The
- * resolved binary is probed with `--version` once so a broken or wrong-arch
+ * resolved binary is probed once (see {@link PROBE_ARGS}) so a broken or wrong-arch
* download surfaces as a clear error instead of an opaque spawn failure
* mid-chat.
*/
@@ -24,6 +24,17 @@ import { findOnPath } from "./binary_lookup.js";
const execFileAsync = promisify(execFile);
+/**
+ * Prints the build label and exits without starting the server. The Linux and
+ * macOS `.par` builds print it for `--version`; the Windows build defines no
+ * such flag, so `--undefok` lets it through and `--only_check_args` makes it
+ * exit once the flags parse.
+ */
+const PROBE_ARGS = [ "--undefok=version", "--version", "--only_check_args" ];
+
+/** The Windows build unpacks its bundled Python on every start, which takes about 15 seconds. */
+const PROBE_TIMEOUT_MS = 60_000;
+
/** Where the setup steps live; the error messages point there. */
const SETUP_HINT = "See \"Google Antigravity\" in the AI section of the User Guide for how to download it.";
@@ -65,8 +76,8 @@ async function probeBinary(): Promise<string> {
// would freeze the whole server for up to the timeout.
let version: string;
try {
- const { stdout } = await execFileAsync(binary, ["--version"], { timeout: 30000, encoding: "utf8" });
- version = parseBuildLabel(stdout);
+ const { stdout } = await execFileAsync(binary, PROBE_ARGS, { timeout: PROBE_TIMEOUT_MS, encoding: "utf8" });
+ version = parseBuildLabel(stdout) || "version not reported";
} catch (err) {
const detail = err instanceof Error ? err.message : String(err);
throw new Error(`Found Google's Antigravity ACP server at "${binary}" but it failed to run (${detail}). ${SETUP_HINT}`);