summaryrefslogtreecommitdiff
path: root/test/process/repls.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-04 16:46:18 -0300
committerGabriel Schneider <[email protected]>2026-11-04 16:55:32 -0300
commit6bcb18e021a09d51539e628106a594748637ead2 (patch)
tree954996560c694dd7f0ab410aa01def00d25c33fe /test/process/repls.zig
parentbe3985092df1c3388cfa09ca5e989d2fa66f55ec (diff)
downloadpardes-6bcb18e021a09d51539e628106a594748637ead2.tar.gz
pardes-6bcb18e021a09d51539e628106a594748637ead2.zip
test: fs.py's inline checks, quic_test, workflow_canary, python_repl_runs_one_line and signal_cleans_up moved to Zig, deleted from fs.py (its named cases stay): 21 process cases in test/process/ (flags: bad options refused in words, --9p naming the socket, forwarding a launch inside a session and the launches that start their own (mount, name, tcp, load, shells, toggle, quic), --wait and its refusals, pardes - and its +Pager (escapes, inks and Filter, progress, 11 MiB, the 256 MiB cut), $winid, the stdin boot, no terminal to draw on, a killed tty editor and its swept sockets, a signal unlinking the socket; mounts: --mount at startup, Mount and Unmount at run time, QUIC and TCP v4 and v6 detached and in a pty (skipped without -Dquic=true, passed with it); tree: the root and /os, 256-byte frames, a held ctl line, a frozen /screen, Look's precedence, 255-byte names; root-ctl: Restore detached and in a pty; builtins: Lspinfo; look-and-exec: the canary; repls: Python's pyrepl) and 3 behaviour tests (a 60 KB body write, truncated, a missing pane refused; a body write's EI record; keyword colour, not bold); process.zig gains, under fsb:, Conn.dialSized, dialTcp, replace, newPane, serials, look, pane, exec, execRefused, removePane, Files.fg, Detached.exists, abs, startTty, and Child (a program in a root's environment, its stdin fed, on a pty if asked, its stderr kept), run, code, entries, canonical, quicIncluded, nowMs, nap, has, check; each checked to fail against a break (no such option reworded, SyntaxBold on by default, a body insert's record not EI, Grep's miss reworded, already inside pardes reworded, a session already running reworded, Lspinfo's servers line reworded, no terminal to draw on reworded, unknown control message reworded); behaviour, process, fs-unit and core tests and the rest of fs.py pass
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test/process/repls.zig')
-rw-r--r--test/process/repls.zig79
1 files changed, 79 insertions, 0 deletions
diff --git a/test/process/repls.zig b/test/process/repls.zig
new file mode 100644
index 00000000..09e25e96
--- /dev/null
+++ b/test/process/repls.zig
@@ -0,0 +1,79 @@
+//! docs/typ/reference.typ, REPLs <repls>: an exec sent to a real REPL in
+//! a real pty.
+const std = @import("std");
+const process = @import("../process.zig");
+const Conn = process.Conn;
+const has = process.has;
+const check = process.check;
+
+pub const cases = .{
+ .{ "repls: a one-line exec sent to Python's own REPL (pyrepl, bracketed paste) runs at once, after idling too, and a block runs whole", pythonRepl },
+};
+
+/// Waits up to `ms` for the terminal's body to hold `text`.
+fn waitFor(a: std.mem.Allocator, c: *Conn, tty: u32, text: []const u8, ms: i64) !bool {
+ const deadline = process.nowMs() + ms;
+ while (process.nowMs() < deadline) {
+ if (has(try c.pane(a, tty, "body"), text)) return true;
+ process.nap(100);
+ }
+ return false;
+}
+
+fn pythonRepl(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var arena = std.heap.ArenaAllocator.init(gpa);
+ defer arena.deinit();
+ const a = arena.allocator();
+ // 3.13's pyrepl asks for bracketed paste; an older one or none is no test.
+ const version = try process.run(a, &.{ "python3", "-c", "import sys; sys.exit(sys.version_info < (3, 13))" }, .{});
+ if (version.code != 0) {
+ std.debug.print("SKIP no python3 3.13 or later\n", .{});
+ return;
+ }
+ var d = try process.Detached.start(gpa, exe, "repl", .{});
+ defer d.deinit();
+ const c = try Conn.dial(gpa, d.socket());
+ defer c.deinit(gpa);
+ const before = try c.serials(a);
+ try c.write("/pane/1/ctl", "Tty\n");
+ const deadline = process.nowMs() + 10_000;
+ var tty: u32 = 0;
+ while (tty == 0 and process.nowMs() < deadline) : (process.nap(50)) {
+ for (try c.serials(a)) |n| if (std.mem.indexOfScalar(u32, before, n) == null) {
+ tty = @max(tty, n);
+ };
+ }
+ try check(tty != 0, "Tty made no pane", .{});
+ try check(try waitFor(a, c, tty, "$", 15_000) or try waitFor(a, c, tty, ">", 15_000), "no prompt: {s}", .{try c.pane(a, tty, "body")});
+ try c.write(try std.fmt.allocPrint(a, "/pane/{d}/pty/data", .{tty}), "python3 -q\r");
+ try check(try waitFor(a, c, tty, ">>>", 15_000), "no >>>: {s}", .{try c.pane(a, tty, "body")});
+ try c.write(try std.fmt.allocPrint(a, "/pane/{d}/ctl", .{tty}), "Repl python\n");
+ // An exec on the REPL's own body goes to the REPL, as its event record
+ // written back does: an empty range acts on its text.
+ const fid = try c.hold(try std.fmt.allocPrint(a, "/pane/{d}/event", .{tty}), 2);
+ defer c.clunk(fid);
+ _ = try c.writeFid(fid, 0, "MX0 0 0 10 print(6*7)\n");
+ try check(try waitFor(a, c, tty, "\n42", 15_000), "no 42: {s}", .{try c.pane(a, tty, "body")});
+ // After the session has sat idle, the Enter still waits for the paste:
+ // core time is as old as the last frame then.
+ for (0..5) |n| {
+ process.nap(2_000);
+ const line = try std.fmt.allocPrint(a, "print({d})", .{1000 + n});
+ _ = try c.writeFid(fid, 0, try std.fmt.allocPrint(a, "MX0 0 0 {d} {s}\n", .{ line.len, line }));
+ try check(try waitFor(a, c, tty, try std.fmt.allocPrint(a, "\n{d}", .{1000 + n}), 15_000), "{d}: {s}", .{ n, try c.pane(a, tty, "body") });
+ }
+ // More than one line, with and without a newline at the end, and a block
+ // with a statement after it: each runs whole, and the REPL is back at
+ // its prompt, not at `...`.
+ for ([_]struct { []const u8, []const []const u8 }{
+ .{ "print(11)\nprint(22)", &.{ "11", "22" } },
+ .{ "print(33)\nprint(44)\n", &.{ "33", "44" } },
+ .{ "for i in range(2):\n print(55 + i)\nprint(77)\n", &.{ "55", "56", "77" } },
+ }) |row| {
+ _ = try c.writeFid(fid, 0, try std.fmt.allocPrint(a, "MX0 0 0 {d} {s}\n", .{ row[0].len, row[0] }));
+ for (row[1]) |out| try check(try waitFor(a, c, tty, try std.fmt.allocPrint(a, "\n{s}\n", .{out}), 15_000), "{s}: no {s}: {s}", .{ row[0], out, try c.pane(a, tty, "body") });
+ process.nap(500);
+ const body = try c.pane(a, tty, "body");
+ try check(std.mem.endsWith(u8, std.mem.trimEnd(u8, body, " \t\r\n"), ">>>"), "{s}: not at its prompt: {s}", .{ row[0], body[body.len -| 200..] });
+ }
+}