From 757cdaa826131dc5ff2d3ff0b270b8abe041c81a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Tue, 17 Nov 2026 02:40:21 -0300 Subject: plumber: external ports (docs/next-plumber.md, phase 3): every port a rule names has a file, plumb/ (0444), listed after rules and send in the order rules named them and never dropped (Plumb.ports, dumped: seeded at boot from the rules in force, grown by each apply, refused past 32), its node a third family in the tree beside panes and columns (Node.ofPort, Target.port; port_bit is 1 << 40, clear of the host tree's and the archive's high bits, which 1 << 57 hit); an open reads (Open.what.port, an events.Queue of its own, 64 KiB): the messages sent from then on, packed, one a read, a short read the front and the next the rest, a read with none held until one comes (p.fs.news, answered by the listener as event reads are); every open gets its copy (fanOut, plumber(4)'s queuesend), one over the queue is not sent to it and the log says so; a port pardes reads itself (edit, web, a loaded kind) hands its readers copies without asking anyone, so a look stays speculated whole; another port's readers are the authority's to know, asked through tape.authority (a replica's own look waits for the first answer and guesses the last), with none its rule set's start runs, or its client, the message held in p.fs.plumb_held for the port's first opener (Plumb.opened, plumber(4)'s queueheld); test: plumber.zig, two opens of plumb/edit each read a look's message while the file opens, an open made after reads nothing, a client's message reaches the first opener and the next goes to the reader with nothing started, a port is not written; monkey9p.zig gains the plumb/ files, rules and messages that start no program, the ports' reads as held reads, and plumb/rules' rest read at the close (whose refusal is the log's alone, as a line file's: restAtClose); replicas.zig: a look to a port a program reads, the second of a replica's own speculated whole and confirmed, digests equal; tree.zig's readdir test lists web and edit; the reference's tree and plumber section, fs-help and the changelog say so --- test/monkey9p.zig | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'test/monkey9p.zig') diff --git a/test/monkey9p.zig b/test/monkey9p.zig index c9dd5083..a4bf92a3 100644 --- a/test/monkey9p.zig +++ b/test/monkey9p.zig @@ -92,7 +92,7 @@ const builtins = [_][]const u8{ "Theme", "Get", "Put", "Undo", "Redo", "Zerox", "Snarf", "Paste", "Cut", "Sort", "Font", "Local", }; const pane_files = [_][]const u8{ "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata", "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec", "pty", "pty/run", "pty/data", "pty/ctl", "pty/status" }; -const root_files = [_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "pane/new", "col", "" }; +const root_files = [_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "look", "exec", "log", "screen", "listeners", "layout", "tag", "tagexec", "pane", "pane/new", "col", "plumb", "plumb/rules", "plumb/send", "plumb/edit", "plumb/web", "plumb/seemail", "" }; const long_x: [300]u8 = @splat('x'); const col_files = [_][]const u8{ "tag", "ctl", "exec" }; const writable = [_][]const u8{ "ctl", "exec", "look", "tag", "tagexec", "focus", "body", "data", "xdata", "addr", "dot", "limit", "name", "sel", "dirty", "mark", "scroll", "errors", "event", "pty/run", "pty/data", "pty/ctl", "log" }; @@ -199,7 +199,7 @@ fn pickCol(r: Random, a: Allocator) []const u8 { fn randomPath(r: Random, a: Allocator, write: bool) []const u8 { const x = chance(r); if (x < 0.6) return print(a, "/pane/{s}/{s}", .{ pickSerial(r, a), if (write) pick(r, &writable) else pick(r, &pane_files) }); - if (x < 0.75) return cat(a, &.{ "/", if (write) pick(r, &[_][]const u8{ "ctl", "exec", "look", "tag", "tagexec", "focus", "log" }) else pick(r, &root_files) }); + if (x < 0.75) return cat(a, &.{ "/", if (write) pick(r, &[_][]const u8{ "ctl", "exec", "look", "tag", "tagexec", "focus", "log", "plumb/rules", "plumb/send", "plumb/edit" }) else pick(r, &root_files) }); if (x < 0.85) return print(a, "/col/{s}/{s}", .{ pickCol(r, a), pick(r, &col_files) }); if (x < 0.93) return print(a, "/pane/{s}/{s}", .{ pickSerial(r, a), weirdName(r, a) }); var out: []const u8 = ""; @@ -230,6 +230,10 @@ fn dataFor(r: Random, a: Allocator, path: []const u8) []const u8 { return cat(a, &.{ shellSafe(a, pick(r, &[_][]const u8{ "alpha", "alpha.txt", "alpha.txt:2", "utf8.txt:#3", "nothere", "bad.txt", "crlf.txt:1", "gamma", "beta" })), "\n" }); if (is(b, &.{ "dirty", "mark", "scroll" })) return pick(r, &[_][]const u8{ "0", "1", "0\n", "1\n", "2\n", "", "yes\n" }); if (std.mem.eql(u8, b, "log")) return pick(r, &[_][]const u8{ "follow\n", "follow new\n", "follow", "nope\n" }); + // The plumber's: rule sets that start no program, half ones, bad ones; + // messages whole, short of their data, malformed. + if (std.mem.eql(u8, b, "rules")) return pick(r, &[_][]const u8{ "type is text\ndata matches 'letter-[0-9]+'\nplumb to seemail\n\n", "include basic\n", "type is text\narg isfile $data\nplumb to edit\n", "data isnt x\n", "plumb to seemail\n\n", "x='[a-z]+'\n", "" }); + if (std.mem.eql(u8, b, "send")) return pick(r, &[_][]const u8{ "monkey\n\n/\ntext\n\n9\nletter-42", "monkey\n\n/\ntext\n\n9\nalpha.txt", "monkey\nseemail\n/\ntext\n\n1\nx", "monkey\n\n/\ntext\n\n20\nshort", "a\nb\n" }); return payload(r, a, 200); } @@ -704,7 +708,8 @@ fn hostPath(path: []const u8) bool { fn isHeld(path: []const u8) bool { return std.mem.eql(u8, std.mem.trimEnd(u8, path, "/"), "/log") or std.mem.endsWith(u8, path, "/event") or - std.mem.endsWith(u8, path, "/pty/data") or std.mem.endsWith(u8, path, "/pty/run"); + std.mem.endsWith(u8, path, "/pty/data") or std.mem.endsWith(u8, path, "/pty/run") or + (std.mem.startsWith(u8, path, "/plumb/") and !std.mem.endsWith(u8, path, "/rules") and !std.mem.endsWith(u8, path, "/send")); } /// An open the rule names: pane/new's (it makes a pane) and a truncation @@ -931,7 +936,7 @@ fn exec(c: *Ctx, a: Allocator, res: *Res, op: Op) anyerror!void { } const closed = try clunk(c, a, res, &f, o.path); // What the open holds when it closes: the last line written, if unended. - if (opened and o.mode & 3 != 0 and sent.len > 0 and !std.mem.endsWith(u8, sent, "\n")) + if (opened and o.mode & 3 != 0 and restAtClose(o.path, sent)) res.add(a, .{ .kind = .close_runs, .path = o.path, .ok = closed }); }, .read => |o| { @@ -1014,7 +1019,7 @@ fn exec(c: *Ctx, a: Allocator, res: *Res, op: Op) anyerror!void { } var h = c.handles.orderedRemove(i % c.handles.items.len); const ok = try clunk(c, a, res, &h.fid, h.path); - if (h.fid.mode & 3 != 0 and h.last.len > 0 and !std.mem.endsWith(u8, h.last, "\n")) + if (h.fid.mode & 3 != 0 and restAtClose(h.path, h.last)) res.add(a, .{ .kind = .close_runs, .path = h.path, .ok = ok }); }, .restore => |data| { @@ -1322,7 +1327,15 @@ fn oneFailureRule(c: *Ctx, a: Allocator, res: *Res) ?[]const u8 { return null; } -const line_files = [_][]const u8{ "look", "exec", "tagexec", "ctl" }; +const line_files = [_][]const u8{ "look", "exec", "tagexec", "ctl", "rules" }; + +/// What an open that wrote `sent` last leaves to its close: a line with no +/// newline yet, or of plumb/rules' text a rule set with no blank line +/// after it (plumber(4)'s, read at the close). +fn restAtClose(path: []const u8, sent: []const u8) bool { + if (sent.len == 0) return false; + return !std.mem.endsWith(u8, sent, if (std.mem.endsWith(u8, path, "plumb/rules")) "\n\n" else "\n"); +} /// docs/typ/reference.typ: 'A write of command lines -- to look, exec, /// tagexec, a ctl of the root, a pane or a column, or a column's exec -- -- cgit v1.3