summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-18 18:36:04 -0300
committerGabriel Schneider <[email protected]>2026-11-18 19:13:22 -0300
commit0fe59ed2c7b9673c934c50e7415756e5fda971f9 (patch)
tree2cfc2d4c36c742c6cdef1a835e3640bc14713f33
parent6174a6fe323ecc57fca72282d0c97d24516f4325 (diff)
downloadpardes-0fe59ed2c7b9673c934c50e7415756e5fda971f9.tar.gz
pardes-0fe59ed2c7b9673c934c50e7415756e5fda971f9.zip
replica: the cause of round 5's open fault (a client of a session showing a PDF diverging at a key, `pane N.addon`, `views[k].jumps`, "breaks PA_PLAIN") named and pinned: not `Kind.viewOf` (the hypothesis: refuted; every view's facts, the live view's tag_rows and collapsed and the others' pv[k], are the same in the session and in each client, a late joiner's included, traced at every `view` call), but a kind's job answered at once on the core's side inside the perform of the effect that asked it: the soak's session host had no `job`, so Effect.perform ran KindJob.runHere there, whose job_done step no tape records and a client's replay of that perform skips (`!tape.replaying()`): the PDF's page-text job (asked at a page turn whenever a glyph view, a terminal client, shows it) and its search moved the session's block alone; a real host (tui.zig, gui.zig `job`) answers a job as its loop's own input, or at once inside its `job` call when no worker is free, an input the host made inside its call, which the tape records and a client replays: this test pins that path (every worker busy, the answer inside the key's unit, a client running the kind's code agrees, its block the session's)
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
-rw-r--r--src/replica.zig69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/replica.zig b/src/replica.zig
index 98426949..2b7590ed 100644
--- a/src/replica.zig
+++ b/src/replica.zig
@@ -4860,3 +4860,72 @@ test "a client joined from a dump tells a kind each view's facts as the session
joiner.confirm(try a.local(.tick));
try agrees(a, joiner);
}
+
+/// A plain kind whose key asks a job and whose job's answer moves its
+/// block: run by a client as by its session.
+const Asker = struct {
+ const pa = pardes.Kind.c;
+ fn open(_: [*c]const u8, _: [*c]const u8, _: u64) callconv(.c) ?*anyopaque {
+ return pardes.Kind.api.alloc.?(4);
+ }
+ fn paint(_: ?*anyopaque, _: [*c]const pa.pa_window, _: [*c]pa.pa_paint) callconv(.c) void {}
+ fn press(_: ?*anyopaque, _: [*c]const pa.pa_key) callconv(.c) c_int {
+ _ = pardes.Kind.api.job.?(null, 0);
+ return 1;
+ }
+ fn run(_: [*c]const u8, _: u32, out: [*c]pa.pa_out) callconv(.c) u32 {
+ const b: [*]u8 = @ptrCast(out.*.alloc.?(out, 1) orelse return 0);
+ b[0] = 1;
+ return 1;
+ }
+ fn done(st: ?*anyopaque, _: u32, _: [*c]const u8, _: u32) callconv(.c) void {
+ const n: *u32 = @ptrCast(@alignCast(st.?));
+ n.* += 1;
+ }
+ const words = [_]pa.pa_word{std.mem.zeroInit(pa.pa_word, .{ .name = "Asker", .opens = 1, .doc = "a key a job" })};
+ 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 = "asker".* ++ @as([11]u8, @splat(0)), .version = 1, .exts = "", .flags = pa.PA_PLAIN, .words = &words, .nwords = 1 }),
+ .open = open,
+ .paint = paint,
+ .key = press,
+ .job_run = run,
+ .job_done = done,
+ });
+};
+
+/// A host whose workers are all busy (tui.zig's `job` with its 16 tasks
+/// out): a kind's job runs at once, inside the host's call.
+const BusyHost = struct {
+ var core: ?*Pardes = null;
+ var tasks: @import("selection_pipe.zig").Tasks = .{ .len = @import("selection_pipe.zig").Tasks.capacity };
+ fn job(_: ?*anyopaque, pane: u8, serial: u32, token: u32) void {
+ pardes.host_io.KindJob.start(std.testing.io, core.?, &tasks, pane, serial, token, null, never);
+ }
+ fn never(_: ?*anyopaque, j: *pardes.host_io.KindJob) void {
+ j.drop();
+ }
+ const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .job = job };
+};
+
+test "a kind's job answered at once inside its host's call (no worker free) is taken by a client as the session took it" {
+ const gpa = std.testing.allocator;
+ const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &BusyHost.vtable }, false);
+ defer a.deinit();
+ BusyHost.core = a.core;
+ const r = try Replica.init(gpa, 1, try a.unit(0, 0), false);
+ defer r.deinit();
+ var words: [64]pardes.Kind.LoadedWord = undefined;
+ const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words);
+ r.confirm(try a.local(.{ .addon = .{ .op = .load, .pane = 0, .kind = &asker } }));
+ // The client has its code (as a library of its own found by its scan).
+ r.core().kinds.ops[r.core().kinds.byName("asker").?] = &Asker.ops;
+ r.confirm(try a.local(.{ .command = "Asker" }));
+ const id = a.core.view().active;
+ // Its key asks a job, answered inside the key's unit: an input the
+ // host made inside its call, on the tape (Effect.perform with no host
+ // `job` lands it on the core's side, on no tape: a host must have one).
+ r.confirm(try a.local(.{ .key = .{ .cp = 'x', .text = "x" } }));
+ try agrees(a, r);
+ try std.testing.expectEqual(@as(u32, 1), std.mem.bytesToValue(u32, a.core.panes[id].?.addon.?.plain.?[0..4]));
+ try std.testing.expectEqualSlices(u8, a.core.panes[id].?.addon.?.plain.?, r.core().panes[id].?.addon.?.plain.?);
+}