summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-20 15:50:20 -0300
committerGabriel Schneider <[email protected]>2026-11-20 16:13:22 -0300
commitdf0fe00d35c1a01a852d7518ef884ec7aab7ace6 (patch)
tree603b6bc4c6e371632c5ac7152f374c4153f25d86
parentd720cf44d458e3986d371f4b8b768a97ba489c9c (diff)
downloadpardes-df0fe00d35c1a01a852d7518ef884ec7aab7ace6.tar.gz
pardes-df0fe00d35c1a01a852d7518ef884ec7aab7ace6.zip
test: the tty harness sends an Esc read alone: `key` waits, before an esc and after it, until the app has read every byte typed (Harness.unread: FIONREAD on the pty's own end, opened by ptsname for the look and closed; the master's FIONREAD counts only what the app wrote); ttytaken typed "@`echo ..`", Esc, then h 100 ms later: the backquote and the Esc read together end a read, readInput waits 50 ms for more, a busy app overran it and read h after it, and ESC h is Alt-h by its bytes (reports/pardes-faults-5.md 4b), a TEST fault, not the product's (a terminal cannot tell the two apart); ttytaken pinned to one CPU (taskset -c 5, no made load), on the tip with this and the cursor change: 0 of 100 failed (load 4-13); the base's failure was round 2's, 4 of 17 under a made load, never pinned
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--test/e2e_harness.zig16
-rw-r--r--test/tty.zig23
2 files changed, 36 insertions, 3 deletions
diff --git a/test/e2e_harness.zig b/test/e2e_harness.zig
index 26e942e7..f9ed44c0 100644
--- a/test/e2e_harness.zig
+++ b/test/e2e_harness.zig
@@ -20,6 +20,7 @@ extern "c" fn openpty(
winp: ?*const posix.winsize,
) c_int;
extern "c" fn ttyname(fd: c_int) ?[*:0]const u8;
+extern "c" fn ptsname(fd: c_int) ?[*:0]const u8;
extern "c" fn execvp(file: [*:0]const u8, argv: [*:null]const ?[*:0]const u8) c_int;
extern "c" fn _exit(status: c_int) noreturn;
extern "c" fn unsetenv(name: [*:0]const u8) c_int;
@@ -251,6 +252,21 @@ pub const Harness = struct {
return if (n > 0) @intCast(n) else 0;
}
+ /// Bytes typed that the app has not read yet: its end's input queue
+ /// (the master's FIONREAD counts only what the app wrote).
+ pub fn unread(self: *Harness) usize {
+ const FIONREAD: c_int = switch (@import("builtin").os.tag) {
+ .linux => posix.T.FIONREAD,
+ else => 0x4004667f,
+ };
+ const fd = libc.open(ptsname(self.master) orelse return 0, .{ .ACCMODE = .RDWR, .NOCTTY = true, .CLOEXEC = true });
+ if (fd < 0) return 0;
+ defer _ = libc.close(fd);
+ var n: c_int = 0;
+ if (posix.system.ioctl(fd, FIONREAD, @intFromPtr(&n)) != 0) return 0;
+ return if (n > 0) @intCast(n) else 0;
+ }
+
/// Resize both the pty (SIGWINCH to the app) and our terminal (grid reflows
/// to the new size). Harness terminal first so it's ready for the app's
/// re-render at the new size.
diff --git a/test/tty.zig b/test/tty.zig
index a6e37c6c..47fca229 100644
--- a/test/tty.zig
+++ b/test/tty.zig
@@ -263,11 +263,28 @@ pub const Tty = struct {
}
/// Keys by name, space-separated: enter esc tab bs space up down left
- /// right home end pgup pgdn, a character, c-<ch> and a-<ch>. After esc,
- /// settle: vaxis reads the next byte in the same batch as alt-<ch>.
+ /// right home end pgup pgdn, a character, c-<ch> and a-<ch>. An esc is
+ /// read alone: sent once the app has read what came before it, and
+ /// read before anything after it is sent (a read that ends in ESC waits
+ /// for more, and `ESC h` is alt-h).
pub fn key(t: *Tty, names: []const u8) !void {
var it = std.mem.tokenizeScalar(u8, names, ' ');
- while (it.next()) |name| try t.live().send(keyBytes(name) orelse return error.BadKey);
+ while (it.next()) |name| {
+ const esc = std.mem.eql(u8, name, "esc");
+ if (esc) try t.allRead();
+ try t.live().send(keyBytes(name) orelse return error.BadKey);
+ if (esc) try t.allRead();
+ }
+ }
+
+ /// Pump until the app has read every byte typed (10 s at most).
+ fn allRead(t: *Tty) !void {
+ const h = t.live();
+ const until = eh.nowMs() + 10_000;
+ while (h.unread() > 0) {
+ if (eh.nowMs() > until) return error.InputNeverRead;
+ _ = try h.pumpOnce(2);
+ }
}
/// An SGR mouse press, release or drag (motion with it held) of