summaryrefslogtreecommitdiff
path: root/src/ninep
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 /src/ninep
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 'src/ninep')
-rw-r--r--src/ninep/ctl.zig64
-rw-r--r--src/ninep/events.zig24
2 files changed, 12 insertions, 76 deletions
diff --git a/src/ninep/ctl.zig b/src/ninep/ctl.zig
index 3176ebc8..1b9d73f5 100644
--- a/src/ninep/ctl.zig
+++ b/src/ninep/ctl.zig
@@ -2075,8 +2075,7 @@ test "Zerox twins dump their text once and come back on one buffer from a Restor
try pardes.dump.dumpState(p);
const text = p.dump_out.?;
// The text is kept once though three panes show it.
- const encoded = try pardes.dump.encodeBytes(p.scratch.allocator(), p.panes[0].?.file.?.content);
- try testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, encoded));
+ try testing.expectEqual(@as(usize, 1), std.mem.count(u8, text, p.panes[0].?.file.?.content));
const restored = try pardes.dump.restore(p, text, "/tmp/pardes.dump.zon");
defer restored.deinit();
var files: [3]*pardes.panes.File.State = undefined;
@@ -2838,7 +2837,7 @@ test "a Restore of a file that is no dump fails the write before any warning, an
const root_ctl = @backingInt(tree.TopFile.ctl);
const refused = wr(p, root_ctl, line);
try testing.expectEqual(E.IO, refused.errno());
- try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: line 1: ") != null);
+ try testing.expect(std.mem.indexOf(u8, refused.reply.ename, "not a pardes dump: it does not begin as one") != null);
try testing.expect(p.restore_req == null);
try testing.expect(p.panes[0].?.discard_warned == null);
@@ -4899,46 +4898,6 @@ test "Petscii, Palette and Ascii take the state their tag word names, set rather
try testing.expect(th.logHas(p, "Petscii takes on or off"));
}
-test "a Restore reads a clean file from disk; an unsaved one whose file changed since is said so, and its first Save asks" {
- if (comptime !pardes.hosted) return;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "one\n" });
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- var path_buf: [4200]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/a.txt", .{dir});
- const p = try Pardes.init(gpa, .{ .file = path, .tty_only = true, .cols = 80, .rows = 24 });
- defer p.deinit();
- // Clean: the dump keeps no text, and the newer disk is what comes back.
- try pardes.dump.dumpState(p);
- try testing.expect(std.mem.indexOf(u8, p.dump_out.?, "b25lCg==") == null); // "one\n" in base64
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "two\n" });
- {
- const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
- defer restored.deinit();
- const f = pane_files.fileOf(restored.panes[0].?).?;
- try testing.expectEqualStrings("two\n", f.content);
- try testing.expectEqual(f.saved_revision, f.revision);
- }
- // Unsaved: its text comes back, the disk changed under it is said, and
- // Save asks once before overwriting it.
- const f = pane_files.fileOf(p.panes[0].?).?;
- const edited = try gpa.dupe(u8, "edited\n");
- pardes.panes.File.setContent(p, f, edited);
- try testing.expect(f.revision != f.saved_revision);
- try pardes.dump.dumpState(p);
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "a.txt", .data = "three\n" });
- const restored = try pardes.dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
- defer restored.deinit();
- const rf = pane_files.fileOf(restored.panes[0].?).?;
- try testing.expectEqualStrings("edited\n", rf.content);
- try testing.expect(rf.disk_newer != null);
- pardes.exec.saveFile(restored, 0);
- try testing.expect(th.logHas(restored, "modified on disk since read (Save again to overwrite)"));
-}
-
test "a Rename the server answered for this file alone, with other open files saying the name, is previewed and says so" {
const p = try withFile(testing.allocator, "x\n");
defer p.deinit();
@@ -5086,25 +5045,6 @@ test "a command or a terminal refused for room is refused before anything is log
}
}
-test "an unsaved pane from a dump that says nothing of its disk asks at its first Save" {
- if (comptime !pardes.hosted) return;
- const gpa = testing.allocator;
- var tmp = testing.tmpDir(.{});
- defer tmp.cleanup();
- try tmp.dir.writeFile(testing.io, .{ .sub_path = "old.txt", .data = "disk\n" });
- var dir_buf: [4096]u8 = undefined;
- const dir = dir_buf[0..try tmp.dir.realPath(testing.io, &dir_buf)];
- var path_buf: [4200]u8 = undefined;
- const path = try std.fmt.bufPrint(&path_buf, "{s}/old.txt", .{dir});
- const p = try withFile(gpa, "x\n");
- defer p.deinit();
- const id = p.freeSlot().?;
- const pane = try pardes.panes.File.restore(p, id, .{ .kind = .file, .tag = "", .body = "", .file = .{ .path = path, .content = "unsaved\n", .dirty = true } });
- try testing.expect(pane.file.?.disk_newer != null);
- pardes.exec.saveFile(p, id);
- try testing.expect(th.logHas(p, "modified on disk since read (Save again to overwrite)"));
-}
-
test "a Mount of a socket path that is not there says no such socket, ENOENT" {
if (comptime !pardes.hosted) return;
const p = try withFile(testing.allocator, "x\n");
diff --git a/src/ninep/events.zig b/src/ninep/events.zig
index 78788c3c..f24c6120 100644
--- a/src/ninep/events.zig
+++ b/src/ninep/events.zig
@@ -1305,27 +1305,23 @@ test "a Dump written and a Restore made are in the log, with their files" {
var want: [64]u8 = undefined;
try testing.expect(std.mem.indexOf(u8, log.bytes, try std.fmt.bufPrint(&want, "{s} /tmp/pardes.dump.zon\n", .{what})) != null);
}
- // The replacement's last says which serial each pane had.
- const log = try freezeLog(restored);
- defer restored.gpa.free(log.bytes);
- var want: [64]u8 = undefined;
- try testing.expect(std.mem.indexOf(u8, log.bytes, try std.fmt.bufPrint(&want, "restore /tmp/pardes.dump.zon\nrestored {d} {d}\n", .{ p.panes[0].?.serial, restored.panes[0].?.serial })) != null);
- // ...and each column's: restoredcol <old> <new>.
- try testing.expect(std.mem.endsWith(u8, log.bytes, try std.fmt.bufPrint(&want, "restoredcol {d} {d}\n", .{ pardes.layout.columnSerial(p, 0), pardes.layout.columnSerial(restored, 0) })));
+ // Its panes and columns are the dump's, serials and all.
+ try testing.expectEqual(p.panes[0].?.serial, restored.panes[0].?.serial);
+ try testing.expectEqual(pardes.layout.columnSerial(p, 0), pardes.layout.columnSerial(restored, 0));
}
-test "a Restore gives columns fresh serials, past every serial the old session handed out" {
+test "after a Restore a new pane or column takes a serial past every one the old session handed out" {
const p = try withFile(testing.allocator, "one\n");
defer p.deinit();
- const first = pardes.layout.columnSerial(p, 0);
- // Serials spent on columns since deleted.
- p.next_column_serial += 5;
- const spent = p.next_column_serial;
try dump.dumpState(p);
+ // Serials spent since the dump, on panes and columns since deleted.
+ p.next_serial += 5;
+ p.next_column_serial += 5;
+ const spent = p.next_serial;
+ const spent_col = p.next_column_serial;
const restored = try dump.restore(p, p.dump_out.?, "/tmp/pardes.dump.zon");
defer restored.deinit();
- for (0..restored.ncol) |c| try testing.expect(pardes.layout.columnSerial(restored, c) >= spent);
- try testing.expect(pardes.layout.columnSerial(restored, 0) != first);
+ try testing.expect(restored.next_serial >= spent and restored.next_column_serial >= spent_col);
}
test "a pane named before it is announced has its new under that name, and no rename before it" {