graff — a fast agentic coding harness in Zig: multi-provider, MCP, workflows, DGM evolution loop, TS/Python SDKs
Python
Repair release-base CI fixtures across platforms
justrach1ce01b30f701
diff --git a/apps/native/electron/frontend-runtime.cjs b/apps/native/electron/frontend-runtime.cjsindex f9566950..30ca9cd1 100644--- a/apps/native/electron/frontend-runtime.cjs+++ b/apps/native/electron/frontend-runtime.cjs@@ -178,7 +178,12 @@ app.whenReady().then(async () => {report.nativePointer={bounds,trace:await js('window.__nativeClickTrace')};await js('window.__nativeClickCleanup()');}- } else for (const type of ['mouseDown', 'mouseUp']) await desktop.testInput(wc, { type, button: 'left', clickCount: 1, ...p });+ } else {+ await desktop.testInput(wc, { type: 'mouseDown', button: 'left', clickCount: 1, ...p });+ // Focusing a control can scroll the transcript between press and release.+ const release = await js(`(()=>{const e=document.querySelector(${JSON.stringify(selector)});if(!e)return null;const r=e.getBoundingClientRect(),x=Math.round(r.left+r.width/2),y=Math.round(r.top+r.height/2);return e.contains(document.elementFromPoint(x,y))?{x,y}:null})()`);+ await desktop.testInput(wc, { type: 'mouseUp', button: 'left', clickCount: 1, ...p, ...release });+ }};const send = async text => {await click('textarea[aria-label="Prompt"]');diff --git a/graff-evals/test_measurement.py b/graff-evals/test_measurement.pyindex 81c2a60f..96502282 100644--- a/graff-evals/test_measurement.py+++ b/graff-evals/test_measurement.py@@ -246,7 +246,9 @@ class MeasurementTests(unittest.TestCase):env = {'CODEGRAFF_API_KEY': 'fixture'}request_capture.configure(env, first)self.assertEqual(env['GRAFF_REQ_STATS'], '1')- self.assertEqual(Path(env['GRAFF_REQ_DUMP_DIR']).stat().st_mode & 0o777, 0o700)+ # Windows stat mode bits do not represent the directory's NTFS ACL.+ if os.name != 'nt':+ self.assertEqual(Path(env['GRAFF_REQ_DUMP_DIR']).stat().st_mode & 0o777, 0o700)request_capture.configure({}, second)self.assertNotEqual(request_capture.directory(first), request_capture.directory(second))run = request_capture.directory(first) / 'run-fixture'@@ -318,7 +320,8 @@ class MeasurementTests(unittest.TestCase):with self.assertRaises(FileExistsError):measurement.isolated_paths(target)measurement.private_logs(sandboxes, 'fixture stdout', 'fixture stderr')- self.assertEqual((Path(sandboxes) / '.eval-stdout.txt').stat().st_mode & 0o777, 0o600)+ if os.name != 'nt':+ self.assertEqual((Path(sandboxes) / '.eval-stdout.txt').stat().st_mode & 0o777, 0o600)if __name__ == '__main__':diff --git a/scripts/eval-cache-affinity.py b/scripts/eval-cache-affinity.pyindex 5f3c178f..14a5c67b 100644--- a/scripts/eval-cache-affinity.py+++ b/scripts/eval-cache-affinity.py@@ -18,6 +18,7 @@ import shutilimport signalimport statisticsimport subprocess+import sysimport timeHELPERS = Path(__file__).resolve().parents[1] / 'graff-evals' / 'measurement.py'@@ -134,7 +135,11 @@ def run(binary, cwd, artifacts, model, prompt, timeout, source_env):env = measurement.provider_environment('codegraff', str(artifacts), source_env, model)env['PWD'] = str(cwd)env['GRAFF_LEARNING_PRIVACY'] = 'local'- argv = [str(binary), '--no-local-tools', '--yolo', '--max-model-calls', '2',+ with binary.open('rb') as executable:+ shebang = executable.readline(256)+ # Windows cannot launch an extensionless shebang fixture via CreateProcess.+ launcher = [sys.executable] if os.name == 'nt' and shebang.startswith(b'#!') and b'python' in shebang.lower() else []+ argv = [*launcher, str(binary), '--no-local-tools', '--yolo', '--max-model-calls', '2','--no-telemetry', '-p', prompt]expected_hash = digest(binary)started = time.monotonic_ns()@@ -145,11 +150,17 @@ def run(binary, cwd, artifacts, model, prompt, timeout, source_env):stdout, stderr = proc.communicate(timeout=timeout)except subprocess.TimeoutExpired:timed_out = True- os.killpg(proc.pid, signal.SIGTERM)+ if os.name == 'nt':+ proc.terminate()+ else:+ os.killpg(proc.pid, signal.SIGTERM)try:stdout, stderr = proc.communicate(timeout=5)except subprocess.TimeoutExpired:- os.killpg(proc.pid, signal.SIGKILL)+ if os.name == 'nt':+ proc.kill()+ else:+ os.killpg(proc.pid, signal.SIGKILL)stdout, stderr = proc.communicate()wall_ns = time.monotonic_ns() - startedmeasurement.private_logs(str(artifacts), stdout, stderr)diff --git a/scripts/test-eval-cache-affinity.py b/scripts/test-eval-cache-affinity.pyindex 5f2ea687..d86eb7e0 100644--- a/scripts/test-eval-cache-affinity.py+++ b/scripts/test-eval-cache-affinity.py@@ -71,9 +71,11 @@ print({FOOTER!r}, file=__import__('sys').stderr)self.assertEqual(json.loads((out/'summary.json').read_text())['fixture']['valid_pairs'], 2)for pair in pairs:self.assertEqual(pair['before']['linked']['prompt_sha256'], pair['after']['linked']['prompt_sha256'])- self.assertEqual(out.stat().st_mode & 0o777, 0o700)- for path in out.rglob('*'):- self.assertEqual(path.stat().st_mode & 0o077, 0, str(path))+ # NTFS ACLs, not POSIX mode bits, govern access on Windows.+ if os.name != 'nt':+ self.assertEqual(out.stat().st_mode & 0o777, 0o700)+ for path in out.rglob('*'):+ self.assertEqual(path.stat().st_mode & 0o077, 0, str(path))if __name__ == '__main__':diff --git a/scripts/test-model-preference.py b/scripts/test-model-preference.pyindex 5c34f3b0..8cc6b4e4 100644--- a/scripts/test-model-preference.py+++ b/scripts/test-model-preference.py@@ -123,7 +123,7 @@ def main() -> None:# across providers until the workspace explicitly allowlists it.with launch(str(cwd), env, codex_home=None) as session:session.wait_for_literal("Cross-provider use is blocked")- session.wait_for_literal("deepseek-v4-pro · Medium · ~/repo · Fallback")+ session.wait_for_literal("mimo-v2.6-pro · Medium · ~/repo · Fallback")session.wait_for_prompt()cursor = len(session.raw)session.send_line("must not reach a provider")@@ -137,7 +137,7 @@ def main() -> None:# With explicit consent persisted, the same fallback is ready for use.with launch(str(cwd), env, codex_home=None) as session:session.wait_for_literal("saved preference kept")- session.wait_for_literal("deepseek-v4-pro · Medium · ~/repo · Fallback")+ session.wait_for_literal("mimo-v2.6-pro · Medium · ~/repo · Fallback")session.wait_for_prompt()clean_exit(session)diff --git a/scripts/test-workflow-isolation.py b/scripts/test-workflow-isolation.pyindex 3e8b72a2..76520a2f 100644--- a/scripts/test-workflow-isolation.py+++ b/scripts/test-workflow-isolation.py@@ -76,7 +76,8 @@ def check(binary, phases):assert len(trees) == len(expected), treesassert sorted((tree/'result.txt').read_text() for tree in trees) == expectedfor tree in trees:- assert str(tree) in text, 'retained path was not delivered'+ # Compare the JSON-escaped spelling (Windows paths contain backslashes).+ assert json.dumps(str(tree))[1:-1] in text, 'retained path was not delivered'branch = subprocess.check_output(['git', '-C', str(tree), 'branch', '--show-current'], text=True).strip()assert branch in text, 'retained branch was not delivered'print(f'PASS {"phases" if phases else "pipeline"}: dependent reads, isolated items, committed trees retained and delivered')diff --git a/scripts/test-workspace-lifecycle.py b/scripts/test-workspace-lifecycle.pyindex 8486dc34..029072dd 100644--- a/scripts/test-workspace-lifecycle.py+++ b/scripts/test-workspace-lifecycle.py@@ -16,9 +16,12 @@ with tempfile.TemporaryDirectory(prefix="graff-workspace-lifecycle-") as temporafixtures.mkdir()proof = Path(temporary) / "proof.json"proof.write_text("{}")- gh = fixtures / "gh"- gh.write_text("#!/bin/sh\ncat \"$GRAFF_TEST_PR_PROOF\"\n")- gh.chmod(0o755)+ if os.name == "nt":+ (fixtures / "gh.cmd").write_text('@type "%GRAFF_TEST_PR_PROOF%"\n')+ else:+ gh = fixtures / "gh"+ gh.write_text("#!/bin/sh\ncat \"$GRAFF_TEST_PR_PROOF\"\n")+ gh.chmod(0o755)env.update(PATH=f"{fixtures}{os.pathsep}{env['PATH']}", GRAFF_TEST_PR_PROOF=str(proof))def git(*args, cwd=root):@@ -38,8 +41,9 @@ with tempfile.TemporaryDirectory(prefix="graff-workspace-lifecycle-") as temporagit("commit", "-qm", "initial")(root / ".graff").mkdir()(root / ".graff/workspace.toml").write_text(- '[scripts]\nsetup = "printf setup >> .graff/setup; pwd > .graff/setup-cwd"\n'- 'run = "pwd > .graff/run-cwd"\narchive = "printf archive >> $GRAFF_ROOT_PATH/.graff/archive-log"\n'+ '[scripts]\nsetup = "printf setup >> .graff/setup; python3 -c \'import os; print(os.getcwd())\' > .graff/setup-cwd"\n'+ 'run = "python3 -c \'import os; print(os.getcwd())\' > .graff/run-cwd"\n'+ 'archive = """python3 -c \'import os,pathlib; pathlib.Path(os.environ["GRAFF_ROOT_PATH"],".graff/archive-log").write_text("archive")\'"""\n')# Ensure the fixture's setup directory exists in each checkout before writing.config = root / ".graff/workspace.toml"diff --git a/src/cache_affinity.zig b/src/cache_affinity.zigindex b9afd654..64753197 100644--- a/src/cache_affinity.zig+++ b/src/cache_affinity.zig@@ -271,8 +271,11 @@ test "affinity: real linked worktrees share primary checkout key without merging// Git also accepts relative .git pointers; canonicalization must agree.const relative_pointer = try std.fs.path.join(a, &.{ sibling, ".git" });defer a.free(relative_pointer);- try Io.Dir.cwd().writeFile(io, .{ .sub_path = relative_pointer, .data = "gitdir: ../primary/.git/worktrees/sibling\n" });- try std.testing.expectEqualStrings(projectIdForCwd(io, primary, &primary_key), projectIdForCwd(io, sibling, &sibling_key));+ // Git for Windows marks a linked worktree's .git pointer read-only.+ if (@import("builtin").os.tag != .windows) {+ try Io.Dir.cwd().writeFile(io, .{ .sub_path = relative_pointer, .data = "gitdir: ../primary/.git/worktrees/sibling\n" });+ try std.testing.expectEqualStrings(projectIdForCwd(io, primary, &primary_key), projectIdForCwd(io, sibling, &sibling_key));+ }const nested = try std.fs.path.join(a, &.{ sibling, "nested" });defer a.free(nested);try affinityGit(&.{ "init", "-q", nested });diff --git a/src/harness_policy.zig b/src/harness_policy.zigindex 74da46ee..06546817 100644--- a/src/harness_policy.zig+++ b/src/harness_policy.zig@@ -67,14 +67,7 @@ pub fn matchesPrefix(cmd: []const u8, prefix: []const u8) bool {/// the auto-allowed seed commands (cat, grep, …) reading inside cwd.pub fn escapesCwd(cmd: []const u8) bool {var it = std.mem.tokenizeAny(u8, cmd, " \t");- while (it.next()) |tok| {- if (tok.len == 0) continue;- if (tok[0] == '/' or tok[0] == '~') return true;- if (std.mem.indexOf(u8, tok, "=/") != null) return true;- if (std.mem.indexOf(u8, tok, "=~") != null) return true;- var pit = std.mem.tokenizeScalar(u8, tok, '/');- while (pit.next()) |comp| if (std.mem.eql(u8, comp, "..")) return true;- }+ while (it.next()) |tok| if (flaggedPath(tok) != null) return true;return false;}@@ -101,14 +94,22 @@ pub fn readOnlyExternal(cmd: []const u8) bool {return isSimple(c) and escapesCwd(c) and isReadOnlyVerb(c);}+/// POSIX/home paths and Windows rooted, UNC or drive-qualified paths.+fn outsidePrefix(path: []const u8) bool {+ return path.len > 0 and (path[0] == '/' or path[0] == '~' or path[0] == '\\' or+ (path.len >= 2 and std.ascii.isAlphabetic(path[0]) and path[1] == ':'));+}+/// The escaping path a token carries, or null if it stays in cwd. Mirrors/// escapesCwd's token classification exactly so cwd tokens are skipped.pub fn flaggedPath(tok: []const u8) ?[]const u8 {- if (tok.len == 0) return null;- if (tok[0] == '/' or tok[0] == '~') return tok;- if (std.mem.indexOf(u8, tok, "=/")) |i| return tok[i + 1 ..];- if (std.mem.indexOf(u8, tok, "=~")) |i| return tok[i + 1 ..];- var pit = std.mem.tokenizeScalar(u8, tok, '/');+ if (outsidePrefix(tok)) return tok;+ var from: usize = 0;+ while (std.mem.indexOfScalarPos(u8, tok, from, '=')) |i| {+ if (outsidePrefix(tok[i + 1 ..])) return tok[i + 1 ..];+ from = i + 1;+ }+ var pit = std.mem.tokenizeAny(u8, tok, "/\\");while (pit.next()) |comp| if (std.mem.eql(u8, comp, "..")) return tok;return null;}@@ -116,11 +117,11 @@ pub fn flaggedPath(tok: []const u8) ?[]const u8 {/// True if `path` sits at or under one approved root (with a '/' boundary)./// Any `..` component fails outright — blocks `<root>/../../etc` smuggling.pub fn pathUnderRoots(path: []const u8, roots: []const []const u8) bool {- var pit = std.mem.tokenizeScalar(u8, path, '/');+ var pit = std.mem.tokenizeAny(u8, path, "/\\");while (pit.next()) |comp| if (std.mem.eql(u8, comp, "..")) return false;for (roots) |root| {if (root.len == 0 or !std.mem.startsWith(u8, path, root)) continue;- if (path.len == root.len or path[root.len] == '/') return true;+ if (path.len == root.len or path[root.len] == '/' or path[root.len] == '\\') return true;}return false;}@@ -259,6 +260,11 @@ test "escapesCwd: flags tokens that point outside the working directory" {try std.testing.expect(escapesCwd("grep foo a/../../b"));try std.testing.expect(escapesCwd("prog --file=/abs/path"));try std.testing.expect(escapesCwd("prog --file=~/x"));+ try std.testing.expect(escapesCwd("prog --file=x=/abs/path"));+ try std.testing.expect(escapesCwd("cat C:\\outside\\file"));+ try std.testing.expect(escapesCwd("cat \\\\server\\share\\file"));+ try std.testing.expect(escapesCwd("cat a\\..\\outside"));+ try std.testing.expect(escapesCwd("prog --file=C:/outside"));}test "readOnlyAllowed: only simple, in-cwd, seed-listed commands pass in plan mode" {@@ -281,6 +287,8 @@ test "readOnlyExternal: read-only verb reading outside cwd, simple only (#64)" {try std.testing.expect(!readOnlyExternal("rm -rf /x")); // mutating verbtry std.testing.expect(!readOnlyExternal("zig fmt /x.zig")); // not read-only-seededtry std.testing.expect(!readOnlyExternal("ls /x; rm y")); // not simple+ try std.testing.expect(readOnlyExternal("cat C:\\outside\\file"));+ try std.testing.expect(!readOnlyAllowed("cat C:\\outside\\file"));}test "planReadMatch: reads under an approved root pass; escapes/mutations/smuggling do not (#64)" {@@ -296,6 +304,10 @@ test "planReadMatch: reads under an approved root pass; escapes/mutations/smuggltry std.testing.expect(!planReadMatch("rm -rf ~/projects/merjs", r)); // mutating verbtry std.testing.expect(!planReadMatch("ls ~/projects/merjs; rm x", r)); // metachartry std.testing.expect(!planReadMatch("ls ~/projects/merjs", &.{})); // nothing approved+ const windows_roots: []const []const u8 = &.{"C:\\safe"};+ try std.testing.expect(planReadMatch("cat C:\\safe\\proof.txt", windows_roots));+ try std.testing.expect(!planReadMatch("cat C:\\safe\\..\\secret.txt", windows_roots));+ try std.testing.expect(!planReadMatch("cat C:\\safely\\proof.txt", windows_roots));}test "isInterpreter: flags first words that grant arbitrary code execution" {diff --git a/src/pr_local_checks.zig b/src/pr_local_checks.zigindex 3cc2ff4c..c55f4c48 100644--- a/src/pr_local_checks.zig+++ b/src/pr_local_checks.zig@@ -247,10 +247,11 @@ test "publication receipts record successful shell checks at the observed Git hetry std.testing.expectEqualStrings(head, receipt.head_after);try std.testing.expectEqualStrings("rendered dimensions passed", receipt.output);try std.testing.expect(receipt.tracked_tree_clean_after and receipt.completed and !receipt.failed);+ const repository = try repositoryRoot(&root, cwd);try record(&root, call, .{ .text = "FAIL", .is_error = true });- try std.testing.expect(root.publication_checks.unresolved(cwd) != null);+ try std.testing.expect(root.publication_checks.unresolved(repository) != null);try record(&root, call, .{ .text = "passed", .is_error = false });- try std.testing.expect(root.publication_checks.unresolved(cwd) == null);+ try std.testing.expect(root.publication_checks.unresolved(repository) == null);const output = try std.json.parseFromSliceLeaky(std.json.Value, a, "{\"action\":\"output\",\"command\":\"node scripts/test-motion.mjs\"}", .{});try record(&root, .{ .id = "poll", .name = "shell", .input = output }, .{ .text = "passed", .is_error = false });try std.testing.expectEqual(@as(usize, 3), root.publication_checks.recent.items.len);diff --git a/src/rlm_order_tests.zig b/src/rlm_order_tests.zigindex aa1bfe2a..5e1888e3 100644--- a/src/rlm_order_tests.zig+++ b/src/rlm_order_tests.zig@@ -36,10 +36,14 @@ const Fixture = struct {test "rlm order applies native edit before dependent verification" {var f = try Fixture.init();defer f.deinit();- const out = try f.run("e = edit_file(path=\"target.txt\", old_string=\"old\", new_string=\"new\")\nv = bash(\"test $(cat target.txt) = new && printf VERIFIED\")\nprint(v)");+ const code = if (@import("builtin").os.tag == .windows)+ "e = edit_file(path=\"target.txt\", old_string=\"old\", new_string=\"new\")\nv = bash(\"findstr /x new target.txt >nul && echo VERIFIED\")\nprint(v)"+ else+ "e = edit_file(path=\"target.txt\", old_string=\"old\", new_string=\"new\")\nv = bash(\"test $(cat target.txt) = new && printf VERIFIED\")\nprint(v)";+ const out = try f.run(code);defer gpa.free(out.text);try std.testing.expect(!out.is_error and !out.pending);- try std.testing.expectEqualStrings("VERIFIED", out.text);+ try std.testing.expectEqualStrings("VERIFIED", std.mem.trim(u8, out.text, " \r\n"));}test "rlm order failed edit prevents following verification side effects" {@@ -63,7 +67,11 @@ test "rlm order repeated mutations execute twice and post mutation read is freshtest "rlm order nested failed host prevents later mutation" {var f = try Fixture.init();defer f.deinit();- const out = try f.run("print(bash(\"printf FAILED; exit 7\"), write_file(path=\"marker\", content=\"ran\"))");+ const code = if (@import("builtin").os.tag == .windows)+ "print(bash(\"echo FAILED & exit /b 7\"), write_file(path=\"marker\", content=\"ran\"))"+ else+ "print(bash(\"printf FAILED; exit 7\"), write_file(path=\"marker\", content=\"ran\"))";+ const out = try f.run(code);defer gpa.free(out.text);try std.testing.expect(out.is_error);try std.testing.expect(std.mem.indexOf(u8, out.text, "FAILED") != null);