diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-29 17:01:35 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-29 21:13:33 -0300 |
| commit | 70de5ec5ff3dad01afcc45244ad5e5a481486da6 (patch) | |
| tree | cd4b723dcc2cfd94c4ba2361c134927b0e2df60b /src/file_watch.zig | |
| parent | 349790339897466f323ff28748916aa48aa344f7 (diff) | |
| download | pardes-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/file_watch.zig')
| -rw-r--r-- | src/file_watch.zig | 57 |
1 files changed, 17 insertions, 40 deletions
diff --git a/src/file_watch.zig b/src/file_watch.zig index 9b41d146..f640fa5f 100644 --- a/src/file_watch.zig +++ b/src/file_watch.zig @@ -669,30 +669,27 @@ pub fn identify(io: std.Io, path: []const u8) !Identity { }; } -test "restored file watches preserve snapshots and accept later disk changes" { +test "a restored file is watched again: one clean takes what its file became since the dump, one unsaved keeps its text" { if (comptime !supported or !filesystem.platform_has_fs) return; const io = std.testing.io; const gpa = std.testing.allocator; - for ([_]struct { dirty: bool, exists: bool }{ - .{ .dirty = false, .exists = true }, - .{ .dirty = true, .exists = true }, - .{ .dirty = true, .exists = false }, - }) |case| { + for ([_]bool{ false, true }) |dirty| { var tmp = std.testing.tmpDir(.{}); defer tmp.cleanup(); - if (case.exists) try tmp.dir.writeFile(io, .{ .sub_path = "watched", .data = "disk baseline\n" }); + try tmp.dir.writeFile(io, .{ .sub_path = "watched", .data = "dumped\n" }); var path_buf: [256]u8 = undefined; const path = try std.fmt.bufPrint(&path_buf, ".zig-cache/tmp/{s}/watched", .{tmp.sub_path}); - const core = try pardes.Pardes.init(gpa, .{ .tty_only = true }); + const source = try pardes.Pardes.init(gpa, .{ .tty_only = true }); + defer source.deinit(); + const id: u8 = @intCast(source.freeSlot().?); + const opened = try pardes.panes.File.open(source, id, path, 0); + if (dirty) _ = pardes.ctlfs.pane.spliceBody(source, opened, 0, 0, "unsaved ").?; + try pardes.dump.dumpState(source); + // Changed on disk between the dump and its load. + try tmp.dir.writeFile(io, .{ .sub_path = "watched", .data = "changed since\n" }); + const core = try pardes.dump.initFromDump(gpa, .{ .tty_only = true }, source.dump_out.?); defer core.deinit(); - while (core.nextEffect()) |_| {} - const id: u8 = @intCast(core.freeSlot().?); - const pane = try pardes.panes.File.restore(core, id, .{ - .kind = .file, - .tag = "", - .body = "", - .file = .{ .path = path, .content = "restored snapshot\n", .dirty = case.dirty }, - }); + const pane = core.panes[id].?; const fd = init(true); if (fd < 0) return error.NoWatcher; defer _ = libc.close(fd); @@ -701,36 +698,16 @@ test "restored file watches preserve snapshots and accept later disk changes" { var armed = false; while (core.nextEffect()) |effect| switch (effect) { .watch => |watch| if (watch.pane == id and watch.on) { - try std.testing.expectEqual(.baseline_disk, watch.mode); - try std.testing.expect(!applyEffect(core, io, fd, &watches, id, watch.on, watch.mode)); + _ = applyEffect(core, io, fd, &watches, id, watch.on, watch.mode); armed = true; }, else => {}, }; try std.testing.expect(armed and watches[id] != null); - // A clean pane's text is its file's, read at the Restore: a dump - // that kept other text (an older dump) is not what comes back. - const restored: []const u8 = if (case.dirty) "restored snapshot\n" else "disk baseline\n"; - try std.testing.expectEqualStrings(restored, pane.file.?.content); - try std.testing.expectEqual(@as(usize, 0), pane.file.?.history.undo_len); - try std.testing.expectEqual(case.dirty, pane.file.?.revision != pane.file.?.saved_revision); - _ = reloadChanged(core, io, gpa, &watches); - try std.testing.expectEqualStrings(restored, pane.file.?.content); - - try tmp.dir.writeFile(io, .{ .sub_path = "watched", .data = "later disk save\n" }); - _ = reloadChanged(core, io, gpa, &watches); - // A snapshot restored with unsaved text keeps it: a later disk - // change is said, never loaded over it (File.changed). - if (case.dirty) { - try std.testing.expectEqualStrings("restored snapshot\n", pane.file.?.content); + if (dirty) { + try std.testing.expectEqualStrings("unsaved dumped\n", pane.file.?.content); try std.testing.expect(pane.file.?.disk_newer != null); - continue; - } - try std.testing.expectEqualStrings("later disk save\n", pane.file.?.content); - pardes.panes.File.undo(core, pane); - try std.testing.expectEqualStrings(restored, pane.file.?.content); - _ = reloadChanged(core, io, gpa, &watches); - try std.testing.expectEqualStrings(restored, pane.file.?.content); + } else try std.testing.expectEqualStrings("changed since\n", pane.file.?.content); } } |
