Skip to content

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

Python

fix(tui): use Zig 0.17 Io writeFile in #577 tests

Cursor Agent9ec3352bbb81
diff --git a/TUI/image.zig b/TUI/image.zig
index 3c474b84..26ca0351 100644
--- a/TUI/image.zig
+++ b/TUI/image.zig
@@ -504,9 +504,12 @@ test "pathBacked is true only when the file is there (#577)" {
try std.testing.expect(!pathBacked("/no/such/image-577.png"));
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(.{ .sub_path = "y.png", .data = "y" });
+ const io = std.testing.io;
+ try tmp.dir.writeFile(io, .{ .sub_path = "y.png", .data = "y" });
+ var dir_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const dir_n = try tmp.dir.realPath(io, &dir_buf);
var buf: [std.fs.max_path_bytes]u8 = undefined;
- const live = try tmp.dir.realpath("y.png", &buf);
+ const live = try std.fmt.bufPrint(&buf, "{s}/y.png", .{dir_buf[0..dir_n]});
try std.testing.expect(pathBacked(live));
}
diff --git a/TUI/keys_tests.zig b/TUI/keys_tests.zig
index 98a6573a..b8d2c447 100644
--- a/TUI/keys_tests.zig
+++ b/TUI/keys_tests.zig
@@ -318,9 +318,12 @@ test "Ctrl+R walks prompt history" {
test "Ctrl+R after an image prompt restores the attachment (#577)" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(.{ .sub_path = "shot.png", .data = "png" });
+ const io = std.testing.io;
+ try tmp.dir.writeFile(io, .{ .sub_path = "shot.png", .data = "png" });
+ var dir_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const dir_n = try tmp.dir.realPath(io, &dir_buf);
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
- const live = try tmp.dir.realpath("shot.png", &path_buf);
+ const live = try std.fmt.bufPrint(&path_buf, "{s}/shot.png", .{dir_buf[0..dir_n]});
var m: Model = undefined;
m.setup(std.testing.allocator);
diff --git a/TUI/markdown_tests.zig b/TUI/markdown_tests.zig
index 3ae7fafb..e3e4d981 100644
--- a/TUI/markdown_tests.zig
+++ b/TUI/markdown_tests.zig
@@ -111,9 +111,12 @@ test "no code background leaks past a closed fence or off the last fence row" {
test "renderUser chips @[path] and paints slash commands" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(.{ .sub_path = "a.png", .data = "png" });
+ const io = std.testing.io;
+ try tmp.dir.writeFile(io, .{ .sub_path = "a.png", .data = "png" });
+ var dir_buf: [std.fs.max_path_bytes]u8 = undefined;
+ const dir_n = try tmp.dir.realPath(io, &dir_buf);
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
- const live = try tmp.dir.realpath("a.png", &path_buf);
+ const live = try std.fmt.bufPrint(&path_buf, "{s}/a.png", .{dir_buf[0..dir_n]});
const src = try std.fmt.allocPrint(std.testing.allocator, "@[{s}] /goal look at this", .{live});
defer std.testing.allocator.free(src);
const text = try renderUser(std.testing.allocator, src, theme_mod.emerald, theme_mod.zinc200);
diff --git a/TUI/prompt_history.zig b/TUI/prompt_history.zig
index 17315aae..3be85366 100644
--- a/TUI/prompt_history.zig
+++ b/TUI/prompt_history.zig
@@ -117,12 +117,21 @@ fn freePaths(self: *Model, paths: []const []const u8) void {
if (paths.len > 0) self.alloc.free(paths);
}
+fn writeTmp(tmp: anytype, name: []const u8, data: []const u8, buf: []u8) ![]const u8 {
+ const io = std.testing.io;
+ try tmp.dir.writeFile(io, .{ .sub_path = name, .data = data });
+ const n = try tmp.dir.realPath(io, buf);
+ if (n + 1 + name.len > buf.len) return error.NameTooLong;
+ buf[n] = '/';
+ @memcpy(buf[n + 1 ..][0..name.len], name);
+ return buf[0 .. n + 1 + name.len];
+}
+
test "remember + recall restores backed image paths and drops missing ones" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(.{ .sub_path = "shot.png", .data = "png" });
var path_buf: [std.fs.max_path_bytes]u8 = undefined;
- const live = try tmp.dir.realpath("shot.png", &path_buf);
+ const live = try writeTmp(&tmp, "shot.png", "png", &path_buf);
var m: Model = undefined;
m.setup(std.testing.allocator);
@@ -146,12 +155,10 @@ test "remember + recall restores backed image paths and drops missing ones" {
test "down past newest restores the draft and its attachments" {
var tmp = std.testing.tmpDir(.{});
defer tmp.cleanup();
- try tmp.dir.writeFile(.{ .sub_path = "a.png", .data = "a" });
- try tmp.dir.writeFile(.{ .sub_path = "b.png", .data = "b" });
var a_buf: [std.fs.max_path_bytes]u8 = undefined;
var b_buf: [std.fs.max_path_bytes]u8 = undefined;
- const older = try tmp.dir.realpath("a.png", &a_buf);
- const draft_path = try tmp.dir.realpath("b.png", &b_buf);
+ const older = try writeTmp(&tmp, "a.png", "a", &a_buf);
+ const draft_path = try writeTmp(&tmp, "b.png", "b", &b_buf);
var m: Model = undefined;
m.setup(std.testing.allocator);