summaryrefslogtreecommitdiff
path: root/test/process/tty_boot.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-08 23:21:47 -0300
committerGabriel Schneider <[email protected]>2026-11-09 01:28:28 -0300
commit094b562b5b90558e82a9c3e2beea386d93bd1803 (patch)
tree23e49a2f2c308acbacba532a126bb6b1631d7aca /test/process/tty_boot.zig
parent80db18269dd9f7153a02f3efa6ff92c69948a623 (diff)
downloadpardes-094b562b5b90558e82a9c3e2beea386d93bd1803.tar.gz
pardes-094b562b5b90558e82a9c3e2beea386d93bd1803.zip
tests: the boot, argv and builtins snapshot scripts (22: argv badutf boot builtins dump load restore headersweep headersweep-restored logquiet tutor topbarexec leader mini ninep nested nested-optout shellset msg winch savepane filewatch) are process cases, test/process/tty_boot.zig, each its script's steps as Tty calls and its golden unchanged as its expectation; checked against the old runner by two breaks, the message stamp's spacing (3 fail in both) and the tty reading a middle press as a right one (the same 9 in both)
Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/process/tty_boot.zig')
-rw-r--r--test/process/tty_boot.zig992
1 files changed, 991 insertions, 1 deletions
diff --git a/test/process/tty_boot.zig b/test/process/tty_boot.zig
index 79413cbf..1d49dc8e 100644
--- a/test/process/tty_boot.zig
+++ b/test/process/tty_boot.zig
@@ -1,3 +1,993 @@
//! The tty frontend's own cases (test/tty.zig), starting: argv, the flags, the topbar's builtins, dumps and loads.
+const std = @import("std");
+const Tty = @import("../tty.zig").Tty;
-pub const cases = .{};
+pub const cases = .{
+ .{ "tty boot: argv", argv },
+ .{ "tty boot: badutf", badutf },
+ .{ "tty boot: boot", boot },
+ .{ "tty boot: builtins", builtins },
+ .{ "tty boot: dump", dump },
+ .{ "tty boot: load", load },
+ .{ "tty boot: restore", restore },
+ .{ "tty boot: headersweep", headersweep },
+ .{ "tty boot: headersweep-restored", headersweep_restored },
+ .{ "tty boot: logquiet", logquiet },
+ .{ "tty boot: tutor", tutor },
+ .{ "tty boot: topbarexec", topbarexec },
+ .{ "tty boot: leader", leader },
+ .{ "tty boot: mini", mini },
+ .{ "tty boot: ninep", ninep },
+ .{ "tty boot: nested", nested },
+ .{ "tty boot: nested-optout", nested_optout },
+ .{ "tty boot: shellset", shellset },
+ .{ "tty boot: msg", msg },
+ .{ "tty boot: winch", winch },
+ .{ "tty boot: savepane", savepane },
+ .{ "tty boot: filewatch", filewatch },
+};
+
+// argv: bare `pardes` boots one shell already in tty mode; a FILE argument
+// opens it ALONE, filling the window (file:LINE scrolls there) — naming a file
+// is asking to read it, not to be handed a shell beside it; a DIRECTORY
+// argument becomes the cwd the shell spawns in
+fn argv(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "argv");
+ defer t.deinit();
+ try t.lines("notes.txt", 8, "");
+ try t.file("zmarker.txt", "x");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("echo ARGV''TTY");
+ try t.key("enter");
+ try t.wait(8000, "ARGVTTY");
+ try t.stable(700, 10000);
+ try t.snap("noargs");
+ try t.start(31, 100, &.{"notes.txt:3"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "line 3");
+ try t.stable(700, 20000);
+ try t.snap("filearg");
+ // -n and a FILE are not a combination: the file names the whole boot layout, so
+ // `-n 3` boots the very same single pane (it always did — the file arm never
+ // looked at the count; before this it merely also stapled a shell to the right)
+ try t.start(31, 100, &.{ "-n", "3", "notes.txt" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "line 1");
+ try t.stable(700, 20000);
+ try t.snap("filearg-n3");
+ try t.dir("sub");
+ try t.file("sub/inside.txt", "marker");
+ try t.start(31, 100, &.{"sub"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "inside.txt");
+ try t.stable(700, 20000);
+ try t.snap("dirarg");
+ try t.done();
+}
+
+// Invalid UTF-8 must RENDER, never panic. Two sources, both ordinary use:
+// a file pane holds whatever bytes are on disk (latin-1, a truncated sequence,
+// an ELF opened by mistake). Undecodable bytes come out as U+FFFD, while
+// horizontal scrolling must start at a complete grapheme boundary.
+fn badutf(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "badutf");
+ defer t.deinit();
+ try t.file("bad.txt", "hello \xff\xfe world\nlatin-1 caf\xe9 tail\ntruncated \xe6\x97 here\nend\n");
+ try t.file("wide.txt", "日本語 日本語 日本語 日本語 日本語 日本語 日本語 tail\nsecond line\n");
+ try t.start(31, 100, &.{"bad.txt"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ try t.snap("badbytes");
+ // 50 columns, not 100: a FILE boots alone and fills the window, and at 100 the
+ // whole line fits, so `$` scrolls nowhere. This is
+ // the width the left column used to be, i.e. the pane this case was written for
+ try t.start(31, 50, &.{"wide.txt"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ // SPC t w turns soft wrap OFF: hscroll is the other half of this case and a
+ // wrapped body has nothing to scroll sideways. The unwrapped view must keep the
+ // first visible CJK glyph intact instead of starting inside its UTF-8 bytes.
+ try t.key("space t w");
+ try t.stable(400, 5000);
+ try t.key("g l");
+ try t.stable(700, 10000);
+ try t.snap("hscroll-midglyph");
+ try t.done();
+}
+
+// -n 1: one shell pane in normal mode, greets with ls; prompts hidden
+fn boot(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "boot");
+ defer t.deinit();
+ try t.file("hello.txt", "marker-content");
+ try t.start(31, 100, &.{ "-n", "1" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "hello.txt");
+ try t.stable(700, 20000);
+ try t.snap("boot");
+ try t.style("boot");
+ try t.done();
+}
+
+fn builtins(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "builtins");
+ defer t.deinit();
+ try t.lines("notes.txt", 6, "");
+ try t.start(67, 120, &.{"notes.txt"});
+ try t.wait(8000, "notes.txt");
+ try t.stable(700, 20000);
+ try t.snap("boot");
+
+ // The full index includes commands without leader paths.
+ try t.key("space ?");
+ try t.wait(10000, "pardes builtins, and how to run each:");
+ try t.wait(10000, "ClipPasteBefore");
+ try t.key("g e");
+ // Every builtin added since adds an index line, and one wheel tick is one row
+ // (config.wheel_rows): scroll far enough to expose Look and Exec above the
+ // bottom viewport while keeping the same pane geometry for the later clicks.
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wheel("up", "110", 50);
+ try t.wait(10000, "Look enter, right-click");
+ try t.wait(10000, "Exec tab, middle-click");
+ try t.wait(10000, "Filter");
+ try t.wait(10000, "Theme");
+ 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.key("space c ?");
+ try t.wait(10000, "under SPC c");
+ try t.wait(10000, "Joincol");
+ try t.stable(700, 15000);
+ try t.snap("column-group");
+
+ try t.key("space h ?");
+ try t.wait(10000, "Tutor");
+ try t.stable(700, 15000);
+ try t.snap("docs-group");
+ try t.press("middle", "@Tutor", 16);
+ try t.release("middle", "@Tutor", 16);
+ try t.wait(10000, "PARDES TUTOR");
+ try t.stable(700, 15000);
+ try t.snap("tutor-from-index");
+ try t.done();
+}
+
+// Dump writes the whole session to this fixture's $DUMP path, a dump of the
+// walk (src/walk.zig), and `-l` of it is that session again: the text typed
+// into a terminal over its history comes back where it was.
+fn dump(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "dump");
+ defer t.deinit();
+ try t.file("d.txt", "x");
+ try t.start(31, 100, &.{ "-n", "3" });
+ try t.wait(8000, "d.txt");
+ try t.stable(700, 20000);
+ try t.press("left", "5", 10);
+ try t.release("left", "5", 10);
+ try t.stable(400, 5000);
+ try t.key("i");
+ try t.send("typed-marker");
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(400, 5000);
+ try t.press("middle", "@Dump", 1);
+ try t.release("middle", "@Dump", 1);
+ try t.stable(600, 8000);
+ try t.start(31, 100, &.{ "-l", t.dump });
+ try t.wait(8000, "typed-marker");
+ try t.stable(700, 20000);
+ try t.snap("loaded");
+ try t.done();
+}
+
+// pardes -l loads another instance's dump: the session as it was dumped, each
+// terminal's view where it was (scrolled back into the seq output), its
+// history above a "restored history" banner and a new shell below it.
+fn load(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "load");
+ defer t.deinit();
+ try t.file("d.txt", "x");
+ try t.start(31, 100, &.{ "-n", "3" });
+ try t.wait(8000, "d.txt");
+ try t.stable(700, 20000);
+ try t.key("c-b");
+ try t.stable(600, 8000);
+ try t.send("echo LOAD''MARK; seq 1 40; echo E''ND");
+ try t.key("enter");
+ try t.wait(8000, "END");
+ try t.stable(700, 10000);
+ try t.key("c-b");
+ try t.stable(600, 8000);
+ try t.wheel("up", "10", 8);
+ try t.wheel("up", "10", 8);
+ try t.stable(500, 8000);
+ try t.press("middle", "@Dump", 1);
+ try t.release("middle", "@Dump", 1);
+ try t.stable(600, 8000);
+ try t.start(31, 100, &.{ "-l", t.dump });
+ try t.wait(8000, "restored");
+ try t.stable(700, 20000);
+ try t.snap("loaded");
+ try t.style("loaded");
+ try t.done();
+}
+
+// Dump writes to the resolved dump path ($PARDES_DUMP here; a timestamped file
+// under ~/.local/share/pardes in live runs) and the topbar grows Restore <path>;
+// middle-click Restore loads that dump back into the live session: output on
+// screen at Dump time survives (pty history), later output does not
+fn restore(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "restore");
+ defer t.deinit();
+ try t.start(31, 100, &.{ "-n", "1" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ try t.key("c-b");
+ try t.stable(600, 8000);
+ try t.send("echo KEEP''ME");
+ try t.key("enter");
+ try t.wait(8000, "KEEPME");
+ try t.stable(700, 10000);
+ try t.press("middle", "@Dump", 1);
+ try t.release("middle", "@Dump", 1);
+ try t.stable(700, 10000);
+ try t.snap("dumped");
+ try t.send("echo GONE''SOON");
+ try t.key("enter");
+ try t.wait(8000, "GONESOON");
+ try t.stable(700, 10000);
+ try t.press("middle", "@Restore", 1);
+ try t.release("middle", "@Restore", 1);
+ try t.stable(900, 15000);
+ try t.snap("restored");
+ try t.done();
+}
+
+// A middle sweep over a column's tag or the workspace's runs what it swept,
+// as it does over a pane's tag: highlighted while the button is held, run
+// when it comes up. Both headers used to run the word under the PRESS, on
+// the press, so a sweep of `echo SWEPT-COL` ran a bare `echo`. A right sweep
+// looks for what it swept the same way, and the other button cancels.
+fn headersweep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "headersweep");
+ defer t.deinit();
+ try t.file("hay.txt", "ZQNEEDLE");
+ try t.start(21, 120, &.{ "-n", "3" });
+ try t.wait(8000, "Newcol");
+ try t.stable(700, 20000);
+ // the column tag: type a command onto it, then sweep the whole command
+ try t.press("left", "50", 2);
+ try t.release("left", "50", 2);
+ try t.key("i");
+ try t.key("space");
+ try t.send("echo SW''EPT-COL");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("middle", "@echo", 2);
+ try t.drag("middle", "@echo+8", 2);
+ try t.stable(300, 5000);
+ try t.style("col-sweeping");
+ try t.drag("middle", "@echo+16", 2);
+ try t.release("middle", "@echo+16", 2);
+ try t.wait(8000, "SWEPT-COL");
+ try t.stable(700, 15000);
+ try t.snap("col-swept");
+ // the workspace tag, the same
+ try t.press("left", "110", 1);
+ try t.release("left", "110", 1);
+ try t.key("i");
+ try t.key("space");
+ try t.send("echo SW''EPT-WS");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("middle", "@echo", 1);
+ try t.drag("middle", "@echo+15", 1);
+ try t.release("middle", "@echo+15", 1);
+ try t.wait(8000, "SWEPT-WS");
+ try t.stable(700, 15000);
+ try t.snap("ws-swept");
+ // a right sweep over part of a word looks for the part: `hay.txt` opens,
+ // where a click would look for all of `xxhay.txtxx`
+ try t.press("left", "118", 1);
+ try t.release("left", "118", 1);
+ try t.key("i");
+ try t.key("space");
+ try t.send("xxhay.txtxx");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("right", "@xxhay.txtxx+2", 1);
+ try t.drag("right", "@xxhay.txtxx+9", 1);
+ try t.release("right", "@xxhay.txtxx+9", 1);
+ try t.wait(8000, "ZQNEEDLE");
+ try t.stable(700, 15000);
+ try t.snap("ws-looked");
+ // the look button tapped during a middle sweep cancels it: nothing runs
+ try t.press("middle", "@echo", 2);
+ try t.drag("middle", "@echo+16", 2);
+ try t.press("right", "@echo+16", 2);
+ try t.release("right", "@echo+16", 2);
+ try t.release("middle", "@echo+16", 2);
+ try t.stable(700, 15000);
+ try t.snap("cancelled");
+ // for comparison, a select sweep over the second column's tag selects, in
+ // the tag's selection colours, and runs nothing
+ try t.press("left", "@Find#2", 2);
+ try t.drag("left", "@Grep#2+4", 2);
+ try t.release("left", "@Grep#2+4", 2);
+ try t.stable(700, 15000);
+ try t.style("selected");
+ try t.done();
+}
+
+// headersweep.snap in a session restored from a dump: its column and
+// workspace tags are rebuilt, and a middle sweep over each runs what it
+// swept, as it does in a fresh session.
+fn headersweep_restored(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "headersweep-restored");
+ defer t.deinit();
+ try t.start(21, 120, &.{ "-n", "3" });
+ try t.wait(8000, "Newcol");
+ try t.stable(700, 20000);
+ try t.press("middle", "@Dump", 1);
+ try t.release("middle", "@Dump", 1);
+ try t.stable(700, 10000);
+ try t.press("middle", "@Restore", 1);
+ try t.release("middle", "@Restore", 1);
+ try t.stable(900, 15000);
+ try t.press("left", "50", 2);
+ try t.release("left", "50", 2);
+ try t.key("i");
+ try t.key("space");
+ try t.send("echo RE''STORED-COL");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("middle", "@echo", 2);
+ try t.drag("middle", "@echo+8", 2);
+ try t.stable(300, 5000);
+ try t.style("col-sweeping");
+ try t.drag("middle", "@echo+19", 2);
+ try t.release("middle", "@echo+19", 2);
+ try t.wait(8000, "RESTORED-COL");
+ try t.stable(700, 15000);
+ try t.snap("col-swept");
+ try t.press("left", "118", 1);
+ try t.release("left", "118", 1);
+ try t.key("i");
+ try t.key("space");
+ try t.send("echo RE''STORED-WS");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("middle", "@echo", 1);
+ try t.drag("middle", "@echo+8", 1);
+ try t.stable(300, 5000);
+ try t.style("ws-sweeping");
+ try t.drag("middle", "@echo+18", 1);
+ try t.release("middle", "@echo+18", 1);
+ try t.wait(8000, "RESTORED-WS");
+ try t.stable(700, 15000);
+ try t.snap("ws-swept");
+ try t.done();
+}
+
+// ghostty-vt narrates every sequence it does not implement through std.log,
+// and a pardes child's stderr is this pty — so a library log line lands on the
+// rendered grid, exactly where it does on a real user's terminal. The two
+// sequences below are the cheapest ones that trip it: a kitty graphics query
+// (`debug(kitty_gfx): executing kitty graphics command`) and a private CSI p
+// (`warning(stream): ignoring unimplemented CSI p with intermediates: >`).
+// The golden is the assertion that neither reaches the screen.
+fn logquiet(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "logquiet");
+ defer t.deinit();
+ try t.start(31, 100, &.{ "-n", "1" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ try t.key("c-b");
+ try t.stable(600, 8000);
+ try t.send("printf '\\033_Ga=q,i=1,s=1,v=1,f=24,t=d;AAAA\\033\\\\\\033[>0p'");
+ try t.key("enter");
+ try t.stable(700, 20000);
+ try t.snap("quiet");
+ try t.done();
+}
+
+// topbar middle-click Tutor opens the embedded tutor below its source shell
+fn tutor(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "tutor");
+ defer t.deinit();
+ try t.start(31, 150, &.{ "-n", "3" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ try t.press("middle", "@Tutor", 1);
+ try t.release("middle", "@Tutor", 1);
+ try t.stable(700, 15000);
+ try t.snap("tutor");
+ try t.done();
+}
+
+// A topbar word runs on a middle click, and it runs WITH whatever is selected:
+// sweep a word, click Grep, it greps that word. That is acme's 2-1 chord with
+// no drag to chord into, and it is the whole reason the topbar reads the
+// selection at all.
+//
+// But a selection is only an argument to a builtin that has somewhere to put
+// one. `Exit`, `Debug`, `NextColor` and the rest match their name WHOLE — that
+// is what makes `Exit foo` a shell command and not Exit — so splicing a sweep
+// onto them produced a name matching no builtin, which fell out of the builtin
+// parser and into a SHELL, as a command nobody typed (`bash: Debug: command
+// not found`). It only ever bit you with a terminal open, because that is
+// where the stray text went.
+//
+// So both halves are pinned here, against the same live selection: the no-arg
+// builtin runs, and the arg-taking one still gets the word.
+fn topbarexec(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "topbarexec");
+ defer t.deinit();
+ try t.file("zmarkfile.txt", "hay ZQNEEDLE stack");
+ try t.start(21, 90, &.{ "-n", "3" });
+ try t.wait(8000, "zmarkfile.txt");
+ try t.stable(700, 20000);
+ // sweep `zmarkfile.txt` out of the shell's own greeting: an ordinary left drag,
+ // and the kind of stale highlight that is simply lying around in real use
+ try t.press("left", "3", 6);
+ try t.drag("left", "15", 6);
+ try t.release("left", "15", 6);
+ try t.stable(700, 15000);
+ try t.snap("selected");
+ // Debug takes NO argument. Middle-clicked with that sweep live it must open the
+ // overlay — not send `Debug zmarkfile.txt` to bash. The box IS the assertion.
+ try t.press("middle", "@Debug", 1);
+ try t.release("middle", "@Debug", 1);
+ try t.stable(700, 15000);
+ try t.snap("noarg-runs");
+ // ...and off again, so the overlay does not cover what comes next
+ try t.press("middle", "@Debug", 1);
+ try t.release("middle", "@Debug", 1);
+ try t.stable(700, 15000);
+ // Find DOES take one, and still gets it: the sweep is the pattern, so the
+ // results buffer names the file it matched. An empty buffer would mean Find
+ // ran with no argument (which arms the prompt instead), so the ROW is the
+ // assertion — the splice is what put it there.
+ try t.press("middle", "@Find", 1);
+ try t.release("middle", "@Find", 1);
+ try t.wait(10000, "+Search");
+ try t.stable(700, 15000);
+ try t.snap("arg-still-spliced");
+ try t.done();
+}
+
+fn leader(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "leader");
+ defer t.deinit();
+ try t.file("cmds.txt", "Help");
+ try t.start(41, 100, &.{"cmds.txt"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "cmds.txt");
+ try t.stable(700, 20000);
+
+ try t.key("space");
+ try t.stable(400, 5000);
+ try t.snap("spc");
+ try t.key("h");
+ try t.stable(400, 5000);
+ try t.snap("spc-h");
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(400, 5000);
+ try t.snap("abandoned");
+ try t.key("space x");
+ try t.stable(400, 5000);
+ try t.snap("unmapped");
+
+ // Executing Help as text opens the full index, not a filtered group.
+ try t.press("middle", "@Help", 4);
+ try t.release("middle", "@Help", 4);
+ try t.wait(10000, "pardes builtins, and how to run each:");
+ try t.wait(10000, "ClipPasteBefore");
+ try t.key("space h ?");
+ try t.wait(10000, "under SPC h");
+ try t.stable(700, 15000);
+ try t.snap("help-group");
+
+ try t.key("space h t");
+ try t.wait(10000, "PARDES TUTOR");
+ try t.stable(700, 15000);
+ try t.snap("tutor");
+ // the tutor is at the foot of its column (acme's placement put it under the
+ // +Help's text), so SPC d has nothing to ask and closes it at once
+ try t.key("space d");
+ try t.stable(700, 15000);
+ try t.snap("deleted");
+ // ...and the +Help it squeezed goes too, so the full index below opens with
+ // room to show it
+ try t.key("c-w j enter");
+ try t.key("space d");
+ try t.stable(700, 15000);
+
+ try t.key("space ?");
+ try t.wait(10000, "pardes builtins, and how to run each:");
+ try t.wait(10000, "ClipPasteBefore");
+
+ // PDF commands depend on the build; these toggles do not.
+ try t.key("space t ?");
+ try t.wait(10000, "under SPC t");
+ try t.wait(10000, "Ascii");
+ try t.wait(10000, "Palette");
+ try t.wait(10000, "Petscii");
+ try t.wait(10000, "Wrap");
+ // SPC w is Window itself now, not a group; the column group stands in
+ try t.key("space c ?");
+ try t.wait(10000, "under SPC c");
+ try t.wait(10000, "Joincol");
+ try t.stable(700, 15000);
+ try t.snap("help-column");
+ try t.key("space l ?");
+ try t.wait(10000, "WsDiagnostics");
+ try t.stable(700, 15000);
+ try t.snap("help-language");
+ try t.key("space d");
+ try t.settle(100);
+ try t.stable(700, 15000);
+ try t.snap("del-output");
+ try t.done();
+}
+
+fn mini(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "mini");
+ defer t.deinit();
+ try t.file("commands.txt", "@`Mini demo.zig`");
+ try t.file("demo.zig", "const greeting = \"café λ 界 é\";\n\npub fn choose(ok: bool) u32 {\n if (ok) return 42;\n return 7;\n}\n\n// space and color survive compression\nconst answer = choose(true);\n");
+ try t.start(23, 90, &.{"commands.txt"});
+ try t.wait(8000, "Mini demo.zig");
+ try t.stable(400, 10000);
+ try t.press("middle", "@Mini", 4);
+ try t.release("middle", "@Mini", 4);
+ try t.wait(8000, "/Mini demo.zig");
+ try t.stable(500, 10000);
+ try t.snap("opened");
+ try t.style("opened");
+ try t.snap9p("opened");
+ try t.resize(27, 105);
+ try t.stable(400, 10000);
+ try t.snap("resized");
+ try t.snap9p("resized");
+ try t.done();
+}
+
+fn ninep(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "ninep");
+ defer t.deinit();
+ try t.file("demo.zig", "const greeting = \"café λ 界 é\";\n\npub fn choose(ok: bool) u32 {\n if (ok) return 42;\n return 7;\n}\n");
+ try t.start(15, 90, &.{"demo.zig"});
+ try t.wait(8000, "choose");
+ try t.stable(400, 10000);
+ try t.snap("opened");
+ try t.style("opened");
+ try t.snap9p("opened");
+ try t.key("g g i");
+ try t.send("// café λ 界\n");
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(300, 8000);
+ try t.snap("edited");
+ try t.snap9p("edited");
+ try t.style("edited");
+ try t.resize(20, 105);
+ try t.stable(400, 10000);
+ try t.style("resized");
+ try t.snap9p("resized");
+ try t.snap("resized");
+ try t.snap9p("unchanged");
+ try t.done();
+}
+
+fn nested(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "nested");
+ defer t.deinit();
+ try t.dir("nestdir");
+ try t.file("nestdir/inside-nested.txt", "marker");
+ try t.file("nested.txt", "hello-from-nested\nsecond-nested-line\n");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("$(readlink /proc/$PPID/exe) nested.txt");
+ try t.key("enter");
+ try t.wait(15000, "hello-from-nested");
+ try t.stable(700, 20000);
+ try t.snap("file-arg");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("$(readlink /proc/$PPID/exe)");
+ try t.key("enter");
+ try t.wait(15000, "already inside pardes");
+ try t.stable(700, 20000);
+ try t.snap("no-arg");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("$(readlink /proc/$PPID/exe) nestdir");
+ try t.key("enter");
+ try t.wait(15000, "inside-nested.txt");
+ try t.stable(700, 20000);
+ try t.snap("dir-arg");
+ try t.done();
+}
+
+fn nested_optout(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "nested-optout");
+ defer t.deinit();
+ try t.file("nested.txt", "optout-marker\nsecond-optout-line\n");
+ try t.dir("innerdir");
+ try t.file("innerdir/deeper.txt", "deepest-marker\n");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("$(readlink /proc/$PPID/exe) --nested nested.txt");
+ try t.key("enter");
+ try t.wait(20000, "optout-marker");
+ try t.stable(700, 20000);
+ try t.snap("optout-file");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("(cd innerdir && $(readlink /proc/$PPID/exe) --nested)");
+ try t.key("enter");
+ try t.wait(20000, "cwd/innerdir");
+ try t.stable(700, 20000);
+ try t.snap("inner-shell");
+ try t.send("$(readlink /proc/$PPID/exe) deeper.txt");
+ try t.key("enter");
+ try t.wait(20000, "deepest-marker");
+ try t.stable(700, 20000);
+ try t.snap("inner-launch");
+ try t.done();
+}
+
+// The Shell builtin names the binary the NEXT terminal execs. What is pinned
+// here is the case that has to hold on a machine you did not set up: the name
+// resolves to nothing, so Shell refuses it and says why on the message row,
+// and the next pane opens anyway with the shell that was set before.
+//
+// A default $SHELL that names nothing executable falls back to /bin/sh
+// (config.defaultShell), and the host's lookup still falls back at spawn for
+// a shell that went away after it was set: a pane never gets a child that
+// dies at exec and shows one EOF.
+//
+// The rest of the feature is unit-tested rather than pinned here, on purpose.
+// Which family a binary belongs to, what argv each one gets and where the
+// lookup searches are in host_io.Shell's own tests; the fish end of it cannot
+// be a golden at all, because fish's prompt carries a hostname and its greeting
+// a version number. (Every script in this suite runs bash, pinned through an
+// ordinary config file the harness writes — see snapshot.zig.)
+fn shellset(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "shellset");
+ defer t.deinit();
+ try t.file("cmd.txt", "Shell zznosuchshell");
+ try t.file("zmarkfile.txt", "x");
+ try t.start(21, 90, &.{"cmd.txt"});
+ try t.wait(8000, "Shell zznosuchshell");
+ try t.stable(700, 20000);
+ try t.snap("boot");
+ // execute the line the way you would run any command: select it, Tab. Nothing
+ // on any machine is installed under that name, so the resolver runs out of
+ // directories. (A file pane, so the line executed is the line you can see —
+ // typing into a terminal's overlay would leave `gg`/`x` selecting its output.)
+ try t.key("g g");
+ try t.key("x");
+ try t.stable(400, 5000);
+ try t.key("tab");
+ try t.stable(700, 15000);
+ // NOTHING happened on screen, and that is the assertion: a name the builtin
+ // parser does not know is a command line, so it would have forked a terminal
+ // for this directory and printed `Shell: command not found` into it. One
+ // pane, no error — `Shell` was consumed as a builtin and its argument went
+ // with it.
+ try t.snap("builtin-ran");
+ // a new terminal, which asks for a shell that is not there. It gets the
+ // fallback: the pane greets, `ls` runs, and its output is on screen. Alt-n and
+ // Alt-c, because `New`/`Newcol` open an empty +New scratch rather than a shell.
+ try t.key("a-n");
+ try t.key("a-c");
+ try t.wait(15000, "zmarkfile.txt");
+ try t.stable(700, 20000);
+ try t.snap("fallback-shell");
+ try t.done();
+}
+
+// The transient message row: the LAST row of a pane, left-aligned at the text
+// area's origin, saying what just happened to that pane and when. An OVERLAY,
+// not geometry — nothing shrinks to make room, so a pane with nothing to say is
+// not touched at all, which is why the other 71 goldens only moved where a
+// prompt or a message actually appears.
+//
+// The clock reads `--:--:--` here and only here: $PARDES_NOTIME (set by
+// snapshot.zig, the same flag that hides the language backend's durations)
+// blanks the DIGITS rather than the row, because a message that disappeared
+// under the harness could not be pinned at all.
+//
+// The row has exactly two possible occupants and they are not the same kind of
+// thing. A MESSAGE is a report of something that already happened, and the next
+// key or mouse event wipes it. An armed PROMPT is what that keystroke is being
+// typed INTO, it lives until Enter or Esc, and it WINS.
+fn msg(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "msg");
+ defer t.deinit();
+ try t.lines("a.txt", 6, "");
+ try t.start(15, 70, &.{"a.txt"});
+ try t.wait(8000, "Newcol Joincol");
+ try t.wait(8000, "a.txt");
+ try t.stable(700, 20000);
+ try t.snap("opened");
+ // Save (SPC f s) writes the file; the SHELL is where the write and the clock
+ // both are, so the shell is what posts the message once the bytes are down.
+ try t.key("space f s");
+ try t.stable(700, 15000);
+ try t.snap("saved");
+ // A REPAINT is not input. A resize redraws every cell in the window from
+ // scratch and the message is still there on the other side of it — the row is
+ // state, not one frame's flash. (Different rows, or the kernel sends no
+ // SIGWINCH and nothing repaints.)
+ try t.resize(17, 70);
+ try t.stable(700, 15000);
+ try t.snap("repainted");
+ // ...but the next KEY takes it away. `j` is a plain cursor motion and changes
+ // nothing else on screen, so the vanishing message is the whole diff.
+ try t.key("j");
+ try t.stable(700, 15000);
+ try t.snap("keycleared");
+ // Again, and this time a bare mouse MOTION — no button, nothing clicked —
+ // clears it: any mouse event counts, the rule is "you are back", not "you did
+ // something".
+ try t.key("space f s");
+ try t.stable(700, 15000);
+ try t.snap("saved-again");
+ try t.motion("20", 6);
+ try t.stable(700, 15000);
+ try t.snap("mousecleared");
+ // The other message: an external write lands in the pane (filewatch.snap owns
+ // that contract) and the row says which of the two things happened. `run` is a
+ // child of the RUNNER, so the app receives no keystroke here and nothing but
+ // the watch could have posted this.
+ try t.run("printf 'EXTERNAL\\n' > a.txt");
+ try t.wait(10000, "EXTERNAL");
+ try t.stable(700, 15000);
+ try t.snap("reloaded");
+ // `/` still types into the tag tail — same buffer, same offsets, same one-line
+ // editor, same Enter and Esc — but it is DRAWN here now, so the tagline keeps
+ // its builtins instead of losing them to a long pattern. Note the tag row above
+ // ends at `Del`: the marker and the pattern are no longer on it at all. (The
+ // `/` keystroke also cleared the reload message, which is the rule above.)
+ try t.key("s");
+ try t.send("EXT");
+ try t.stable(700, 15000);
+ try t.snap("prompt");
+ // ...and a message arriving UNDER an armed prompt does not disturb it: a second
+ // external write reloads the pane and posts one, the row stays the prompt's.
+ try t.run("printf 'AGAIN\\n' > a.txt");
+ try t.wait(10000, "AGAIN");
+ try t.stable(700, 15000);
+ try t.snap("prompt-wins");
+ // Esc abandons the input, and the very key that abandoned it is also the key
+ // that clears the message queued underneath — so the row goes empty rather than
+ // handing back a report from before you started typing.
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(700, 15000);
+ try t.snap("esc");
+ // Every other writer of this row is something going WRONG, which is a poor way
+ // to look at a row: `Msg <text>` is the word that writes it on purpose. An
+ // ordinary builtin, so it runs the ordinary way — write it in the buffer,
+ // select the line, execute it — and what lands is the text, verbatim, with the
+ // same stamped-looking left edge as the reports above. (The clock belongs to
+ // the SHELL, which is why this one has none: the core has no clock.)
+ try t.key("o");
+ try t.send("Msg hand-written report");
+ try t.key("esc");
+ try t.settle(100);
+ try t.key("x");
+ try t.key("tab");
+ try t.stable(700, 15000);
+ try t.snap("msgbuiltin");
+ // A message wider than the pane keeps its TAIL, not its head: the end of a
+ // message is the part that says something -- a path's file name, an error's
+ // reason -- so the head is what a narrow pane goes without.
+ try t.key("j");
+ try t.key("o");
+ try t.send("Msg 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 0123456789 THE-END");
+ try t.key("esc");
+ try t.settle(100);
+ try t.key("x");
+ try t.key("tab");
+ try t.stable(700, 15000);
+ try t.snap("msgtail");
+ try t.done();
+}
+
+// SIGWINCH crash (reported as "crash on font-size change"): resizing the outer
+// terminal delivers SIGWINCH, and vaxis's default handler locks std.Io mutexes
+// from signal context — landing on a thread inside an Io.Threaded syscall
+// region (pty readers in read(2), main parked in queue.pop) panicked the Io
+// machinery and killed pardes. Now every thread blocks SIGWINCH and a sigwait
+// watcher consumes it. The in-pane kill storm below crashed pardes before the
+// fix; the resize after proves the watcher still reflows the grid.
+fn winch(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "winch");
+ defer t.deinit();
+ try t.start(31, 100, &.{ "-n", "3" });
+ try t.stable(700, 20000);
+ try t.key("c-b");
+ try t.stable(600, 8000);
+ try t.send("for i in $(seq 600); do kill -WINCH $PPID; done; echo SUR''VIVED");
+ try t.key("enter");
+ try t.wait(15000, "SURVIVED");
+ try t.stable(700, 15000);
+ try t.snap("storm");
+ try t.resize(35, 106);
+ try t.stable(700, 15000);
+ try t.snap("resized");
+ try t.done();
+}
+
+// `Save` with NO argument on a +New scratch: the prompt is drawn in the tag,
+// prefilled with the pane's own directory, and submitting it turns the scratch
+// into an ordinary file pane whose bytes are on disk.
+//
+// config.zig's save_marker is rendered in no other golden in the suite. Ten
+// unit tests assert the STRING startSavePrompt builds (pardes.zig's "Save on a
+// scratch asks for a path in its inherited dir and makes it a file"); none of
+// them can see it drawn, land on the tag rather than the message row, or show
+// what the pane becomes afterwards. That is what this script is for.
+fn savepane(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "savepane");
+ defer t.deinit();
+ try t.start(31, 100, &.{ "-n", "1" });
+ try t.wait(8000, "Newcol Joincol");
+ try t.stable(700, 20000);
+ // a scratch of our own, with something in it to save
+ try t.key("space f n");
+ try t.stable(400, 5000);
+ try t.key("i");
+ try t.send("scratch bytes");
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(400, 5000);
+ try t.snap("scratch");
+ // Save, no argument: the tag gains the armed ` Save <dir>/` prompt, and the
+ // pane is still the scratch — nothing is written until the path is submitted
+ try t.key("space f s");
+ try t.stable(400, 5000);
+ try t.snap("prompt");
+ // name it: the prompt submits, the pane becomes that file (its tag is the path,
+ // and the `*` is gone because what is on screen is what is on disk)
+ try t.send("saved.txt");
+ try t.key("enter");
+ try t.stable(700, 15000);
+ try t.snap("saved");
+ try t.snapFile("bytes", "saved.txt");
+ try t.done();
+}
+
+// external file updates: a write from outside pardes lands in an open pane
+// that has no unsaved edits, committed like any other edit; a pane WITH
+// unsaved edits keeps them and says the file changed on disk (File.changed).
+//
+// The writer must be a STRANGER to the editor. This script used to have a
+// pardes PANE run the write, which proved much less than it looked: that
+// shell's own pty output wakes the loop and paints a frame, so the reload
+// could be riding on the keystroke's frame instead of on the watch. `run` is a
+// child of the RUNNER — nothing it does reaches an app pty — and every
+// assertion below it is a `wait`, which only READS the pty. So between the
+// write and the reload the app receives no keystroke, no resize, no mouse: if
+// the watch does not wake the loop by itself, these waits time out.
+//
+// Two files in two directories, written the two ways files actually change:
+// w.txt in place (CLOSE_WRITE) and sub/s.txt by rename-over, which is what
+// `zig fmt`, `git checkout` and every editor's atomic save do (MOVED_TO, and
+// a new inode — the reason the mark is on the directory).
+fn filewatch(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "filewatch");
+ defer t.deinit();
+ try t.dir("sub");
+ try t.file("w.txt", "line 1\nline 2\n/tmp/pardes-snap/filewatch/cwd/sub/s.txt\nline 4\nline 5\nline 6\nline 7\nline 8\nline 9\nline 10\nline 11\nline 12\n");
+ try t.lines("sub/s.txt", 8, "");
+ // Builtins announce themselves by default, and an announcement is a band at
+ // the top of the body -- which moves every row this script clicks. What the
+ // verbs do is what is under test, not the announcement.
+ try t.config("Verbose off");
+ try t.start(31, 210, &.{ "-n", "1" });
+ try t.wait(8000, "w.txt");
+ try t.stable(700, 20000);
+ // open w.txt as a file pane: type the name into the shell, right-click it
+ try t.press("left", "5", 9);
+ try t.release("left", "5", 9);
+ try t.stable(400, 5000);
+ try t.key("i");
+ try t.send("w.txt");
+ try t.key("esc");
+ try t.settle(100);
+ try t.press("right", "6", 9);
+ try t.release("right", "6", 9);
+ try t.wait(10000, "line 4");
+ try t.stable(700, 15000);
+ // ...and open sub/s.txt from the path sitting on line 3 of that pane, so the
+ // second watched pane is in a DIFFERENT directory from the first
+ try t.press("right", "20", 10);
+ try t.release("right", "20", 10);
+ try t.wait(10000, "line 8");
+ try t.stable(700, 15000);
+ // an UNSAVED edit on line 1 of w.txt
+ try t.press("left", "10", 8);
+ try t.release("left", "10", 8);
+ try t.stable(400, 5000);
+ try t.key("i");
+ try t.send("MYEDIT");
+ try t.key("esc");
+ try t.settle(100);
+ try t.stable(400, 5000);
+ try t.snap("edited");
+ // ---- from here to `snap reloaded_sub`, pardes is sent NOTHING ----
+ // w.txt has the unsaved edit: it is kept, and the change is said
+ try t.run("printf 'EXTERNAL\\n' > w.txt");
+ try t.wait(10000, "changed on disk");
+ try t.stable(700, 10000);
+ try t.snap("kept");
+ // sub/s.txt has none: it takes the new text
+ try t.run("printf 'RENAMED\\n' > sub/t && mv sub/t sub/s.txt");
+ try t.wait(10000, "RENAMED");
+ try t.stable(700, 10000);
+ try t.snap("reloaded_sub");
+ try t.done();
+}