summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 17:01:35 -0300
committerGabriel Schneider <[email protected]>2026-10-29 21:13:33 -0300
commit70de5ec5ff3dad01afcc45244ad5e5a481486da6 (patch)
treecd4b723dcc2cfd94c4ba2361c134927b0e2df60b /test
parent349790339897466f323ff28748916aa48aa344f7 (diff)
downloadpardes-70de5ec5ff3dad01afcc45244ad5e5a481486da6.tar.gz
pardes-70de5ec5ff3dad01afcc45244ad5e5a481486da6.zip
dump: one walker dump of the whole session, by name across builds, for Restore, -l, Handover and the store; dump.zig's hand-written schema gone
A dump is walk.zig's walk of the core with a table of every type it reaches (fields, enum and union names, number widths), read back by name; terminals are ghostty's snapshot (screens, history, kitty images); a failed load frees what it made. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test')
-rw-r--r--test/fs.py5
-rw-r--r--test/fs_namespace.zig44
-rw-r--r--test/kitty.zig6
-rw-r--r--test/monkey.zig9
-rw-r--r--test/output.zig17
-rw-r--r--test/panes.zig61
-rw-r--r--test/pdf.zig39
-rw-r--r--test/snapshot.zig9
-rw-r--r--test/snapshots/dump.snap9
9 files changed, 51 insertions, 148 deletions
diff --git a/test/fs.py b/test/fs.py
index e351d295..473036ec 100644
--- a/test/fs.py
+++ b/test/fs.py
@@ -1439,10 +1439,9 @@ def test(binary, quic=False):
# The new log names its panes, then where they came from.
log = restored.read('/log')
assert b'\nrestore ' + str(saved).encode() + b'\n' in log, log
- # then which serial each pane had: restored <old> <new>
- assert (b'\n'.join(b'restored %d %d' % (old, new) for old, new in zip(sorted(old_ids), sorted(int(r.split()[0]) for r in restored.read('/index').splitlines()))) + b'\nrestoredcol ') in log, log
+ # Its panes are the dump's, their serials too.
restored_ids = [int(row.split()[0]) for row in restored.read('/index').splitlines()]
- assert len(restored_ids) == 2 and old_ids.isdisjoint(restored_ids), restored_ids
+ assert len(restored_ids) == 2 and set(restored_ids) == old_ids, restored_ids
file_id, control_id = restored_ids
contents = restored.read(f'/pane/{file_id}/body')
assert contents == b'dumped state\n', (contents, saved.read_text(), restored.read('/index'))
diff --git a/test/fs_namespace.zig b/test/fs_namespace.zig
index 30c656ca..c68a438b 100644
--- a/test/fs_namespace.zig
+++ b/test/fs_namespace.zig
@@ -100,13 +100,14 @@ test "transactional restore preserves host capabilities and advances pane identi
try std.testing.expectEqual(@as(u32, 73), restored.pipe.seq);
try std.testing.expectEqual(p.cell_pixels, restored.cell_pixels);
try std.testing.expect(restored.native_images);
- try std.testing.expect(restored.panes[0].?.serial > p.next_serial);
- try std.testing.expect(restored.paneBySerial(pane.serial) == null);
+ // The dump's pane, its serial too; a new one is past the old session's.
+ try std.testing.expectEqual(pane.serial, restored.panes[0].?.serial);
+ try std.testing.expect(restored.next_serial >= p.next_serial);
try std.testing.expectEqual(p.screen_w, restored.screen_w);
try std.testing.expectEqual(p.screen_h, restored.screen_h);
try std.testing.expect(p.panes[0] == pane);
try std.testing.expectEqualStrings("before\n", pane.file.?.content);
- try std.testing.expectError(error.BadDumpMagic, pardes.dump.restore(
+ try std.testing.expectError(error.BadDump, pardes.dump.restore(
p,
".{ .magic = \"wrong\", .screen = .{.cols = 80, .rows = 24} }",
"test",
@@ -201,23 +202,24 @@ test "explicit OS file opens and restores keep their names and request watches"
const pane = try pardes.panes.File.open(p, opened, path, 0);
try std.testing.expectEqualStrings(path, pane.file.?.path);
try std.testing.expectEqualStrings("const disk = 1;\n", pane.file.?.content);
- const restored = p.freeSlot().?;
- const copy = try pardes.panes.File.restore(p, restored, .{
- .kind = .file,
- .tag = path,
- .body = "",
- // Unsaved text: kept (a clean pane's is read from disk).
- .file = .{ .path = path, .content = "const unsaved = 2;\n", .dirty = true },
- });
- try std.testing.expectEqualStrings(path, copy.file.?.path);
- try std.testing.expectEqualStrings("const unsaved = 2;\n", copy.file.?.content);
var watched_open = false;
- var watched_restore = false;
while (p.nextEffect()) |effect| if (effect == .watch and effect.watch.on) {
if (effect.watch.pane == opened) watched_open = true;
- if (effect.watch.pane == restored) watched_restore = true;
};
- try std.testing.expect(watched_open and watched_restore);
+ try std.testing.expect(watched_open);
+ // Unsaved, dumped and loaded: its text kept, its file watched again.
+ _ = pardes.ctlfs.pane.spliceBody(p, pane, 0, 0, "// unsaved\n").?;
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
+ defer restored.deinit();
+ const copy = restored.panes[opened].?;
+ try std.testing.expectEqualStrings(path, copy.file.?.path);
+ try std.testing.expectEqualStrings("// unsaved\nconst disk = 1;\n", copy.file.?.content);
+ var watched_restore = false;
+ while (restored.nextEffect()) |effect| if (effect == .watch and effect.watch.on) {
+ if (effect.watch.pane == opened) watched_restore = true;
+ };
+ try std.testing.expect(watched_restore);
}
test "virtual file opens do not request OS watches" {
@@ -308,9 +310,9 @@ test "images decode through explicit filesystem mounts, and a dump reads one on
const state = pane.image.?;
try std.testing.expectEqual(@as(usize, 1), state.iw);
try std.testing.expectEqual(@as(usize, 1), state.ih);
- // On disk, the picture is no part of the dump: Restore reads it there.
- const saved = try pardes.panes.Image.dumpPane(p, arena.allocator(), pane, "", "", 0, path, state.raw);
- try std.testing.expectEqualStrings("", saved.image.?.bytes_b64);
- const restored = try pardes.panes.Image.restore(p, p.freeSlot().?, saved);
- try std.testing.expectEqualStrings(bytes, restored.image.?.raw);
+ // The picture's bytes are in the dump: it comes back as it was shown.
+ try pardes.dump.dumpState(p);
+ const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, p.dump_out.?);
+ defer restored.deinit();
+ try std.testing.expectEqualStrings(bytes, restored.panes[0].?.image.?.raw);
}
diff --git a/test/kitty.zig b/test/kitty.zig
index 07e89cf9..1e1e8331 100644
--- a/test/kitty.zig
+++ b/test/kitty.zig
@@ -1241,11 +1241,11 @@ test "kitty: a dumped and restored terminal keeps its images" {
defer r.deinit();
r.feed(0, "\x1b[1;1Hpicture" ++ apc("a=T,i=25,f=24,s=4,v=2,c=2,r=1,q=2", rgb_b64));
try pardes.dump.dumpState(r.p);
- const restored = try pardes.dump.restore(r.p, r.p.dump_out.?, "/tmp/pardes-kitty.dump.zon");
+ const restored = try pardes.dump.restore(r.p, r.p.dump_out.?, "/tmp/pardes-kitty.dump");
defer restored.deinit();
const pane = restored.panes[0].?;
- const kept = pane.terminal != null and pane.terminal.?.vt.screens.active.kitty_images.placements.count() > 0;
- try knownGap("a terminal's kitty images do not survive a dump (Dump/Load, Handover, a closed pane reopened from the Store): dumpPane writes the screen as VT text (ScreenFormatter), which has no images; ghostty's snapshot format carries them but is unstable (v1)", kept);
+ // ghostty's snapshot of the emulator (src/terminal.zig) carries them.
+ try std.testing.expect(pane.terminal.?.vt.screens.active.kitty_images.placements.count() > 0);
}
// ---- Real clients' traffic ----
diff --git a/test/monkey.zig b/test/monkey.zig
index d35599ff..2e19cb21 100644
--- a/test/monkey.zig
+++ b/test/monkey.zig
@@ -177,7 +177,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] [--keep] [--tape=DIR] [--views=N]\n", .{});
+ std.debug.print("usage: pardes-monkey <pardes-snap> <pardes> <seeds> [steps] [--from=N] [--out=DIR] [--keep] [--tape=DIR] [--views=N] [--dump]\n", .{});
std.process.exit(2);
}
const snap = args[1];
@@ -192,6 +192,9 @@ pub fn main(init: std.process.Init) !void {
// seed is a hit if one does not replay (pardes-snap --tape).
var tape: ?[]const u8 = null;
var views: usize = 1;
+ // --dump (with --tape): each replay loads the session's dump at its end
+ // too (pardes-snap --dump).
+ var dump = false;
var positional: usize = 0;
for (args[3..]) |a| {
if (std.mem.startsWith(u8, a, "--views=")) {
@@ -202,6 +205,8 @@ pub fn main(init: std.process.Init) !void {
keep = true;
} else if (std.mem.startsWith(u8, a, "--tape=")) {
tape = a;
+ } else if (std.mem.eql(u8, a, "--dump")) {
+ dump = true;
} else if (std.mem.startsWith(u8, a, "--out=")) {
out = a["--out=".len..];
} else {
@@ -223,7 +228,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 = if (tape) |t| &.{ snap, app, "--update", "--no-retry", "--jobs=1", t, path } else &.{ snap, app, "--update", "--no-retry", "--jobs=1", path },
+ .argv = if (tape) |t| (if (dump) &.{ snap, app, "--update", "--no-retry", "--jobs=1", t, "--dump", path } else &.{ 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| {
diff --git a/test/output.zig b/test/output.zig
index 530db77c..2d872bd1 100644
--- a/test/output.zig
+++ b/test/output.zig
@@ -495,23 +495,6 @@ test "Mini syntax colors survive toggles themes and rendering without source acc
}
}
-test "Mini restore rejects inconsistent metadata before publishing a pane" {
- const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- const id = p.freeSlot().?;
- const serial = p.next_serial;
- for ([_]pardes.dump.File{
- .{ .content = "x", .mini_source = "/source.zig", .mini_colors_b64 = "AA==" },
- .{ .content = "x", .origin = "Mini", .mini_source = "/source.zig", .mini_colors_b64 = "" },
- .{ .content = "x", .origin = "Mini", .mini_source = "/source.zig", .mini_colors_b64 = "BQ==" },
- .{ .content = "x", .origin = "Mini", .mini_colors_b64 = "AA==" },
- }) |saved| {
- try std.testing.expectError(error.InvalidMini, panes.File.restore(p, id, .{ .kind = .file, .tag = "", .body = "", .file = saved }));
- try std.testing.expect(p.panes[id] == null);
- try std.testing.expectEqual(serial, p.next_serial);
- }
-}
-
test "Mini failures leave its existing snapshot and focus unchanged" {
const p = try Pardes.init(std.testing.allocator, .{ .tty_only = true });
defer p.deinit();
diff --git a/test/panes.zig b/test/panes.zig
index 996accf1..fc3f7804 100644
--- a/test/panes.zig
+++ b/test/panes.zig
@@ -2297,7 +2297,7 @@ test "a prompt opens with one allocation" {
}
test "file history construction failures preserve existing panes" {
- const Case = enum { open, restore, output, tutor, replace };
+ const Case = enum { open, output, tutor, replace };
for (std.enums.values(Case)) |case| {
var succeeded = false;
for (0..32) |failure| {
@@ -2314,12 +2314,6 @@ test "file history construction failures preserve existing panes" {
failing.fail_index = failing.alloc_index + failure;
const result = switch (case) {
.open => panes.File.open(p, p.freeSlot().?, path, 0),
- .restore => panes.File.restore(p, 1, .{
- .kind = .file,
- .tag = "",
- .body = "",
- .file = .{ .path = "/restored.zig", .content = "restored\n" },
- }),
.output => panes.Output.open(p, p.freeSlot().?, "/", .{ .cmd = .Help }, "", incoming.?),
.tutor => p.openTutorView(1),
.replace => p.setTestFile("replacement\n"),
@@ -2405,39 +2399,6 @@ test "file history allocation precedes reading the served tree" {
}
}
-test "file history survives PDF fallback restoration and allocation failures" {
- const saved =
- \\.{
- \\ .screen = .{ .cols = 40, .rows = 12 },
- \\ .columns = .{.{ .panes = .{0} }},
- \\ .panes = .{.{
- \\ .kind = .image, .tag = "", .body = "",
- \\ .image = .{ .path = "/virtual/missing-history.pdf", .bytes_b64 = "cmF3" },
- \\ }},
- \\}
- ;
- var succeeded = false;
- for (0..256) |failure| {
- var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = failure });
- if (pardes.dump.initFromDump(failing.allocator(), .{ .tty_only = true }, saved)) |p| {
- defer p.deinit();
- const pane = p.panes[0].?;
- try std.testing.expect(pane.file != null);
- try std.testing.expectEqualStrings("raw", pane.file.?.content);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len);
- try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.redo_len);
- if (!failing.has_induced_failure) {
- succeeded = true;
- break;
- }
- } else |err| {
- try std.testing.expect(failing.has_induced_failure);
- try std.testing.expect(err == error.OutOfMemory or err == error.WriteFailed);
- }
- }
- try std.testing.expect(succeeded);
-}
-
test "Save rearms renamed file watches only after a successful write" {
const Host = struct {
const Result = enum { success, failure, edited, replaced, closed };
@@ -2695,7 +2656,6 @@ const OutputTests = struct {
const max_arg = panes.Output.max_arg;
const State = panes.Output.State;
const setArg = panes.Output.setArg;
- const fromWord = panes.Output.fromWord;
const fillResults = panes.Output.fillResults;
test "Locations align Unicode paths by display width and preserve source indentation" {
@@ -3218,12 +3178,6 @@ const OutputTests = struct {
try std.testing.expect(!result.body.vsel.active and !result.body.msel.active);
}
- test "dump origins accept only builtins that actually own output panes" {
- try std.testing.expectEqual(Origin{ .cmd = .Help }, fromWord("Help").?);
- try std.testing.expect(fromWord("Kill") == null);
- try std.testing.expect(fromWord("Theme") == null);
- }
-
test "result refill identity retains the full bounded argument" {
const p = try Pardes.init(std.testing.allocator, .{
.tty_only = true,
@@ -3296,7 +3250,6 @@ const OutputTests = struct {
const ImageTests = struct {
const State = panes.Image.State;
- const restore = panes.Image.restore;
const toggleGlyphArt = panes.Image.toggleGlyphArt;
const togglePalette = panes.Image.togglePalette;
const toggleAscii = panes.Image.toggleAscii;
@@ -3315,18 +3268,6 @@ const ImageTests = struct {
);
}
- test "dump restore propagates malformed embedded image bytes" {
- const p = try pardes.Pardes.init(std.testing.allocator, .{ .tty_only = true });
- defer p.deinit();
- try std.testing.expect(p.panes[1] == null);
- try std.testing.expectError(error.InvalidCharacter, restore(p, 1, .{
- .kind = .image,
- .tag = "img /tmp/bad.ppm",
- .body = "",
- .image = .{ .path = "/tmp/bad.ppm", .bytes_b64 = "A..A" },
- }));
- try std.testing.expect(p.panes[1] == null);
- }
};
const PdfTests = struct {
diff --git a/test/pdf.zig b/test/pdf.zig
index a50f3bf6..3bb751e2 100644
--- a/test/pdf.zig
+++ b/test/pdf.zig
@@ -278,45 +278,6 @@ test "PDF feature gates keep argv and builtin behavior coherent" {
}
}
-test "PDF dump fallback remains a byte-preserving file" {
- const gpa = std.testing.allocator;
- const path = "/definitely/missing/pardes-dump-fallback.PDF";
- const source = "%PDF embedded fallback bytes\x00\xff";
- const encoded = try dump.encodeBytes(gpa, source);
- defer gpa.free(encoded);
- const ids = [_]usize{0};
- const columns = [_]dump.Column{.{ .panes = &ids }};
- const saved_panes = [_]dump.Pane{.{
- .kind = .image,
- .tag = "pdf 3/9 height PdfFit full PdfTint PdfSections " ++ path ++ " Keep Del",
- .tag_tail = " Keep Del",
- .body = "",
- .scroll = 2,
- .cols = 80,
- .rows = 24,
- .image = .{ .path = path, .bytes_b64 = encoded },
- }};
- const state = dump.State{
- .screen = .{ .cols = 80, .rows = 24 },
- .columns = &columns,
- .panes = &saved_panes,
- };
- var out: std.Io.Writer.Allocating = .init(gpa);
- defer out.deinit();
- try std.zon.stringify.serialize(state, .{ .whitespace = true }, &out.writer);
-
- const restored = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, out.written());
- defer restored.deinit();
- const pane = restored.panes[0].?;
- try std.testing.expect(pane.file != null);
- try std.testing.expect(pane.image == null);
- try std.testing.expect(!hasPdf(pane));
- try std.testing.expectEqualStrings(path, pane.file.?.path);
- try std.testing.expectEqualSlices(u8, source, pane.file.?.content);
- try std.testing.expect(pane.tag.own != null);
- try std.testing.expectEqualStrings(" Keep Del", pane.tag.own.?);
-}
-
test "a +PdfSections row's first number is the page: a section not there, or on another page, is a miss said" {
if (!pdf_enabled or platform == .web) return;
const gpa = std.testing.allocator;
diff --git a/test/snapshot.zig b/test/snapshot.zig
index 8a0583e3..030733d0 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;
+/// --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).
+var dump_check = false;
const gpa = std.heap.page_allocator;
pub fn main(init: std.process.Init) !void {
@@ -133,6 +137,8 @@ pub fn main(init: std.process.Init) !void {
record_dir = try absPath(arena, orig_cwd, a["--record=".len..]);
} else if (std.mem.startsWith(u8, a, "--tape=")) {
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, "--jobs=")) {
jobs = @max(1, try std.fmt.parseInt(usize, a["--jobs=".len..], 10));
} else if (exe == null) {
@@ -159,6 +165,7 @@ pub fn main(init: std.process.Init) !void {
std.mem.startsWith(u8, a, "--lspmock=") or
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, "--jobs=")) continue;
if (!saw_exe) {
saw_exe = true;
@@ -527,7 +534,7 @@ 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}' timeout 300 '{s}' > '{s}/{s}.replay' 2>&1", .{ dir, entry.name, 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) "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";
diff --git a/test/snapshots/dump.snap b/test/snapshots/dump.snap
index 29e7b09e..5a602304 100644
--- a/test/snapshots/dump.snap
+++ b/test/snapshots/dump.snap
@@ -1,4 +1,6 @@
-# Dump serializes the session to this fixture's $DUMP path.
+# Dump writes the whole session to this fixture's $DUMP path, a dump of the
+# walk (src/walk.zig), and `-l` of it is that session again: the text typed
+# into a terminal over its history comes back where it was.
file d.txt x
start 31 100 -n 3
wait 8000 d.txt
@@ -14,4 +16,7 @@ stable 400 5000
press middle @Dump 1
release middle @Dump 1
stable 600 8000
-snapfile dump $DUMP
+start 31 100 -l $DUMP
+wait 8000 typed-marker
+stable 700 20000
+snap loaded