summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/jj.zig30
-rw-r--r--core/replica.zig62
2 files changed, 92 insertions, 0 deletions
diff --git a/core/jj.zig b/core/jj.zig
index a0dfec10..3d4ca17d 100644
--- a/core/jj.zig
+++ b/core/jj.zig
@@ -2552,6 +2552,36 @@ test "the lanes ride with the text: a line typed in a nested block is nobody's,
try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
}
+test "a client's own line opened over pinned changes, rolled back by the session's key first: the lanes it spliced under its copy are the copy's again, freed once; the client ends equal" {
+ var repo = try Stack.repo(null) orelse return error.SkipZigTest;
+ defer repo.deinit(testing.allocator);
+ const R = pardes.replica;
+ const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{});
+ defer a.deinit();
+ const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0));
+ defer r.deinit();
+ var line: [4200]u8 = undefined;
+ r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}", .{repo.file}) }));
+ r.confirm(try a.local(.{ .command = "Changes ::@" }));
+ r.confirm(try a.local(.{ .command = "Look a.zig:4" }));
+ r.settle();
+ const serial = a.core.panes[a.core.view().active].?.serial;
+ // The client opens a line below: an edit of the file, whose step splices
+ // the pinned lines' values (jj.edited) under the copy it takes.
+ const typed = try testing.allocator.dupe(u8, try r.input(.{ .key = .{ .cp = 'o', .text = "o" } }));
+ defer testing.allocator.free(typed);
+ try testing.expectEqual(@as(usize, 1), r.applied);
+ // The session's own key comes first: the copy put back, the `o` applied
+ // again over it, then confirmed.
+ r.confirm(try a.local(.{ .key = .{ .cp = 'k', .text = "k" } }));
+ r.settle();
+ r.confirm(try a.take(typed));
+ r.settle();
+ try testing.expect(r.diverged == null);
+ try testing.expectEqualSlices(Line, answered(a.core, serial).?.lines, answered(r.core(), serial).?.lines);
+ try testing.expectEqual(pardes.tape.digestOf(a.core), pardes.tape.digestOf(r.core()));
+}
+
/// Two functions four changes wrote: `fn` both, `f2` and `f3` rewrote
/// f's line, `g2` g's: f three changes, g two.
const Churned = struct {
diff --git a/core/replica.zig b/core/replica.zig
index 0ae302e8..936eb3e4 100644
--- a/core/replica.zig
+++ b/core/replica.zig
@@ -4012,6 +4012,68 @@ test "the count of writes outside the copy is digested: a session's emulator wri
try std.testing.expectEqualStrings("outside ", try partsApart(b.a, b.r, arena.allocator()));
}
+test "bytes: a terminal's rows read before an idle client's copy are the copy's: a rollback puts them back, neither dropped nor freed twice" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const b = try BytesPair.init();
+ defer b.deinit();
+ try b.output("a line of the program's\r\nand another\r\n");
+ // Its rows read between steps (a draw's), then the copy taken while it
+ // idles (`ready`): the rows are what the core holds at the copy.
+ const pane = b.r.core().panes[b.shell.index()].?;
+ _ = try pardes.edit.shellRows(b.r.core(), pane);
+ const cached = b.r.core().shell_rows.text_alloc.ptr;
+ b.r.ready();
+ try std.testing.expect(b.r.copy.held);
+ // A key of the client's on top, the session's own key first: the copy
+ // put back, the rows with it (not left orphaned in the epoch).
+ try b.rollback();
+ try std.testing.expectEqual(cached, b.r.core().shell_rows.text_alloc.ptr);
+ try agrees(b.a, b.r);
+ try b.output("after\r\n");
+ _ = try pardes.edit.shellRows(b.r.core(), pane);
+ try agrees(b.a, b.r);
+}
+
+test "bytes: a client's key that reads a terminal's rows, the session's output before it in the session's order: the output rolls it back, its read is made again over the fed rows, and the input is kept on the fast path with the session's reading" {
+ if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
+ const gpa = std.testing.allocator;
+ const b = try BytesPair.init();
+ defer b.deinit();
+ try b.output("l1\r\nl2\r\nl3\r\n");
+ // The shell's pane focused and out of its tty mode (^B): a cursor over
+ // its rows.
+ const id = b.shell.index();
+ const rect = b.a.core.view().rects[id];
+ for ([_]pardes.Event{
+ .{ .mouse = .{ .button = .left, .kind = .press, .col = rect.x + 2, .row = rect.y + 1 } },
+ .{ .mouse = .{ .button = .left, .kind = .release, .col = rect.x + 2, .row = rect.y + 1 } },
+ .{ .key = .{ .cp = 'b', .ctrl = true } },
+ }) |ev| {
+ b.r.confirm(try b.a.own(ev));
+ b.r.settle();
+ }
+ try agrees(b.a, b.r);
+ // G: to the last of its rows, which it reads (edit.shellRows).
+ const last = try gpa.dupe(u8, try b.r.input(.{ .key = .{ .cp = 'G', .text = "G" } }));
+ defer gpa.free(last);
+ try std.testing.expectEqual(@as(usize, 1), b.r.applied);
+ const read_before = b.r.core().panes[id].?.body.cur_row;
+ // The program prints two lines before the session takes the G: the
+ // emulator fed (its count moved, so never a neutral unit), the G
+ // undone and read again over the rows as fed.
+ b.a.output(.{ .output = .{ .pane = b.shell, .bytes = "l4\r\nl5\r\n" } });
+ b.r.confirm((try b.a.pending()).?);
+ b.r.settle();
+ try std.testing.expectEqual(@as(usize, 1), b.r.applied);
+ try std.testing.expect(b.r.core().panes[id].?.body.cur_row > read_before);
+ const fast = b.r.stats.fast;
+ b.r.confirm(try b.a.take(last));
+ b.r.settle();
+ try std.testing.expectEqual(fast + 1, b.r.stats.fast);
+ try agrees(b.a, b.r);
+ try std.testing.expectEqual(b.a.core.panes[id].?.body.cur_row, b.r.core().panes[id].?.body.cur_row);
+}
+
test "bytes: what a terminal's emulator gains while a copy is held is its own: a rollback frees none of it" {
if (pardes.Term.ops == null) return error.SkipZigTest; // a shell
const b = try BytesPair.init();