Skip to content

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

Python

Repair inherited Windows and fallback CI failures

justrachb6e78d878187
diff --git a/scripts/test-model-preference.py b/scripts/test-model-preference.py
index 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/src/cache_affinity.zig b/src/cache_affinity.zig
index b9afd654..dd272a5b 100644
--- a/src/cache_affinity.zig
+++ b/src/cache_affinity.zig
@@ -269,10 +269,13 @@ test "affinity: real linked worktrees share primary checkout key without merging
try std.testing.expectEqualStrings(sibling, gitRootOf(io, sibling, &checkout_buf).?);
try expectStableRequests(&primary_key, &sibling_key);
// 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));
+ // Windows marks Git-owned worktree pointers read-only, so do not overwrite one there.
+ if (@import("builtin").os.tag != .windows) {
+ 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));
+ }
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.zig
index 74da46ee..e0f2cdac 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;
}
@@ -103,12 +96,19 @@ pub fn readOnlyExternal(cmd: []const u8) bool {
/// The escaping path a token carries, or null if it stays in cwd. Mirrors
/// escapesCwd's token classification exactly so cwd tokens are skipped.
+fn windowsAbsolute(path: []const u8) bool {
+ return path.len >= 3 and std.ascii.isAlphabetic(path[0]) and path[1] == ':' and
+ (path[2] == '/' or path[2] == '\\');
+}
+
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 (tok[0] == '/' or tok[0] == '~' or tok[0] == '\\' or windowsAbsolute(tok)) return tok;
+ if (std.mem.indexOfScalar(u8, tok, '=')) |i| {
+ const value = tok[i + 1 ..];
+ if (value.len > 0 and (value[0] == '/' or value[0] == '~' or value[0] == '\\' or windowsAbsolute(value))) return value;
+ }
+ var pit = std.mem.tokenizeAny(u8, tok, "/\\");
while (pit.next()) |comp| if (std.mem.eql(u8, comp, "..")) return tok;
return null;
}
@@ -116,11 +116,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;
}
@@ -277,6 +277,8 @@ test "readOnlyAllowed: only simple, in-cwd, seed-listed commands pass in plan mo
test "readOnlyExternal: read-only verb reading outside cwd, simple only (#64)" {
try std.testing.expect(readOnlyExternal("ls ~/projects/merjs"));
try std.testing.expect(readOnlyExternal("cat /abs/file"));
+ try std.testing.expect(readOnlyExternal("cat C:\\repo\\proof.txt"));
+ try std.testing.expect(!readOnlyAllowed("cat C:\\repo\\proof.txt"));
try std.testing.expect(!readOnlyExternal("cat src/main.zig")); // in cwd
try std.testing.expect(!readOnlyExternal("rm -rf /x")); // mutating verb
try std.testing.expect(!readOnlyExternal("zig fmt /x.zig")); // not read-only-seeded
@@ -286,6 +288,10 @@ test "readOnlyExternal: read-only verb reading outside cwd, simple only (#64)" {
test "planReadMatch: reads under an approved root pass; escapes/mutations/smuggling do not (#64)" {
const r: []const []const u8 = &.{ "~/projects/merjs", "/opt/data" };
try std.testing.expect(planReadMatch("ls ~/projects/merjs", r));
+ const windows_roots: []const []const u8 = &.{"C:\\repo"};
+ try std.testing.expect(planReadMatch("cat C:\\repo\\proof.txt", windows_roots));
+ try std.testing.expect(!planReadMatch("cat C:\\repo-other\\proof.txt", windows_roots));
+ try std.testing.expect(!planReadMatch("cat C:\\repo\\..\\secret.txt", windows_roots));
try std.testing.expect(planReadMatch("ls ~/projects/merjs/src", r));
try std.testing.expect(planReadMatch("cat ~/projects/merjs/README.md", r));
try std.testing.expect(planReadMatch("grep foo /opt/data/x.txt", r));
diff --git a/src/list_dir.zig b/src/list_dir.zig
index f7b569ea..c94cee33 100644
--- a/src/list_dir.zig
+++ b/src/list_dir.zig
@@ -121,7 +121,8 @@ fn fill(w: *Walk, node: *Node, rel: []const u8) !void {
if (dir.openFile(w.io, ".gitignore", .{ .follow_symlinks = false })) |file| {
defer file.close(w.io);
if ((try file.stat(w.io)).kind == .file) {
- var reader = file.reader(w.io, &.{});
+ var buffer: [4096]u8 = undefined;
+ var reader = file.readerStreaming(w.io, &buffer);
const text = try reader.interface.allocRemaining(w.arena, .limited(64 * 1024));
const extra = try gitignore.parse(w.arena, text, abs);
try w.rules.appendSlice(w.arena, extra);
diff --git a/src/pr_local_checks.zig b/src/pr_local_checks.zig
index 3cc2ff4c..3142b2bb 100644
--- a/src/pr_local_checks.zig
+++ b/src/pr_local_checks.zig
@@ -58,7 +58,12 @@ pub fn isCheck(command: []const u8) bool {
pub fn repositoryRoot(root: anytype, cwd: []const u8) ![]const u8 {
const ev = @import("pr_evidence.zig");
const found = ev.capture(root.gpa, root.io, root.arena, .{ .cwd = cwd, .selector = "" }, &.{ "git", "rev-parse", "--show-toplevel" }) catch return cwd;
- return if (std.fs.path.isAbsolute(found)) found else cwd;
+ if (!std.fs.path.isAbsolute(found)) return cwd;
+ var dir = std.Io.Dir.cwd().openDir(root.io, found, .{}) catch return cwd;
+ defer dir.close(root.io);
+ var path: [std.fs.max_path_bytes]u8 = undefined;
+ const len = dir.realPath(root.io, &path) catch return cwd;
+ return root.arena.dupe(u8, path[0..len]);
}
pub fn record(root: anytype, call: ToolCall, result: ExecResult) !void {
diff --git a/src/rlm_order_tests.zig b/src/rlm_order_tests.zig
index aa1bfe2a..e95568b0 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(\"type target.txt\")\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(if (@import("builtin").os.tag == .windows) "new" else "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 fresh
test "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);