From fe650384496d7ff8234fc10e62ea46c18c599b46 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Thu, 19 Nov 2026 20:43:55 -0300 Subject: core: the two tests that failed when their edits straddle a wall-clock second compare what was done, not when, and a failed rollback test no longer poisons the next: an edit stamps its text's mtime with the second (core/File.zig:782, CLOCK_REALTIME through tape.value(.mtime)), so rollback's "a copy put back..." (rollback.zig:599) and Places' "...loaded from its dump..." (Places.zig:893), each comparing whole-core digests of one edit made twice a moment apart, failed whenever a second turned between them (reproduced at will with an LD_PRELOAD that makes each CLOCK_REALTIME read a second later: 1 of 1 each; plainly 0 of 50 and 0 of 104 started 5-60 ms before a second turned); no clock can be handed in there (a tape's stamp answers only inside a step of a stepping tape, tape.zig:814, and Places' edit is no step), so each test sets the second edit's mtime to the first's before comparing, as draw.zig's twin test leaves mtime out by name; and the failed rollback test left syntax.held_trees pointing into its dead Epoch (Epoch.begin sets it, only end puts it back), so the next test ("a text written in place...") panicked in syntax.parseTree: Epoch.deinit now lets go of a hold that is its own (+3, product code no user could reach: an epoch dies held only in a failed test); with the shim the rollback file passes 14/14 and Places' 8/8, 50 runs each plain and shimmed 0 failures (load 17-18); tui core-test 848/991 (143 skipped), the base's Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/Places.zig | 3 +++ core/rollback.zig | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/core/Places.zig b/core/Places.zig index 1416dbd3..9ffbff88 100644 --- a/core/Places.zig +++ b/core/Places.zig @@ -890,5 +890,8 @@ test "a session's places loaded from its dump find what an edit makes as the ses pn.places.fill(p, pn, 0, frame_steps); try std.testing.expectEqual(@as(usize, 3), pn.places.hits.items.len); } + // An edit stamps the text with the wall clock's second (File.edit's + // mtime): the two cores' edits, a moment apart, can fall in two. + b.panes[b.view().active].?.file.?.mtime = a.panes[a.view().active].?.file.?.mtime; try std.testing.expectEqual(pardes.walk.digest(Pardes, a), pardes.walk.digest(Pardes, b)); } diff --git a/core/rollback.zig b/core/rollback.zig index 3d5ab921..c7d0a4e8 100644 --- a/core/rollback.zig +++ b/core/rollback.zig @@ -88,6 +88,9 @@ pub const Epoch = struct { } pub fn deinit(e: *Epoch) void { + // Gone with a copy still held (a test that failed between take and + // restore): the process-wide hold must not point into it. + if (pardes.syntax.held_trees == &e.trees) pardes.syntax.held_trees = null; var it = e.live.iterator(); while (it.next()) |kv| e.child.rawFree(@as([*]u8, @ptrFromInt(kv.key_ptr.*))[0..kv.value_ptr.len], kv.value_ptr.alignment, @returnAddress()); e.live.deinit(e.meta); @@ -579,6 +582,9 @@ test "a copy put back is the core as it was; one let go keeps what was done" { const gpa = e.allocator(); const p = try Pardes.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .image_allocator = gpa, .tree_sitter_allocator = gpa, .frame_allocator = gpa }); p.pump(.{}) catch {}; + const f = for (p.panes) |slot| { + if (slot) |pane| if (pane.file) |*file| break file; + } else return error.NoFile; const before = walk.digest(Pardes, p); var c: Copy = .{}; defer c.deinit(); @@ -588,6 +594,7 @@ test "a copy put back is the core as it was; one let go keeps what was done" { p.update(.{ .key = .{ .cp = pardes.Key.escape } }); p.pump(.{}) catch {}; const edited = walk.digest(Pardes, p); + const stamped = f.mtime; try std.testing.expect(edited != before); try std.testing.expect(c.restore()); try std.testing.expectEqual(before, walk.digest(Pardes, p)); @@ -596,6 +603,9 @@ test "a copy put back is the core as it was; one let go keeps what was done" { for (typed) |k| p.update(.{ .key = .{ .cp = k, .text = &.{k} } }); p.update(.{ .key = .{ .cp = pardes.Key.escape } }); p.pump(.{}) catch {}; + // An edit stamps the text with the wall clock's second (File.edit's + // mtime): the same typing in the next second is the same edit. + f.mtime = stamped; try std.testing.expectEqual(edited, walk.digest(Pardes, p)); c.release(); try std.testing.expectEqual(edited, walk.digest(Pardes, p)); -- cgit v1.3