summaryrefslogtreecommitdiff
path: root/test/tty.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/tty.zig')
-rw-r--r--test/tty.zig45
1 files changed, 45 insertions, 0 deletions
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`.