summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-16 23:58:16 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitfa504c392b5f3c04a7cfce74566e23cb94ddd6cf (patch)
tree71dbd6320f6238c07deb23e5727b4c5afd96a61f /test
parent162d7ec610b770c27b9a7c481f66c6f2e4898bd5 (diff)
downloadpardes-fa504c392b5f3c04a7cfce74566e23cb94ddd6cf.tar.gz
pardes-fa504c392b5f3c04a7cfce74566e23cb94ddd6cf.zip
test: a +Diff pinned before it moves: process-test's `diffstack` pages a patch into `pardes -` and snaps the +Diff it is restacked into (its hunk found two lines down where the file moved it, under the declaration it stands in, `a.zig:3` and `const S = struct {`, its label one level deep, `a.zig:5 *`; the changed word on a stronger ground in both lines, a line added whole on a faint one, the markers in their tints' hue), as text and as styles; replicas opens with a .patch looked at by the authority and as the replica's own input, the first stopped at its first read and confirmed with no rollback, the replica's digest and +Diff the authority's either way; the soak's fixture is a repository whose last commit changes code.zig, and `gitshow` pages `git show HEAD` into `pardes -` from a shell
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
-rw-r--r--test/process/tty_editing.zig24
-rw-r--r--test/replicas.zig76
-rw-r--r--test/snapshots/diffstack.golden61
-rw-r--r--test/soak.py21
4 files changed, 180 insertions, 2 deletions
diff --git a/test/process/tty_editing.zig b/test/process/tty_editing.zig
index 72cbb573..b5f0495c 100644
--- a/test/process/tty_editing.zig
+++ b/test/process/tty_editing.zig
@@ -35,6 +35,7 @@ pub const cases = .{
.{ "tty editing: lsp-rename-files", lsp_rename_files },
.{ "tty editing: callstack", callstack },
.{ "tty editing: diffview", diffview },
+ .{ "tty editing: diffstack", diffstack },
.{ "tty editing: dirpane", dirpane },
.{ "tty editing: scrolloff", scrolloff },
.{ "tty editing: wrap", wrap },
@@ -2018,6 +2019,29 @@ fn diffview(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
try t.done();
}
+// A diff paged (`pardes -`) is stacked in a +Diff: its hunk found where the
+// file has moved it since (two lines further down), under the declaration it
+// stands in (`a.zig:3`, `const S = struct {`) and its label one level deep
+// (`a.zig:5 *`); a changed line's changed word on a stronger ground in both
+// lines (`c` and `a`), and a line added whole (`log();`) on a faint one, each
+// marker in its tint's hue.
+fn diffstack(gpa: std.mem.Allocator, exe: [:0]const u8) !void {
+ var t = try Tty.init(gpa, exe, "diffstack");
+ defer t.deinit();
+ try t.file("a.zig", "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n log();\n }\n};\n");
+ try t.file("change.patch", "--- a.zig\n+++ a.zig\n@@ -3,4 +3,5 @@ git's guess\n fn f() void {\n- c();\n+ a();\n b();\n+ log();\n }\n");
+ try t.start(31, 100, &.{});
+ try t.wait(8000, "$");
+ try t.stable(700, 20000);
+ try t.send("cat change.patch | $(readlink /proc/$PPID/exe) -");
+ try t.key("enter");
+ try t.wait(20000, "a.zig:5 *");
+ try t.stable(700, 20000);
+ try t.snap("diff-stack");
+ try t.style("diff-stack-colours");
+ try t.done();
+}
+
// a look at a directory opens a pane named for it with a trailing /, its
// entries in columns as acme's directory window lays them out: down each
// column first, a directory's marked /, dotfiles shown. A look at an entry
diff --git a/test/replicas.zig b/test/replicas.zig
index f50fb04f..038d747a 100644
--- a/test/replicas.zig
+++ b/test/replicas.zig
@@ -213,6 +213,13 @@ fn writeFile(path: [:0]const u8, lines: usize) !void {
}
}
+fn writeText(path: [:0]const u8, text: []const u8) !void {
+ const fd = libc.open(path, .{ .ACCMODE = .WRONLY, .CREAT = true, .TRUNC = true }, @as(libc.mode_t, 0o644));
+ if (fd < 0) return error.OpenFailed;
+ defer _ = libc.close(fd);
+ if (libc.write(fd, text.ptr, text.len) != @as(isize, @intCast(text.len))) return error.WriteFailed;
+}
+
const Run = struct { seed: u64, rtt_ms: u64, steps: usize, clients: u16, shared: bool, flood_mb: u64 };
/// The terminal pane's screen as a hash of screen_state's dump of it.
@@ -470,6 +477,73 @@ fn run(r: Run, dir: []const u8, totals: *Totals) !void {
}
}
+/// A .patch looked at opens a +Diff, whose rows are made from files read
+/// in the step (hunks.zig: the patch, the file each section names, its
+/// declarations). Looked at by the authority, a replica replays the reads
+/// the unit carries and makes the same +Diff; looked at as the replica's own
+/// input, the first read poisons the speculation, which shows nothing and
+/// waits for the authority's unit (no rollback of what it showed). Either
+/// way the replica's digest and the +Diff's text are the authority's.
+fn diffCase(dir: []const u8) !bool {
+ var host: Host = .{};
+ defer {
+ for (host.echo.items) |e| gpa.free(e.bytes);
+ host.echo.deinit(gpa);
+ }
+ var buf: [256]u8 = undefined;
+ const source = try std.fmt.bufPrintSentinel(&buf, "{s}/a.zig", .{dir}, 0);
+ try writeText(source, "// one\n// two\nconst S = struct {\n fn f() void {\n a();\n b();\n log();\n }\n};\n");
+ var pbuf: [256]u8 = undefined;
+ const patch = try std.fmt.bufPrintSentinel(&pbuf, "{s}/change.patch", .{dir}, 0);
+ try writeText(patch, "--- a.zig\n+++ a.zig\n@@ -3,4 +3,5 @@\n fn f() void {\n- c();\n+ a();\n b();\n+ log();\n }\n");
+ var lbuf: [300]u8 = undefined;
+ const look = try std.fmt.bufPrint(&lbuf, "Look {s}", .{patch});
+ var ok = true;
+ 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();
+ if (own) {
+ const msg = try gpa.dupe(u8, try rp.input(.{ .command = look }));
+ defer gpa.free(msg);
+ if (rp.stats.stopped != 1) {
+ std.debug.print("diff: the replica's own look at a .patch was not stopped at its first read ({d} stopped, {d} applied)\n", .{ 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 named = for (a.core.panes, 0..) |slot, pid| {
+ const f = (slot orelse continue).file orelse continue;
+ if (std.mem.endsWith(u8, f.path, "/+Diff")) break pid;
+ } else null;
+ const mine = if (named) |pid| if (rp.core().panes[pid]) |pane| pane.file else null else null;
+ if (named == null or mine == null or !std.mem.eql(u8, a.core.panes[named.?].?.file.?.content, mine.?.content) or
+ std.mem.indexOf(u8, mine.?.content, "a.zig:5 *") == null)
+ {
+ std.debug.print("diff: {s}: the replica holds no +Diff of the authority's\n", .{if (own) "its own look" else "the authority's look"});
+ ok = false;
+ }
+ if (rp.diverged) |why| {
+ std.debug.print("diff: {s}: the replica diverged: {s}\n", .{ if (own) "its own look" else "the authority's look", why });
+ ok = false;
+ } else if (!rp.quiet() or rp.digest() != replica.digestOf(a)) {
+ std.debug.print("diff: {s}: the replica's digest is not the authority's\n", .{if (own) "its own look" else "the authority's look"});
+ ok = false;
+ }
+ if (rp.stats.mispredicted + rp.stats.foreign != 0) {
+ std.debug.print("diff: {s}: {d} rollbacks\n", .{ if (own) "its own look" else "the authority's look", rp.stats.mispredicted + rp.stats.foreign });
+ ok = false;
+ }
+ }
+ std.debug.print("diff: a .patch looked at by the authority and as a replica's own input: {s}\n", .{if (ok) "the same +Diff" else "FAILED"});
+ return ok;
+}
+
fn push(q: *std.PriorityQueue(Msg, void, Msg.order), nn: *u64, m: Msg) !void {
var mm = m;
mm.n = nn.*;
@@ -1437,7 +1511,7 @@ pub fn main(init: std.process.Init) !void {
if (!try echoMain(seeds, first, rtts)) std.process.exit(1);
return;
}
- var failed = false;
+ var failed = !try diffCase(dir);
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;
diff --git a/test/snapshots/diffstack.golden b/test/snapshots/diffstack.golden
new file mode 100644
index 00000000..51251c4c
--- /dev/null
+++ b/test/snapshots/diffstack.golden
@@ -0,0 +1,61 @@
+== snap diff-stack grid=100x31 cursor=4,4
+| Newcol Joincol Find Grep Help Changelog Tutor Dump Themes Config History Debug Exit
+| New Term Find Grep Joincol Delcol
+|$ /tmp/pardes-snap/diffstack/cwd Term+bash Save Mode Filter Collapse Del
+| $ cat change.patch | $(readlink /proc/$PPID/exe) -
+| $
+| /tmp/pardes-snap/diffstack/cwd/+Diff Save Term Diff Collapse LocationsConfig Del
+| a.zig:3
+| const S = struct {
+| a.zig:5 *
+| fn f() void {
+| - c();
+| + a();
+| b();
+| + log();
+| }
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+|
+| /tmp/pardes-snap/diffstack/cwd/+New Save Term Collapse Follow Del
+| 1
+== style diff-stack-colours grid=100x31
+|0: 0-1 d,#1d2824, 2-99 #b2c3b8,#1d2824,
+|1: 0-1 d,#887455, 2-99 #becfc4,#314738,
+|2: 0-1 #000000,#add38a, 2-32 #becfc4,#314738, 33-42 #dfbce5,#314738, 43-99 #becfc4,#314738,
+|3: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410,
+|4: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #e5eee5,#0d1410,
+|5: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-38 #d3b0d9,#1d2824, 39-99 #b2c3b8,#1d2824,
+|6: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410,
+|7: 0-0 d,#608269, 1-2 d,#0d1410, 3-99 #59675c,#0d1410,
+|8: 0-0 d,#608269, 1-1 d,#0d1410, 2-99 #59675c,#0d1410,
+|9: 0-0 d,#608269, 1-6 d,#0d1410, 7-9 #c9a7ed,#0d1410, 10-99 #e5eee5,#0d1410,
+|10: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #f1a39b,#0d1410,b 3-10 #f1a39b,#0d1410, 11-11 #e5eee5,#453832, 12-99 #e5eee5,#0d1410,
+|11: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#0d1410,b 3-10 #b6ce94,#0d1410, 11-11 #e5eee5,#364131, 12-99 #e5eee5,#0d1410,
+|12: 0-0 d,#608269, 1-10 d,#0d1410, 11-99 #e5eee5,#0d1410,
+|13: 0-0 d,#608269, 1-1 d,#0d1410, 2-2 #b6ce94,#171f18,b 3-10 #b6ce94,#171f18, 11-99 #e5eee5,#171f18,
+|14: 0-0 d,#608269, 1-6 d,#0d1410, 7-99 #e5eee5,#0d1410,
+|15: 0-0 d,#608269, 1-99 d,#0d1410,
+|16: 0-0 d,#608269, 1-99 d,#0d1410,
+|17: 0-0 d,#608269, 1-99 d,#0d1410,
+|18: 0-0 d,#608269, 1-99 d,#0d1410,
+|19: 0-0 d,#608269, 1-99 d,#0d1410,
+|20: 0-0 d,#608269, 1-99 d,#0d1410,
+|21: 0-0 d,#608269, 1-99 d,#0d1410,
+|22: 0-0 d,#608269, 1-99 d,#0d1410,
+|23: 0-0 d,#608269, 1-99 d,#0d1410,
+|24: 0-0 d,#608269, 1-99 d,#0d1410,
+|25: 0-0 d,#608269, 1-99 d,#0d1410,
+|26: 0-1 d,#496656, 2-32 #b2c3b8,#1d2824, 33-37 #d3b0d9,#1d2824, 38-99 #b2c3b8,#1d2824,
+|27: 0-0 d,#608269, 1-4 d,#0d1410, 5-99 #59675c,#0d1410,
+|28: 0-0 d,#608269, 1-99 d,#0d1410,
+|29: 0-0 d,#608269, 1-99 d,#0d1410,
+|30: 0-0 d,#608269, 1-99 d,#0d1410,
diff --git a/test/soak.py b/test/soak.py
index 401cb84e..faf447ab 100644
--- a/test/soak.py
+++ b/test/soak.py
@@ -148,6 +148,15 @@ def fixture(at, rng):
sub.mkdir(exist_ok=True)
(sub / 'inner.txt').write_text(''.join(f'inner {i} {rng.choice(WORDS)}\n' for i in range(60)))
(sub / 'more.md').write_text('# More\n\n' + ''.join(f'- item {i} {rng.choice(WORDS)}\n' for i in range(40)))
+ # A repository whose last commit changes code.zig, for act_gitshow.
+ if shutil.which('git'):
+ git = ['git', '-c', 'user.name=soak', '-c', 'user.email=soak@invalid', '-c', 'init.defaultBranch=main']
+ subprocess.run(git + ['init', '-q'], cwd=at, check=True)
+ subprocess.run(git + ['add', 'code.zig'], cwd=at, check=True)
+ subprocess.run(git + ['commit', '-qm', 'code'], cwd=at, check=True)
+ code = (at / 'code.zig').read_text().replace('return x * 7 +', 'return x * 8 +').replace('pub fn f9(', 'pub fn nine(')
+ (at / 'code.zig').write_text(code)
+ subprocess.run(git + ['commit', '-qam', 'change'], cwd=at, check=True)
# ---- terminals ----
@@ -681,6 +690,16 @@ def act_shell(c, rng, k):
k(rng.choice([b'k', b'j', b'']))
+def act_gitshow(c, rng, k):
+ # A commit paged into `pardes -` (git's pager): the +Pager restacked into
+ # a +Diff, whose rows come from the files the step reads (hunks.zig).
+ k(b' nt')
+ time.sleep(rng.uniform(0.8, 1.5))
+ k(b'git show HEAD | "$(readlink /proc/$PPID/exe)" -\r')
+ time.sleep(rng.uniform(1.0, 2.0))
+ k(b'\x02')
+
+
def act_window(c, rng, k):
# Enter ends window mode, as a person would: left open, it took the next
# action's keys, and a `k` at a column's top went to its tag, where `SPC q` ran Exit
@@ -762,7 +781,7 @@ ACTIONS = [
('panes', 3, act_panes), ('find', 3, act_find), ('shell', 3, act_shell), ('window', 4, act_window),
('column', 1, act_column), ('del', 2, act_del), ('new', 2, act_new), ('esc', 4, act_esc),
('click', 8, act_click), ('wheel', 8, act_wheel), ('hover', 6, act_hover), ('paste', 2, act_paste),
- ('settings', 1, act_settings), ('idle', 6, act_idle),
+ ('settings', 1, act_settings), ('gitshow', 1, act_gitshow), ('idle', 6, act_idle),
]