graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Compare ACP spawn cwd through realpath
Cursor Agent92f4d3fc7c6f
diff --git a/apps/native/lib/acp-bootstrap.test.ts b/apps/native/lib/acp-bootstrap.test.tsindex 67817647..08346e07 100644--- a/apps/native/lib/acp-bootstrap.test.ts+++ b/apps/native/lib/acp-bootstrap.test.ts@@ -1,6 +1,9 @@import { test, expect } from "bun:test";import { spawn } from "node:child_process";import { once } from "node:events";+import { mkdirSync, mkdtempSync, rmSync, symlinkSync } from "node:fs";+import os from "node:os";+import path from "node:path";import { AcpTransport } from "./acp-transport";import { bindSessionCwd, initializeWorker, serializeBootstrap } from "./acp-bootstrap";import { retireWorker } from "./acp-retire";@@ -58,6 +61,26 @@ test("bindSessionCwd keeps the spawn workspace when session/new reports the hostexpect(bindSessionCwd(host, host, host)).toBe(host);});+test("bindSessionCwd treats a host cwd symlink as the host, not a checkout", () => {+ const root = mkdtempSync(path.join(os.tmpdir(), "graff-bind-cwd-"));+ try {+ const host = path.join(root, "apps-native");+ const workspace = path.join(root, "workspace");+ mkdirSync(host);+ mkdirSync(workspace);+ const alias = path.join(root, "host-alias");+ symlinkSync(host, alias);+ expect(bindSessionCwd(workspace, alias, host)).toBe(workspace);+ expect(bindSessionCwd(workspace, host, alias)).toBe(workspace);+ expect(bindSessionCwd(workspace, workspace, host)).toBe(path.resolve(workspace));+ const tree = path.join(workspace, ".graff", "worktrees", "session-1");+ mkdirSync(tree, { recursive: true });+ expect(bindSessionCwd(workspace, tree, host)).toBe(path.resolve(tree));+ } finally {+ rmSync(root, { recursive: true, force: true });+ }+});+test("session/new checkout binds the worker to its isolated worktree", async () => {const isolated = await worker("isolated");try {diff --git a/apps/native/lib/acp-bootstrap.ts b/apps/native/lib/acp-bootstrap.tsindex 1dbecb22..04bef207 100644--- a/apps/native/lib/acp-bootstrap.ts+++ b/apps/native/lib/acp-bootstrap.ts@@ -1,11 +1,17 @@+import { realpathSync } from "node:fs";import path from "node:path";import type { AcpTransport } from "./acp-transport";+function sameDir(left: string, right: string): boolean {+ if (left === right) return true;+ try { return realpathSync(left) === realpathSync(right); } catch { return false; }+}+/** Keep the spawn workspace unless session/new named a real absolute checkout* that is not the host process cwd. A relative "." (g_cwd_display default) or* inherited PWD from `next start` in apps/native would otherwise enroll* `apps/native/.graff/sessions` instead of the fixture workspace. Isolated- * worktrees stay adopted. */+ * worktrees stay adopted. Host aliases (`/var` vs `/private/var`) stay host. */export function bindSessionCwd(requested: string, reported?: string, hostCwd = process.cwd()): string {if (!reported) return requested;const checkout = reported.trim();@@ -13,7 +19,7 @@ export function bindSessionCwd(requested: string, reported?: string, hostCwd = pconst resolved = path.resolve(checkout);const spawned = path.resolve(requested);const host = path.resolve(hostCwd);- if (resolved === host && resolved !== spawned) return requested;+ if (sameDir(resolved, host) && !sameDir(resolved, spawned)) return requested;return resolved;}diff --git a/apps/native/lib/acp-route.test.ts b/apps/native/lib/acp-route.test.tsindex 5889686b..d061b39d 100644--- a/apps/native/lib/acp-route.test.ts+++ b/apps/native/lib/acp-route.test.ts@@ -400,9 +400,10 @@ require('node:readline').createInterface({input:process.stdin}).on('line', lineexpect(hostReport.status).toBe(200);expect(await hostReport.json()).toMatchObject({ sessionId: "enroll", cwd: path.resolve(temp) });const spawned = JSON.parse(readFileSync(path.join(temp, "spawn.env"), "utf8"));- expect(path.resolve(spawned.cwd)).toBe(path.resolve(temp));- expect(path.resolve(spawned.pwd)).toBe(path.resolve(temp));- expect(path.resolve(spawned.graffCwd)).toBe(path.resolve(temp));+ // process.cwd() is realpath; os.tmpdir() on macOS is /var → /private/var.+ expect(realpathSync(spawned.cwd)).toBe(realpathSync(temp));+ expect(realpathSync(spawned.pwd)).toBe(realpathSync(temp));+ expect(realpathSync(spawned.graffCwd)).toBe(realpathSync(temp));const store = attachmentStore();const image = store.create("enroll.png", new Uint8Array([1, 2, 3]));const prompted = await call("session/prompt", { prompt: [{ type: "text", text: `See @[${image}]` }] });