A desktop coding agent with free access to frontier models.
TypeScript
fix(capture): treat a missing developer folder as missing Command Line Tools
ogsamrat3bd16d3fbcea
diff --git a/apps/server/src/command-guard.test.ts b/apps/server/src/command-guard.test.tsindex 26a3a6c7..bb7ac11d 100644--- a/apps/server/src/command-guard.test.ts+++ b/apps/server/src/command-guard.test.ts@@ -26,7 +26,7 @@ import { readArchiveGit } from "./session-archive/manifest.js";const hasZstd = typeof zlib.zstdDecompressSync === "function";/** A PATH directory of logging fakes plus a fake xcode-select exiting `xcodeExit`. */-function fakeTools(xcodeExit) {+function fakeTools(xcodeExit, devDir?) {const dir = fs.mkdtempSync(path.join(os.tmpdir(), "omnirush-clt-"));const log = path.join(dir, "invocations.log");fs.writeFileSync(log, "");@@ -34,7 +34,7 @@ function fakeTools(xcodeExit) {script("git", 'echo "git version 2.39.5"');script("python3", 'echo "Python 3.9.6"');script("make", 'echo "GNU Make 3.81"');- script("xcode-select", `exit ${xcodeExit}`);+ script("xcode-select", xcodeExit === 0 ? `echo "${devDir ?? dir}"` : `exit ${xcodeExit}`);const invocations = () => fs.readFileSync(log, "utf8").split("\n").filter(Boolean);return { dir, log, invocations, xcodeSelectBin: path.join(dir, "xcode-select") };}@@ -208,3 +208,25 @@ test.skipIf(!hasZstd || process.platform === "win32")("without the tools, the enassert.ok(start.files.some((file) => file.path === "README.md"), "the snapshot still lists the project without git");assert.deepEqual(tools.invocations(), ["xcode-select -p"], "no shim was spawned");});++test("xcode-select succeeding with a developer folder that is gone counts as missing tools", async () => {+ if (process.platform === "win32") return;+ const tools = fakeTools(0, path.join(os.tmpdir(), "omnirush-clt-gone-" + process.pid));+ fakeMac(tools, ["git"]);+ try {+ assert.equal(await guard.xcodeCltMissing(), true);+ } finally {+ guard.configureCltProbe(null);+ }+});++test("xcode-select succeeding with an existing developer folder counts as installed", async () => {+ if (process.platform === "win32") return;+ const tools = fakeTools(0);+ fakeMac(tools, ["git"]);+ try {+ assert.equal(await guard.xcodeCltMissing(), false);+ } finally {+ guard.configureCltProbe(null);+ }+});diff --git a/apps/server/src/command-guard.ts b/apps/server/src/command-guard.tsindex a9b60a0a..dd2f1e40 100644--- a/apps/server/src/command-guard.ts+++ b/apps/server/src/command-guard.ts@@ -32,6 +32,15 @@ export type ResolveOptions = {isFile?: (path: string) => boolean;};+function isDirectory(path: string): boolean {+ if (!path) return false;+ try {+ return statSync(path).isDirectory();+ } catch {+ return false;+ }+}+function defaultIsFile(path: string): boolean {try {return statSync(path).isFile();@@ -100,7 +109,7 @@ function runXcodeSelect(bin = "/usr/bin/xcode-select"): Promise<boolean> {};let child: ReturnType<typeof spawn>;try {- child = spawn(bin, ["-p"], { stdio: "ignore", windowsHide: true });+ child = spawn(bin, ["-p"], { stdio: ["ignore", "pipe", "ignore"], windowsHide: true });} catch {resolvePromise(false);return;@@ -111,7 +120,14 @@ function runXcodeSelect(bin = "/usr/bin/xcode-select"): Promise<boolean> {}, XCODE_SELECT_TIMEOUT_MS);timer.unref?.();child.on("error", () => finish(false));- child.on("close", (code) => finish(code === 0));+ let printed = "";+ child.stdout?.on("data", (chunk: Buffer) => {+ if (printed.length < 4096) printed += chunk.toString("utf8");+ });+ // Installed only when it succeeds AND the folder it prints exists (as the+ // engine's guard checks): a removed CLT or a stale DEVELOPER_DIR exits 0+ // with a path that is gone, and the /usr/bin shims then fail or prompt.+ child.on("close", (code) => finish(code === 0 && isDirectory(printed.trim())));});}