From fac51df2abec19e57932e0fbe4492d372d7daac2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 21:23:04 -0300 Subject: pty/run: a run waiting for a new terminal's first prompt is the only line typed there: the Term's greeting ls is dropped when the run's line goes (pty.zig noteMarks), as on the window (resized, so it greets) both were typed at that prompt and ls's C, read with true's in one chunk, left the run waiting for ever (4 runs of 6); the window's process sessions run on a 160x50 pty (Child.Pty's cols and rows), as a test window follows its terminal's size and the 80x24 one made the canary's Newcol find no room; terminals' pty/run case and the canary run on both backends (10 of 10 each on the window), their next-tests Open bullets gone; a pty.zig unit test that fails without the fix (truels) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- docs/next-tests.md | 6 ------ src/ninep/pty.zig | 24 ++++++++++++++++++++++++ test/process.zig | 14 +++++++++----- test/process/look_and_exec.zig | 4 ---- test/process/terminals.zig | 3 --- 5 files changed, 33 insertions(+), 18 deletions(-) diff --git a/docs/next-tests.md b/docs/next-tests.md index a16a7cf9..35d82ac3 100644 --- a/docs/next-tests.md +++ b/docs/next-tests.md @@ -59,12 +59,6 @@ agent's survey. The `e2e` line (kbdin, mousein) is its first step. capture. - **A case about one frontend's own behaviour says `process.only(.tty)`.** On the window, 31 cases pass and 5 skip. - - **Open:** on the window the canary's Newcol is refused after its - terminal steps (a fresh window takes it), and one run hung there. The - canary is tty-only until that is found. - - **Open, likely the same:** on the window a fresh terminal pane's first - pty/run sometimes never answers (4 runs of 6, before its shell's first - prompt). terminals' pty/run case is tty-only until it is found. Before the port, the plan was: the Python suites in the build (fs.py, monkey9p.py, gui_monkey.py, agent_session_test.py) move onto it or onto Session, then diff --git a/src/ninep/pty.zig b/src/ninep/pty.zig index 5c9a6289..5a974adf 100644 --- a/src/ninep/pty.zig +++ b/src/ninep/pty.zig @@ -324,6 +324,9 @@ pub fn noteMarks(p: *Pardes, id: usize, pane: *Pane) void { p.emitWrite(id, slot.line); p.emitWrite(id, "\r"); pardes.panes.terminal.noteCommand(pane, slot.line); + // The run is the shell's first command: a greeting `ls` typed at the + // same prompt would run after it, and its C would be taken for ours. + pane.greet = false; slot.phase = .sent; return; } @@ -768,6 +771,27 @@ test "pty/data writes at the shell and reads the raw stream" { try testing.expectEqualStrings("still", rd(p, data, 0, 64).bytes); } +test "a run waiting for a new terminal's first prompt is the only line typed there, no greeting after it" { + const gpa = testing.allocator; + const p = try withTerm(gpa); + defer p.deinit(); + p.panes[0].?.greet = true; // a Term's, in a window (resized) + p.update(.{ .resize = .{ .cols = 80, .rows = 24 } }); + while (p.nextEffect()) |_| {} + const node = Node.of(serialOf(p), .pty_run); + const h = call(p, .{ .tag = 1, .op = .open, .node = node }).reply.handle; + _ = call(p, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" }); + p.update(.{ .output = .{ .pane = 0, .bytes = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07" } }); + var sent: [32]u8 = undefined; + var len: usize = 0; + while (p.nextEffect()) |e| if (e == .write) { + const b = e.write.bytes.slice(); + @memcpy(sent[len..][0..b.len], b); + len += b.len; + }; + try testing.expectEqualStrings("true\r", sent[0..len]); +} + test "run answers how its command ended once the shell is back at a prompt" { const gpa = testing.allocator; const p = try withTerm(gpa); diff --git a/test/process.zig b/test/process.zig index bba795de..ba6a84a8 100644 --- a/test/process.zig +++ b/test/process.zig @@ -621,8 +621,9 @@ pub const Detached = struct { .root = dir, .env = env[0..n], .unset = if (gui) &.{ "WAYLAND_DISPLAY", "DISPLAY" } else &.{}, - // A window runs on a terminal of its own, as one started from a shell. - .pty = if (gui) .{ .log = try std.fmt.bufPrintSentinel(&bufs[3], "{s}/{s}.pty", .{ dir, name }, 0) } else null, + // A window runs on a terminal of its own, as one started from a + // shell, the grid's size: a test window follows its terminal's. + .pty = if (gui) .{ .log = try std.fmt.bufPrintSentinel(&bufs[3], "{s}/{s}.pty", .{ dir, name }, 0), .cols = 160, .rows = 50 } else null, .err_log = try std.fmt.bufPrintSentinel(&bufs[4], "{s}/{s}.stderr", .{ dir, name }, 0), }); errdefer d.child.deinit(); @@ -793,6 +794,9 @@ pub const Child = struct { log: [:0]const u8, /// Made its controlling terminal; else a pty that is no one's. ctty: bool = true, + /// Its size: a test window follows its terminal's (gui.zig's StdinFeed). + cols: u16 = 80, + rows: u16 = 24, }; pub const Options = struct { @@ -806,7 +810,7 @@ pub const Child = struct { unset: []const [:0]const u8 = &.{}, /// Its stdin, written whole and closed; null: /dev/null. stdin: ?[]const u8 = null, - /// Started in a 24x80 pty, its stdin and stdout. + /// Started in a pty (80x24 unless it says), its stdin and stdout. pty: ?Pty = null, /// Its stderr to this file, not a pipe: a long session's, which /// nobody reads while it runs and which must never fill. `said` @@ -837,8 +841,8 @@ pub const Child = struct { @memcpy(c.err_path[0..path.len], path); c.err_path_len = path.len; } - if (opts.pty != null) { - var ws: std.posix.winsize = .{ .row = 24, .col = 80, .xpixel = 0, .ypixel = 0 }; + if (opts.pty) |p| { + var ws: std.posix.winsize = .{ .row = p.rows, .col = p.cols, .xpixel = 0, .ypixel = 0 }; if (openpty(&c.master, &c.slave, null, null, &ws) != 0) return error.NoPty; for ([_]c_int{ c.master, c.slave }) |fd| _ = libc.fcntl(fd, libc.F.SETFD, @as(c_int, 1)); // FD_CLOEXEC } diff --git a/test/process/look_and_exec.zig b/test/process/look_and_exec.zig index 83836def..5a42b844 100644 --- a/test/process/look_and_exec.zig +++ b/test/process/look_and_exec.zig @@ -63,10 +63,6 @@ const Flow = struct { }; fn canary(gpa: std.mem.Allocator, exe: [:0]const u8) !void { - // shortcut: on the window, after its terminal steps, Newcol is refused - // (or a run hangs), where a fresh window takes it; tui alone until that - // is found (docs/next-tests.md). - try process.only(.tui); const started = process.nowMs(); var arena = std.heap.ArenaAllocator.init(gpa); defer arena.deinit(); diff --git a/test/process/terminals.zig b/test/process/terminals.zig index 96804adf..250c4fb0 100644 --- a/test/process/terminals.zig +++ b/test/process/terminals.zig @@ -79,9 +79,6 @@ const Other = struct { }; fn runFile(gpa: std.mem.Allocator, exe: [:0]const u8) !void { - // shortcut: on the window a fresh Term's first pty/run sometimes never - // answers (4 runs of 6); tui alone until that is found (docs/next-tests.md). - try process.only(.tui); var d = try process.Detached.start(gpa, exe, "run", .{}); defer d.deinit(); const f = &d.files; -- cgit v1.3