summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 02:07:32 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit83b9d45b8665a80bdb70934aa23bbde5cc03d202 (patch)
treec902b557ef624b07cd139659d0a891cd4809e03e /test
parentb3d32656413734952bc918c2d4cfd12fede6c214 (diff)
downloadpardes-83b9d45b8665a80bdb70934aa23bbde5cc03d202.tar.gz
pardes-83b9d45b8665a80bdb70934aa23bbde5cc03d202.zip
plumber: a look sends what it looks at (docs/next-plumber.md, phase 2): after the pane's own readings and once a name already open in a pane is focused (never sent), lookAt sends the trimmed name, type text, src pardes (term from a raw terminal, a kind's name from its pane), wdir the pane's directory, with what resolveLookTarget found of it (Plumb.Seen: isfile and isdir take it, so no second stat and Look's own readings of a URL or `//` stay no file); a message the rules give back to `edit` as sent is Look's own (Sent.look) and runs lookAt's switch on that target, one nothing takes or a started word declines is Look's own too, whose `.url` arm is now the word's search; the edit port's open of another message runs with look_text, which now means "unplumbed", so the edit port's lookAt never sends again (the recursion trap); the three diff hooks become the default rules of the record's §5.2 (a bare .diff/.patch to `Diff $file`, a commit hash in the editor to `Diff $0`, after the two edit sets), and `Diff` takes a file or a revision, a rule's Diff declining in silence (Pardes.plumb_declined) where it cannot (no hunk, not readable, no .git above): hunks.lookedAt and lookedAtCommit go, their bodies in hunks.word, the `needs` check of the bare form in the word, PaneKind.diff gone; the old one-line `Plumb` word, Core.plumb, look.Port, plumbRuleError, plumbTarget and resolve's rules block go: bare, `Plumb` opens <config>/plumbing as Config opens init (both through builtins.openConfigFile; `include basic` in a new one), an argument is refused in words, Save applies it (host_io.writeFile beside reapplyInitFile, Plumb.saved), and boot reads it (Plumb.boot in applyStartupConfig); a started program now runs detached as Plan 9's plumber's (the coordinator's decision for the user's question 4): Effect.start, every host's host_io.startDetached (double fork, setsid, /dev/null for 0-2, every other fd closed, argv exec'd in wdir with no shell, the child's errno back through a close-on-exec pipe, said as `plumb start: <prog>: <why>`), so exec_dir goes; resolveLookTarget's and Plumb.Send.search's directory walk is one look.Dirs; test: look.zig's Plumb test rewritten onto the rules (a rule's word, an open pane unsent, the hover's resolve, a URL with no web rule searched for) and a hash inside and outside a git work tree; addons.zig's Plumb test onto plumb/rules (a port no kind reads, its kind gone: Look's own); Plumb.zig: the word, the save and boot; replicas.zig gains a URL (speculated whole, confirmed, no rollback) and a hash, each the authority's and a replica's own; every look golden unchanged; the reference quotes src/plumbing whole and says the order, the changelog says so
Diffstat (limited to 'test')
-rw-r--r--test/behaviour/addons.zig13
-rw-r--r--test/behaviour/plumber.zig2
-rw-r--r--test/replicas.zig69
3 files changed, 79 insertions, 5 deletions
diff --git a/test/behaviour/addons.zig b/test/behaviour/addons.zig
index 9b96a3d6..451cb1e3 100644
--- a/test/behaviour/addons.zig
+++ b/test/behaviour/addons.zig
@@ -185,7 +185,7 @@ test "addons: the image addon opens the pictures a Look names, fitted, with the
try std.testing.expect(has(try s.read("/screen"), "\"src\":[0,0,4,2]"));
}
-test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused naming one not loaded, and with its kind gone the look falls through to text" {
+test "addons: a plumbing rule to a loaded kind opens that kind's pane; to one not loaded, or with its kind gone, the look falls through to text" {
var s = try Session.initFile(std.testing.allocator, "x\n");
defer s.deinit();
try load(&s, Session.image_addon);
@@ -196,9 +196,14 @@ test "addons: a Plumb rule to a loaded kind opens that kind's pane, is refused n
// A PNG under a name no kind claims.
const png = "\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x01\x00\x00\x00\x01\x08\x02\x00\x00\x00\x90wS\xde\x00\x00\x00\x0cIDATx\x9cc\xf8\xcf\xc0\x00\x00\x03\x01\x01\x00\xc9\xfe\x92\xef\x00\x00\x00\x00IEND\xaeB`\x82";
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "red.pic", .data = png });
- try std.testing.expect(try s.refused("/ctl", "Plumb suffix .pic to nokind\n") != 0);
- try std.testing.expect(has(s.said, "Plumb: invalid port: url, dir, file or a loaded kind"));
- try s.write("/ctl", "Plumb suffix .pic to image\n");
+ // A port no kind reads is no refusal (plumber(4) never refuses one):
+ // nothing reads it, the rule set starts nothing, and Look looks itself.
+ const rule = "type is text\ndata matches '.*\\.pic'\narg isfile $data\nplumb to {s}\n\ninclude basic\n";
+ try s.replace("/plumb/rules", s.at(rule, .{"nokind"}));
+ try s.write("/look", s.at("{s}/red.pic\n", .{dir}));
+ try std.testing.expect(has(try s.read(s.at("/pane/{d}/tag", .{try s.focused()})), "red.pic"));
+ try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n");
+ try s.replace("/plumb/rules", s.at(rule, .{"image"}));
try s.write("/look", s.at("{s}/red.pic\n", .{dir}));
try std.testing.expectEqual(try paneOf(&s, "image"), try s.focused());
try s.write(s.at("/pane/{d}/ctl", .{try s.focused()}), "Del\n");
diff --git a/test/behaviour/plumber.zig b/test/behaviour/plumber.zig
index f87c0449..28451222 100644
--- a/test/behaviour/plumber.zig
+++ b/test/behaviour/plumber.zig
@@ -14,7 +14,7 @@ test "plumber: plumb/rules reads the rules in force, a write adds rule sets, > r
try std.testing.expect(has(try s.read("/plumb/rules"), "type\tis\ttext\ndata\tmatches\t'https?://.*'\nplumb\tto\tweb\n\n"));
// Added, the last rule set at the close.
try s.write("/plumb/rules", "type is text\ndata matches 'gopher://.*'\nplumb to web\n");
- try std.testing.expect(std.mem.endsWith(u8, try s.read("/plumb/rules"), "plumb\tto\tedit\n\ntype\tis\ttext\ndata\tmatches\t'gopher://.*'\nplumb\tto\tweb\n\n"));
+ try std.testing.expect(std.mem.endsWith(u8, try s.read("/plumb/rules"), "plumb\tstart\tDiff $0\n\ntype\tis\ttext\ndata\tmatches\t'gopher://.*'\nplumb\tto\tweb\n\n"));
// A rule set refused at the write it is whole in, said with its line;
// the rules stay as they were.
const before = try s.read("/plumb/rules");
diff --git a/test/replicas.zig b/test/replicas.zig
index 038d747a..0f23d5a8 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -544,6 +544,74 @@ fn diffCase(dir: []const u8) !bool {
return ok;
}
+/// Looks the plumber takes (src/plumbing), each as the authority's input
+/// and as a replica's own: a URL (its web port: no disk asked, so a
+/// replica's own look speculates whole and is confirmed with no rollback),
+/// and a commit hash in a git work tree (Diff's `git show`, its `.git`
+/// asked at a read the unit carries). The replica's digest is the
+/// authority's either way.
+fn plumbCase(dir: []const u8) !bool {
+ var host: Host = .{};
+ defer {
+ for (host.echo.items) |e| gpa.free(e.bytes);
+ host.echo.deinit(gpa);
+ }
+ var gbuf: [256]u8 = undefined;
+ try std.Io.Dir.createDirAbsolute(std.Io.Threaded.global_single_threaded.io(), try std.fmt.bufPrint(&gbuf, "{s}/.git", .{dir}), .default_dir);
+ var nbuf: [256]u8 = undefined;
+ const notes = try std.fmt.bufPrintSentinel(&nbuf, "{s}/notes.txt", .{dir}, 0);
+ try writeText(notes, "fixed in 3f2a9c1, see https://ziglang.org\n");
+ var obuf: [300]u8 = undefined;
+ const open = try std.fmt.bufPrint(&obuf, "Look {s}", .{notes});
+ var ok = true;
+ for ([_][]const u8{ "Look https://ziglang.org", "Look 3f2a9c1" }) |look| for ([_]bool{ false, true }) |own| {
+ const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, host.host(), true);
+ defer a.deinit();
+ const first = try gpa.dupe(u8, try a.unit(0, 0));
+ defer gpa.free(first);
+ const rp = try replica.Replica.init(gpa, 1, first, true);
+ defer rp.deinit();
+ rp.confirm(try a.local(.{ .command = open }));
+ rp.settle();
+ const before = rp.stats;
+ const url = std.mem.indexOf(u8, look, "://") != null;
+ if (own) {
+ const msg = try gpa.dupe(u8, try rp.input(.{ .command = look }));
+ defer gpa.free(msg);
+ if (url and (rp.stats.stopped != before.stopped or rp.stats.speculated == before.speculated)) {
+ std.debug.print("plumb: {s}: the replica's own look did not speculate whole ({d} stopped, {d} applied)\n", .{ look, rp.stats.stopped, rp.stats.speculated });
+ ok = false;
+ }
+ if (try a.pending()) |batch| rp.confirm(batch);
+ rp.confirm(try a.take(msg));
+ } else rp.confirm(try a.local(.{ .command = look }));
+ rp.settle();
+ const who = if (own) "its own look" else "the authority's look";
+ if (!url) {
+ const paged = for (a.core.panes) |slot| {
+ if ((slot orelse continue).command_pages) break true;
+ } else false;
+ if (!paged) {
+ std.debug.print("plumb: {s}: {s}: no git show paged\n", .{ look, who });
+ ok = false;
+ }
+ }
+ if (rp.diverged) |why| {
+ std.debug.print("plumb: {s}: {s}: the replica diverged: {s}\n", .{ look, who, why });
+ ok = false;
+ } else if (!rp.quiet() or rp.digest() != replica.digestOf(a)) {
+ std.debug.print("plumb: {s}: {s}: the replica's digest is not the authority's\n", .{ look, who });
+ ok = false;
+ }
+ if (rp.stats.mispredicted + rp.stats.foreign != 0) {
+ std.debug.print("plumb: {s}: {s}: {d} rollbacks\n", .{ look, who, rp.stats.mispredicted + rp.stats.foreign });
+ ok = false;
+ }
+ };
+ std.debug.print("plumb: a URL and a commit hash looked at by the authority and as a replica's own input: {s}\n", .{if (ok) "the same session" else "FAILED"});
+ return ok;
+}
+
fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void {
var mm = m;
mm.n = nn.*;
@@ -1512,6 +1580,7 @@ pub fn main(init: std.process.Init) !void {
return;
}
var failed = !try diffCase(dir);
+ if (!try plumbCase(dir)) failed = true;
std.debug.print("{d} seeds x {d} inputs from each of {d} clients, {s}, a TUI then {d} MB of yes in the shell; costs in us (frame {d})\n", .{ seeds, steps, clients, if (shared) "sharing one view" else "a view each", flood_mb, frame_us });
std.debug.print(" rtt inputs at-once stopped view units fast rollback(mis+foreign) rate rebase spec p50/p99 copy p50/p99 (KB) rollback p50/p99 diverged unequal\n", .{});
var term_lines: std.ArrayList(u8) = .empty;