From 174e031985db910b4907ba324d6fd12c67898a5a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sun, 8 Nov 2026 23:49:04 -0300 Subject: tests: monkey and replay are modes of the T1 runner and snapshot.zig goes: behaviour-test runs test/monkey9p.zig bare (its smoke), `-- --monkey ` drives an in-process session with test/monkey.zig's input (keys, leader bursts, the mouse, tiny resizes, over /kbdin, /mousein and Session.resize) hunting panics and hangs, `-- --replay` records each seed's sessions as a tape in memory and replays it (tape.replayBytes, replayMain's loop: three replicas and the dump), and `process-test -- --replay` records and replays the tty cases' real sessions as `zig build replay` did (with the addons it lacked, so images passes); the snap, snap-driver-test, monkey, monkey-test (it no longer compiled), replay and monkey-session steps, pardes-snap and build/snap.zig (now build/process.zig) go; checked: a counter outside the core bumped at the 40th update diverges every T1 seed and 89 of 103 old tapes, one bumped on terminal output diverges no T1 seed but 69 tty cases and 70 old tapes (why the tty replay stays), a panic on a window under 5x5 is found by the T1 monkey (seeds 1 8 17 20) and the old one (seed 13) Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/tty.zig | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'test/tty.zig') diff --git a/test/tty.zig b/test/tty.zig index d139cb6a..2fdf5952 100644 --- a/test/tty.zig +++ b/test/tty.zig @@ -45,6 +45,16 @@ pub var goldens: []const u8 = "test/snapshots"; /// The deterministic mock language server `.rs` files speak to /// (`--lspmock=`); empty leaves every language client off. pub var lspmock: []const u8 = ""; +/// `--replay`: every session a case starts records its tape +/// (PARDES_RECORD, src/tape.zig), and the case fails unless each replays +/// (PARDES_REPLAY) into its three replicas, the session's dump at its end +/// loaded to its digest: what a real session's host answered (its shells, +/// ptys and files) replayed, as the T1 runner's `--replay` replays an +/// in-process session's. `replay_with`, another build of pardes (a +/// window's), replays each tape too, agreeing in the replica that draws +/// nothing, as a replica client draws none of its session's frames. +pub var replay = false; +pub var replay_with: ?[]const u8 = null; const base_dir = "/tmp/pardes-snap"; const gpa = std.heap.page_allocator; @@ -119,6 +129,10 @@ pub const Tty = struct { for ([_][*:0]const u8{ "PARDES_LSP_C", "PARDES_LSP_GO", "PARDES_LSP_TS", "PARDES_LSP_PY" }) |v| _ = setenv(v, "", 1); const dump = try std.fmt.allocPrintSentinel(arena, "{s}/dump.zon", .{base}, 0); _ = setenv("PARDES_DUMP", dump, 1); + if (replay) { + try mkdir(arena, try std.fmt.allocPrint(arena, "{s}/tapes", .{base}), false); + _ = setenv("PARDES_RECORD", try std.fmt.allocPrintSentinel(arena, "{s}/tapes/s-", .{base}, 0), 1); + } if (libc.chdir(try arena.dupeSentinel(u8, work, 0)) < 0) return error.ChdirFailed; return .{ .arena = arena, .exe = exe, .name = name, .base = base, .config_home = config_home, .dump = dump }; } @@ -129,6 +143,13 @@ pub const Tty = struct { /// The captures against the golden, or written to it under `--update`. pub fn done(t: *Tty) !void { + if (replay) { + // The session over first: its tape is whole. + if (t.h) |*h| h.deinit(); + t.h = null; + try t.replayTapes(t.exe, false); + if (replay_with) |other| try t.replayTapes(other, true); + } const path = try std.fmt.allocPrint(t.arena, "{s}/{s}.golden", .{ goldens, t.name }); if (update) return eh.writeFile(try t.arena.dupeSentinel(u8, path, 0), t.out.items); const want = readFileAlloc(t.arena, path) catch ""; @@ -140,6 +161,30 @@ pub const Tty = struct { return error.GoldenMismatch; } + /// Each tape the case's sessions wrote, replayed by `exe`. + fn replayTapes(t: *Tty, exe: []const u8, headless: bool) !void { + const tapes_dir = try std.fmt.allocPrint(t.arena, "{s}/tapes", .{t.base}); + const io = std.Io.Threaded.global_single_threaded.io(); + var d = try std.Io.Dir.cwd().openDir(io, tapes_dir, .{ .iterate = true }); + defer d.close(io); + var it = d.iterate(); + var tapes: usize = 0; + while (try it.next(io)) |entry| { + if (!std.mem.endsWith(u8, entry.name, ".tape")) continue; + tapes += 1; + const cmd = try std.fmt.allocPrintSentinel(t.arena, "PARDES_RECORD= PARDES_REPLAY='{s}/{s}' {s}timeout 300 '{s}' > '{s}/{s}.replay' 2>&1", .{ tapes_dir, entry.name, if (headless) "" else "PARDES_REPLAY_DUMP=1 ", exe, tapes_dir, entry.name }, 0); + if (system(cmd) == 0) continue; + const said = readFileAlloc(t.arena, try std.fmt.allocPrint(t.arena, "{s}/{s}.replay", .{ tapes_dir, entry.name })) catch ""; + // Another build's replay need agree only in the replica that draws nothing. + if (headless) if (std.mem.indexOf(u8, said, ": headless replica: ")) |at| { + if (std.mem.startsWith(u8, std.mem.trimStart(u8, said[at + ": headless replica: ".len ..], "0123456789"), " digests agree")) continue; + }; + std.debug.print(" {s}: its tape {s} did not replay:\n{s}", .{ t.name, entry.name, said }); + return error.Diverged; + } + if (tapes == 0) return error.NoTape; + } + /// A setting appended to the startup config the fake home has, so a /// case can pin one instead of spelling out what a default implies. /// Before `start`. -- cgit v1.3