diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-26 10:44:54 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-26 10:44:54 -0300 |
| commit | 8723462d8e02bc9d78b5004de38b910e83540575 (patch) | |
| tree | f264bf364d41f3b334416618e973ec12cba0ddc9 /core/replica.zig | |
| parent | 7911c53d5f08c7d8df3eb59061841daddb1d0e83 (diff) | |
| parent | f11b123a8f4c38b6582c03d2acf84143ed1e7fd3 (diff) | |
| download | pardes-8723462d8e02bc9d78b5004de38b910e83540575.tar.gz pardes-8723462d8e02bc9d78b5004de38b910e83540575.zip | |
merge: M2's fix (dump.load resolves the chrome) + FP (PDF preview leaks, the spawn stop, PDF hits ABI 3.4)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBFhdevVu48bvL9kCE
Diffstat (limited to 'core/replica.zig')
| -rw-r--r-- | core/replica.zig | 152 |
1 files changed, 151 insertions, 1 deletions
diff --git a/core/replica.zig b/core/replica.zig index 49ccd85b..a19340bd 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -7318,7 +7318,10 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re /// `addon`: a kind whose state is its own on the session (a PDF's), which /// the walk does not stand in (its Still has no search, place or word): /// the soak's (test/replicas.zig) PDF and pictures are, judged by name. -const On = enum { any, file, kind, shell, shell_normal, addon, dir }; +/// `command`: a pane in a directory with a finished command pane, which a +/// line run there runs in again (exec.runCommand); the walk stands in none: +/// the soak's are, judged by name, and the test after the walk. +const On = enum { any, file, kind, shell, shell_normal, addon, dir, command }; /// What a far client may wait a round trip for (the user's line, P14: a /// side effect on the system may be slow; motions, edits and layout are @@ -7352,6 +7355,7 @@ const may_wait = [_]Wait{ .{ .what = "Find *", .on = .any, .stop = "kind", .why = "the work tree it lists from, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the listing itself is the session's" }, .{ .what = "Grep *", .on = .any, .stop = "kind", .why = "the work tree it searches, a `.jj` or `.git` above the pane's directory asked of the session's disk (Pick.workTree), as the search itself is the session's" }, .{ .what = "Exec *", .on = .any, .stop = "tty_taken", .why = "a program run in a shell: whether one has it, the session's" }, + .{ .what = "Exec *", .on = .command, .stop = "run a command", .why = "a line run again in its directory's finished command pane: its process and its emulator are the session's" }, .{ .what = "Term", .on = .any, .stop = "kind", .why = "a shell opened: its name asked of the disk first" }, .{ .what = "A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened" }, .{ .what = "* A-n", .on = .any, .stop = "open a terminal", .why = "a shell opened (Alt-n after a prefix is still the global key)" }, @@ -7715,6 +7719,40 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' try std.testing.expectEqual(@as(u32, 0), stale); } +test "a far client's line run again in its directory's finished command pane waits for the session's order, at a stop may_wait lists: its process and its emulator are the session's" { + // The soak's (test/replicas.zig, seed 3 rtt 80): a client's key stopped + // at `spawn`, which may_wait does not list. Its speculation ran the + // reused pane's whole run (exec.runCommand): the emulator's writes + // refused (`a terminal's output`), then the spawn effect (a host entry + // that keeps stopping), the last one naming the stop. + if (pardes.Term.ops == null) return error.SkipZigTest; // a command pane's terminal + const gpa = std.testing.allocator; + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + const file = a.core.view().active; + _ = try a.local(.{ .command = "Exec true" }); + const cmd = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.command != null) break id; + } else return error.NoCommandPane; + _ = try a.local(.{ .exited = .{ .pane = .at(cmd), .status = 0 } }); + _ = try a.local(.{ .eof = .{ .pane = .at(cmd) } }); + try std.testing.expect(a.core.panes[cmd].?.command_done); + a.core.view().active = file; + const r = try joinedFresh(a); + defer r.deinit(); + // The same line from the file's pane: its directory's finished pane runs it. + const stopped = r.stats.stopped; + const msg = try gpa.dupe(u8, try r.input(.{ .command = "Exec true" })); + defer gpa.free(msg); + try std.testing.expectEqual(stopped + 1, r.stats.stopped); + if (!mayWait(r.t.poisoned_by)) std.debug.print("stopped at `{s}`\n", .{r.t.poisoned_by}); + try std.testing.expect(mayWait(r.t.poisoned_by)); + r.confirm(try a.take(msg)); + r.settle(); + try agrees(a, r); + try std.testing.expect(!a.core.panes[cmd].?.command_done); +} + test "a far client's click into a shell whose program asked for focus events is instant: the session's step tells the program, a round trip later, and the client's guess is confirmed" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; @@ -9201,3 +9239,115 @@ test "a client joined after its session's shell was found to have no prompt mark _ = try n.serve(.{ .tag = 4, .op = .release, .node = run, .handle = h, .opened = true }, true); try n.agree(); } + +test "a picker's preview opens and closes a plain kind's state in the pane it lands in, no pane opened or closed: a client with a copy ahead never replays it over the copy, and every state the kind opens is closed once" { + // The soak's (test/replicas.zig with the pdf addon): `allocator leaks + // detected` at seed 0 rtt 80, the documents of PDFs a picker previewed + // (Pick.showKind) on a client, opened by a unit it kept to replay over + // its copy and opened again by the replay, the first never closed. + // A plain kind that holds something of its own outside its block for + // each state it opens, as the pdf addon holds a document (its `Own`): + // each open notes its block, each close lets it go, so a state opened + // and never closed stays noted. Its files are `.own`. + const Owned = struct { + const pa = pardes.Kind.c; + var noted: [8]?*anyopaque = @splat(null); + fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque { + const st = pardes.Kind.api.alloc.?(4); + for (¬ed) |*n| if (n.* == null) { + n.* = st; + break; + }; + return st; + } + fn close(st: ?*anyopaque) callconv(.c) void { + for (¬ed) |*n| if (n.* == st) { + n.* = null; + return; + }; + } + fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {} + fn held() usize { + var n: usize = 0; + for (noted) |st| n += @intFromBool(st != null); + return n; + } + const ops = std.mem.zeroInit(pardes.Kind.Ops, .{ + .head = std.mem.zeroInit(pa.pa_head, .{ .size = @sizeOf(pa.pa_head), .abi = pardes.Kind.abi, .name = "owned".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = ".own", .flags = pa.PA_PLAIN }), + .open = open, + .close = close, + .paint = paint, + }); + }; + const gpa = std.testing.allocator; + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + try tmp.dir.createDir(std.testing.io, ".git", .default_dir); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "notes.txt", .data = "the notes\n" }); + try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "paper.own", .data = "own" }); + var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; + const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; + var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined; + { + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); + defer a.deinit(); + var words: [64]pardes.Kind.LoadedWord = undefined; + const owned = pardes.Kind.loadedOf(&Owned.ops, "/x/owned.so", @splat(7), &words); + _ = try a.local(.{ .addon = .{ .op = .load, .pane = .at(0), .kind = &owned } }); + _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/notes.txt", .{dir}) }); + // A client in a view of its own, running the kind's code. + const joined = (try a.join(1, null)).?; + defer gpa.free(joined.dump); + const r = try Replica.initDump(gpa, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); + defer r.deinit(); + r.core().kinds.ops[r.core().kinds.byName("owned").?] = &Owned.ops; + // SPC f f p at the session, in its view: its picker lists the tree, + // and paper.own, the one row, shows through the kind in the pane it + // lands in. The client idle meanwhile: its copy taken ahead, each + // unit replayed on top of it. + const At = struct { + fn sessionView(au: *Authority) void { + const was = Stepping.begin(&au.t, null); + au.core.toView(.at(0)); + was.end(); + } + }; + At.sessionView(a); + for (" ffp") |c| { + r.ready(); + r.confirm(try a.local(.{ .key = .{ .cp = c, .text = &.{c} } })); + r.ready(); + r.confirm(try a.local(.tick)); + } + const landing = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.addon != null) break id; + } else return error.NoPreview; + try std.testing.expect(r.core().panes[landing].?.addon != null); + // A key of the client's own on top, and the session's own key + // first: the client back to its copy, the units since replayed. + var sent: std.ArrayListUnmanaged([]u8) = .empty; + defer { + for (sent.items) |m| gpa.free(m); + sent.deinit(gpa); + } + try key(r, 'j', &sent); + try std.testing.expectEqual(@as(usize, 1), r.applied); + const foreign = r.stats.foreign; + r.confirm(try a.local(.{ .key = .{ .cp = 'q', .text = "q" } })); + r.settle(); + try std.testing.expectEqual(foreign + 1, r.stats.foreign); + for (sent.items) |m| { + r.confirm(try a.take(m)); + r.settle(); + } + try agrees(a, r); + // Esc in the picker's view: the preview's state closed, the pane's + // own text back. + At.sessionView(a); + r.confirm(try a.local(.{ .key = .{ .cp = pardes.Key.escape } })); + r.settle(); + try agrees(a, r); + try std.testing.expect(r.core().panes[landing].?.addon == null); + } + try std.testing.expectEqual(@as(usize, 0), Owned.held()); +} |
