summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-22 03:03:55 -0300
committerGabriel Schneider <[email protected]>2026-11-22 10:31:04 -0300
commit9158de5d50831e115e14e2ed502300ee8c1d9930 (patch)
tree2b5e60569307e02d82b19bd419279392a6da257b /test
parent70c9e3fbf9cdc7139b4da0142f3a44741a7e1491 (diff)
downloadpardes-9158de5d50831e115e14e2ed502300ee8c1d9930.tar.gz
pardes-9158de5d50831e115e14e2ed502300ee8c1d9930.zip
term: screen_state.zig deleted, and the terminal module's side of the delta road (the old road's deletion, piece 5 of 8): core/term/screen_state.zig (1,213 lines: the encoder, tracks, peers' flights, a replica's apply and holes, its own soak and four tests) goes whole; core/term/terminal.zig loses `encode`/`encodeRows`/`encoder`/`encoderFree`/`track`/`untrack`/`replica`/`replicaFree`/`replicaTop`/`missing`/`apply`/`applyRows`/`shown`/`blank`, `takeMarks` (`marksOf` stays, private: the tests compare two terminals by it), the State's `changes` (a version's counter for the tracks), `read` with `markRead`/`wasRead`/`clearRead` (the rows a step read, for the fills), and `resize_to` with `resizeDeferred` and `resize`'s `later` (screen state's authority sized its terminals after a step's unit); abi/term.zig loses the `Encoder`/`Track`/`Replica` handles, `flight_bound`, `Peer`, `Applied` and those entries of `Ops` (and `dumpScreen`, which nothing in the core called); core/Term.zig its wrappers; core/term/term.zig its ops, its handle map and its `screen_state` export; core/panes.zig its `resizeDeferred` and resizes now (its later screen-state lines go in piece 6); core/edit.zig its `markRead`; the cell-for-cell dump the soak compares a client's terminal with its session's by moves to terminal.zig (`dumpScreen`, over the emulator), the soak's three streams (a shell's, a full-screen program's, `yes`) into test/replicas.zig, their one user; test/terminal.zig loses `a replica's terminal pane draws as its authority's does` (a delta's) and `a terminal made fresh has no size waiting` (`resize_to`'s); core-test 911/1068 (157 skipped), shell-test 1110/1113, term-test 15/15, pane-test 181/182 (again after the machines reboot, on a wiped cache), the soaks small run and `--echo` rc 0
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/replicas.zig62
-rw-r--r--test/terminal.zig95
2 files changed, 58 insertions, 99 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index aa10d4a9..f4d8d450 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -39,7 +39,7 @@ const pardes = @import("pardes");
const replica = pardes.replica;
const client_loop = @import("runtime").client;
const session_loop = @import("runtime").session;
-const screen_state = @import("term").screen_state;
+const term = @import("term");
const Echo = pardes.Echo;
const Key = pardes.Key;
@@ -440,10 +440,10 @@ fn writeText(path: [:0]const u8, text: []const u8) !void {
const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, flood_mb: u64 };
/// The terminal pane's screen as a hash of a dump of its cells.
-fn screenHash(t: *screen_state.Terminal) u64 {
+fn screenHash(t: anytype) u64 {
var buf: [8192]u8 = undefined;
var h: std.Io.Writer.Hashing(std.hash.Wyhash) = .initHasher(.init(0), &buf);
- screen_state.dumpScreen(t, &h.writer) catch {};
+ term.terminal.dumpScreen(t, &h.writer) catch {};
h.writer.flush() catch {};
return h.hasher.final();
}
@@ -2125,9 +2125,9 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void {
// What the shell's program prints: a full-screen program, a shell's
// session (prompts, titles, directories, a clear now and then), then a
// flood of `yes` and of a `cat`, read 4 KB at a time as a pty gives it.
- const tui = try screen_state.tuiStream(gpa);
+ const tui = try tuiStream();
defer gpa.free(tui);
- const session_only = try screen_state.shellStream(gpa);
+ const session_only = try shellStream();
defer gpa.free(session_only);
const shell_session = try std.mem.concat(gpa, u8, &.{ session_only, questions });
defer gpa.free(shell_session);
@@ -2140,7 +2140,7 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void {
_ = shm.shm_unlink(object);
}
}
- const yes_only = try screen_state.yesStream(gpa, @intCast(r.flood_mb * (1 << 20) / 3));
+ const yes_only = try yesStream(@intCast(r.flood_mb * (1 << 20) / 3));
defer gpa.free(yes_only);
const yes = try std.mem.concat(gpa, u8, &.{ yes_only, shown });
defer gpa.free(yes);
@@ -2263,6 +2263,56 @@ fn images(dir: []const u8, seed: u64, media: *Media) ![]u8 {
/// `before`, then `n` bytes of what a `cat` of source text prints through a
/// pty: this file's lines, CR LF after each, again and again.
+/// A shell's: prompts marked (OSC 133), colours of the three kinds, wide
+/// and combined graphemes, hyperlinks, tabs, a title and a directory, long
+/// lines that wrap, and a clear (ED2, ED3) now and then.
+fn shellStream() ![]u8 {
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ errdefer out.deinit();
+ const w = &out.writer;
+ try w.writeAll("\x1b]0;a shell\x07\x1b]7;file://host/home/someone\x07");
+ for (0..400) |i| {
+ try w.print("\x1b]133;A\x07$ \x1b]133;B\x07ls -l {d}\r\n\x1b]133;C\x07", .{i});
+ try w.print("\x1b[1;31mred\x1b[0m \x1b[4;38;5;{d}m256\x1b[0m \x1b[38;2;{d};100;200;48;5;17mtrue\x1b[0m 漢字 e\u{301} 👩\u{200d}💻 ", .{ i % 256, i % 256 });
+ try w.print("\x1b]8;;https://example.com/{d}\x07link\x1b]8;;\x07\tx\r\n", .{i});
+ if (i % 7 == 0) {
+ for (0..12) |_| try w.writeAll("a long line that wraps ");
+ try w.writeAll("\r\n");
+ }
+ try w.writeAll("\x1b]133;D;0\x07");
+ if (i % 97 == 96) try w.writeAll("\x1b[H\x1b[2J\x1b[3J");
+ if (i % 50 == 0) try w.print("\x1b]2;title {d}\x07\x1b]4;1;rgb:{x:0>2}/20/30\x07", .{ i, i % 256 });
+ }
+ return out.toOwnedSlice();
+}
+
+/// A full-screen program's: the alternate screen and its modes, a status
+/// line, a scrolling region scrolled both ways, lines inserted and
+/// deleted, cursor shapes, the kitty keyboard pushed and popped.
+fn tuiStream() ![]u8 {
+ var out: std.Io.Writer.Allocating = .init(gpa);
+ errdefer out.deinit();
+ const w = &out.writer;
+ try w.writeAll("before the program\r\n\x1b[?1049h\x1b[?25l\x1b[?1000h\x1b[?1006h\x1b[?2004h\x1b[?1h\x1b[>1u\x1b[4 q\x1b[H\x1b[2J");
+ for (0..300) |f| {
+ try w.print("\x1b[1;1H\x1b[44;97m status {d} \x1b[K\x1b[0m", .{f});
+ try w.print("\x1b[3;18r\x1b[18;1H\r\n\x1b[3{d}mline {d}\x1b[0m", .{ f % 8, f });
+ if (f % 3 == 0) try w.writeAll("\x1b[3;1H\x1bM\x1b[2mreversed in\x1b[0m");
+ if (f % 5 == 0) try w.writeAll("\x1b[6;1H\x1b[2L\x1b[9;1H\x1b[M");
+ try w.writeAll("\x1b[r");
+ try w.print("\x1b[{d};{d}H\x1b[7m*\x1b[0m\x1b[{d}X", .{ 2 + f % 20, 1 + (f * 7) % 70, f % 5 });
+ if (f % 11 == 0) try w.writeAll("\x1b[?25h\x1b[6 q") else if (f % 11 == 5) try w.writeAll("\x1b[?25l\x1b[2 q");
+ }
+ try w.writeAll("\x1b[<u\x1b[?1049l\x1b[?25h\x1b[?1000l\x1b[0 qafter the program\r\n");
+ return out.toOwnedSlice();
+}
+
+fn yesStream(lines: usize) ![]u8 {
+ const out = try gpa.alloc(u8, lines * 3);
+ for (0..lines) |i| @memcpy(out[i * 3 ..][0..3], "y\r\n");
+ return out;
+}
+
fn catAfter(before: []const u8, n: usize) ![]u8 {
var out: std.ArrayListUnmanaged(u8) = .empty;
errdefer out.deinit(gpa);
diff --git a/test/terminal.zig b/test/terminal.zig
index ec050c7a..7e7106a1 100644
--- a/test/terminal.zig
+++ b/test/terminal.zig
@@ -1,6 +1,6 @@
//! The terminal through the core (docs/next-terminal.md, Phase 1): what
-//! were core/term/terminal.zig's and screen_state.zig's tests of a terminal
-//! pane, moved as they were. They boot a core and read the emulator behind
+//! were core/term/terminal.zig's tests of a terminal pane, moved as they
+//! were. They boot a core and read the emulator behind
//! it, so they need both modules, which only a suite outside both has:
//! pane-test's (test/panes.zig). The emulator's own tests stay in core/term/.
const std = @import("std");
@@ -9,12 +9,6 @@ const plain = @import("plain");
const term = @import("term");
const ghostty_vt = @import("ghostty-vt");
const emu = term.terminal;
-const screen_state = term.screen_state;
-const Encoder = screen_state.Encoder;
-const Track = screen_state.Track;
-const Peer = screen_state.Peer;
-const Replica = screen_state.Replica;
-const encode = screen_state.encode;
const Surface = pardes.Surface;
const Pane = pardes.Pane;
const FilterPalette = Term.FilterPalette;
@@ -100,39 +94,6 @@ test "replay ownership is terminal-only and construction rolls back on allocatio
try std.testing.checkAllAllocationFailures(std.testing.allocator, Case.run, .{true});
}
-test "a terminal made fresh has no size waiting: one never resized keeps its grid when a unit is cut" {
- // Fresh memory as a Debug build's allocator hands it out: 0xAA. A field
- // `create` left unset read a size of 43690x43690 (fixer 2's, 2026-10-30).
- const Filling = struct {
- child: std.mem.Allocator,
- fn alloc(ctx: *anyopaque, len: usize, a: std.mem.Alignment, ra: usize) ?[*]u8 {
- const self: *@This() = @ptrCast(@alignCast(ctx));
- const ptr = self.child.rawAlloc(len, a, ra) orelse return null;
- @memset(ptr[0..len], 0xAA);
- return ptr;
- }
- fn grow(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, n: usize, ra: usize) bool {
- const self: *@This() = @ptrCast(@alignCast(ctx));
- return self.child.rawResize(buf, a, n, ra);
- }
- fn remap(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, n: usize, ra: usize) ?[*]u8 {
- const self: *@This() = @ptrCast(@alignCast(ctx));
- return self.child.rawRemap(buf, a, n, ra);
- }
- fn free(ctx: *anyopaque, buf: []u8, a: std.mem.Alignment, ra: usize) void {
- const self: *@This() = @ptrCast(@alignCast(ctx));
- self.child.rawFree(buf, a, ra);
- }
- const vtable: std.mem.Allocator.VTable = .{ .alloc = alloc, .resize = grow, .remap = remap, .free = free };
- };
- var filling: Filling = .{ .child = std.testing.allocator };
- const gpa: std.mem.Allocator = .{ .ptr = &filling, .vtable = &Filling.vtable };
- const pane = try panes.createTerminal(gpa, 40, 12);
- defer gpa.destroy(pane);
- defer if (pane.terminal) |state| close(state, gpa);
- try std.testing.expect(of(pane.terminal.?).resize_to == null);
-}
-
test "document construction allocates only the pane and has inert terminal defaults" {
var failing = std.testing.FailingAllocator.init(std.testing.allocator, .{ .fail_index = 1 });
const allocator = failing.allocator();
@@ -926,55 +887,3 @@ test "colors.xterm is the palette the emulator starts from, all 256" {
for (pardes.colors.xterm, ghostty_vt.color.default) |ours, its| try std.testing.expectEqual(ours, [3]u8{ its.r, its.g, its.b });
}
-test "a replica's terminal pane draws as its authority's does" {
- const testing = std.testing;
- const gpa = testing.allocator;
- const a = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 });
- defer a.deinit();
- const b = try pardes.Pardes.init(gpa, .{ .tty_only = true, .cols = 60, .rows = 16 });
- defer b.deinit();
- while (a.nextEffect()) |_| {}
- while (b.nextEffect()) |_| {}
- var fa = std.heap.ArenaAllocator.init(gpa);
- defer fa.deinit();
- var fb = std.heap.ArenaAllocator.init(gpa);
- defer fb.deinit();
- // Laid out once, so both panes have their size before the first delta.
- _ = try a.render(fa.allocator());
- _ = try b.render(fb.allocator());
- const ta = &of(a.panes[0].?.terminal.?).vt;
- const tb = &of(b.panes[0].?.terminal.?).vt;
- var enc: Encoder = .init(gpa);
- defer enc.deinit();
- var peer: Peer = .{};
- defer peer.deinit(gpa);
- var tr: Track = .init(gpa);
- defer tr.deinit(gpa, ta);
- var rep: Replica = .{};
- defer rep.deinit(gpa);
- var delta: std.Io.Writer.Allocating = .init(gpa);
- defer delta.deinit();
- var line: [256]u8 = undefined;
- for (0..60) |i| {
- const bytes = try std.fmt.bufPrint(&line, "\x1b[1;3{d}m{d}\x1b[0m 漢字 e\u{301} \x1b[48;2;{d};40;60mbg\x1b[0m and then some text that wraps past the width of the pane\r\n", .{ i % 8, i, i * 4 % 256 });
- a.update(.{ .output = .{ .pane = .at(0), .bytes = bytes } });
- delta.clearRetainingCapacity();
- try testing.expect(try encode(&enc, &tr, &peer, ta, @intCast(i + 1), "", &delta.writer));
- peer.ack((try rep.apply(gpa, std.Io.Threaded.global_single_threaded.io(), tb, delta.written())).seq);
- b.needs_frame = true;
- _ = fa.reset(.retain_capacity);
- _ = fb.reset(.retain_capacity);
- const sa = try a.render(fa.allocator());
- const sb = try b.render(fb.allocator());
- const r = a.view().rects[0];
- // The body: below the pane's tag row.
- for (r.y + 1..r.y + r.h) |y| for (r.x..r.x + r.w) |x| {
- const ca = sa.at(@intCast(x), @intCast(y));
- const cb = sb.at(@intCast(x), @intCast(y));
- if (!ca.visuallyEqual(cb)) {
- std.debug.print("step {d}: cell {d},{d}: '{s}' vs '{s}'\n", .{ i, x, y, ca.grapheme(), cb.grapheme() });
- return error.ReplicaDrawsDifferently;
- }
- };
- }
-}