diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 21:33:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 21:36:28 -0300 |
| commit | 9acf9f558de00f4588b51dee2cd56b9150c7fb35 (patch) | |
| tree | 3231f30f2f0c1155aa7a87615641435ec97d7bf2 | |
| parent | 3f250d0f963f375d699f11ffc02b07f2e2cbbbee (diff) | |
| download | pardes-9acf9f558de00f4588b51dee2cd56b9150c7fb35.tar.gz pardes-9acf9f558de00f4588b51dee2cd56b9150c7fb35.zip | |
terminals' views: the carry's fuzz against ghostty's own view at 3,000 seeds, and its one disagreement ruled (pardes-term-join-11, item 1b: round 10's late finding, seed 1956: "carried 46, ghostty's own null"): the failing run first, a probe of seed 1956 step by step: a 44x3 terminal, the view on row 23 (the active area 24-26), resized to 21x6 (narrower AND taller): ghostty narrows in two phases, the rows first (PageList.resizeWithoutReflow: the active area grows to rows 21-26 and takes the view's row, so its pinned viewport is set to the output there, PageList.zig:2944-2950), then the reflow (row 23's line on rows 46-47 of 55, the active area 49-54): the row is history again, but ghostty decided in between; the carry (terminal.zig `carry`/`carried`) reads the pin's row once, after the whole write: 46, history; the ruling (the coordinator's lean, 2026-11-22): nothing under the view went away, ghostty's jump is the order of its own two phases (a widening's reflow checks before its growth too, PageList.zig:1525-1531), so the view stays on its line, and a view stays a function of the end state, not of the emulator's steps; so the carry is right and the oracle is taught: the fuzz's body is `carryFuzz` (one seed, how many it put back), whose oracle holds a pin of its own at its view's row through each resize, and where ghostty's view went to the output while that pin's row is history again, puts its view back on that row and counts it; the seed is its own test ("a scrolled-back view stays on its line through a narrowing that grows the rows ...", exactly one put back); the fuzz at 3,000 seeds (a local run, the bound put back to 300): clean, every disagreement of that one kind; not exercised by the fuzz and checked by reading: an erase of the history (CSI 3 J: the pin is garbage, the history empty, the place on the output, as ghostty's), a reset (ESC c: the screen made again, the place on the output, as ghostty's), a pruned row at the cap (the history's top, as ghostty's `.top`); a user could see it: a scrolled-back view of a pane made narrower and taller at once stays where it was reading, where ghostty the terminal would have jumped to the live screen; term-test 17/17 (the base's 16 and the seed's test), the 3,000 seeds 2/2
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
| -rw-r--r-- | core/term/terminal.zig | 130 |
1 files changed, 79 insertions, 51 deletions
diff --git a/core/term/terminal.zig b/core/term/terminal.zig index b1beff15..45c01841 100644 --- a/core/term/terminal.zig +++ b/core/term/terminal.zig @@ -1586,60 +1586,88 @@ test "a view's place at the history's cap: it keeps showing its line while outpu } test "a view's place is carried through output, the history's cap and reflows as ghostty carries a view of its own, a row's first cell each time (a fuzz)" { - // The oracle: an emulator scrolled by ghostty itself to the same row, - // fed and resized alike, its view put at its row's first cell after a - // reflow (a widening can leave ghostty's mid-row: pardes-term-join-6), - // and at the output when it reaches the active area. - const gpa = std.testing.allocator; var seed: u64 = 0; - while (seed < 300) : (seed += 1) { - var prng: std.Random.DefaultPrng = .init(seed); - const rnd = prng.random(); - var cols: u16 = rnd.intRangeAtMost(u16, 20, 60); - var rows: u16 = rnd.intRangeAtMost(u16, 2, 6); - const ours = try open(gpa, cols, rows); - defer close(ours); - const oracle = try open(gpa, cols, rows); - defer close(oracle); - const capped = rnd.boolean(); - for ([_]*State{ ours, oracle }) |s| if (capped) s.vt.screens.active.pages.setMaxBytes(1); - var places = [_]?usize{null}; - var line: [200]u8 = undefined; - for (0..80) |_| { - switch (rnd.uintLessThan(u8, 4)) { - 0, 1 => for (0..rnd.intRangeAtMost(usize, 1, 400)) |i| { - const len = rnd.intRangeAtMost(usize, 0, 150); - for (line[0..len], 0..) |*c, j| c.* = 'a' + @as(u8, @intCast((i + j) % 26)); - _ = feed(ours, line[0..len], &.{}, &.{}, &.{}, &places); - _ = feed(ours, "\r\n", &.{}, &.{}, &.{}, &places); - ingest(oracle, line[0..len]); - ingest(oracle, "\r\n"); - }, - 2 => { - if (rnd.boolean()) cols = rnd.intRangeAtMost(u16, 20, 60); - rows = rnd.intRangeAtMost(u16, 2, 6); - resize(ours, cols, rows, &places); - oracle.vt.resize(gpa, .{ .cols = cols, .rows = rows }) catch {}; - const pages = &oracle.vt.screens.active.pages; - if (pages.viewport == .pin) pages.viewport_pin.x = 0; - }, - else => { - const sb = ours.vt.screens.active.pages.scrollbar(); - const to = rnd.uintLessThan(usize, sb.total); - places[0] = if (to >= sb.total - sb.len) null else to; - oracle.vt.screens.active.scroll(.{ .row = to }); - }, - } - const pages = &oracle.vt.screens.active.pages; - const sb = pages.scrollbar(); - if (sb.offset >= sb.total - sb.len) pages.scroll(.active); - const want: ?usize = if (pages.viewport == .active) null else pages.scrollbar().offset; - if (want != places[0]) { - std.debug.print("seed {d}: carried {?d}, ghostty's own {?d}\n", .{ seed, places[0], want }); - return error.TestExpectedEqual; - } + while (seed < 300) : (seed += 1) _ = try carryFuzz(std.testing.allocator, seed); +} + +test "a scrolled-back view stays on its line through a narrowing that grows the rows, where ghostty's own went to the output in the middle of the resize (the carry's fuzz, seed 1956)" { + // 44x3, the view on row 23 (the active area 24-26), resized to 21x6: + // ghostty grows the rows first (the active area 21-26 takes the view's + // row: to the output), then reflows (the line on rows 46-47 of 55, the + // active area 49-54). Its history is all there: the view stays on it. + try std.testing.expectEqual(@as(usize, 1), try carryFuzz(std.testing.allocator, 1956)); +} + +/// One run of the carry's fuzz: 80 random reads of output (lines 0-150 +/// long, wrapped), resizes and scrolls of two emulators alike, a view's +/// place carried in one (`feed`, `resize`) and ghostty's own view in the +/// other (the oracle): its view put at its row's first cell after a reflow +/// (a widening can leave ghostty's mid-row: pardes-term-join-6), and at the +/// output when it reaches the active area. Where ghostty's view went to the +/// output only in the MIDDLE of a resize and its row is in the history +/// again after it (ghostty grows the rows before a narrowing's reflow, +/// PageList.resizeWithoutReflow, and checks before a widening's growth, +/// PageList.resizeCols: an order of its own, nothing under the view gone), +/// the view stays on its line (pardes-term-join-11): the oracle is put back +/// on the row a pin of its own was carried to through the resize, and the +/// run counts it. How many it put back. +fn carryFuzz(gpa: std.mem.Allocator, seed: u64) !usize { + var prng: std.Random.DefaultPrng = .init(seed); + const rnd = prng.random(); + var cols: u16 = rnd.intRangeAtMost(u16, 20, 60); + var rows: u16 = rnd.intRangeAtMost(u16, 2, 6); + const ours = try open(gpa, cols, rows); + defer close(ours); + const oracle = try open(gpa, cols, rows); + defer close(oracle); + const capped = rnd.boolean(); + for ([_]*State{ ours, oracle }) |s| if (capped) s.vt.screens.active.pages.setMaxBytes(1); + const pages = &oracle.vt.screens.active.pages; + var places = [_]?usize{null}; + var line: [200]u8 = undefined; + var kept: usize = 0; + for (0..80) |_| { + switch (rnd.uintLessThan(u8, 4)) { + 0, 1 => for (0..rnd.intRangeAtMost(usize, 1, 400)) |i| { + const len = rnd.intRangeAtMost(usize, 0, 150); + for (line[0..len], 0..) |*c, j| c.* = 'a' + @as(u8, @intCast((i + j) % 26)); + _ = feed(ours, line[0..len], &.{}, &.{}, &.{}, &places); + _ = feed(ours, "\r\n", &.{}, &.{}, &.{}, &places); + ingest(oracle, line[0..len]); + ingest(oracle, "\r\n"); + }, + 2 => { + if (rnd.boolean()) cols = rnd.intRangeAtMost(u16, 20, 60); + rows = rnd.intRangeAtMost(u16, 2, 6); + resize(ours, cols, rows, &places); + const held: ?*ghostty_vt.Pin = if (pages.viewport == .pin) pages.trackPin(pages.viewport_pin.*) catch null else null; + oracle.vt.resize(gpa, .{ .cols = cols, .rows = rows }) catch {}; + if (pages.viewport == .pin) pages.viewport_pin.x = 0; + if (held) |pin| { + defer pages.untrackPin(pin); + const row: usize = @intCast(pinnedRow(pages, .{ .pin = pin })); + if (pages.viewport == .active and !pin.garbage and row < pages.total_rows - pages.rows) { + pages.scroll(.{ .row = row }); + kept += 1; + } + } + }, + else => { + const sb = ours.vt.screens.active.pages.scrollbar(); + const to = rnd.uintLessThan(usize, sb.total); + places[0] = if (to >= sb.total - sb.len) null else to; + oracle.vt.screens.active.scroll(.{ .row = to }); + }, + } + const sb = pages.scrollbar(); + if (sb.offset >= sb.total - sb.len) pages.scroll(.active); + const want: ?usize = if (pages.viewport == .active) null else pages.scrollbar().offset; + if (want != places[0]) { + std.debug.print("seed {d}: carried {?d}, ghostty's own {?d}\n", .{ seed, places[0], want }); + return error.TestExpectedEqual; } } + return kept; } test "the luminance table answers exactly what ghostty computes" { |
