From 6bcb18e021a09d51539e628106a594748637ead2 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 4 Nov 2026 16:46:18 -0300 Subject: 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 Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge --- test/process/tree.zig | 178 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 178 insertions(+) create mode 100644 test/process/tree.zig (limited to 'test/process/tree.zig') diff --git a/test/process/tree.zig b/test/process/tree.zig new file mode 100644 index 00000000..c7b9e657 --- /dev/null +++ b/test/process/tree.zig @@ -0,0 +1,178 @@ +//! docs/typ/reference.typ, The tree , through a real session's +//! socket: what a client on the wire sees, and /os on the disk. +const std = @import("std"); +const process = @import("../process.zig"); +const Conn = process.Conn; +const has = process.has; +const check = process.check; + +pub const cases = .{ + .{ "tree: the root lists its files and not self; /os reads the disk, `..` taken as a walk takes it, and writes it truncated", rootAndOs }, + .{ "tree: a client of 256-byte frames lists /os whole, a dangling link left out; one of 64 KiB is agreed", frames }, + .{ "tree: a ctl line with no newline is held whatever its write's size, and runs at the close, its failure in the log", heldLine }, + .{ "tree: /screen freezes at its open; a dozen connections in turn each read a body", frozenScreen }, + .{ "tree: a Look at a relative name finds the disk's file first; /n/self is the session's tree, /n/os the disk", looks }, + .{ "tree: names up to 255 bytes list, read, write and open through /os and /n/os, and a directory lists them", longNames }, +}; + +fn rootAndOs(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "first", .{}); + defer d.deinit(); + const c = try Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + const root = d.root(); + const names = try c.list(a, "/"); + for ([_][]const u8{ "pane", "index", "status", "look", "exec", "log", "os" }) |want| { + for (names) |n| { + if (std.mem.eql(u8, n, want)) break; + } else return error.NotListed; + } + for (names) |n| try check(!std.mem.eql(u8, n, "self"), "self listed", .{}); + try std.testing.expectEqualStrings("initial\n", try c.read(a, "/pane/1/body")); + const os_path = try std.fmt.allocPrint(a, "/os{s}/first.txt", .{root}); + try std.testing.expectEqualStrings("initial\n", try c.read(a, os_path)); + const listed = try c.list(a, try std.fmt.allocPrint(a, "/os{s}", .{root})); + for (listed) |n| { + if (std.mem.eql(u8, n, "first.txt")) break; + } else return error.NotListed; + try std.testing.expectEqualStrings("initial\n", try c.read(a, "/pane/1/../1/body")); + try std.testing.expectEqualStrings("initial\n", try c.read(a, try std.fmt.allocPrint(a, "/os{s}/../{s}/first.txt", .{ root, std.fs.path.basename(root) }))); + try c.replace(os_path, "written through 9P\n"); + try std.testing.expectEqualStrings("written through 9P\n", try d.get(a, "first.txt")); + try std.testing.expectEqualStrings("written through 9P\n", try c.read(a, os_path)); +} + +fn frames(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "frames", .{}); + defer d.deinit(); + _ = std.c.mkdir(d.abs("listing"), 0o755); + _ = symlink(d.abs("listing/missing"), d.abs("listing/broken")); + for (0..24) |i| try d.put(try std.fmt.allocPrint(a, "listing/entry-{d:0>2}", .{i}), ""); + const small = try Conn.dialSized(gpa, d.socket(), 256); + defer small.deinit(gpa); + const names = try small.list(a, try std.fmt.allocPrint(a, "/os{s}/listing", .{d.root()})); + try check(names.len == 24, "listed {d}: {any}", .{ names.len, names }); + for (names) |n| try check(std.mem.startsWith(u8, n, "entry-"), "listed {s}", .{n}); + const big = try Conn.dial(gpa, d.socket()); + defer big.deinit(gpa); + try std.testing.expectEqual(@as(u32, 65536), big.msizeAgreed()); +} + +extern "c" fn symlink(target: [*:0]const u8, path: [*:0]const u8) c_int; + +fn heldLine(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "held", .{}); + defer d.deinit(); + // 64 KiB frames: a line with no newline is held whatever the size of its + // write (a mount cuts lines anywhere), and runs at the close. + const c = try Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + const ctl = try c.hold("/pane/1/ctl", 1); + const line = try a.alloc(u8, 5 + 20000); + @memcpy(line[0..5], "bogus"); + @memset(line[5..], 'x'); + _ = try c.writeFid(ctl, 0, line); + try check(!has(try c.read(a, "/log"), "ctl: unknown control message"), "ran before the close", .{}); + c.clunk(ctl); + try check(has(try c.read(a, "/log"), "ctl: unknown control message"), "never ran", .{}); +} + +fn frozenScreen(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "frozen", .{}); + defer d.deinit(); + const c = try Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + const frozen = try c.hold("/screen", 0); + var before: std.ArrayList(u8) = .empty; + try before.appendSlice(a, try c.readFid(frozen, 0, 31)); + try c.write("/pane/1/body", "screen changed\n"); + while (true) { + const chunk = try c.readFid(frozen, before.items.len, 65536); + if (chunk.len == 0) break; + try before.appendSlice(a, chunk); + } + c.clunk(frozen); + const json = try std.json.parseFromSliceLeaky(std.json.Value, a, before.items, .{}); + var old: std.ArrayList(u8) = .empty; + for (json.object.get("cells").?.array.items) |cell| try old.appendSlice(a, cell.array.items[0].string); + try check(has(old.items, "initial") and !has(old.items, "screen changed"), "the open's screen moved", .{}); + try check(has(try d.files.screen(), "screen changed"), "a new open shows the old screen", .{}); + const body = "initial\nscreen changed\n"; + for (0..12) |i| { + const other = try Conn.dial(gpa, d.socket()); + defer other.deinit(gpa); + try check(std.mem.eql(u8, try other.read(a, "/pane/1/body"), body), "connection {d}", .{i}); + } +} + +fn looks(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "first", .{}); + defer d.deinit(); + const c = try Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + // A build with its sources (-Dembed-sources) serves them under /src. + for (try c.list(a, "/")) |n| if (std.mem.eql(u8, n, "src")) { + const source = try c.look(a, "/virtual/src/pardes.zig", null); + try check(has(try c.pane(a, source, "body"), "pub const Pardes"), "/virtual/src", .{}); + }; + try d.put("index", "OS takes precedence\n"); + var opened = try c.look(a, "index", null); + try std.testing.expectEqualStrings("OS takes precedence\n", try c.pane(a, opened, "body")); + opened = try c.look(a, "/n/self/index", null); + const index = try c.pane(a, opened, "body"); + try check(std.mem.startsWith(u8, index, "1 ") and has(index, "first.txt"), "/n/self/index: {s}", .{index}); + try d.put("explicit.txt", "explicit OS mount\n"); + opened = try c.look(a, try std.fmt.allocPrint(a, "/n/os{s}", .{d.abs("explicit.txt")}), null); + try std.testing.expectEqualStrings("explicit OS mount\n", try c.pane(a, opened, "body")); +} + +fn longNames(gpa: std.mem.Allocator, exe: [:0]const u8) !void { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const a = arena.allocator(); + var d = try process.Detached.start(gpa, exe, "long-names", .{}); + defer d.deinit(); + const c = try Conn.dial(gpa, d.socket()); + defer c.deinit(gpa); + const dir_rel = try a.alloc(u8, 64); + @memcpy(dir_rel[0..10], "directory-"); + @memset(dir_rel[10..], 'd'); + _ = std.c.mkdir(d.abs(dir_rel), 0o755); + const dir = d.abs(dir_rel); + for ([_]usize{ 29, 63, 127, 255 }) |length| { + const name = try a.alloc(u8, length); + @memset(name[0 .. length - 4], 'f'); + @memcpy(name[length - 4 ..], ".txt"); + const rel = try std.fmt.allocPrint(a, "{s}/{s}", .{ dir_rel, name }); + try d.put(rel, "long filename\n"); + const wire = try std.fmt.allocPrint(a, "/os{s}", .{d.abs(rel)}); + const listed = try c.list(a, try std.fmt.allocPrint(a, "/os{s}", .{dir})); + for (listed) |n| { + if (std.mem.eql(u8, n, name)) break; + } else return error.NotListed; + try std.testing.expectEqualStrings("long filename\n", try c.read(a, wire)); + try c.replace(wire, "written through long filename\n"); + try std.testing.expectEqualStrings("written through long filename\n", try d.get(a, rel)); + const opened = try c.look(a, try std.fmt.allocPrint(a, "/n/os{s}", .{d.abs(rel)}), null); + try std.testing.expectEqualStrings("written through long filename\n", try c.pane(a, opened, "body")); + try c.removePane(opened); // a long name's tag takes rows + } + const opened = try c.look(a, try std.fmt.allocPrint(a, "/n/os{s}", .{dir}), null); + const listing = try c.pane(a, opened, "body"); + for (try process.entries(a, dir)) |n| try check(has(listing, try std.fmt.allocPrint(a, "/n/os{s}/{s}", .{ dir, n })), "{s} not listed", .{n}); +} -- cgit v1.3