summaryrefslogtreecommitdiff
path: root/test/snapshot.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 15:57:57 -0300
committerGabriel Schneider <[email protected]>2026-10-30 16:29:54 -0300
commitd667965902512147f976fbbf89cb1ee77d0a37d0 (patch)
treef5f9ed32160edaf7e1db23a0b805253206f54cfb /test/snapshot.zig
parentd0ed8056ba90a12fa3bc40ccd8642ec4ae8d9cc0 (diff)
downloadpardes-d667965902512147f976fbbf89cb1ee77d0a37d0.tar.gz
pardes-d667965902512147f976fbbf89cb1ee77d0a37d0.zip
test/cross_replay.py: a session that meets the host's failures (a Look of a fifo and of a directory, a Save into a file, a Restore of no dump, a stat and a read under /os) recorded by one build of pardes and replayed by others, its errors by name in the tape; --record and --replay alone, for the box; pardes-snap --replay-with (zig build replay -Dreplay-with=<pardes-gui>) replays every script's tape with another build too, whose replica that draws nothing must agree (a replica client draws none of its session's frames)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/snapshot.zig')
-rw-r--r--test/snapshot.zig27
1 files changed, 24 insertions, 3 deletions
diff --git a/test/snapshot.zig b/test/snapshot.zig
index 030733d0..1bd4dabf 100644
--- a/test/snapshot.zig
+++ b/test/snapshot.zig
@@ -94,6 +94,10 @@ var record_dir: ?[]const u8 = null;
/// --tape=DIR: each session records its tape there (PARDES_RECORD, src/tape.zig)
/// and the script fails unless every tape replays without diverging.
var tape_dir: ?[]const u8 = null;
+/// --replay-with=EXE (with --tape): each tape replayed by that build of
+/// pardes too, a window's build replaying a terminal's sessions (a replica
+/// of another build reads them so: docs/next-daemon.md).
+var replay_with: ?[:0]const u8 = null;
/// --dump (with --tape): each replay also loads the session's dump at its
/// end, which must be the same session and dump to the same bytes
/// (PARDES_REPLAY_DUMP, src/tape.zig).
@@ -139,6 +143,8 @@ pub fn main(init: std.process.Init) !void {
tape_dir = try absPath(arena, orig_cwd, a["--tape=".len..]);
} else if (std.mem.eql(u8, a, "--dump")) {
dump_check = true;
+ } else if (std.mem.startsWith(u8, a, "--replay-with=")) {
+ replay_with = try arena.dupeSentinel(u8, try absPath(arena, orig_cwd, a["--replay-with=".len..]), 0);
} else if (std.mem.startsWith(u8, a, "--jobs=")) {
jobs = @max(1, try std.fmt.parseInt(usize, a["--jobs=".len..], 10));
} else if (exe == null) {
@@ -166,6 +172,7 @@ pub fn main(init: std.process.Init) !void {
std.mem.startsWith(u8, a, "--record=") or
std.mem.startsWith(u8, a, "--tape=") or
std.mem.eql(u8, a, "--dump") or
+ std.mem.startsWith(u8, a, "--replay-with=") or
std.mem.startsWith(u8, a, "--jobs=")) continue;
if (!saw_exe) {
saw_exe = true;
@@ -521,8 +528,18 @@ fn runOne(arena: std.mem.Allocator, exe_z: [:0]const u8, script_path: []const u8
}
/// Every tape the script's sessions wrote, replayed by the same build
-/// (PARDES_REPLAY): why the first that diverged did, or null.
+/// (PARDES_REPLAY), and by --replay-with's: why the first that diverged
+/// did, or null. Another build's replay need agree only in its replica that
+/// draws nothing, as a replica client draws none of its session's frames:
+/// the two that draw meet a window's drawing where the session had a
+/// terminal's.
fn replayTapes(arena: std.mem.Allocator, exe_z: [:0]const u8, stem: []const u8) ?[]const u8 {
+ if (replayTapesWith(arena, exe_z, stem, false)) |why| return why;
+ const other = replay_with orelse return null;
+ return replayTapesWith(arena, other, stem, true);
+}
+
+fn replayTapesWith(arena: std.mem.Allocator, exe_z: [:0]const u8, stem: []const u8, headless: bool) ?[]const u8 {
const dir = tape_dir.?;
const io = std.Io.Threaded.global_single_threaded.io();
var d = std.Io.Dir.cwd().openDir(io, dir, .{ .iterate = true }) catch return "the tape directory cannot be read";
@@ -534,10 +551,14 @@ fn replayTapes(arena: std.mem.Allocator, exe_z: [:0]const u8, stem: []const u8)
const pid = entry.name[stem.len..][0 .. entry.name.len - stem.len - ".tape".len];
if (pid.len < 2 or pid[0] != '-' or std.mem.indexOfNone(u8, pid[1..], "0123456789") != null) continue;
tapes += 1;
- const cmd = std.fmt.allocPrintSentinel(arena, "PARDES_RECORD= PARDES_REPLAY='{s}/{s}' {s}timeout 300 '{s}' > '{s}/{s}.replay' 2>&1", .{ dir, entry.name, if (dump_check) "PARDES_REPLAY_DUMP=1 " else "", exe_z, dir, entry.name }, 0) catch return "out of memory";
+ const cmd = std.fmt.allocPrintSentinel(arena, "PARDES_RECORD= PARDES_REPLAY='{s}/{s}' {s}timeout 300 '{s}' > '{s}/{s}.replay' 2>&1", .{ dir, entry.name, if (dump_check and !headless) "PARDES_REPLAY_DUMP=1 " else "", exe_z, dir, entry.name }, 0) catch return "out of memory";
if (system(cmd) != 0) {
const why_path = std.fmt.allocPrint(arena, "{s}/{s}.replay", .{ dir, entry.name }) catch return "out of memory";
- return readFileAlloc(arena, why_path) catch "the replay failed and said nothing";
+ const said = readFileAlloc(arena, why_path) catch return "the replay failed and said 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;
+ };
+ return said;
}
}
if (tapes == 0) return "no session wrote a tape";