From b1fb4242c0ab52767df1b8e155edcf2692f37873 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 23 Nov 2026 18:00:35 -0300 Subject: scroll: a view's top is a line and a row within that line's own wrapped rows, and a scroll moves it by rows (P62, round 3, on the layer's new model where the `Changes` layer's lines are lines of the buffer): a wheel's notch, the glide, PageDown/PageUp, zj/zk, Ctrl-d/u, zt/zz/zb and the margin (`scroll_off` now ROWS) go a row at a time through a line wrapped over many rows and through a long description line of the layer, where the base jumped all of a wrapped line's rows at once (the user, 2026-11-23: "the scroll view jumps around near deleted lines on the diff view"; one-row deleted lines were cured by the layer's second step, a wrapped one was not): TESTS FIRST: core/jj.zig "a view scrolls by rows through a line wrapped over 12 rows and a change's description wrapped over several (a line of the layer): ..." (a notch is one row down the whole text and back, the notches the text's rows exactly; PageDown/PageUp a page of rows; zj/zk one; a held j and k keep the cursor's row `scroll_off` rows inside the body) failing on the base at notch 21 (line 20's 12 rows crossed at once), and "a client wheels its session's view a row a notch into a change's description wrapped over several rows ..., agreeing at every notch; a client joined over that view loads its row"; kept from round 1: core/replica.zig's join over a view scrolled into a wrapped line (with a rollback and a dump) and the explorer of a view's rows (30 seeds), dev/gui's glide a row a notch; THE CHANGE, taken from pardes-row-scroll (`xrxmqlnw`) and -2 (`xxzmwnvq`) without their ghost-row "blocks" (a block is now just a line's own rows): `File.State.scroll_row` and `views.PaneView.scroll_row` in the generic walk (digested, dumped, copied; a dump of 34 loads at its lines' first rows), the wire 35; core/File.zig `Top`, `rowIn`/`rowWalked` (a line's rows as fillBody wraps them, `guideOf` shared), `rowOf`, `lineRows`, `top`/`setTop`, `walkRows`/`walkKnown`, `rowsTo`, `rowsOf` (off the map where it holds the line), `mapFresh`, `scrollRows`, `shownRows` (the geometry laid out first), `show` (a cursor's or a result's row inside the band, the line's rows whole when they fit), `textRowLine`, fillBody's skip to the top's row walked once a geometry (`Pane.top_skip`, derived), the geometry's key with `scroll_row` and stored as what the map was made from; the one-row fact `State.widest` (`Widest`, an upper bound kept by the index's own vector passes `countLines`/`fillLines`) so a view whose lines are each one row walks nothing (`oneRow`: line arithmetic, checked against the walk in Debug); `fitEnd` a vector of printable ASCII at a time; the callers in rows: panes.zig `scrollBy(tab, delta)` and `ensureCursorVisible` (a file's through `File.show`), the wheel and the rail and the edge scroll (mouse.zig), Ctrl-d/u (normal.zig `halfPageMove`), zt/zz/zb, Ctrl-f/b and PgUp/PgDn (Text.zig `scrollViewMove`), Look's reveal and centring, Places' `goTo`/`restore`, Query's `showCurrent`/`caretTo`, the frames' `Region.row` and the glide (dev/glide.zig, the window's `topOf`); test/perf.zig's checks by (line, row) and its seek at a line's first row; Debug in the workspace: core-test 963/1129 (166 skipped), shell-test 1172/1175 (3 skipped) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 2 +- test/kitty.zig | 2 +- test/panes.zig | 28 +++++++++++++++------------- test/perf.zig | 14 +++++++++++--- test/terminal.zig | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/daemon.py b/test/daemon.py index 90977ef4..cfdac2ec 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -328,7 +328,7 @@ class Replica: """A replica's connection (abi/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 34 + WIRE = 35 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout diff --git a/test/kitty.zig b/test/kitty.zig index 0bd849c2..37e64949 100644 --- a/test/kitty.zig +++ b/test/kitty.zig @@ -1224,7 +1224,7 @@ test "kitty: scrolled back by pardes, an image shows on its row; scrolled forwar r.feed(0, &nl); try std.testing.expectEqual(@as(usize, 0), (try r.placesOf(20)).len); // Back to the top of the history: the marker row is the body's first. - pane.scrollBy(-1000); + pane.scrollBy(pardes.config.tab_width, -1000); const o = r.origin(0); const drawn = try r.placesOf(20); try std.testing.expectEqual(@as(usize, 1), drawn.len); diff --git a/test/panes.zig b/test/panes.zig index bd39beba..eea4b36d 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -157,7 +157,7 @@ const BodyHitTests = struct { p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 }; const pane = try TreeContextTests.setZigFile(p, "const Box = struct {\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([60][16]u8, @splat(" // body\n".*))) ++ " }\n};\n"); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(10); + pane.scrollBy(pardes.config.tab_width, 10); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); p.sync(); @@ -205,7 +205,7 @@ const LineNumberLookTests = struct { p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 }; const pane = try TreeContextTests.setZigFile(p, "const Box = struct {\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([60][16]u8, @splat(" // body\n".*))) ++ " }\n};\n"); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(30); + pane.scrollBy(pardes.config.tab_width, 30); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); p.sync(); @@ -219,7 +219,7 @@ const LineNumberLookTests = struct { const rows = [_]u16{ 1, pane.context_rows + 3 }; for (rows) |row| { // Each Look recentres the view; come back under the headers. - pane.scrollBy(30 - pane.scroll()); + pane.scrollBy(pardes.config.tab_width, 30 - pane.scroll()); _ = frame.reset(.retain_capacity); _ = try p.render(frame.allocator()); const expected = pane.wrapAt(config.tab_width, row).line; @@ -262,7 +262,7 @@ const TreeContextTests = struct { const pane = try setZigFile(p, "const Box = struct {\n\n // omitted member comment\n\n pub fn work(\n value: usize,\n ) void {\n" ++ std.mem.asBytes(&@as([30][16]u8, @splat(" // body\n".*))) ++ " }\n};\n"); p.view().row_metrics = .{ .body_w = 10, .body_h = 20, .tagline_w = 8, .tagline_h = 10 }; try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(10); + pane.scrollBy(pardes.config.tab_width, 10); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); p.sync(); @@ -278,7 +278,7 @@ const TreeContextTests = struct { // A one-pixel separator remains inside its existing header row. try std.testing.expectEqual(row, layer.bodyHit(x, y, 10, 20, 8, 10).?.row); } - pane.scrollBy(-5); + pane.scrollBy(pardes.config.tab_width, -5); _ = try p.render(frame.allocator()); try std.testing.expectEqual(@as(u16, 2), layer.context_rows); try std.testing.expect(layer.hasContextBorderAfter(0)); @@ -317,7 +317,7 @@ const TreeContextTests = struct { const pane = try setZigFile(p, source); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); - pane.scrollBy(7); + pane.scrollBy(pardes.config.tab_width, 7); p.sync(); _ = try p.render(frame.allocator()); try std.testing.expectEqual(@as(u16, 0), pane.context_rows); @@ -348,7 +348,7 @@ const TreeContextTests = struct { p.update(.{ .key = .{ .cp = Key.escape } }); var previous: u16 = pane.context_rows; while (pane.scroll() > 0) { - pane.scrollBy(-1); + pane.scrollBy(pardes.config.tab_width, -1); _ = try p.render(frame.allocator()); try std.testing.expect(pane.context_rows <= previous); previous = pane.context_rows; @@ -357,7 +357,7 @@ const TreeContextTests = struct { try std.testing.expectEqual(@as(u16, 0), pane.context_rows); try std.testing.expectEqual(@as(i32, 0), pane.wrapRow(config.tab_width, 0, pane.body.cur_col).row); try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(7); + pane.scrollBy(pardes.config.tab_width, 7); _ = try p.render(frame.allocator()); try std.testing.expectEqual(@as(u16, 0), pane.context_rows); } @@ -370,7 +370,7 @@ const TreeContextTests = struct { p.sync(); p.settings.wrap = false; try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(8); + pane.scrollBy(pardes.config.tab_width, 8); pane.hscroll = 4; var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); @@ -409,7 +409,9 @@ const TreeContextTests = struct { p.sync(); p.settings.wrap = true; try std.testing.expect(p.executeBuiltinLine(0, "TreeContext")); - pane.scrollBy(2); + // The view's top on line 2 (a scroll's rows would stop in line 0's + // three: File.Top). + panes.File.setTop(pane, .{ .line = 2 }); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); p.sync(); @@ -994,7 +996,7 @@ test "terminal output keeps following new rows after scrollback eviction" { for (0..3) |phase| { if (phase > 0) { pane.body.mode = .normal; - pane.scrollBy(-30); + pane.scrollBy(pardes.config.tab_width, -30); try std.testing.expect(pane.termTop() < pages.scrollbar().total - pane.rows); pardes.keys.enterTty(p, 0); } @@ -2032,7 +2034,7 @@ const OutputTests = struct { try std.testing.expectEqual(next, panes.Output.nextResult(restored_file.content, restored_file.location_rows, path, .{ .line = 2, .col = 5 })); var frame = std.heap.ArenaAllocator.init(p.gpa); defer frame.deinit(); - result.scrollBy(-1000); + result.scrollBy(pardes.config.tab_width, -1000); layout.compute(p); const surface = try p.render(frame.allocator()); const rect = p.view().rects[pane.search_pane.?]; @@ -2690,7 +2692,7 @@ const TerminalTests = struct { p.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } }); } p.shell_rows.stale = true; - pane.scrollBy(-20); + pane.scrollBy(pardes.config.tab_width, -20); // ONE buffer line standing in for SIX shell rows: everything below slides // UP five, so the last rows of the body resolve past the viewport's bottom diff --git a/test/perf.zig b/test/perf.zig index 8622e31b..f36d64ac 100644 --- a/test/perf.zig +++ b/test/perf.zig @@ -631,7 +631,7 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u for (0..warmup + reps) |n| { if (op != .deep_selection) seek(pane, fx, n); _ = try frame(core); // settle the view at the new spot, untimed - const before = .{ .row = pane.body.cur_row, .col = pane.body.cur_col, .scroll = pane.scroll(), .len = pane.file.?.content.len }; + const before = .{ .row = pane.body.cur_row, .col = pane.body.cur_col, .scroll = pane.scroll(), .scroll_row = pane.file.?.scroll_row, .len = pane.file.?.content.len }; const rect = core.view().rects[id]; const wheel_col = rect.x + pardes.config.GUTTER; const wheel_row = rect.y + pardes.BOX_H; @@ -658,9 +658,11 @@ fn measure(op: Op, fx: Fixture, path: []const u8, expected_bytes: usize, reps: u return error.RenderChangedDocument, .key_down => if (pane.body.cur_row != before.row + 1) return error.DownDidNotMove, .key_right => if (pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) return error.RightDidNotMove, - .page_down => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) + // A view moves by rows (File.Top): inside a wrapped line's + // block its line stays and its row goes on. + .page_down => if (!past(pane, before.scroll, before.scroll_row) and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) return error.PageDidNotScroll, - .wheel => if (pane.scroll() <= before.scroll and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) + .wheel => if (!past(pane, before.scroll, before.scroll_row) and before.scroll < @as(i32, @intCast(fx.lines)) - pane.rows) return error.WheelDidNotScroll, .edit_char, .edit_twin => { if (pane.file.?.content.len != before.len + 1 or pane.body.cur_row != before.row or pane.body.cur_col != before.col + 1) @@ -1884,6 +1886,7 @@ fn seek(pane: *pardes.Pane, fx: Fixture, n: usize) void { const span = @max(1, fx.lines * 8 / 10); const row = fx.lines / 10 + (n *% 7919) % span; f.scroll = @min(row, fx.lines -| 1); + f.scroll_row = 0; f.syntax_dirty = true; pane.body.cur_row = @intCast(f.scroll); pane.body.cur_col = if (fx.cols > 200) @intCast(fx.cols * 3 / 4) else 0; @@ -2401,3 +2404,8 @@ fn readFileAlloc(path: []const u8) ![]u8 { } return buf; } + +/// Whether `pane`'s view's top is past (`line`, `row`). +fn past(pane: *pardes.Pane, line: i32, row: u32) bool { + return pane.scroll() > line or (pane.scroll() == line and pane.file.?.scroll_row > row); +} diff --git a/test/terminal.zig b/test/terminal.zig index 03bcd294..2873c278 100644 --- a/test/terminal.zig +++ b/test/terminal.zig @@ -107,7 +107,7 @@ test "document construction allocates only the pane and has inert terminal defau try std.testing.expectEqual(Term.Grid{}, grid(pane.terminal)); try std.testing.expectEqual(Term.Modes{}, modes(pane.terminal)); try std.testing.expectEqual(Term.Prompt{}, prompt(pane.terminal)); - pane.scrollBy(100); + pane.scrollBy(pardes.config.tab_width, 100); pane.followOutput(); pane.resizeGrid(undefined, 80, 24); // no terminal: the core is never read try std.testing.expectEqual(Term.Grid{}, grid(pane.terminal)); -- cgit v1.3 From 59b6ac1bae9cb6720252e1c3e1cc9d4f3a8ab3b1 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 01:02:27 -0300 Subject: tests: two process cases read the view in rows (P62 round 3): the gate's process-test on the tip failed two cases the base passes, both the behaviour this line changes: "tty boot: builtins" waited after `/^ +Look ` Enter for Look's row AND Exec's row on the screen; the jump puts Look's row `scroll_off` ROWS above the body's bottom (round 2's ruling: the margin counts rows) and Look's documentation wraps, so Exec's row is under the body (the base's margin of three LINES showed it): the case now waits for Look's row and the first words of its documentation (its point unchanged: the search lands on Look, `n` executes nothing); its `tutor-from-index` snapshot and "tty boot: leader"'s `tutor` snapshot have the new pane one row lower, below the +Help pane's last text row (a wrapped line there counted two rows by item 3's `blankRows`; the base laid the new pane over that row): test/snapshots/builtins.golden and leader.golden updated a case at a time (`-- --update builtins`, `-- --update leader`) and read: their rows' texts the same but the shift, the Help pane's line 15 shown again in leader's, the Tutor's last row gone in each; process-test 0 of 146 failed (2 skipped), Debug Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/process/tty_boot.zig | 7 ++-- test/snapshots/builtins.golden | 71 ++++++++++++++++++++------------------- test/snapshots/leader.golden | 75 +++++++++++++++++++++--------------------- 3 files changed, 77 insertions(+), 76 deletions(-) (limited to 'test') diff --git a/test/process/tty_boot.zig b/test/process/tty_boot.zig index 6373de84..01b35a24 100644 --- a/test/process/tty_boot.zig +++ b/test/process/tty_boot.zig @@ -130,14 +130,17 @@ fn builtins(gpa: std.mem.Allocator, exe: [:0]const u8) !void { try t.key("/"); try t.send("^ +Look "); try t.key("enter"); + // Look's row and its documentation under it (the margin below the row + // a search lands on is `scroll_off` rows, and Look's documentation + // wraps: Exec's row is under the body). try t.wait(10000, "Look enter, right-click"); - try t.wait(10000, "Exec tab, middle-click"); + try t.wait(10000, "Look at its argument as B3 does"); try t.stable(700, 15000); // n moves through look-able text; it must not execute command names. try t.key("space j n space j n space j n"); try t.wait(10000, "Look enter, right-click"); - try t.wait(10000, "Exec tab, middle-click"); + try t.wait(10000, "Look at its argument as B3 does"); try t.key("space c ?"); try t.wait(10000, "under SPC c"); try t.wait(10000, "Joincol"); diff --git a/test/snapshots/builtins.golden b/test/snapshots/builtins.golden index 6d5739ef..e9786c8a 100644 --- a/test/snapshots/builtins.golden +++ b/test/snapshots/builtins.golden @@ -55,40 +55,39 @@ |28: |29: |30: -== snap tutor-from-index grid=120x67 cursor=7,36 +== snap tutor-from-index grid=120x67 cursor=7,37 |10: 1 pardes builtins under SPC h Tutor -|25: +Search 1/1 Save Undock Del -|26: /^ +Look -|27: @p2:220:1 Look enter, right-click -|35: /tmp/pardes-snap/builtins/cwd/+Tutor Save Term Collapse Follow Del -|36: 1 -|37: 2 PARDES TUTOR -|38: 3 -|39: 4 This pane is +Tutor, a copy: edit it freely; there is no need to -|40: 5 Save it (a bare Save asks for a path to write a copy to). -|41: 6 `Del` in its tag closes it; once you have edited it, `Del` refuses -|42: 7 once and the second `Del` discards. `Tutor` or SPC h t opens a -|43: 8 fresh copy. -|44: 9 -|45: 10 The guide (docs/typ/guide.typ) explains; this is the hands-on part. -|46: 11 Each lesson is a few things to do, then names its guide section. -|47: 12 Words in backticks, like `Save`, are builtins. -|48: 13 `Exec` (B2) runs the builtin a word names, or else runs it as a -|49: 14 shell line; `Look` (B3) opens what the text names, or else finds -|50: 15 it. Type a builtin in any tag and `Exec` it. Lines starting with -|51: 16 "| " are tags. -|52: 17 -|53: 18 Press j until you reach part 1. -|54: 19 -|55: 20 -|56: 21 ================================================================= -|57: 22 = PART 1 — MODES = -|58: 23 ================================================================= -|59: 24 -|60: 25 1. The box left of this pane's tag is blank, so you are in -|61: 26 NORMAL mode. Press i: it shows ^ (INSERT). Type a word, then -|62: 27 Esc: blank again. -|63: 28 2. Press Esc once more, in NORMAL: the keyboard goes back to the -|64: 29 pane you were in before (not what helix does). Come back with -|65: 30 Esc again. -|66: 31 3. Press Alt-n: a terminal opens, in NORMAL mode, and pardes types +|26: +Search 1/1 Save Undock Del +|27: /^ +Look +|28: @p2:220:1 Look enter, right-click +|36: /tmp/pardes-snap/builtins/cwd/+Tutor Save Term Collapse Follow Del +|37: 1 +|38: 2 PARDES TUTOR +|39: 3 +|40: 4 This pane is +Tutor, a copy: edit it freely; there is no need to +|41: 5 Save it (a bare Save asks for a path to write a copy to). +|42: 6 `Del` in its tag closes it; once you have edited it, `Del` refuses +|43: 7 once and the second `Del` discards. `Tutor` or SPC h t opens a +|44: 8 fresh copy. +|45: 9 +|46: 10 The guide (docs/typ/guide.typ) explains; this is the hands-on part. +|47: 11 Each lesson is a few things to do, then names its guide section. +|48: 12 Words in backticks, like `Save`, are builtins. +|49: 13 `Exec` (B2) runs the builtin a word names, or else runs it as a +|50: 14 shell line; `Look` (B3) opens what the text names, or else finds +|51: 15 it. Type a builtin in any tag and `Exec` it. Lines starting with +|52: 16 "| " are tags. +|53: 17 +|54: 18 Press j until you reach part 1. +|55: 19 +|56: 20 +|57: 21 ================================================================= +|58: 22 = PART 1 — MODES = +|59: 23 ================================================================= +|60: 24 +|61: 25 1. The box left of this pane's tag is blank, so you are in +|62: 26 NORMAL mode. Press i: it shows ^ (INSERT). Type a word, then +|63: 27 Esc: blank again. +|64: 28 2. Press Esc once more, in NORMAL: the keyboard goes back to the +|65: 29 pane you were in before (not what helix does). Come back with +|66: 30 Esc again. diff --git a/test/snapshots/leader.golden b/test/snapshots/leader.golden index 1bd0bb41..9f523992 100644 --- a/test/snapshots/leader.golden +++ b/test/snapshots/leader.golden @@ -27,28 +27,27 @@ |20: 14 Open the tutor, a document to work through. |21: 15 |22: ~ -== snap tutor grid=100x41 cursor=7,22 +== snap tutor grid=100x41 cursor=7,23 |6: 1 pardes builtins under SPC h Tutor -|21: /tmp/pardes-snap/leader/cwd/+Tutor Save Term Collapse Follow Del -|22: 1 -|23: 2 PARDES TUTOR -|24: 3 -|25: 4 This pane is +Tutor, a copy: edit it freely; there is no need to -|26: 5 Save it (a bare Save asks for a path to write a copy to). -|27: 6 `Del` in its tag closes it; once you have edited it, `Del` refuses -|28: 7 once and the second `Del` discards. `Tutor` or SPC h t opens a -|29: 8 fresh copy. -|30: 9 -|31: 10 The guide (docs/typ/guide.typ) explains; this is the hands-on part. -|32: 11 Each lesson is a few things to do, then names its guide section. -|33: 12 Words in backticks, like `Save`, are builtins. -|34: 13 `Exec` (B2) runs the builtin a word names, or else runs it as a -|35: 14 shell line; `Look` (B3) opens what the text names, or else finds -|36: 15 it. Type a builtin in any tag and `Exec` it. Lines starting with -|37: 16 "| " are tags. -|38: 17 -|39: 18 Press j until you reach part 1. -|40: 19 +|22: /tmp/pardes-snap/leader/cwd/+Tutor Save Term Collapse Follow Del +|23: 1 +|24: 2 PARDES TUTOR +|25: 3 +|26: 4 This pane is +Tutor, a copy: edit it freely; there is no need to +|27: 5 Save it (a bare Save asks for a path to write a copy to). +|28: 6 `Del` in its tag closes it; once you have edited it, `Del` refuses +|29: 7 once and the second `Del` discards. `Tutor` or SPC h t opens a +|30: 8 fresh copy. +|31: 9 +|32: 10 The guide (docs/typ/guide.typ) explains; this is the hands-on part. +|33: 11 Each lesson is a few things to do, then names its guide section. +|34: 12 Words in backticks, like `Save`, are builtins. +|35: 13 `Exec` (B2) runs the builtin a word names, or else runs it as a +|36: 14 shell line; `Look` (B3) opens what the text names, or else finds +|37: 15 it. Type a builtin in any tag and `Exec` it. Lines starting with +|38: 16 "| " are tags. +|39: 17 +|40: 18 Press j until you reach part 1. == snap deleted grid=100x41 cursor=7,3 |5: |6: @@ -69,23 +68,23 @@ |21: |22: |23: -|24: -|25: /tmp/pardes-snap/leader/cwd/+Help Save Term Collapse Follow Del -|26: 1 pardes builtins under SPC h -|27: 2 -|28: 3 SPC h b Build -|29: 4 Show this build in a +Build: its version, compiler, optimize mode, target and dependencies. -|30: 5 A stamped build's (a release, or the ~/.local install) commit, jj change and build time too,↩ -|31: its platform, its grammars, and whether the addons are compiled in. -|32: 6 -|33: 7 SPC h c Changelog topbar -|34: 8 Show this build's version and what changed to reach it, in a +Changelog. -|35: 9 -|36: 10 SPC h m Messages -|37: 11 Show the messages said so far in a +Messages. -|38: 12 -|39: 13 SPC h t Tutor topbar -|40: 14 Open the tutor, a document to work through. +|24: /tmp/pardes-snap/leader/cwd/+Help Save Term Collapse Follow Del +|25: 1 pardes builtins under SPC h +|26: 2 +|27: 3 SPC h b Build +|28: 4 Show this build in a +Build: its version, compiler, optimize mode, target and dependencies. +|29: 5 A stamped build's (a release, or the ~/.local install) commit, jj change and build time too,↩ +|30: its platform, its grammars, and whether the addons are compiled in. +|31: 6 +|32: 7 SPC h c Changelog topbar +|33: 8 Show this build's version and what changed to reach it, in a +Changelog. +|34: 9 +|35: 10 SPC h m Messages +|36: 11 Show the messages said so far in a +Messages. +|37: 12 +|38: 13 SPC h t Tutor topbar +|39: 14 Open the tutor, a document to work through. +|40: 15 == snap help-column grid=100x41 cursor=7,6 |5: /tmp/pardes-snap/leader/cwd/+Help Save Term Collapse Follow Del |6: 1 pardes builtins under SPC c -- cgit v1.3 From e332c4c300bd39ba9b2da797391e37ddebda5319 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 06:03:39 -0300 Subject: soak: a join's dump that loads as another session says the fields it differs by, as a client's join says them (replica.fromDump's words: `loadDiffers` made pub): the coordinator's merge67b release soak had 'seed 3 rtt 207 ms: client 3's dump loaded as another session' and no field (1 in 12 seed-runs), not reproduced yet Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 2 +- test/replicas.zig | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/core/replica.zig b/core/replica.zig index 182d25c2..48cb1838 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -3100,7 +3100,7 @@ fn loadAgain(gpa: Allocator, j: *Joined, have: ?*Have, why: []u8, session: []con /// The fields a replica loaded from the join's dump `bytes` has other than /// the session as it dumped them (the digest a field at a time the dump /// ends with: dump.joinParts), named in `out`. -fn loadDiffers(r: *Replica, bytes: []const u8, out: []u8) []const u8 { +pub fn loadDiffers(r: *Replica, bytes: []const u8, out: []u8) []const u8 { const want = pardes.dump.joinParts(r.gpa, bytes) orelse return "(the dump names no field) "; defer r.gpa.free(want); var arena: std.heap.ArenaAllocator = .init(r.gpa); diff --git a/test/replicas.zig b/test/replicas.zig index 3aa9263e..cd0a3459 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -1986,7 +1986,9 @@ const Soak = struct { rp.echo.now = m.at * 1000; if (!rp.loaded(cl.digest)) { s.totals.unequal += 1; - std.debug.print("seed {d} rtt {d} ms: client {d}'s dump loaded as another session\n", .{ s.r.seed, s.r.rtt_ms, m.who }); + // The fields it differs by, as a client's join says them (replica.fromDump). + var named: [400]u8 = undefined; + std.debug.print("seed {d} rtt {d} ms: client {d}'s dump loaded as another session: {s}differs\n", .{ s.r.seed, s.r.rtt_ms, m.who, replica.loadDiffers(rp, m.bytes, &named) }); } cl.live = m.gen; var j: replica.Joined = .{ .fd = cl.cfd, .pid = 0, .client = cl.id, .view = cl.view, .gmtoff = 0, .dump = &.{} }; -- cgit v1.3 From 6fdf2bf2b1a90714ba998fa959db33089abb9f56 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:09:41 -0300 Subject: test/daemon.py --client-idle (FAILING on nvuylkxw, the multi-client line's flood: "a PDF in a window's session floods every client"): a session showing a PDF, one terminal client attached, nobody typing for 5 s, takes no more steps than the same session showing the text alone, plus 40 for the PDF's opening (its page drawn, its views told), in boundaries and in the client's units: a window's session on the test surface, a window's loop offscreen with no test mode (asleep until an event or its deadline, as a real window's is: `loop`), and a terminal's with its own terminal; on the base (Debug, load 4): the test surface 388 boundaries and 389 units against the text alone's 206 and 207, the window's loop 4871 and 4872 against 5 and 6 (the session's CPU 1070 ms in the 5 s, the client's 360), the terminal's 7 and 8 against 5 and 6 (passes); the bound's terms: on the test surface the window's loop polls its feed every 16 ms, a step and a unit each, which the text alone's count is; a window's own loop and a terminal's session step for nothing; pdf.so beside both binaries (`zig build install addons` into their prefix): one missing fails the test, never skips it Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- test/daemon.py | 113 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) (limited to 'test') diff --git a/test/daemon.py b/test/daemon.py index 5603131d..97d7a2bb 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -55,6 +55,11 @@ private HOME and runtime directory: a client window showing a PDF resized 30 times in a second by the real compositor (driftwm), the caller's display: no SDL assertion, the last size taken, an input a size at most + python3 -B test/daemon.py --client-idle + a window's session (the test surface, and offscreen with no test + mode) and a terminal's, each with a PDF and a terminal client, + nobody typing: no more steps than the text alone (pdf.so in both + prefixes) """ import fcntl import json @@ -2278,6 +2283,112 @@ def client_motion(binary, gui_binary): shutil.rmtree(root, ignore_errors=True) +def idle_session(binary, gui_binary, surface, pdf, secs): + """One session (`surface`: a window's on the test surface; a window's + offscreen with no test mode, `loop`: the loop a real window runs, asleep + until an event or its deadline; or a terminal's with its own terminal), + a text and, with `pdf`, a PDF, one terminal client attached, nobody + typing for `secs`: the session's boundaries and the units the client + took over its whole life, and the CPU each spent in the idle seconds + (ticks of 10 ms).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='ci-', dir=os.environ.get('TMPDIR') or scratch)) + env = base_env() + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(60))) + stats = root / 'session.stats' + started, terms, windows = [], [], [] + try: + if surface == 'window': + win = Window(root, 'win', [gui_binary, '--9p=idle', str(notes)], dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats))) + windows.append(win) + started.append(win.pid) + elif surface == 'loop': + started.append(subprocess.Popen([gui_binary, '--9p=idle', str(notes)], cwd=root, stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, start_new_session=True, + env=dict(env, PARDES_DAEMON='on', PARDES_REPLICA_STATS=str(stats), SDL_VIDEO_DRIVER='offscreen')).pid) + else: + ts = Term(30, 100) + terms.append(ts) + started.append(ts.spawn([binary, '--tty', '--9p=idle', str(notes)], dict(env, PARDES_REPLICA_STATS=str(stats))).pid) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-idle.sock').exists, timeout=30) + nine = Client(root / 'pardes-9p-idle.sock') + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + started.append(session) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists, timeout=30) + pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + if pdf: + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + nine.write(f'/pane/{pane}/look', f'{doc}\n'.encode()) + wait_for('the PDF shown', lambda: any(row.split()[1] == b'pdf' for row in nine.read('/index').splitlines()), timeout=30) + tc = Term(24, 80) + terms.append(tc) + c = tc.spawn([binary, f'--attach={sock}:idle'], dict(env, PARDES_REPLICA_STATS=str(root / 'c.stats'))) + started.append(c.pid) + wait_for('the client\'s first frame', lambda: b'notes' in tc.text(), timeout=30) + # Its join and the frames after it over. + time.sleep(1.5) + cpu = (cpu_ticks(session), cpu_ticks(c.pid)) + time.sleep(secs) + cpu = (cpu_ticks(session) - cpu[0], cpu_ticks(c.pid) - cpu[1]) + c.send_signal(signal.SIGHUP) + c.wait(timeout=10) + line = checks(root / 'c.stats')[-1].split() + units = int(line[line.index('units') + 1]) + exit_session(nine, pane) + wait_for('the session ended', lambda: not alive(session), timeout=60) + nine.socket.close() + return int(session_stats(stats)[0]['boundaries']), units, cpu + finally: + for t in terms: + t.close() + for w in windows: + if w.p.poll() is None: + w.p.kill() + for pid in started + processes(root): + try: + os.kill(pid, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + +def client_idle(binary, gui_binary, secs=5): + """An idle session sends nothing (2026-11-24: a PDF in a window's session + with a client attached stepped the session ~700 times a second, nobody + typing, each step a unit every client replayed): a session showing a + text and a PDF, one terminal client, nobody typing for `secs`, takes at + most the steps the same session with the text alone takes, plus the + PDF's own opening (its page drawn, its views told: `opening`). On the + test surface the window's loop polls its feed every 16 ms, a step and a + unit each (the text alone's count is that rate); a window's own loop + (`loop`: offscreen, no test mode) and a terminal's session step for + nothing. The PDF's addon (`/lib/pardes/addons/pdf.so`, `zig + build addons`) beside each binary.""" + for b in (binary, gui_binary): + lib = Path(b).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + assert lib.exists(), f'no {lib}: the PDF is this test\'s subject (zig build install addons into that prefix)' + opening = 40 + flooded = [] + for surface in ('window', 'loop', 'tty'): + text = idle_session(binary, gui_binary, surface, False, secs) + shown = idle_session(binary, gui_binary, surface, True, secs) + print(f'daemon: a {surface}\'s session idle {secs} s, a terminal client attached: ' + f'text alone {text[0]} boundaries, the client {text[1]} units, CPU {text[2][0] * 10}/{text[2][1] * 10} ms; ' + f'with a PDF {shown[0]} boundaries, {shown[1]} units, CPU {shown[2][0] * 10}/{shown[2][1] * 10} ms (session/client)') + if shown[0] > text[0] + opening or shown[1] > text[1] + opening: + flooded.append(f'{surface}: {shown[0]} boundaries and {shown[1]} units against the text alone\'s {text[0]} and {text[1]}') + assert not flooded, (f'a session showing a PDF, a client attached, nobody typing for {secs} s, steps with nothing to do, ' + f'a unit every client replays: {"; ".join(flooded)}') + + def client_resize_real(binary, gui_binary): """A client window resized by a real compositor (driftwm's `msg resize`, the configures a drag sends: 30 sizes in a second) while it shows a PDF: @@ -4493,6 +4604,8 @@ if __name__ == '__main__': client_motion(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--client-resize-real']: client_resize_real(sys.argv[2], sys.argv[3]) + elif sys.argv[1:2] == ['--client-idle']: + client_idle(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--ping']: ping(sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5]) if len(sys.argv) > 5 else 50) elif sys.argv[1:2] == ['--pair-gui']: -- cgit v1.3 From 4ae132650106242a5130aad5230c4f429bf02b29 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 24 Nov 2026 14:43:18 -0300 Subject: replica, gui, tui: the clock a session's pump reads after its wait is held only while a client's post waits for it (Peers.heldNow, which both shells' clocks call), so a wait that ran out always reads the clock and its step meets the deadline it waited for: a window's session showing a PDF with a client attached stepped ~700 times a second with nobody typing, each step a unit every client replayed (the multi-client line's "a PDF in a window's session floods every client"); RUN (an instrumented Debug build, the window's loop offscreen with no test mode, a terminal client; .scratch reorg/pardes-idle-flood/runs/probe): the client's view of the PDF (pane 1, view 1: 78x9, 8x16, glyphs) owed to the kind from its join on (Kind.wake: now, so nextWake a frame on), and 2247 of 2268 pumps 'mail_only true, mail false, wait ran out', the clock read after each the one held at the join (1.302 s while the real one ran to 2.93 s), so advance never reached the deadline, the view was never told, and the next wait was 1 ms: for ever; THE CAUSE: dev/gui/gui.zig guiNow held the clock after any wait whose `mail_only` was still set, and waitInput sets it at a wait's start and clears it only for an event that is not a replica's wake or a queue message: a wait that ran out (SDL_WaitEventTimeout false, waitDetached's too) took no post and still held the clock; a terminal's session never did (its wait ends in a .wake event, tui.zig apply clears it); THE FIX: Peers.heldNow (core/replica.zig): held only when the wait took nothing else (the shell's `mail_only`), a client is attached (`recording`), a post waits to be taken (`mail`, set by post, cleared at the boundary) and the clock has started; gui.zig guiNow and tui.zig clockNow call it (their own copies of the rule gone), so no shell's wait can hold the clock without a post; TEST FIRST: test/panes.zig "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" (on the base's rule, the same function without `mail`: fails at panes.zig:4120, the view still owed after the pump); test/daemon.py --client-idle on this build: the window's loop 7 boundaries and 8 units with a PDF against the text alone's 5 and 6 (4871 and 4872 on the base), the test surface 223 against 207 (388 against 206), the terminal's 8 against 5; a user hit it: every window's session with a client attached and a deadline owed (a PDF's view, a message's linger, a Life's tick, a look's hover) stepped and sent a unit a millisecond until someone typed in the window Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 12 ++++++++ dev/gui/gui.zig | 7 ++--- dev/tui/tui.zig | 7 ++--- test/panes.zig | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/core/replica.zig b/core/replica.zig index 829972c2..875a7828 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -1911,6 +1911,18 @@ pub const Peers = struct { return n; } + /// The time the session's pump reads after its wait, when that wait + /// took a client's post and nothing else (`only_mail`, the shell's word + /// for its wait): the core's clock as it stands, so the pump's unit + /// moves nothing a client's speculation stands on; null otherwise (the + /// shell's clock). Held only while a post waits (`mail`): a wait that + /// ran out took none, and the pump after it is the one its deadline + /// asked for (a window's wait that ran out was held, 2026-11-24: a + /// deadline never met, the session stepped a millisecond for ever). + pub fn heldNow(ps: *const Peers, core: *const Pardes, only_mail: bool) ?u64 { + return if (only_mail and ps.recording and ps.mail.load(.acquire) and core.clock.started) core.clock.now_ns else null; + } + pub fn post(ps: *Peers, note: Note) void { ps.lock.lockUncancelable(ps.io); if (note == .join and ps.upgrading.load(.monotonic)) { diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index 9ea813fc..8fd8c24c 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -2457,9 +2457,8 @@ const Shell = struct { /// of their own with no window here; the session loop's /// (runtime/session.zig), a client's none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the pump - /// after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (tui.zig's `mail_only`). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// With replica clients, a wait takes one person's input (tui.zig @@ -3167,7 +3166,7 @@ fn guiNow(ctx: ?*anyopaque) u64 { const s = shellOf(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse s.paced_ns orelse c.SDL_GetTicksNS(); } diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index e2cdd2fa..312a0846 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -1240,9 +1240,8 @@ const Shell = struct { /// The session's replica clients (core/replica.zig), on sockets: the /// session loop's (runtime/session.zig); a client's, none. peers: *replica.Peers, - /// This wait took only a replica's post (its input, its join): the - /// pump after it reads no new time, so it moves nothing the replicas' - /// speculations stand on (a replica takes such a unit as is). + /// This wait took nothing but a replica's post, if one (its input, its + /// join): the pump after one reads no new time (Peers.heldNow). mail_only: bool = false, waited: bool = false, /// This wait's steps so far, and the input held for the next (`split`). @@ -1321,7 +1320,7 @@ const Shell = struct { const s = of(ctx); if (s.waited) { s.waited = false; - if (s.mail_only and s.peers.count() > 0 and s.core.clock.started) return s.core.clock.now_ns; + if (s.peers.heldNow(s.core, s.mail_only)) |held| return held; } return s.test_clock orelse @intCast(std.Io.Clock.awake.now(s.io).nanoseconds); } diff --git a/test/panes.zig b/test/panes.zig index bd39beba..28a3b256 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -4047,6 +4047,90 @@ const PdfAddon = struct { } } + /// A session's loop with nobody typing: each wait runs out at its + /// deadline, and the clock read after it is the shells' (Peers.heldNow, + /// as gui.zig `guiNow` and tui.zig `clockNow` read it: a wait that took + /// nothing else, `only_mail`). + const Idle = struct { + now: u64 = std.time.ns_per_s, + waited: bool = false, + core: ?*Pardes = null, + peers: pardes.replica.Peers = .{ .gpa = std.testing.allocator, .io = std.testing.io }, + + const vtable: pardes.Host.VTable = .{ + .wait_input = wait, + .now = clock, + .watched = host_vtable.watched, + .job = host_vtable.job, + }; + + fn wait(ctx: ?*anyopaque, timeout_ms: u32) void { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + h.now += @as(u64, timeout_ms) * std.time.ns_per_ms; + h.waited = true; + } + + fn clock(ctx: ?*anyopaque) u64 { + const h: *Idle = @ptrCast(@alignCast(ctx.?)); + if (!h.waited) return h.now; + h.waited = false; + return h.peers.heldNow(h.core orelse return h.now, true) orelse h.now; + } + }; + + test "a PDF shown and a client's view its kind was not told: the session's next pump, its wait run out with nobody typing, tells it, and nothing is owed after; a client's post waiting holds the clock" { + // 2026-11-24: a window's session showing a PDF, a client attached, + // stepped ~700 times a second with nobody typing: the client's view + // owed to the kind (Kind.wake: now), a wait of a millisecond that + // ran out, and the clock after it held as if a client had posted + // (gui.zig guiNow: its wait's `mail_only` is cleared by an event, + // and one that ran out had none), so no step met the deadline. + if (!addons.has_pdf) return error.SkipZigTest; + const R = pardes.replica; + var idle: Idle = .{}; + defer idle.peers.deinit(); + const a = try R.Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .ctx = &idle, .vtable = &Idle.vtable }); + defer a.deinit(); + idle.core = a.core; + const Land = struct { + a: *R.Authority, + fn step(l: @This(), ev: pardes.Event) !void { + _ = try l.a.local(ev); + } + }; + const id = try opened(a, Land{ .a = a }); + const slot = a.core.panes[id].?.addon.?; + // A client attached (units go to it), its view sized by its input: + // a client's step tells no kind (17.2), so its view is owed. + idle.peers.recording = true; + const k = (try a.openView(2)).view; + const was = pardes.tape.on; + pardes.tape.on = &a.t; + const bytes = try pardes.dump.byteDump(a.core); + pardes.tape.resync(&a.t); + pardes.tape.on = was; + defer a.core.gpa.free(bytes); + const win = try R.Replica.initDump(std.testing.allocator, 2, k, bytes, .{ .cols = 80, .rows = 24 }); + defer win.deinit(); + _ = try a.take(try win.input(.{ .resize = .{ .cols = 80, .rows = 24 } })); + try std.testing.expect(pardes.Kind.viewOwed(a.core, slot, id)); + // ONE pump, nobody typing: its wait runs out at the wake, the step + // it asked for tells the view, and nothing is owed after. + a.pump(); + try std.testing.expect(!pardes.Kind.viewOwed(a.core, slot, id)); + try std.testing.expect((pardes.Kind.wake(a.core) orelse std.math.maxInt(u64)) > a.core.clock.now_ns); + // A client's post waiting (its input, its join): the pump before + // the boundary takes it reads the clock as it stands. + const at = a.core.clock.now_ns; + idle.now += std.time.ns_per_s; + idle.peers.mail.store(true, .release); + a.pump(); + try std.testing.expectEqual(at, a.core.clock.now_ns); + idle.peers.mail.store(false, .release); + a.pump(); + try std.testing.expectEqual(idle.now, a.core.clock.now_ns); + } + test "a PDF pane whose file changes on disk opens again from it at its page, its fit kept" { if (!addons.has_pdf) return error.SkipZigTest; const gpa = std.testing.allocator; -- cgit v1.3