diff options
Diffstat (limited to 'src/ninep/tree.zig')
| -rw-r--r-- | src/ninep/tree.zig | 198 |
1 files changed, 172 insertions, 26 deletions
diff --git a/src/ninep/tree.zig b/src/ninep/tree.zig index bca89466..73468ef8 100644 --- a/src/ninep/tree.zig +++ b/src/ninep/tree.zig @@ -25,6 +25,7 @@ pub const sources = @import("sources.zig"); pub const screen = @import("screen.zig"); const daemon = @import("../daemon.zig"); const panes = @import("../panes.zig"); +const Plumb = @import("../Plumb.zig"); const Pardes = pardes.Pardes; const Pane = pardes.Pane; @@ -99,7 +100,8 @@ fn truncates(req: Req) bool { return switch (Node.target(req.node) orelse return false) { .pane => true, .col => |c| c.file == .tag, - .top => |f| f == .tag, + .top => |f| f == .tag or f == .rules, + .port => false, }; } @@ -151,6 +153,13 @@ pub const Open = struct { /// text after that line held in `pending` until its read puts it /// in (ctl.fillPager), or its close hands it to the editor's step. pager: u32, + /// An open writing plumb/rules or plumb/send: `pending` holds what + /// is not whole yet (rule sets with no blank line after them, a + /// message short of its data). + plumb, + /// An open reading a plumb port (Plumb.zig's ports, plumber(4)'s): + /// the messages sent to it since the open, packed, a read each. + port: struct { index: u8, queue: events.Queue = .{} }, } = .{ .snapshot = null }, /// What a write to a file of command lines left unfinished: a last line /// with no newline yet, or an Edit block still open. A write through a @@ -207,7 +216,8 @@ pub const Open = struct { gpa.free(run.line); }, .frozen => |bytes| gpa.free(bytes), - .event, .pty_data, .ctl, .lines, .writes, .pager => {}, + .port => |*port| port.queue.deinit(gpa), + .event, .pty_data, .ctl, .lines, .writes, .pager, .plumb => {}, } o.pending.deinit(gpa); if (o.replay) |r| gpa.free(r.bytes); @@ -269,6 +279,13 @@ pub const TopFile = enum(u5) { /// the addons refused, a line each: `<kind> <version> <abi> /// static|loaded|refused: why [path]`. addons, + /// The plumber's (Plumb.zig, Plan 9's plumber(4)): `rules` and `send`. + plumb, + /// plumb/rules: the rules in force, plumb(6)'s; a write adds rule + /// sets, a `>` replaces them. + rules, + /// plumb/send: a write is a message, plumb(6)'s six lines and data. + send, pub fn fileName(f: TopFile) []const u8 { return if (f == .root) "/" else @tagName(f); @@ -276,15 +293,15 @@ pub const TopFile = enum(u5) { pub fn mode(f: TopFile) u16 { return switch (f) { - .root, .pane, .col => 0o755, - .look, .exec, .log, .focus, .ctl, .tag, .tagexec, .pager => 0o666, + .root, .pane, .col, .plumb => 0o755, + .look, .exec, .log, .focus, .ctl, .tag, .tagexec, .pager, .rules => 0o666, .README, .index, .status, .screen, .listeners, .new, .commands, .layout, .recent, .dumps, .sessions, .addons => 0o444, - .kbdin, .mousein => 0o222, + .kbdin, .mousein, .send => 0o222, }; } pub fn dir(f: TopFile) bool { - return f == .root or f == .pane or f == .col; + return f == .root or f == .pane or f == .col or f == .plumb; } }; @@ -313,6 +330,9 @@ pub const PaneFile = enum(u5) { /// A word run as a click in the pane's tag, as /tagexec is in the /// workspace's and col/<n>/exec in a column's. tagexec, + /// A line a body row: where it points and how it is coloured + /// (locations.formatRows), a results pane's; written, the pane's. + rows, pty, pty_ctl, pty_status, @@ -365,6 +385,10 @@ pub const ColFile = enum(u5) { } }; const col_bit: u59 = 1 << 58; +/// plumb/<port>: a port by its place in Plumb's list, which only grows; +/// past a pane serial's 32 bits and clear of the host tree's and the +/// archive's high bits (fs.os_node, sources.archive_node). +const port_bit: u59 = 1 << 40; pub const Node = packed struct(u64) { file: u5 = 0, @@ -379,11 +403,16 @@ pub const Node = packed struct(u64) { return @bitCast(Node{ .file = @backingInt(file), .serial = col_bit | @as(u59, serial) }); } + pub fn ofPort(index: u8) u64 { + return @bitCast(Node{ .serial = port_bit | @as(u59, index) }); + } + pub fn target(node: u64) ?Target { const n: Node = @bitCast(node); if (n.serial == 0) { return .{ .top = std.enums.fromInt(TopFile, n.file) orelse return null }; } + if (n.serial & port_bit != 0) return .{ .port = std.math.cast(u8, n.serial & ~port_bit) orelse return null }; if (n.serial & col_bit != 0) return .{ .col = .{ .serial = std.math.cast(u32, n.serial & ~col_bit) orelse return null, .file = std.enums.fromInt(ColFile, n.file) orelse return null, @@ -399,6 +428,7 @@ pub const Target = union(enum) { top: TopFile, pane: struct { serial: u32, file: PaneFile }, col: struct { serial: u32, file: ColFile }, + port: u8, }; /// Opening /pane/new makes a pane and reading the open fid answers its @@ -559,7 +589,7 @@ fn serve(p: *Pardes, req: Req) Reply { const target = Node.target(req.node) orelse return Reply.fail(req.tag, E.NOENT); if (req.op == .write or req.op == .setattr) p.fs.origin = switch (target) { .pane => |t| @as(u8, if (t.file == .body or t.file == .tag) 'E' else 'F'), - .top, .col => 'F', + .top, .col, .port => 'F', }; return switch (req.op) { .lookup => lookup(p, req, target), @@ -581,7 +611,7 @@ fn serve(p: *Pardes, req: Req) Reply { fn runAttr(p: *Pardes, req: Req, target: Target) ?Reply.Attr { const t = switch (target) { .pane => |t| t, - .top, .col => return null, + .top, .col, .port => return null, }; if (t.file != .pty_run) return null; const run = if (req.handle != 0) openOf(p, req) else for (&p.fs.opens) |*o| { @@ -593,6 +623,12 @@ fn runAttr(p: *Pardes, req: Req, target: Target) ?Reply.Attr { fn attrOf(p: *Pardes, target: Target) ?Reply.Attr { switch (target) { + .port => |i| return .{ + .name = Plumb.portName(p, i) orelse return null, + .node = Node.ofPort(i), + .mode = 0o444, + .mtime = p.fs.started, + }, .top => |f| return .{ .name = f.fileName(), .node = @backingInt(f), @@ -658,7 +694,7 @@ fn topSize(p: *Pardes, f: TopFile) u64 { // frame, /pane/new until an open has a pane to name, and the index, // layout, recent list and listeners, which a stat would otherwise // have to build to count. - .root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .addons, .listeners, .sessions, .kbdin, .mousein => 0, + .root, .pane, .col, .screen, .new, .layout, .index, .recent, .dumps, .addons, .listeners, .sessions, .kbdin, .mousein, .plumb, .rules, .send => 0, .tag => cols.headerText(p, null).?.len, .README => fs.help.len, .status => if (ctl.statusText(p)) |text| text.len else |_| 0, @@ -689,6 +725,7 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply { else => return Reply.fail(req.tag, E.NOTDIR), }, .col => |c| if (c.file == .dir) @backingInt(TopFile.col) else return Reply.fail(req.tag, E.NOTDIR), + .port => return Reply.fail(req.tag, E.NOTDIR), }; return handle(p, .{ .tag = req.tag, .op = .getattr, .node = parent }); } @@ -697,8 +734,9 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply { .top => |f| switch (f) { .root => root: { if (std.mem.eql(u8, name, "os")) return fs.osHandle(p, .{ .tag = req.tag, .op = .getattr, .node = fs.os_root }); - // `new` is reached in /pane, where the panes it makes are. - if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new) break :root @backingInt(t); + // `new` is reached in /pane, where the panes it makes are, + // `rules` and `send` in /plumb. + if (std.meta.stringToEnum(TopFile, name)) |t| if (t != .root and t != .new and t != .rules and t != .send) break :root @backingInt(t); if (sources.node(name)) |n| return sources.handle(p, .{ .tag = req.tag, .op = .getattr, .node = n }); return Reply.fail(req.tag, E.NOENT); }, @@ -712,8 +750,10 @@ fn lookup(p: *Pardes, req: Req, target: Target) Reply { if (serial == 0) return Reply.fail(req.tag, E.NOENT); break :dir if (f == .pane) Node.of(serial, .dir) else Node.ofCol(serial, .dir); }, + .plumb => if (std.mem.eql(u8, name, "rules")) @backingInt(TopFile.rules) else if (std.mem.eql(u8, name, "send")) @backingInt(TopFile.send) else if (Plumb.portIndex(p, name)) |i| Node.ofPort(i) else return Reply.fail(req.tag, E.NOENT), else => return Reply.fail(req.tag, E.NOTDIR), }, + .port => return Reply.fail(req.tag, E.NOTDIR), .col => |c| col: { if (c.file != .dir) return Reply.fail(req.tag, E.NOTDIR); const f = std.meta.stringToEnum(ColFile, name) orelse return Reply.fail(req.tag, E.NOENT); @@ -752,7 +792,7 @@ fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error .root => { // The guide, then what describes the session, then the // files that act, then the directories. - inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.dumps, TopFile.addons, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.kbdin, TopFile.mousein, TopFile.pane, TopFile.col }) |t| { + inline for (.{ TopFile.README, TopFile.index, TopFile.status, TopFile.focus, TopFile.ctl, TopFile.commands, TopFile.recent, TopFile.dumps, TopFile.addons, TopFile.look, TopFile.exec, TopFile.pager, TopFile.log, TopFile.screen, TopFile.listeners, TopFile.sessions, TopFile.layout, TopFile.tag, TopFile.tagexec, TopFile.kbdin, TopFile.mousein, TopFile.plumb, TopFile.pane, TopFile.col }) |t| { if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(t), t.dir(), t.fileName()); } if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, fs.os_root, true, "os"); @@ -773,6 +813,16 @@ fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error try stageDirent(out, p.gpa, Node.of(serial, .dir), true, name); } }, + // plumber(4)'s order: rules, send, then the ports as rules + // named them. + .plumb => { + inline for (.{ TopFile.rules, TopFile.send }) |t| { + if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, @backingInt(t), false, t.fileName()); + } + for (p.plumber.ports.items, 0..) |name, i| { + if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.ofPort(@intCast(i)), false, name); + } + }, .col => for (0..p.view().ncol) |c| { if (skip > 0) { skip -= 1; @@ -792,6 +842,7 @@ fn stageDir(p: *Pardes, out: *std.ArrayList(u8), target: Target, off: u64) error if (skip > 0) skip -= 1 else try stageDirent(out, p.gpa, Node.ofCol(c.serial, f), false, f.fileName()); } }, + .port => return error.NotDir, .pane => |t| { const id = p.paneBySerial(t.serial) orelse return error.FileNotFound; const terminal = p.panes[id].?.isTerminal(); @@ -842,11 +893,19 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { .index, .layout, .recent, .dumps, .addons, .commands, .status, .listeners, .sessions => .{ .frozen = &.{} }, // The root's ctl opened only to read: its settings, frozen. .ctl => if (linesOpen(target, req)) .lines else .{ .frozen = &.{} }, + // One writer of the rules at a time, as plumber(4)'s. + .rules, .send => if (req.omode & 3 == 0) return .{ .tag = req.tag } else plumb: { + if (f == .rules) for (p.fs.opens) |o| if (o.node == req.node and o.what == .plumb) return failText(req.tag, E.BUSY, e_in_use); + break :plumb .plumb; + }, else => if (linesOpen(target, req)) .lines else return .{ .tag = req.tag }, }, .col => |c| if (layout.columnBySerial(p, c.serial) == null) return Reply.fail(req.tag, E.NOENT) else if (linesOpen(target, req)) .lines else if (c.file == .ctl) .{ .frozen = &.{} } else return .{ .tag = req.tag }, + // A reader of the port: what is sent to it from now on, and what a + // `client` rule held for its first. + .port => |i| if (req.omode & 3 != 0) return Reply.fail(req.tag, E.PERM) else .{ .port = .{ .index = i } }, .pane => |t| what: { const pn = p.panes[p.paneBySerial(t.serial) orelse return Reply.fail(req.tag, E.NOENT)].?; if (t.file.inPty() and !pn.isTerminal()) return Reply.fail(req.tag, E.NOENT); @@ -904,7 +963,8 @@ fn open(p: *Pardes, req: Req, target: Target) Reply { pn.fs.event_reader = pn.fs.event_reader or reader; }, .pty_data => pane_of.?.fs.pty_reader = true, - .run, .ctl, .lines, .writes, .pager => {}, + .port => |*port| Plumb.opened(p, port.index, &port.queue), + .run, .ctl, .lines, .writes, .pager, .plumb => {}, } return .{ .tag = req.tag, .handle = @intCast(i + 1) }; } @@ -915,7 +975,7 @@ fn remove(p: *Pardes, req: Req) Reply { const target = Node.target(req.node) orelse return Reply.fail(req.tag, E.NOENT); const t = switch (target) { .pane => |t| t, - .top => return Reply.fail(req.tag, E.PERM), + .top, .port => return Reply.fail(req.tag, E.PERM), .col => |c| return cols.remove(p, req, c.serial, c.file), }; if (t.file != .dir) return Reply.fail(req.tag, E.PERM); @@ -967,6 +1027,9 @@ fn releaseHandle(p: *Pardes, req: Req) void { if (t == .col and t.col.file == .tag) cols.released(p, t.col.serial); if (t == .top and t.top == .tag) cols.released(p, null); const o = openOf(p, req) orelse return; + // A message short of its data is dropped with its open, as plumber(4) + // drops a fid's writebuf; rule text left goes in at the editor's step. + if (o.what == .plumb and req.node == @backingInt(TopFile.send)) o.pending.clearRetainingCapacity(); // A /pager open's text, not read for, goes in at the editor's next // step (ctl.fillClosedPagers): this close need not wait for quiet. if (o.what == .pager and o.pending.items.len > 0) { @@ -999,7 +1062,7 @@ fn releaseHandle(p: *Pardes, req: Req) void { .ctl => if (pn.fs.lock == req.handle) { pn.fs.lock = null; }, - .snapshot, .log, .lines, .writes, .frozen, .pager => {}, + .snapshot, .log, .lines, .writes, .frozen, .pager, .plumb, .port => {}, }; o.deinit(p.gpa); } @@ -1017,7 +1080,8 @@ fn setattr(p: *Pardes, req: Req, target: Target) Reply { if (pane.truncate(p, p.panes[id].?, t.file) != .ok) return Reply.fail(req.tag, E.NOMEM); }, .col => |c| if (c.file == .tag and cols.truncate(p, c.serial) != .ok) return Reply.fail(req.tag, E.NOENT), - .top => |f| if (f == .tag and cols.truncate(p, null) != .ok) return Reply.fail(req.tag, E.NOMEM), + .top => |f| if (f == .tag and cols.truncate(p, null) != .ok) return Reply.fail(req.tag, E.NOMEM) else if (f == .rules) Plumb.clear(p), + .port => return Reply.fail(req.tag, E.PERM), }; return .{ .tag = req.tag, .attr = attrOf(p, target) orelse return Reply.fail(req.tag, E.NOENT) }; } @@ -1028,6 +1092,8 @@ fn read(p: *Pardes, req: Req, target: Target) Reply { if (open_record) |o| if (o.what == .pager) ctl.fillPager(p, o.what.pager, &o.pending) catch return Reply.fail(req.tag, E.NOMEM); // A listing reads what it was at the open. if (open_record) |o| if (o.what == .frozen) return window(p, req, o.what.frozen); + // A port: a message a read, held until one is sent. + if (open_record) |o| if (o.what == .port) return events.readQueue(p, req, &o.what.port.queue); const stream = if (open_record) |o| switch (o.what) { .log => o, .event => |reader| if (reader) o else null, @@ -1055,8 +1121,9 @@ fn read(p: *Pardes, req: Req, target: Target) Reply { fn readFile(p: *Pardes, req: Req, target: Target) Reply { switch (target) { .top => |f| return switch (f) { - .kbdin, .mousein => Reply.fail(req.tag, E.PERM), + .kbdin, .mousein, .send => Reply.fail(req.tag, E.PERM), .README => window(p, req, fs.help), + .rules => window(p, req, Plumb.inForce(p)), .index => index: { const out = p.fs.stage(p.gpa); var last: u32 = 0; @@ -1128,7 +1195,7 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { break :serial Reply.fail(req.tag, E.NOMEM); break :serial stagedReply(p, req); }, - .root, .pane, .col => Reply.fail(req.tag, E.PERM), + .root, .pane, .col, .plumb => Reply.fail(req.tag, E.PERM), }, .pane => |t| { // A run's answer outlives the pane it ran in. @@ -1153,6 +1220,8 @@ fn readFile(p: *Pardes, req: Req, target: Target) Reply { .exec => ctl.readResults(p, req), else => Reply.fail(req.tag, E.PERM), }, + // Read through its open (read), never without one. + .port => return Reply.fail(req.tag, E.PERM), } } @@ -1163,7 +1232,8 @@ fn linesFile(target: Target) bool { .col => |c| c.file == .ctl or c.file == .exec, // `name` too: one name, however its writes cut it, applied once // its newline comes, or with its write when that is whole. - .pane => |t| t.file == .look or t.file == .exec or t.file == .ctl or t.file == .tagexec or t.file == .name, + .pane => |t| t.file == .look or t.file == .exec or t.file == .ctl or t.file == .tagexec or t.file == .name or t.file == .rows, + .port => false, }; } @@ -1173,6 +1243,7 @@ fn resultsFile(target: Target) bool { .top => |f| f == .look or f == .exec or f == .tagexec or f == .pager, .col => |c| c.file == .exec, .pane => |t| t.file == .look or t.file == .exec or t.file == .tagexec, + .port => false, }; } @@ -1219,6 +1290,7 @@ fn ctlFile(target: Target) bool { .top => |f| f == .ctl, .col => |c| c.file == .ctl, .pane => |t| t.file == .ctl, + .port => false, }; } @@ -1326,6 +1398,9 @@ fn writeLines(p: *Pardes, req: Req, target: Target) Reply { o.pending.shrinkRetainingCapacity(rest); var w = req; w.data = whole; + // At the offset its first byte was written at, an earlier write's + // held line included (a rows write at 0 starts the rows over). + w.off = (req.off + (req.data.len - data.len)) -| (end + rest - data.len); // The command pane this open was answered holds no lease against its // own next command (exec.leased): that one may run there again. if (resultsFile(target)) o.results.len = 0; @@ -1350,6 +1425,8 @@ fn writeNow(p: *Pardes, req: Req, target: Target) Reply { .pager => ctl.writePager(p, req), .tag => cols.write(p, req, null), .tagexec => cols.writeExec(p, req, null), + .rules => writeRules(p, req), + .send => writeSend(p, req), else => Reply.fail(req.tag, E.PERM), }, .pane => |t| { @@ -1364,6 +1441,64 @@ fn writeNow(p: *Pardes, req: Req, target: Target) Reply { .exec => cols.writeExec(p, req, c.serial), .dir => Reply.fail(req.tag, E.PERM), }, + .port => return Reply.fail(req.tag, E.PERM), + } +} + +/// plumb/rules: rule text added to the rules in force a rule set at a time, +/// as each is whole (a blank line after it, rules.c's morerules), the rest +/// at the open's close; a refusal is the write's, in plumb(6)'s words, the +/// rules as they were and the text it held dropped. +fn writeRules(p: *Pardes, req: Req) Reply { + const done: Reply = .{ .tag = req.tag, .written = @intCast(req.data.len) }; + // A close's rest (runClosedLines), or a write with no open: whole. + const o = openOf(p, req) orelse return if (Plumb.apply(p, true, "plumb/rules", req.data)) |why| failText(req.tag, E.INVAL, why) else done; + if (o.pending.items.len + req.data.len > Plumb.max_text) { + o.pending.clearRetainingCapacity(); + return failText(req.tag, E.INVAL, std.fmt.comptimePrint("rules too long; max {d} KiB", .{Plumb.max_text / 1024})); + } + o.pending.appendSlice(p.gpa, req.data) catch return Reply.fail(req.tag, E.NOMEM); + const end = Plumb.wholeSets(o.pending.items); + if (end == 0) return done; + const why = Plumb.apply(p, true, "plumb/rules", o.pending.items[0..end]); + if (why != null) o.pending.clearRetainingCapacity() else { + const rest = o.pending.items.len - end; + std.mem.copyForwards(u8, o.pending.items[0..rest], o.pending.items[end..]); + o.pending.shrinkRetainingCapacity(rest); + } + return if (why) |w| failText(req.tag, E.INVAL, w) else done; +} + +/// plumb/send: a message, its writes put together until its data is all +/// there (plumber(4)), then matched and sent: the write is answered when it +/// has gone where the rules say, or with why not, in Plan 9's words. +fn writeSend(p: *Pardes, req: Req) Reply { + const o = openOf(p, req); + const held = if (o) |op| op.pending.items.len > 0 else false; + if (held) o.?.pending.appendSlice(p.gpa, req.data) catch return Reply.fail(req.tag, E.NOMEM); + defer if (o) |op| if (op.pending.items.len > pending_cap) op.pending.clearRetainingCapacity(); + switch (Plumb.unpack(if (held) o.?.pending.items else req.data)) { + .bad => { + if (o) |op| op.pending.clearRetainingCapacity(); + return failText(req.tag, E.INVAL, Plumb.e_bad_msg); + }, + .more => |n| { + const op = o orelse return failText(req.tag, E.INVAL, Plumb.e_bad_msg); + if (op.pending.items.len + n > pending_cap) { + op.pending.clearRetainingCapacity(); + return failText(req.tag, E.INVAL, Plumb.e_bad_msg ++ ": over 1 MiB"); + } + if (!held) op.pending.appendSlice(p.gpa, req.data) catch return Reply.fail(req.tag, E.NOMEM); + return .{ .tag = req.tag, .written = @intCast(req.data.len) }; + }, + .msg => |m| { + defer if (o) |op| op.pending.clearRetainingCapacity(); + switch (Plumb.send(p, null, m, null)) { + .refused => |why| return failText(req.tag, E.IO, why), + .done, .look => {}, + } + return .{ .tag = req.tag, .written = @intCast(req.data.len) }; + }, } } @@ -1566,13 +1701,23 @@ test "readdir lists the root and a pane directory without creating anything" { @memcpy(top_bytes[0..top_reply.bytes.len], top_reply.bytes); const top = th.dirents(top_bytes[0..top_reply.bytes.len], &buf); try testing.expect(top.len >= 10); - for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "addons", "look", "exec", "pager", "log", "screen", "listeners", "sessions", "layout", "tag", "tagexec", "kbdin", "mousein", "pane", "col", "os" }, 0..) |name, i| { + for ([_][]const u8{ "README", "index", "status", "focus", "ctl", "commands", "recent", "dumps", "addons", "look", "exec", "pager", "log", "screen", "listeners", "sessions", "layout", "tag", "tagexec", "kbdin", "mousein", "plumb", "pane", "col", "os" }, 0..) |name, i| { try testing.expectEqualStrings(name, top[i].name); try testing.expectEqual(i >= 21, top[i].dir); } - try testing.expectEqual(@backingInt(TopFile.pane), top[21].node); - try testing.expectEqual(@backingInt(TopFile.col), top[22].node); - try testing.expectEqual(fs.os_root, top[23].node); + try testing.expectEqual(@backingInt(TopFile.plumb), top[21].node); + try testing.expectEqual(@backingInt(TopFile.pane), top[22].node); + try testing.expectEqual(@backingInt(TopFile.col), top[23].node); + try testing.expectEqual(fs.os_root, top[24].node); + // The plumber's directory: its rules, then send. + const plumb_reply = rdir(p, @backingInt(TopFile.plumb), 0); + var plumb_bytes: [256]u8 = undefined; + @memcpy(plumb_bytes[0..plumb_reply.bytes.len], plumb_reply.bytes); + var plumb_buf: [4]th.Dirent = undefined; + const plumb = th.dirents(plumb_bytes[0..plumb_reply.bytes.len], &plumb_buf); + // Then the ports the default rules name, in their order. + try testing.expectEqual(@as(usize, 4), plumb.len); + for ([_][]const u8{ "rules", "send", "web", "edit" }, plumb) |want, got| try testing.expectEqualStrings(want, got.name); var idbuf: [16]u8 = undefined; try testing.expect(th.nameAt(top, try std.fmt.bufPrint(&idbuf, "{d}", .{serial})) == null); try testing.expect(th.nameAt(top, "self") == null); @@ -1611,10 +1756,10 @@ test "readdir lists the root and a pane directory without creating anything" { const dir = rdir(p, Node.of(serial, .dir), 0); const files = th.dirents(dir.bytes, &buf); - try testing.expectEqual(@as(usize, 18), files.len); + try testing.expectEqual(@as(usize, 19), files.len); for ([_][]const u8{ - "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata", - "sel", "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec", + "name", "body", "tag", "ctl", "addr", "dot", "limit", "data", "xdata", "sel", + "dirty", "mark", "scroll", "errors", "event", "look", "exec", "tagexec", "rows", }, 0..) |name, i| try testing.expectEqualStrings(name, files[i].name); try testing.expect(th.nameAt(files, ".") == null); @@ -2001,6 +2146,7 @@ test "a write with no newline waits for its newline or the close, whatever its s } test "look and exec read back what their own open's write touched; a fresh open reads the session's last" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell, by Term const p = try th.withFile(testing.allocator, "x\n"); defer p.deinit(); const exec = @backingInt(TopFile.exec); |
