summaryrefslogtreecommitdiff
path: root/test/monkey.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 11:14:38 -0300
committerGabriel Schneider <[email protected]>2026-10-29 15:57:34 -0300
commita4b85cb7689c111c9f06891164e765a1b49f63c8 (patch)
tree7204b7978312e398ece4312c0ced0776c3296f68 /test/monkey.zig
parent044da0f75ab5fb5be0213e512741860d95dad8e5 (diff)
downloadpardes-a4b85cb7689c111c9f06891164e765a1b49f63c8.tar.gz
pardes-a4b85cb7689c111c9f06891164e765a1b49f63c8.zip
replay gate: pardes-snap --tape and pardes-monkey --tape record every session's tape and fail a script whose tapes do not replay; `zig build replay`
pardes-snap --tape=DIR sets PARDES_RECORD for each script (each session, a nested pardes's too, writes DIR/<stem>-<pid>.tape) and, once the script has run and its goldens compared, replays every tape with the same build (PARDES_REPLAY): a divergence, or no tape at all, fails the script as DIVERGED with the replay's words. pardes-monkey --tape=DIR passes it on and counts a divergence as a hit. `zig build replay -Dplatform=tty [-Dreplay-seeds=N]` runs every snapshot script, then N monkey seeds of 70 steps (default 20), tapes under .zig-cache/tapes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/monkey.zig')
-rw-r--r--test/monkey.zig14
1 files changed, 10 insertions, 4 deletions
diff --git a/test/monkey.zig b/test/monkey.zig
index dcea0b43..7c9761ff 100644
--- a/test/monkey.zig
+++ b/test/monkey.zig
@@ -166,7 +166,7 @@ pub fn main(init: std.process.Init) !void {
const io = init.io;
const args = try init.minimal.args.toSlice(init.arena.allocator());
if (args.len < 4) {
- std.debug.print("usage: pardes-monkey <pardes-snap> <pardes> <seeds> [steps] [--from=N] [--out=DIR]\n", .{});
+ std.debug.print("usage: pardes-monkey <pardes-snap> <pardes> <seeds> [steps] [--from=N] [--out=DIR] [--keep] [--tape=DIR]\n", .{});
std.process.exit(2);
}
const snap = args[1];
@@ -177,12 +177,17 @@ pub fn main(init: std.process.Init) !void {
var out: []const u8 = "/tmp/pardes-monkey";
// Keep every script and capture, not only a hit's: to see what it did.
var keep = false;
+ // --tape=DIR: each seed's sessions record their tapes there and the
+ // seed is a hit if one does not replay (pardes-snap --tape).
+ var tape: ?[]const u8 = null;
var positional: usize = 0;
for (args[3..]) |a| {
if (std.mem.startsWith(u8, a, "--from=")) {
from = try std.fmt.parseInt(u64, a["--from=".len..], 10);
} else if (std.mem.eql(u8, a, "--keep")) {
keep = true;
+ } else if (std.mem.startsWith(u8, a, "--tape=")) {
+ tape = a;
} else if (std.mem.startsWith(u8, a, "--out=")) {
out = a["--out=".len..];
} else {
@@ -204,7 +209,7 @@ pub fn main(init: std.process.Init) !void {
const path = try std.fmt.bufPrint(&path_buf, "{s}/seed-{d}.snap", .{ out, seed });
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = path, .data = script });
const run = std.process.run(gpa, io, .{
- .argv = &.{ snap, app, "--update", "--no-retry", "--jobs=1", path },
+ .argv = if (tape) |t| &.{ snap, app, "--update", "--no-retry", "--jobs=1", t, path } else &.{ snap, app, "--update", "--no-retry", "--jobs=1", path },
.stdout_limit = .limited(64 << 20),
.stderr_limit = .limited(64 << 20),
}) catch |err| {
@@ -223,14 +228,15 @@ pub fn main(init: std.process.Init) !void {
const crash_path = try std.fmt.bufPrint(&crash_buf, "/tmp/pardes-snap/seed-{d}/home/.config/pardes/crashes", .{seed});
const crashes = readAll(gpa, io, crash_path);
defer gpa.free(crashes);
- if (crashes.len != 0 or hasTrace(run.stdout) or hasTrace(run.stderr) or hasTrace(golden)) {
+ const diverged = tape != null and (std.mem.indexOf(u8, run.stdout, "DIVERGED") != null or std.mem.indexOf(u8, run.stderr, "DIVERGED") != null);
+ if (crashes.len != 0 or diverged or hasTrace(run.stdout) or hasTrace(run.stderr) or hasTrace(golden)) {
hits += 1;
var log_buf: [4096]u8 = undefined;
const log_path = try std.fmt.bufPrint(&log_buf, "{s}/seed-{d}.log", .{ out, seed });
const both = try std.mem.concat(gpa, u8, &.{ crashes, run.stdout, run.stderr });
defer gpa.free(both);
try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = log_path, .data = both });
- std.debug.print("PANIC seed {d}: {s}\n", .{ seed, path });
+ std.debug.print("{s} seed {d}: {s}\n", .{ if (diverged) "DIVERGED" else "PANIC", seed, path });
} else if (!keep) {
std.Io.Dir.cwd().deleteFile(io, path) catch {};
std.Io.Dir.cwd().deleteFile(io, golden_path) catch {};