summaryrefslogtreecommitdiff
path: root/test/monkey.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-29 17:01:35 -0300
committerGabriel Schneider <[email protected]>2026-10-29 19:38:53 -0300
commit2cce341e2c94fb3150dc1f3e7911c26502a70487 (patch)
treec637fcfa9a52aa66f6c34600f4cdea4020088e01 /test/monkey.zig
parentc2b4f235e78735102c691677f08bd1b2403168df (diff)
downloadpardes-2cce341e2c94fb3150dc1f3e7911c26502a70487.tar.gz
pardes-2cce341e2c94fb3150dc1f3e7911c26502a70487.zip
views: several clients on one session, each its own layout, focus, cursors and scroll over the panes they share; a second `pardes --attach` draws on its own terminal beside the first, and `pardes-gui --attach` opens another window
The core still sees one view, the live one, in the fields it always had (src/views.zig): a view's share of the session (`views.fields`: its screen, columns, rects, focus, pointer and gestures, jumps, key prefixes, column tags, presentation and animations, windowed and native_images) and of each pane (`PaneView`: its place in the layout, which text has the keyboard, the body's cursor, selections and mode, its scroll, a document's size, what the step measured of it) is copied out when another view goes live and back when it is live again. One view never parks: the single client pays a test of one byte a step. `toView`, `openView` and `closeView` are taped inputs; the pump draws each other view by going into it and back, which leaves every digested field as it was, so the replica that draws nothing skips it. A parked view is in no digest (its slot is written whenever it goes out); what drawing it made of its own (animations, presentation) is kept, whatever its unpark brought inside a changed text is done again when it is next live. Shared: the panes' text, terminals, tags, prompts, messages, registers (yanked in one view, put in another), the workspace tag and settings. A terminal shown at two sizes takes the size of the view that typed into it last (`Pane.sized_by`), and any view's once that one is gone; the others show it at that size. A text edited in one view moves the other views' cursors and scroll with the splice, as a Zerox twin's (File.ParkedPlaces). A pane closed in one view leaves the others' layouts (by its slot's serial); a pane focused in a view that does not show it is placed in its active column (views.show). tty: each terminal is a Screen of its own (its vaxis, input reader, frame answer, kitty images and shm probe, glide, trail and flash); its input reaches the loop as its view's (a `from` ahead of it when another terminal posted last, so one terminal posts none). A SIGWINCH asks every terminal its size; a SIGHUP asks each whether it hung up or lost its stub. Detach, or a terminal's end, with other views left closes only that view, its stub told `d`; the session's end tells every stub. daemon.zig: an attach names an attached session too (or the only one there is when none is detached). gui: the Gui holds the live window's share of itself (window_fields: the SDL window and its presenting, scroll, glide, scene and post chain, pointer, blink, captures); the others wait in Shell.windows, swapped in (`follow`) as the core's live view changes, and each SDL event first takes its window's view live (`route`). Closing a window while others stay closes its view. Harnesses: `start <rows> <cols> views=N` in a snapshot script gives the app N-1 more terminals (PARDES_TEST_VIEWS, opened as attached ones), `view <k>` types into and captures terminal k, every wait reads them all; `pardes-monkey --views=N` switches among N; `zig build replay` runs its seeds at three views too. views.snap pins two terminals: an edit seen in both, a scroll in one, a line yanked in one and put in the other, Newcol in one, Detach in one. Unit tests: own cursor, scroll, mode, layout and focus; edits shared; registers shared; terminal size by last typist; closing views; drawing the others leaves the digest; a view keeps its place in a text another edits. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'test/monkey.zig')
-rw-r--r--test/monkey.zig34
1 files changed, 24 insertions, 10 deletions
diff --git a/test/monkey.zig b/test/monkey.zig
index 7c9761ff..d35599ff 100644
--- a/test/monkey.zig
+++ b/test/monkey.zig
@@ -1,6 +1,6 @@
// pardes-monkey: random snapshot scripts against the tty, hunting panics.
//
-// zig build monkey -Dplatform=tty -- <seeds> [steps] [--from=N] [--out=DIR] [--keep]
+// zig build monkey -Dplatform=tty -- <seeds> [steps] [--from=N] [--out=DIR] [--keep] [--views=N]
//
// Each seed makes one script (a fixed seed makes the same script, so a hit
// replays): keys and leader bursts, typing, mouse presses, drags and wheel,
@@ -9,7 +9,9 @@
// /tmp/pardes-monkey), and a panic is a record in the app's crash file
// (src/crash.zig, in the script's fake home: found even when the crash cut
// the script short) or a `.zig:N:N: 0x` stack frame in the report or the
-// grid it captured (a trace renders INTO the screen). A hit
+// grid it captured (a trace renders INTO the screen). --views=N gives the
+// session N terminals, each a view of it (views.zig), and types into and
+// sizes each in turn, a `view` switch among the steps. A hit
// keeps DIR/seed-N.snap, its captures and its report; the rest are deleted.
// A panic's trace can scroll off a small grid: replay the kept script, or
// run the app in a larger pty. Every hit gets a fix and a pinned regression
@@ -26,6 +28,9 @@ const Script = struct {
gpa: std.mem.Allocator,
rows: u16 = 24,
cols: u16 = 80,
+ /// Each terminal's size, and the one typed into (`--views`).
+ sizes: [4][2]u16 = @splat(.{ 24, 80 }),
+ view: usize = 0,
fn line(s: *Script, comptime fmt: []const u8, args: anytype) !void {
try s.out.print(s.gpa, fmt ++ "\n", args);
@@ -38,18 +43,24 @@ const commands = [_][]const u8{ "Newcol", "Find", "Grep", "Joincol", "Help", "Du
const leader_keys = "abcdefghijklmnopqrstuvwxyz0123456789$^";
const typed = "abcdefghijklmnopqrstuvwxyz0123456789 -_=+,:;()";
-fn generate(gpa: std.mem.Allocator, seed: u64, steps: usize) ![]u8 {
+fn generate(gpa: std.mem.Allocator, seed: u64, steps: usize, views: usize) ![]u8 {
var prng = std.Random.DefaultPrng.init(seed);
const random = prng.random();
var s: Script = .{ .gpa = gpa };
- try s.line("# pardes-monkey seed {d}, {d} steps", .{ seed, steps });
+ try s.line("# pardes-monkey seed {d}, {d} steps, {d} views", .{ seed, steps, views });
try s.line("file bad.txt hello \\xff\\xfe world\\nlatin-1 caf\\xe9 tail\\ntruncated \\xe6\\x97 here\\nend\\n", .{});
try s.line("file wide.txt {s}tail\\nsecond line\\n", .{std.mem.asBytes(&@as([8][37]u8, @splat("\\xe6\\x97\\xa5\\xe6\\x9c\\xac\\xe8\\xaa\\x9e ".*)))});
try s.line("lines long.txt 400 some words after the number, long enough to wrap in a narrow pane", .{});
- try s.line("start 24 80 bad.txt", .{});
+ if (views > 1) try s.line("start 24 80 views={d} bad.txt", .{views}) else try s.line("start 24 80 bad.txt", .{});
try s.line("wait 8000 Newcol Joincol", .{});
try s.line("stable 300 5000", .{});
for (0..steps) |step| {
+ if (views > 1 and random.uintLessThan(u8, 4) == 0) {
+ s.sizes[s.view] = .{ s.rows, s.cols };
+ s.view = random.uintLessThan(usize, views);
+ s.rows, s.cols = s.sizes[s.view];
+ try s.line("view {d}", .{s.view + 1});
+ }
const wide = s.cols >= 70 and s.rows >= 6;
switch (random.uintLessThan(u8, 12)) {
// A workspace word, run with a middle click: new columns make
@@ -150,9 +161,9 @@ test "a panic trace is found, and ordinary colons are not" {
}
test "a seed makes the same script every time" {
- const a = try generate(std.testing.allocator, 42, 50);
+ const a = try generate(std.testing.allocator, 42, 50, 3);
defer std.testing.allocator.free(a);
- const b = try generate(std.testing.allocator, 42, 50);
+ const b = try generate(std.testing.allocator, 42, 50, 3);
defer std.testing.allocator.free(b);
try std.testing.expectEqualStrings(a, b);
}
@@ -166,7 +177,7 @@ pub fn main(init: std.process.Init) !void {
const io = init.io;
const args = try init.minimal.args.toSlice(init.arena.allocator());
if (args.len < 4) {
- std.debug.print("usage: pardes-monkey <pardes-snap> <pardes> <seeds> [steps] [--from=N] [--out=DIR] [--keep] [--tape=DIR]\n", .{});
+ std.debug.print("usage: pardes-monkey <pardes-snap> <pardes> <seeds> [steps] [--from=N] [--out=DIR] [--keep] [--tape=DIR] [--views=N]\n", .{});
std.process.exit(2);
}
const snap = args[1];
@@ -180,9 +191,12 @@ pub fn main(init: std.process.Init) !void {
// --tape=DIR: each seed's sessions record their tapes there and the
// seed is a hit if one does not replay (pardes-snap --tape).
var tape: ?[]const u8 = null;
+ var views: usize = 1;
var positional: usize = 0;
for (args[3..]) |a| {
- if (std.mem.startsWith(u8, a, "--from=")) {
+ if (std.mem.startsWith(u8, a, "--views=")) {
+ views = std.math.clamp(try std.fmt.parseInt(usize, a["--views=".len..], 10), 1, 4);
+ } else if (std.mem.startsWith(u8, a, "--from=")) {
from = try std.fmt.parseInt(u64, a["--from=".len..], 10);
} else if (std.mem.eql(u8, a, "--keep")) {
keep = true;
@@ -203,7 +217,7 @@ pub fn main(init: std.process.Init) !void {
var hits: usize = 0;
var seed = from;
while (seed < from + seeds) : (seed += 1) {
- const script = try generate(gpa, seed, steps);
+ const script = try generate(gpa, seed, steps, views);
defer gpa.free(script);
var path_buf: [4096]u8 = undefined;
const path = try std.fmt.bufPrint(&path_buf, "{s}/seed-{d}.snap", .{ out, seed });