Skip to content

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

Python

Tests: spill needle sits in the elided middle; ACP view paths per platform

Rach Pradhan2af92e77f520
diff --git a/scripts/test-spill-artifact.py b/scripts/test-spill-artifact.py
index 3eb854ab..38f91b7e 100755
--- a/scripts/test-spill-artifact.py
+++ b/scripts/test-spill-artifact.py
@@ -66,9 +66,9 @@ class SpillModel(ScriptedModel):
return {"text": "no marker in the history"}
self.cited = (int(found.group(1)), found.group(2))
return {"tool": "bash", "arguments": {
- "command": f"tail -c 120 {shlex.quote(found.group(2))}",
+ "command": f"grep -o {NEEDLE} {shlex.quote(found.group(2))}",
}}
- return {"text": "recovered the tail from the artifact"}
+ return {"text": "recovered the elided bytes from the artifact"}
def seed_session(workspace: pathlib.Path, output: str) -> None:
@@ -128,10 +128,13 @@ def main() -> None:
if not os.access(graff, os.X_OK):
sys.exit(f"test-spill-artifact: not an executable: {graff}")
- # A padded output whose needle sits well past the cap, so nothing but the
- # artifact can still produce it.
+ # A padded output whose needle sits in the middle, the part the cap elides
+ # (head and tail are kept, #1271), so nothing but the artifact can still
+ # produce it.
pad = "build step ok\n"
- output = (pad * (OUTPUT_BYTES // len(pad) + 2))[: OUTPUT_BYTES - len(NEEDLE) - 1] + NEEDLE + "\n"
+ body = (pad * (OUTPUT_BYTES // len(pad) + 2))[: OUTPUT_BYTES - len(NEEDLE) - 1]
+ half = len(body) // 2
+ output = body[:half] + NEEDLE + "\n" + body[half:]
assert len(output) == OUTPUT_BYTES, len(output)
failures: list[str] = []
diff --git a/src/acp_tool_view.zig b/src/acp_tool_view.zig
index 691e4cd9..feaa0709 100644
--- a/src/acp_tool_view.zig
+++ b/src/acp_tool_view.zig
@@ -62,18 +62,23 @@ pub fn diffs(arena: Allocator, name: []const u8, input: Value, cwd: []const u8)
return .{ .array = out };
}
+/// An absolute working directory on the host platform.
+const test_cwd = if (@import("builtin").os.tag == .windows) "C:\\repo" else "/repo";
+
test "locations: file tools name an absolute path and optional line; others none" {
var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
defer arena_state.deinit();
const a = arena_state.allocator();
const read = try std.json.parseFromSliceLeaky(Value, a, "{\"path\":\"src/x.zig\",\"start_line\":40}", .{});
- const locs = try locations(a, "read", read, "/repo");
+ const locs = try locations(a, "read", read, test_cwd);
try std.testing.expectEqual(@as(usize, 1), locs.array.items.len);
- try std.testing.expectEqualStrings("/repo/src/x.zig", locs.array.items[0].object.get("path").?.string);
+ try std.testing.expectEqualStrings(try std.fs.path.join(a, &.{ test_cwd, "src/x.zig" }), locs.array.items[0].object.get("path").?.string);
try std.testing.expectEqual(@as(i64, 40), locs.array.items[0].object.get("line").?.integer);
- const abs = try std.json.parseFromSliceLeaky(Value, a, "{\"path\":\"/etc/hosts\"}", .{});
- try std.testing.expectEqualStrings("/etc/hosts", (try locations(a, "edit", abs, "/repo")).array.items[0].object.get("path").?.string);
- try std.testing.expectEqual(@as(usize, 0), (try locations(a, "execute", read, "/repo")).array.items.len);
+ const abs_path = try std.fs.path.join(a, &.{ test_cwd, "hosts" });
+ var abs_obj: std.json.ObjectMap = .empty;
+ try abs_obj.put(a, "path", .{ .string = abs_path });
+ try std.testing.expectEqualStrings(abs_path, (try locations(a, "edit", .{ .object = abs_obj }, "/elsewhere")).array.items[0].object.get("path").?.string);
+ try std.testing.expectEqual(@as(usize, 0), (try locations(a, "execute", read, test_cwd)).array.items.len);
}
test "diffs: edit_file single and batch spans, write_file as new content, nothing else" {
@@ -81,16 +86,16 @@ test "diffs: edit_file single and batch spans, write_file as new content, nothin
defer arena_state.deinit();
const a = arena_state.allocator();
const single = try std.json.parseFromSliceLeaky(Value, a, "{\"path\":\"calc.py\",\"old_string\":\"a - b\",\"new_string\":\"a + b\"}", .{});
- const one = try diffs(a, "edit_file", single, "/repo");
+ const one = try diffs(a, "edit_file", single, test_cwd);
try std.testing.expectEqual(@as(usize, 1), one.array.items.len);
try std.testing.expectEqualStrings("diff", one.array.items[0].object.get("type").?.string);
- try std.testing.expectEqualStrings("/repo/calc.py", one.array.items[0].object.get("path").?.string);
+ try std.testing.expectEqualStrings(try std.fs.path.join(a, &.{ test_cwd, "calc.py" }), one.array.items[0].object.get("path").?.string);
try std.testing.expectEqualStrings("a - b", one.array.items[0].object.get("oldText").?.string);
try std.testing.expectEqualStrings("a + b", one.array.items[0].object.get("newText").?.string);
const batch = try std.json.parseFromSliceLeaky(Value, a, "{\"path\":\"f\",\"edits\":[{\"old_string\":\"1\",\"new_string\":\"2\"},{\"old_string\":\"3\",\"new_string\":\"4\"}]}", .{});
- try std.testing.expectEqual(@as(usize, 2), (try diffs(a, "edit_file", batch, "/repo")).array.items.len);
+ try std.testing.expectEqual(@as(usize, 2), (try diffs(a, "edit_file", batch, test_cwd)).array.items.len);
const write = try std.json.parseFromSliceLeaky(Value, a, "{\"path\":\"new.txt\",\"content\":\"hi\"}", .{});
- const created = try diffs(a, "write_file", write, "/repo");
+ const created = try diffs(a, "write_file", write, test_cwd);
try std.testing.expect(created.array.items[0].object.get("oldText").? == .null);
- try std.testing.expectEqual(@as(usize, 0), (try diffs(a, "read_file", single, "/repo")).array.items.len);
+ try std.testing.expectEqual(@as(usize, 0), (try diffs(a, "read_file", single, test_cwd)).array.items.len);
}