summaryrefslogtreecommitdiff
path: root/test/replicas.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 03:51:15 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit79a1e816ceb13ef81b712007716c8add2de75434 (patch)
tree1714b1bf19da3a58be2623ffe29e3f8be1b21fe3 /test/replicas.zig
parenta22b579ad2df8d1811f0e194fa1bbc06e2282cf8 (diff)
parentf1af015f01e4e8d42f6224c4d4063f3aea218f5a (diff)
downloadpardes-79a1e816ceb13ef81b712007716c8add2de75434.tar.gz
pardes-79a1e816ceb13ef81b712007716c8add2de75434.zip
integration: the terminal a module of its own, with the plumber whole and the walker's cheaper compile
A merge of term-phase1a and pardes-next, no conflicts. core-test (the core with no terminal) 411 passed, 535 skipped of 946; shell-test (the same tests, the terminal compiled in) 989/989, on tui. Co-Authored-By: Claude Fable 5.2 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/replicas.zig')
-rw-r--r--test/replicas.zig114
1 files changed, 114 insertions, 0 deletions
diff --git a/test/replicas.zig b/test/replicas.zig
index f6aa2af2..55efd124 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -554,6 +554,119 @@ 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;
+ }
+ };
+ // A rule to a port a program reads (plumb/seemail), of a URL, which a
+ // look reads no disk for: whether the port is read is the authority's
+ // 9P state, asked through the tape. A replica's own look waits for the
+ // first answer, then guesses the last; the second look speculates whole
+ // and is confirmed with no rollback.
+ {
+ // The rule from the session's plumbing file, read at boot.
+ var pbuf: [256]u8 = undefined;
+ try writeText(try std.fmt.bufPrintSentinel(&pbuf, "{s}/plumbing", .{dir}, 0), "type is text\ndata matches 'https://letters/.*'\nplumb to seemail\n\ninclude basic\n");
+ const a = try replica.Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty, .config_dir = dir }, 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();
+ if (pardes.Plumb.portIndex(rp.core(), "seemail") == null) {
+ std.debug.print("plumb: a look to a port: the plumbing file's port is not the replica's\n", .{});
+ ok = false;
+ }
+ for (0..2) |n| {
+ const before = rp.stats;
+ const msg = try gpa.dupe(u8, try rp.input(.{ .command = "Look https://letters/42" }));
+ defer gpa.free(msg);
+ if (n == 1 and (rp.stats.stopped != before.stopped or rp.stats.speculated == before.speculated)) {
+ std.debug.print("plumb: a look to a port: the replica's second look did not speculate whole ({d} stopped, {d} applied)\n", .{ rp.stats.stopped - before.stopped, rp.stats.speculated - before.speculated });
+ ok = false;
+ }
+ if (try a.pending()) |batch| rp.confirm(batch);
+ rp.confirm(try a.take(msg));
+ rp.settle();
+ }
+ if (rp.diverged) |why| {
+ std.debug.print("plumb: a look to a port: the replica diverged: {s}\n", .{why});
+ ok = false;
+ } else if (!rp.quiet() or rp.digest() != replica.digestOf(a)) {
+ std.debug.print("plumb: a look to a port: the replica's digest is not the authority's\n", .{});
+ ok = false;
+ }
+ if (rp.stats.mispredicted + rp.stats.foreign != 0) {
+ std.debug.print("plumb: a look to a port: {d} rollbacks\n", .{rp.stats.mispredicted + rp.stats.foreign});
+ ok = false;
+ }
+ }
+ std.debug.print("plumb: a URL, a commit hash and a look to a port read by programs, 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.*;
@@ -1522,6 +1635,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;