summaryrefslogtreecommitdiff
path: root/test/behaviour/plumber.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 02:40:21 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit757cdaa826131dc5ff2d3ff0b270b8abe041c81a (patch)
tree96de2e4537bc009d502bdf74b453e6964a12dff0 /test/behaviour/plumber.zig
parent83b9d45b8665a80bdb70934aa23bbde5cc03d202 (diff)
downloadpardes-757cdaa826131dc5ff2d3ff0b270b8abe041c81a.tar.gz
pardes-757cdaa826131dc5ff2d3ff0b270b8abe041c81a.zip
plumber: external ports (docs/next-plumber.md, phase 3): every port a rule names has a file, plumb/<port> (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
Diffstat (limited to 'test/behaviour/plumber.zig')
-rw-r--r--test/behaviour/plumber.zig41
1 files changed, 41 insertions, 0 deletions
diff --git a/test/behaviour/plumber.zig b/test/behaviour/plumber.zig
index 28451222..4144901b 100644
--- a/test/behaviour/plumber.zig
+++ b/test/behaviour/plumber.zig
@@ -63,3 +63,44 @@ test "plumber: plumb/send takes a message in its six lines and data, written in
try s.write("/plumb/send", s.at("test\n\n{s}\ntext\n\n{d}\nplumbed.txt:2", .{ dir, "plumbed.txt:2".len }));
try std.testing.expect(has(try s.read("/index"), "/plumbed.txt"));
}
+
+test "plumber: a port's file is read by programs: each open made before a send gets its own copy, one made after none, and a client rule's message waits for the port's first reader" {
+ var s = try Session.initFile(std.testing.allocator, "x\n");
+ defer s.deinit();
+ var tmp = std.testing.tmpDir(.{});
+ defer tmp.cleanup();
+ try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "seen.txt", .data = "one\ntwo\n" });
+ var buf: [4096]u8 = undefined;
+ const dir = buf[0..try tmp.dir.realPath(std.testing.io, &buf)];
+ // A file for each port the rules name, read-only, as plumber(4)'s.
+ try std.testing.expectEqual(@as(u16, 0o444), (try s.stat("/plumb/web")).mode & 0o777);
+ try std.testing.expectEqual(@as(u16, 0o444), (try s.stat("/plumb/edit")).mode & 0o777);
+ // Two readers of edit, then a look: each reads the look's message,
+ // and the editor opens the file all the same.
+ const a = try s.hold("/plumb/edit", 0);
+ const b = try s.hold("/plumb/edit", 0);
+ try s.write("/look", s.at("{s}/seen.txt\n", .{dir}));
+ const want = s.at("pardes\nedit\n{s}\ntext\n\n{d}\n{s}/seen.txt", .{ "/", dir.len + "/seen.txt".len, dir });
+ try std.testing.expectEqualStrings(want, try s.readFid(a));
+ try std.testing.expectEqualStrings(want, try s.readFid(b));
+ try std.testing.expect(has(try s.read("/index"), "/seen.txt"));
+ // An open made after the send has nothing: its read waits.
+ const late = try s.hold("/plumb/edit", 0);
+ try std.testing.expectError(error.Refused, s.readFid(late));
+ s.clunk(late);
+ s.clunk(a);
+ s.clunk(b);
+ // A port only a program reads, its rule a client: the message waits
+ // for the port's first reader, the program started read nothing.
+ try s.write("/plumb/rules", "type is text\ndata matches 'letter-[0-9]+'\nplumb to seemail\nplumb client true\n\n");
+ try s.write("/plumb/send", "test\n\n/\ntext\n\n9\nletter-42");
+ const first = try s.hold("/plumb/seemail", 0);
+ try std.testing.expectEqualStrings("test\nseemail\n/\ntext\n\n9\nletter-42", try s.readFid(first));
+ try std.testing.expectError(error.Refused, s.readFid(first));
+ // Once read, a port's message goes to its readers, no program started.
+ try s.write("/plumb/send", "test\n\n/\ntext\n\n9\nletter-43");
+ try std.testing.expectEqualStrings("test\nseemail\n/\ntext\n\n9\nletter-43", try s.readFid(first));
+ s.clunk(first);
+ // Not to be written.
+ try std.testing.expectError(error.Refused, s.hold("/plumb/seemail", 1));
+}