Skip to content

graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs

Python

Windows: find programs on PATH with ';' and .exe; ACP tests drain stderr

justrach70dd1e4ce8e3
diff --git a/scripts/test-acp-goal.py b/scripts/test-acp-goal.py
index 1fa61f69..f23b9012 100644
--- a/scripts/test-acp-goal.py
+++ b/scripts/test-acp-goal.py
@@ -71,13 +71,21 @@ def main() -> None:
reader = threading.Thread(target=read_stdout, daemon=True)
reader.start()
+ # Drain stderr while graff runs: an unread pipe fills (about 4 KB on Windows)
+ # and blocks graff mid-write, which reads as a hung reply.
+ stderr_lines: list = []
+ stderr_reader = threading.Thread(target=lambda: stderr_lines.extend(proc.stderr), daemon=True)
+ stderr_reader.start()
def request(rpc_id: int, method: str, params: dict) -> list:
proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": rpc_id, "method": method, "params": params}) + "\n")
proc.stdin.flush()
events = []
while True:
- event = responses.get(timeout=45)
+ try:
+ event = responses.get(timeout=45)
+ except queue.Empty:
+ raise AssertionError("no reply to %s within 45s; graff stderr tail:\n%s" % (method, "".join(stderr_lines)[-3000:]))
assert "invalid_stdout" not in event and "eof" not in event, event
events.append(event)
if event.get("id") == rpc_id:
@@ -118,7 +126,7 @@ def main() -> None:
prompt(command)
assert len(model.requests) == count, command + " unexpectedly started work"
proc.stdin.close()
- assert proc.wait(timeout=15) == 0, proc.stderr.read()
+ assert proc.wait(timeout=15) == 0, "".join(stderr_lines)
finally:
if proc.poll() is None:
proc.kill()
diff --git a/scripts/test-acp-meta-tool-status.py b/scripts/test-acp-meta-tool-status.py
index 7c6e0311..680ddf8f 100755
--- a/scripts/test-acp-meta-tool-status.py
+++ b/scripts/test-acp-meta-tool-status.py
@@ -73,13 +73,21 @@ def main() -> None:
reader = threading.Thread(target=read_stdout, daemon=True)
reader.start()
+ # Drain stderr while graff runs: an unread pipe fills (about 4 KB on Windows)
+ # and blocks graff mid-write, which reads as a hung reply.
+ stderr_lines: list = []
+ stderr_reader = threading.Thread(target=lambda: stderr_lines.extend(proc.stderr), daemon=True)
+ stderr_reader.start()
def request(rpc_id: int, method: str, params: dict) -> list:
proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": rpc_id, "method": method, "params": params}) + "\n")
proc.stdin.flush()
events = []
while True:
- event = responses.get(timeout=45)
+ try:
+ event = responses.get(timeout=45)
+ except queue.Empty:
+ raise AssertionError("no reply to %s within 45s; graff stderr tail:\n%s" % (method, "".join(stderr_lines)[-3000:]))
assert "invalid_stdout" not in event and "eof" not in event, event
events.append(event)
if event.get("id") == rpc_id:
@@ -110,7 +118,7 @@ def main() -> None:
and e["params"]["update"].get("sessionUpdate") == "agent_message_chunk")
assert "META_STATUS_DONE" in answer, answer
proc.stdin.close()
- assert proc.wait(timeout=15) == 0, proc.stderr.read()
+ assert proc.wait(timeout=15) == 0, "".join(stderr_lines)
finally:
if proc.poll() is None:
proc.kill()
diff --git a/scripts/test-acp-yield-once.py b/scripts/test-acp-yield-once.py
index 41075463..033bad8e 100755
--- a/scripts/test-acp-yield-once.py
+++ b/scripts/test-acp-yield-once.py
@@ -70,13 +70,21 @@ def main() -> None:
reader = threading.Thread(target=read_stdout, daemon=True)
reader.start()
+ # Drain stderr while graff runs: an unread pipe fills (about 4 KB on Windows)
+ # and blocks graff mid-write, which reads as a hung reply.
+ stderr_lines: list = []
+ stderr_reader = threading.Thread(target=lambda: stderr_lines.extend(proc.stderr), daemon=True)
+ stderr_reader.start()
def request(rpc_id: int, method: str, params: dict) -> list:
proc.stdin.write(json.dumps({"jsonrpc": "2.0", "id": rpc_id, "method": method, "params": params}) + "\n")
proc.stdin.flush()
events = []
while True:
- event = responses.get(timeout=45)
+ try:
+ event = responses.get(timeout=45)
+ except queue.Empty:
+ raise AssertionError("no reply to %s within 45s; graff stderr tail:\n%s" % (method, "".join(stderr_lines)[-3000:]))
assert "invalid_stdout" not in event and "eof" not in event, event
events.append(event)
if event.get("id") == rpc_id:
@@ -100,7 +108,7 @@ def main() -> None:
ends = [u for u in updates if u["toolCallId"] == call_id and u.get("status") in TERMINAL]
assert len(ends) == 1, "%s ended %d times" % (name, len(ends))
proc.stdin.close()
- assert proc.wait(timeout=15) == 0, proc.stderr.read()
+ assert proc.wait(timeout=15) == 0, "".join(stderr_lines)
finally:
if proc.poll() is None:
proc.kill()
diff --git a/src/main.zig b/src/main.zig
index 598db769..a2b160f7 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -565,7 +565,7 @@ test { // ── Unit tests (`zig build test`): pull in tests from imported modu
_ = .{ @import("session_catalog.zig"), @import("session_prompt.zig"), @import("session_discovery.zig"), @import("session_workspaces.zig"), @import("commands_resume.zig"), @import("peer_live.zig"), @import("presence_tests.zig"), @import("mcp_rpc_tests.zig") };
_ = .{ @import("prompt_astra.zig"), @import("prompt_guidance.zig"), @import("oauth_chatgpt.zig"), @import("chatgpt_reauth.zig") }; // per-model guidance (Astra, GPT-5.6); ChatGPT plan sign-in (ADR 0253)
_ = .{ @import("agent_empty_completion.zig"), @import("agent_model_loop.zig"), @import("publication_policy_tests.zig"), @import("jobs_completion_tests.zig") };
- _ = .{ @import("provider_routing_tests.zig"), @import("codegraff_messages_tests.zig"), @import("tool_result_empty_tests.zig"), @import("history_wire.zig"), @import("agents_prepare.zig"), @import("catalog_price.zig"), @import("readline_paste_number_tests.zig"), @import("test_hooks.zig"), @import("peer_wake_loop.zig") };
+ _ = .{ @import("provider_routing_tests.zig"), @import("codegraff_messages_tests.zig"), @import("tool_result_empty_tests.zig"), @import("history_wire.zig"), @import("path_lookup.zig"), @import("agents_prepare.zig"), @import("catalog_price.zig"), @import("readline_paste_number_tests.zig"), @import("test_hooks.zig"), @import("peer_wake_loop.zig") };
_ = .{ @import("list_dir_nearmiss.zig"), @import("tool_preview_tests.zig") };
_ = @import("repo_map.zig");
_ = @import("agent_overflow_tests.zig"); // #414: and, through it, agent_overflow.zig's table tests
diff --git a/src/path_lookup.zig b/src/path_lookup.zig
new file mode 100644
index 00000000..b7768049
--- /dev/null
+++ b/src/path_lookup.zig
@@ -0,0 +1,77 @@
+//! Find a program on PATH the way the platform does.
+//!
+//! Splitting PATH on ':' broke on Windows, where the delimiter is ';' and every
+//! entry holds a drive colon: `C:\Program Files\Git\bin;D:\tools` became
+//! fragments like `\Program Files\Git\bin;D`, and the probe of each built path
+//! could take seconds (a fragment that reads as a network path) and printed an
+//! error trace in debug builds. A bare name also never matched `codedb.exe`.
+
+const std = @import("std");
+const builtin = @import("builtin");
+const Io = std.Io;
+
+const windows_exts = [_][]const u8{ ".exe", ".cmd", ".bat", ".com" };
+
+/// First `name` on `path_env` that exists, written into `buf`; null when none.
+pub fn resolve(io: Io, path_env: []const u8, name: []const u8, buf: []u8) ?[]const u8 {
+ const exts: []const []const u8 = if (builtin.os.tag == .windows) &windows_exts else &.{};
+ return resolveWith(io, path_env, std.fs.path.delimiter, exts, name, buf);
+}
+
+/// `resolve` with the delimiter and extensions passed in, so both platforms' rules are testable anywhere.
+pub fn resolveWith(io: Io, path_env: []const u8, delimiter: u8, exts: []const []const u8, name: []const u8, buf: []u8) ?[]const u8 {
+ if (name.len == 0) return null;
+ const has_ext = std.fs.path.extension(name).len > 0;
+ var it = std.mem.splitScalar(u8, path_env, delimiter);
+ while (it.next()) |raw| {
+ const dir = std.mem.trim(u8, raw, " \"");
+ if (dir.len == 0) continue;
+ if (exts.len == 0 or has_ext) {
+ if (exists(io, buf, dir, name, "")) |full| return full;
+ if (exts.len == 0) continue;
+ }
+ for (exts) |ext| if (exists(io, buf, dir, name, ext)) |full| return full;
+ }
+ return null;
+}
+
+fn exists(io: Io, buf: []u8, dir: []const u8, name: []const u8, ext: []const u8) ?[]const u8 {
+ const sep: []const u8 = if (dir[dir.len - 1] == '/' or dir[dir.len - 1] == '\\') "" else "/";
+ const full = std.fmt.bufPrint(buf, "{s}{s}{s}{s}", .{ dir, sep, name, ext }) catch return null;
+ const st = Io.Dir.cwd().statFile(io, full, .{}) catch return null;
+ if (st.kind == .directory) return null;
+ return full;
+}
+
+test "resolveWith splits on the platform delimiter and tries Windows extensions" {
+ const a = std.testing.allocator;
+ const io = std.testing.io;
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ const root = try tmp.dir.realPathFileAlloc(io, ".", a);
+ defer a.free(root);
+ try tmp.dir.createDirPath(io, "bin");
+ try tmp.dir.createDirPath(io, "win");
+ try tmp.dir.createDirPath(io, "codedb"); // a directory with the program's name is not the program
+ try tmp.dir.writeFile(io, .{ .sub_path = "bin/codedb", .data = "" });
+ try tmp.dir.writeFile(io, .{ .sub_path = "win/codedb.exe", .data = "" });
+ var buf: [1024]u8 = undefined;
+
+ // POSIX: ':' separated, the bare name.
+ const posix = try std.fmt.allocPrint(a, "{s}/missing:{s}:{s}/bin", .{ root, root, root });
+ defer a.free(posix);
+ const p = resolveWith(io, posix, ':', &.{}, "codedb", &buf) orelse return error.TestExpectedResolve;
+ try std.testing.expect(std.mem.endsWith(u8, p, "bin/codedb"));
+
+ // Windows: ';' separated (each entry may hold a colon), quoted entries, and `.exe` found for a bare name.
+ const win = try std.fmt.allocPrint(a, "{s}/missing;\"{s}/win\"", .{ root, root });
+ defer a.free(win);
+ const w = resolveWith(io, win, ';', &windows_exts, "codedb", &buf) orelse return error.TestExpectedResolve;
+ try std.testing.expect(std.mem.endsWith(u8, w, "win/codedb.exe"));
+ // An explicit extension is used as given.
+ try std.testing.expect(resolveWith(io, win, ';', &windows_exts, "codedb.exe", &buf) != null);
+
+ // Splitting a ';' PATH on ':' (the old bug) finds nothing.
+ try std.testing.expect(resolveWith(io, win, ':', &windows_exts, "codedb", &buf) == null);
+ try std.testing.expect(resolveWith(io, "", ':', &.{}, "codedb", &buf) == null);
+}
diff --git a/src/sandbox_docker.zig b/src/sandbox_docker.zig
index ef848373..df5f765c 100644
--- a/src/sandbox_docker.zig
+++ b/src/sandbox_docker.zig
@@ -284,14 +284,7 @@ pub fn loadedRef(stdout: []const u8) ?[]const u8 {
/// binary is not installed — the "docker is absent" answer, decided before any
/// process is spawned.
pub fn resolveInto(io: Io, path_env: []const u8, name: []const u8, buf: []u8) ?[]const u8 {
- var it = std.mem.splitScalar(u8, path_env, ':');
- while (it.next()) |dir| {
- if (dir.len == 0) continue;
- const full = std.fmt.bufPrint(buf, "{s}/{s}", .{ dir, name }) catch continue;
- Io.Dir.cwd().access(io, full, .{}) catch continue;
- return full;
- }
- return null;
+ return @import("path_lookup.zig").resolve(io, path_env, name, buf);
}
// ── Child-process plumbing ─────────────────────────────────────────────────
diff --git a/src/skills.zig b/src/skills.zig
index 0a801709..e75a66a1 100644
--- a/src/skills.zig
+++ b/src/skills.zig
@@ -137,15 +137,8 @@ pub fn mcpServerConnected(tools: []const mcp.Tool, server: []const u8) bool {
}
pub fn binOnPath(io: Io, name: []const u8) bool {
- var it = std.mem.splitScalar(u8, main_mod.g_path_env, ':');
var buf: [1024]u8 = undefined;
- while (it.next()) |dir| {
- if (dir.len == 0) continue;
- const full = std.fmt.bufPrint(&buf, "{s}/{s}", .{ dir, name }) catch continue;
- Io.Dir.cwd().access(io, full, .{}) catch continue;
- return true;
- }
- return false;
+ return @import("path_lookup.zig").resolve(io, main_mod.g_path_env, name, &buf) != null;
}
pub fn skillInstalled(io: Io, sk: SkillDef) bool {