From 528a66cc720b25252a497adeb358e729dc8f3a62 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 21:29:23 -0300 Subject: test: the window's own tests in Zig (T4, test/process/window.zig), gui_monkey.py and gui_golden.py gone: the monkey drives the hidden window's own input (Detached.typeKeys into its pty, Detached.mouse's OSC 777 events) with clicks, drags, wheels, hovers and keys, and columns, looks, Joincol, Collapse, Delcol and themes over 9P, then the window must settle, alive, with no crash record (two combinations of 30 steps in process-test, all 40 Motion x Lift x Bloom with zig build monkey-gui -Dplatform=gui); the goldens hash the 17 scenes' frames (Detached.capture, a transition's frame 6 too) against test/gui-goldens.txt, regenerated for the offscreen window and twice reproduced, run when asked (zig build gui-golden -Dplatform=gui, PARDES_GUI_GOLDEN=update); Detached's init file, settle and capture; no Python step left in the build Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/process.zig | 68 ++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 12 deletions(-) (limited to 'test/process.zig') diff --git a/test/process.zig b/test/process.zig index bba795de..00f288a7 100644 --- a/test/process.zig +++ b/test/process.zig @@ -546,6 +546,8 @@ pub const Detached = struct { root: ?[]const u8 = null, /// The name its socket is linked as, when `--9p=` names one. socket: ?[]const u8 = null, + /// Its startup file (`config/pardes/init` in the root), written first. + init: ?[]const u8 = null, }; /// A session of the backend's: `pardes --detach=`, or the window @@ -577,6 +579,13 @@ pub const Detached = struct { errdefer if (d.cap_len > 0) removeDir(d.captures()); const dir = d.root(); var bufs: [6][4096]u8 = undefined; + if (opts.init) |text| { + const cfg = try std.fmt.bufPrintSentinel(&bufs[5], "{s}/config", .{dir}, 0); + _ = libc.mkdir(cfg, 0o755); + const pcfg = try std.fmt.bufPrintSentinel(&bufs[5], "{s}/config/pardes", .{dir}, 0); + _ = libc.mkdir(pcfg, 0o755); + try eh.writeFile(try std.fmt.bufPrintSentinel(&bufs[5], "{s}/config/pardes/init", .{dir}, 0), text); + } const fixture = if (opts.file) |f| try std.fmt.bufPrintSentinel(&bufs[0], "{s}", .{f}, 0) else blk: { const path = try std.fmt.bufPrintSentinel(&bufs[0], "{s}/{s}.txt", .{ dir, name }, 0); try eh.writeFile(path, "initial\n"); @@ -672,12 +681,33 @@ pub const Detached = struct { return d.cap_buf[0..d.cap_len]; } - /// The window's frame once it is idle: a loop step two past the one - /// current when this was asked, nothing owing a frame (gui.zig's - /// writeTestStatus). Every request before this one has been served (a - /// 9P write returns once the core has it), so the frame is the scene's - /// however loaded the machine is. A binary PPM (P6), kept by the caller. + /// The window's frame once it is idle (`settle`): a binary PPM (P6), + /// kept by the caller. pub fn frame(d: *Detached, gpa: std.mem.Allocator) ![]u8 { + return d.capture(gpa, "latest.ppm"); + } + + /// A capture the window wrote (`latest.ppm`, a transition's + /// `transition-.ppm`), once it is there and the window is idle. + pub fn capture(d: *Detached, gpa: std.mem.Allocator, name: []const u8) ![]u8 { + try d.settle(gpa); + var path: [256]u8 = undefined; + const at = try std.fmt.bufPrint(&path, "{s}/{s}", .{ d.captures(), name }); + const deadline = eh.nowMs() + 30_000; + while (eh.nowMs() < deadline) : (sleepMs(20)) { + const got = readWhole(gpa, at) catch continue; + if (std.mem.startsWith(u8, got, "P6")) return got; + gpa.free(got); + } + return error.NoCapture; + } + + /// Until the window is idle: a loop step two past the one current when + /// this was asked, nothing owing a frame (gui.zig's writeTestStatus). + /// Every request before this one has been served (a 9P write returns + /// once the core has it), so what it then shows is the scene's however + /// loaded the machine is. + pub fn settle(d: *Detached, gpa: std.mem.Allocator) !void { if (d.cap_len == 0) return error.NotAWindow; var path: [128]u8 = undefined; const status_path = try std.fmt.bufPrint(&path, "{s}/status", .{d.captures()}); @@ -694,16 +724,25 @@ pub const Detached = struct { first_step = step; continue; }; - if (step >= first + 2 and idle and frames > 0) { - var ppm: [128]u8 = undefined; - const got = try readWhole(gpa, try std.fmt.bufPrint(&ppm, "{s}/latest.ppm", .{d.captures()})); - if (std.mem.startsWith(u8, got, "P6")) return got; - gpa.free(got); - } + if (step >= first + 2 and idle and frames > 0) return; } return error.NeverIdle; } + /// Keys typed at the window as its terminal gives them (its pty). + pub fn typeKeys(d: *Detached, bytes: []const u8) !void { + if (d.cap_len == 0) return error.NotAWindow; + if (libc.write(d.child.master, bytes.ptr, bytes.len) != @as(isize, @intCast(bytes.len))) return error.ShortWrite; + } + + /// A mouse event at window pixels, as the window's test shell takes + /// one (OSC 777): `kind` down, up, motion or wheel; `button` 1 left, + /// 2 middle, 3 right, 0 none, a wheel's amount for wheel. + pub fn mouse(d: *Detached, kind: []const u8, button: i32, x: u32, y: u32) !void { + var buf: [96]u8 = undefined; + try d.typeKeys(try std.fmt.bufPrint(&buf, "\x1b]777;mouse;{s};{d};{d};{d}\x07", .{ kind, button, x, y })); + } + fn removeRoot(d: *Detached) void { var cmd: [4200]u8 = undefined; if (std.fmt.bufPrintSentinel(&cmd, "rm -rf -- '{s}'", .{d.root()}, 0)) |c| { @@ -1055,7 +1094,7 @@ fn removeDir(path: []const u8) void { } else |_| {} } -fn readWhole(gpa: std.mem.Allocator, path: []const u8) ![]u8 { +pub fn readWhole(gpa: std.mem.Allocator, path: []const u8) ![]u8 { var buf: [4096]u8 = undefined; const z = try std.fmt.bufPrintSentinel(&buf, "{s}", .{path}, 0); const fd = libc.open(z, .{}, @as(libc.mode_t, 0)); @@ -1072,3 +1111,8 @@ fn readWhole(gpa: std.mem.Allocator, path: []const u8) ![]u8 { } return out.toOwnedSlice(gpa); } + +/// `data` written to `path` whole (made or truncated). +pub fn writeFile(a: std.mem.Allocator, path: []const u8, data: []const u8) !void { + try eh.writeFile(try std.fmt.allocPrintSentinel(a, "{s}", .{path}, 0), data); +} -- cgit v1.3