summaryrefslogtreecommitdiff
path: root/src/replica.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-10-30 18:15:20 -0300
committerGabriel Schneider <[email protected]>2026-10-30 18:27:47 -0300
commitedbdfdd988870caaa11f4676d48c6cecc16e45be (patch)
treefd52dea7c5d48fa10419dd9cde3b236f011edf3f /src/replica.zig
parent945490c9cbbad797c76f165be2718ac40d03941b (diff)
downloadpardes-edbdfdd988870caaa11f4676d48c6cecc16e45be.tar.gz
pardes-edbdfdd988870caaa11f4676d48c6cecc16e45be.zip
terminal: a step that reads a terminal's rows as the core keeps them marks it read too: `fill` sent a client that came since (its history all holes) none of the rows the step read
shellRows set `read` only when it built the rows, not when it handed out the ones kept since the last write, so after a client joined (or was started afresh) a step reading through the cache left the client's holes unsent, and it replayed the step on blanks. Found on the way to H18, whose fix is fixer 1's (wwkwwlzt). Test (failing before): a step that reads a terminal's rows as the core keeps them sends a new client the ones it holds as holes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to 'src/replica.zig')
-rw-r--r--src/replica.zig69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 6a01ec26..c44eebd7 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -3635,3 +3635,72 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize
try agrees(a, old);
try agrees(a, joiner);
}
+
+/// An input of a replica's in the session's order, as `Peers.input` takes
+/// it: the terminals flushed to every peer, the step, the rows it read that
+/// each peer holds as holes (`fill`), then its unit to every replica.
+fn takeAll(a: *Authority, screens: *Screens, rs: []const *Replica, ps: []const u16, msg: []const u8) !void {
+ const gpa = std.testing.allocator;
+ for (rs, ps) |r, peer| try screensTo(a, screens, peer, r);
+ const u = try gpa.dupe(u8, try a.take(msg));
+ defer gpa.free(u);
+ var rows: std.ArrayListUnmanaged([]u8) = .empty;
+ defer rows.deinit(gpa);
+ for (rs, ps) |r, peer| {
+ rows.clearRetainingCapacity();
+ try screens.fill(a.core, peer, &rows);
+ for (rows.items) |m| {
+ _ = r.screen(m);
+ gpa.free(m);
+ }
+ }
+ screens.filled(a.core);
+ for (rs) |r| {
+ r.confirm(u);
+ r.settle();
+ }
+}
+
+fn sendAs(r: *Replica, a: *Authority, screens: *Screens, rs: []const *Replica, ps: []const u16, ev: pardes.Event) !void {
+ const msg = try std.testing.allocator.dupe(u8, try r.input(ev));
+ defer std.testing.allocator.free(msg);
+ try takeAll(a, screens, rs, ps, msg);
+}
+
+test "a step that reads a terminal's rows as the core keeps them sends a new client the ones it holds as holes" {
+ if (comptime !terminal.enabled) return error.SkipZigTest;
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, PtyHost.host(), true);
+ defer a.deinit();
+ var screens: Screens = .init(gpa);
+ defer screens.deinit(a.core);
+ const first = try gpa.dupe(u8, try a.unit(0, 0));
+ defer gpa.free(first);
+ const r1 = try Replica.init(gpa, 1, first, true);
+ defer r1.deinit();
+ const r2 = try Replica.init(gpa, 2, first, true);
+ defer r2.deinit();
+ const shell: u8 = for (a.core.panes, 0..) |slot, id| {
+ if (slot) |pane| if (pane.isTerminal()) break @intCast(id);
+ } else return error.NoShell;
+ a.core.active = shell;
+ var line: [64]u8 = undefined;
+ for (0..60) |i| a.output(.{ .output = .{ .pane = shell, .bytes = try std.fmt.bufPrint(&line, "line {d} of the shell's history\r\n", .{i}) } });
+ const out = try gpa.dupe(u8, (try a.pending()).?);
+ defer gpa.free(out);
+ for ([_]*Replica{ r1, r2 }) |r| r.confirm(out);
+ // The first client alone has the terminal; it reads all of its rows
+ // (its text, the cursor on the first): the core keeps them.
+ const p1 = [_]u16{try screens.addPeer()};
+ for ([_]pardes.Event{ .{ .key = .{ .cp = 'b', .ctrl = true } }, .{ .key = .{ .cp = 'g', .text = "g" } }, .{ .key = .{ .cp = 'g', .text = "g" } } }) |ev| {
+ const msg = try gpa.dupe(u8, try r1.input(ev));
+ defer gpa.free(msg);
+ try takeAll(a, &screens, &.{r1}, &p1, msg);
+ r2.confirm(a.out.items);
+ }
+ // A second comes: its history all holes. The first reads the rows the
+ // core kept, nothing written since.
+ const ps = [_]u16{ p1[0], try screens.addPeer() };
+ try sendAs(r1, a, &screens, &.{ r1, r2 }, &ps, .{ .key = .{ .cp = 'O', .text = "O" } });
+ for ([_]*Replica{ r1, r2 }) |r| try agrees(a, r);
+}