diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 03:00:12 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 03:00:49 -0300 |
| commit | d56973aa92d0de6d84446dff73eba9d5654fe6f4 (patch) | |
| tree | 3dfda432d095b480c26b0bf2701add7ff172803f /core | |
| parent | 02099b716e5320cbee7f829d93fd53717fd2a57d (diff) | |
| download | pardes-d56973aa92d0de6d84446dff73eba9d5654fe6f4.tar.gz pardes-d56973aa92d0de6d84446dff73eba9d5654fe6f4.zip | |
replica: the delta protocol deleted, with the wire's screen messages (the old road's deletion, piece 3 of 8): core/replica.zig loses the screen-state section (the screen message's head, `Screens`: tracks, peers, flush, fill, filled, take), `Peers.screens`/`msgs`/`flushed`/`screensOut`/`screensTo`, the `.screen` note and its arm in `boundary`, `Peers.input`'s flushes and fills, a joiner's `addPeer` and a leaver's `dropPeer`, `Peer.sid` and its `screen_ack` arm, `Replica.screen`/`screenRequest`/`screenMessage`/`overTerminals`, `Replica.screens`/`screen_out`/`ScreenOf`, `Stats.apply_ns`, `Said.screen` (and its arms in dev/tui/tui.zig and dev/gui/gui.zig: a delta no longer counts as an echo there, nor is its latency noted), the Link's `.screen` arm and `drawn`'s row requests, `sendScreen`, and the `screens` argument of `Authority.init` and `Replica.init` (every caller: core/jj.zig 10, core/tape.zig 2, core/echo.zig 2, test/panes.zig 15, test/perf.zig 2, runtime/client.zig 1, test/rollback_bench.zig 1, test/replicas.zig 10, core/replica.zig 98); a replica's own `made` no longer starts on screen state, and `confirm` and `applyPending` keep only their one-road branches; abi/wire.zig retires the replica's `screen_ack` (0x04) and the session's `screen` (0x06) as gaps (the version moves once, in piece 4); test/daemon.py's round trip passes over units alone; the tests that were the old road's alone go: a delta under a speculation, a terminal sized again by a client's key (screen state's deferred size), pardes's own keys over a terminal's history and a delta while they wait, a unit kept over a copy and a delta after it, a step's rows sent as a new client's holes, the screen-state twin of the 9P pty/run test, and the 9P open over a copy taken ahead (on the one road a unit that feeds a terminal lets the copy go: `Term.writes`, so no copy is held across the run's output: its premise was the old road's); the others that ran on screen state now run on the bytes road (a kitty image: the client's emulator has it as the session's does; prompt marks and Kill; the far client's may_wait walk, its click into a focus-reporting shell, its backed-up queue; a view that sized a terminal closing; a closed terminal brought back; a leave's queued resize before a join); FOUND AND FIXED on the way (those tests on the one road failed: the far click `expected 0, found 1` stopped, and may_wait named `Del`, `DelAbove`, `Up`, `C-w a`, `click shell`, `Look` stopped at `pty_write`): a client's own step that moved the focus in a session whose shell asked for focus events wrote the report (CSI I/O) through pty_write, which a speculation stops at (`keeps_stopping`), so the key or click waited a round trip, and the session's write was on the tape; on screen state both were skipped (core/Core.zig `reportFocus` skipped the write only `speculating and screen_state`, core/tape.zig `hostCall` kept pty_write off the tape only under screen state): both now on every road (a user on the flip's build could hit it: a far client's click, pane switch or Del beside vim or tmux waited a round trip); core/root.zig `machine_lines` for replica.zig 76 -> 74 (Authority.init's getenv and a joiner's `addPeer` failure's shutdown gone); core-test 911/1068 (157 skipped: 7 tests gone, each one skipped there for want of a shell), shell-test 1110/1113 (the 7 gone)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'core')
| -rw-r--r-- | core/Core.zig | 5 | ||||
| -rw-r--r-- | core/echo.zig | 4 | ||||
| -rw-r--r-- | core/jj.zig | 20 | ||||
| -rw-r--r-- | core/replica.zig | 1314 | ||||
| -rw-r--r-- | core/root.zig | 2 | ||||
| -rw-r--r-- | core/tape.zig | 13 |
6 files changed, 159 insertions, 1199 deletions
diff --git a/core/Core.zig b/core/Core.zig index 72e92212..4c8c98dd 100644 --- a/core/Core.zig +++ b/core/Core.zig @@ -949,8 +949,9 @@ fn reportFocus(p: *Pardes) void { // A client's own step records what it told and writes nothing: the // session's step makes the write, off the tape on both sides // (tape.hostCall's pty_write), so the switch shows at once and the - // program hears of it a round trip later. - if (p.tape.speculating and p.tape.screen_state) return; + // program hears of it a round trip later (a write there would stop the + // speculation: pty_write is `keeps_stopping`'s). + if (p.tape.speculating) return; if (v.focus_told) |old| if (p.panes[old.id]) |pane| { if (pane.serial == old.serial and pardes.Term.modes(pane.terminal).focus) p.emitWrite(old.id, "\x1b[O"); }; diff --git a/core/echo.zig b/core/echo.zig index 95127f55..e2a6521c 100644 --- a/core/echo.zig +++ b/core/echo.zig @@ -588,8 +588,8 @@ const Rig = struct { g.now = 1_000 * ms; // The one road: the shell's bytes in the units, fed to the // replica's own emulator. - g.a = try replica.Authority.init(gpa, .{ .cols = 60, .rows = 16, .boot = .tty_shell }, .{ .ctx = g, .vtable = &vtable }, false); - g.r = try replica.Replica.init(gpa, 1, try g.a.unit(0, 0), false); + g.a = try replica.Authority.init(gpa, .{ .cols = 60, .rows = 16, .boot = .tty_shell }, .{ .ctx = g, .vtable = &vtable }); + g.r = try replica.Replica.init(gpa, 1, try g.a.unit(0, 0)); g.r.core().echo = &g.r.echo; g.shell = for (g.a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); diff --git a/core/jj.zig b/core/jj.zig index dd54dfc5..6a7d7da4 100644 --- a/core/jj.zig +++ b/core/jj.zig @@ -1528,9 +1528,9 @@ test "a client replays the open of a file at a revision and ends equal" { var repo = try Repo.init(gpa) orelse return error.SkipZigTest; defer repo.deinit(gpa); const R = pardes.replica; - const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{}, false); + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{}); defer a.deinit(); - const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try R.Replica.init(gpa, 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}@@-:2", .{repo.file}) })); @@ -1636,9 +1636,9 @@ test "a client replays Changes from what the session's jj answered and ends equa var repo = try Repo.init(gpa) orelse return error.SkipZigTest; defer repo.deinit(gpa); const R = pardes.replica; - const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{}, false); + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{}); defer a.deinit(); - const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try R.Replica.init(gpa, 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}) })); @@ -1676,10 +1676,10 @@ const WorkerJj = struct { fn init(repo: *const Repo, at: []const u8) !WorkerJj { const shell = try testing.allocator.create(Shell); shell.* = .{ .q = .{ .gpa = testing.allocator, .lsp_allocator = testing.allocator, .io = testing.io } }; - const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{ .vtable = &vtable, .ctx = shell }, false); + const a = try R.Authority.init(testing.allocator, .{ .cols = 80, .rows = 24 }, .{ .vtable = &vtable, .ctx = shell }); errdefer a.deinit(); shell.core = a.core; - const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0), false); + const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0)); var line: [4200]u8 = undefined; r.confirm(try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}{s}", .{ repo.file, at }) })); const id = a.core.view().active; @@ -2011,9 +2011,9 @@ test "ghost rows ride with the text: a line deleted above moves them up, a line var repo = try Ghosts.repo() 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 }, .{}, false); + 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), false); + 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}) })); @@ -2193,9 +2193,9 @@ test "the lanes ride with the text: a line typed in a nested block is nobody's, 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 }, .{}, false); + 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), false); + const r = try R.Replica.init(testing.allocator, 1, try a.unit(0, 0)); defer r.deinit(); const Keys = struct { fn send(au: *R.Authority, re: *R.Replica, keys: []const u8) !void { diff --git a/core/replica.zig b/core/replica.zig index 993d9e2c..3f897044 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -164,9 +164,7 @@ pub const Authority = struct { /// A session booted with `opts`; `unit` is its first, which a replica /// is made from. - /// `screens`: its terminals cross as screen state (`Screens`), not as - /// their pty's bytes. - pub fn init(gpa: Allocator, options: pardes.Options, host: pardes.Host, screens: bool) !*Authority { + pub fn init(gpa: Allocator, options: pardes.Options, host: pardes.Host) !*Authority { // A replay gives its core every allocator (tape.zig), and a digest // tells an allocator from none. var opts = options; @@ -177,9 +175,6 @@ pub const Authority = struct { errdefer gpa.destroy(a); a.* = .{ .gpa = gpa, .t = tape.memory(gpa), .core = undefined, .host = host }; errdefer tape.release(&a.t); - a.t.screen_state = screens; - // One word a digest: every pty read is a unit. - a.t.whole_digest = screens and std.c.getenv("PARDES_REPLICA_TRACE") == null; // A digest at a unit's end, as the session's (Peers.unit). a.t.no_digest = true; opts.tape = &a.t; @@ -355,208 +350,6 @@ pub const Authority = struct { } }; -// ---- terminals as screen state (core/term/screen_state.zig) ---- -// -// A message of either side is u8 pane, u32 the pane's serial (a slot's -// next pane is another), u8 kind, and the kind's bytes: -// to a replica: kind 1, a delta; kind 2, rows (encodeRows): asked for, -// or a step read them; -// to the authority: kind 1, an acknowledgement (u32 seq); kind 2, a -// request for rows (u64 lo, u64 hi, absolute); kind 3, a -// delta refused: start this terminal afresh. -// In the authority's stream to a peer, before it steps any input but a -// pty's output, and once a frame: its own steps since the last unit, as one -// (`Authority.pending`), then what the peer is owed of the terminals -// (`Screens.flush`). After a step, before its unit: the rows it read that -// the peer holds as holes (`Screens.fill`, then `filled`). A replica takes -// them in that order between units (`Replica.screen`), so a step it replays -// reads the terminal its authority's step read. - -const kind_delta = 1; -const kind_rows = 2; -const kind_ack = 1; -const kind_reset = 3; - -const ScreenMsg = struct { pane: u8, serial: u32, kind: u8, payload: []const u8 }; - -fn parseScreen(msg: []const u8) ?ScreenMsg { - if (msg.len < 6) return null; - return .{ .pane = msg[0], .serial = std.mem.readInt(u32, msg[1..5], .little), .kind = msg[5], .payload = msg[6..] }; -} - -fn writeScreenHead(out: *std.ArrayListUnmanaged(u8), gpa: Allocator, pane: u8, serial: u32, kind: u8) !void { - var head: [6]u8 = undefined; - head[0] = pane; - std.mem.writeInt(u32, head[1..5], serial, .little); - head[5] = kind; - try out.appendSlice(gpa, &head); -} - -/// The authority's side of its replicas' terminals: a track each terminal -/// pane, and what each peer was sent of it. -pub const Screens = struct { - gpa: Allocator, - /// Made the first time a terminal is encoded (`encoder`). - enc: ?*Term.Encoder = null, - tracks: [pardes.MAX_PANES]?Tracked = @splat(null), - peers: std.ArrayListUnmanaged(*[pardes.MAX_PANES]PeerOf) = .empty, - free_peers: std.ArrayListUnmanaged(u16) = .empty, - out: std.ArrayListUnmanaged(u8) = .empty, - /// Nanoseconds: what each flush spent encoding, for every peer. - encode_ns: u64 = 0, - - const Tracked = struct { serial: u32, state: *Term.State, track: *Term.Track }; - const PeerOf = struct { serial: u32 = 0, peer: Term.Peer = .{} }; - - pub fn init(gpa: Allocator) Screens { - return .{ .gpa = gpa }; - } - - /// `core` is the session's, its terminals still there. - pub fn deinit(s: *Screens, core: *Pardes) void { - for (&s.tracks, 0..) |*slot, id| if (slot.*) |*tr| Term.untrack(tr.track, s.gpa, if (s.live(core, id, tr)) tr.state else null); - for (s.peers.items) |p| { - for (p) |*pp| pp.peer.deinit(s.gpa); - s.gpa.destroy(p); - } - s.peers.deinit(s.gpa); - s.free_peers.deinit(s.gpa); - s.out.deinit(s.gpa); - if (s.enc) |e| Term.encoderFree(e); - } - - fn live(_: *const Screens, core: *Pardes, id: usize, tr: *const Tracked) bool { - const pane = core.panes[id] orelse return false; - return pane.serial == tr.serial and pane.terminal == tr.state; - } - - /// A new peer, with nothing yet: its first delta of each terminal - /// starts it afresh. - pub fn addPeer(s: *Screens) !u16 { - if (s.free_peers.pop()) |again| return again; - const p = try s.gpa.create([pardes.MAX_PANES]PeerOf); - p.* = @splat(.{}); - try s.peers.append(s.gpa, p); - return @intCast(s.peers.items.len - 1); - } - - /// Peer `peer` gone: what it was sent forgotten, its number free for - /// the next `addPeer` (a socket's clients come and go). - pub fn dropPeer(s: *Screens, peer: u16) void { - for (s.peers.items[peer]) |*pp| pp.peer.deinit(s.gpa); - s.peers.items[peer].* = @splat(.{}); - s.free_peers.append(s.gpa, peer) catch {}; - } - - /// What `peer` is owed of every terminal, each a message onto `out` - /// (owned): nothing for one it has as it is, or with `bound` in flight. - pub fn flush(s: *Screens, core: *Pardes, peer: u16, out: *std.ArrayListUnmanaged([]u8)) !void { - const t0 = nowNs(); - defer s.encode_ns += nowNs() - t0; - for (core.panes, 0..) |slot, id| { - const pane = slot orelse continue; - const state = pane.terminal orelse continue; - const tr = try s.track(core, id); - const pp = &s.peers.items[peer][id]; - if (pp.serial != pane.serial) { - pp.peer.reset(); - pp.serial = pane.serial; - } - s.out.clearRetainingCapacity(); - try writeScreenHead(&s.out, s.gpa, @intCast(id), pane.serial, kind_delta); - var w: std.Io.Writer.Allocating = .fromArrayList(s.gpa, &s.out); - defer s.out = w.toArrayList(); - if (!try Term.encode(state, try s.encoder(), tr.track, &pp.peer, &w.writer)) continue; - try out.append(s.gpa, try s.gpa.dupe(u8, w.written())); - } - } - - /// Rows a peer holds as holes of every terminal a step read (its rows, - /// history and all: text mode over a shell), each a rows message onto - /// `out` (owned): sent after the step and before its unit, so the - /// replica's replay reads what the authority's step read. A history row - /// never changes, so each goes once. Then `filled`. - // ponytail: a step that reads a terminal's rows reads all of them (its - // motion surface), so the first after a flood sends its whole history. - pub fn fill(s: *Screens, core: *Pardes, peer: u16, out: *std.ArrayListUnmanaged([]u8)) !void { - for (core.panes, 0..) |slot, id| { - const pane = slot orelse continue; - const state = pane.terminal orelse continue; - if (!Term.wasRead(state)) continue; - const pp = &s.peers.items[peer][id]; - if (pp.serial != pane.serial or pp.peer.holes.items.len == 0) continue; - const tr = try s.track(core, id); - for (pp.peer.holes.items) |hole| { - var lo = hole[0]; - while (lo < hole[1]) { - const hi = @min(hole[1], lo + 512); - s.out.clearRetainingCapacity(); - try writeScreenHead(&s.out, s.gpa, @intCast(id), pane.serial, kind_rows); - var w: std.Io.Writer.Allocating = .fromArrayList(s.gpa, &s.out); - defer s.out = w.toArrayList(); - try Term.encodeRows(state, try s.encoder(), tr.track, lo, hi, &w.writer); - try out.append(s.gpa, try s.gpa.dupe(u8, w.written())); - lo = hi; - } - } - pp.peer.holes.clearRetainingCapacity(); - } - } - - /// Every peer is filled: the steps' reads are forgotten. - pub fn filled(_: *Screens, core: *Pardes) void { - for (core.panes) |slot| if (slot) |pane| if (pane.terminal) |state| { - Term.clearRead(state); - }; - } - - fn track(s: *Screens, core: *Pardes, id: usize) !*Tracked { - const pane = core.panes[id].?; - if (s.tracks[id]) |*tr| { - if (s.live(core, id, tr)) return tr; - // Its pane closed (its emulator, the pin with it, gone). - Term.untrack(tr.track, s.gpa, null); - s.tracks[id] = null; - } - s.tracks[id] = .{ .serial = pane.serial, .state = pane.terminal.?, .track = try Term.track(s.gpa) }; - return &s.tracks[id].?; - } - - /// The encoder, made the first time a terminal is encoded. - fn encoder(s: *Screens) !*Term.Encoder { - if (s.enc) |e| return e; - s.enc = try Term.encoder(s.gpa); - return s.enc.?; - } - - /// A peer's message (`Replica.screen`'s, `Replica.screenRequest`'s): - /// an answer for it (owned), or null. - pub fn take(s: *Screens, core: *Pardes, peer: u16, msg: []const u8) !?[]u8 { - const m = parseScreen(msg) orelse return null; - const pane = core.panes[m.pane] orelse return null; - if (pane.serial != m.serial) return null; - const state = pane.terminal orelse return null; - const pp = &s.peers.items[peer][m.pane]; - if (pp.serial != m.serial) return null; - switch (m.kind) { - kind_ack => if (m.payload.len == 4) pp.peer.ack(std.mem.readInt(u32, m.payload[0..4], .little)), - kind_reset => pp.peer.reset(), - kind_rows => { - if (m.payload.len != 16) return null; - const tr = try s.track(core, m.pane); - s.out.clearRetainingCapacity(); - try writeScreenHead(&s.out, s.gpa, m.pane, m.serial, kind_rows); - var w: std.Io.Writer.Allocating = .fromArrayList(s.gpa, &s.out); - defer s.out = w.toArrayList(); - try Term.encodeRows(state, try s.encoder(), tr.track, std.mem.readInt(u64, m.payload[0..8], .little), std.mem.readInt(u64, m.payload[8..16], .little), &w.writer); - return try s.gpa.dupe(u8, w.written()); - }, - else => {}, - } - return null; - } -}; - // ---- a replica ---- pub const Stats = struct { @@ -588,8 +381,6 @@ pub const Stats = struct { rollback_ns: std.ArrayListUnmanaged(u64) = .empty, copy_bytes: u64 = 0, copies: u32 = 0, - /// Nanoseconds: a terminal's delta applied. - apply_ns: std.ArrayListUnmanaged(u64) = .empty, /// What stopped them (`Tape.poisoned_by`), a count a name. stops: [16]Stop = @splat(.{}), @@ -619,7 +410,6 @@ pub const Stats = struct { s.spec_ns.deinit(gpa); s.copy_ns.deinit(gpa); s.rollback_ns.deinit(gpa); - s.apply_ns.deinit(gpa); } }; @@ -689,17 +479,14 @@ pub const Replica = struct { rtt_ns: u64 = 0, gmtoff: i32 = 0, - /// Its terminals' screen state, as the authority's deltas made it. - screens: [pardes.MAX_PANES]?ScreenOf = @splat(null), - /// Each terminal's view (`Term.grid`'s view) as the copy was taken, or - /// as the last delta since set it: the copy holds no emulator, and a - /// speculation may move a view, so a rollback puts these back. + /// Each terminal's view (`Term.grid`'s view) as the copy was taken: the + /// copy holds no emulator, and a speculation may move a view, so a + /// rollback puts these back. views: [pardes.MAX_PANES]?usize = @splat(null), /// Its panes' serials as the copy was taken, and whether one was being /// torn down then (`panesMoved`). serials: [pardes.MAX_PANES]u32 = @splat(0), retiring: bool = false, - screen_out: std.ArrayListUnmanaged(u8) = .empty, /// A record's bytes by hash coming in pieces (`blobPiece`), and how /// many of them came. incoming: ?tape.Big = null, @@ -709,26 +496,16 @@ pub const Replica = struct { cache: ?Cache = null, io: std.Io = undefined, /// Its predicted echo (core/term/echo.zig), drawn over its core's terminals: - /// fed by its keys, its units and its deltas here, and by `echoFrame`. + /// fed by its keys and its units here, and by `echoFrame`. echo: Echo = .{}, - const ScreenOf = struct { - serial: u32, - rep: *Term.Replica, - /// A delta was refused, and a reset asked for: those in flight - /// before it are refused unasked. - refused: bool = false, - /// The rows asked for and not yet answered. - asked: ?[2]u64 = null, - }; - - /// A replica of the session whose first unit is `first`; `screens` - /// as the authority's (its terminals fed by `screen`). In process, its - /// timing samples kept for the harness that reads them. - pub fn init(gpa: Allocator, id: u16, first: []const u8, screens: bool) !*Replica { + /// A replica of the session whose first unit is `first`, its terminals + /// fed the pty's bytes the units carry. In process, its timing samples + /// kept for the harness that reads them; no predicted echo (a joined + /// client's has one: `made`). + pub fn init(gpa: Allocator, id: u16, first: []const u8) !*Replica { const r = try gpa.create(Replica); r.* = .{ .gpa = gpa, .id = id, .t = tape.memory(gpa), .stats = .{ .samples = true } }; - r.t.screen_state = screens; r.t.core_gpa = r.epoch.allocator(); r.t.checks = false; r.confirm(first); @@ -736,7 +513,6 @@ pub const Replica = struct { r.deinit(); return error.NoCore; } - if (screens) r.core().echo = &r.echo; return r; } @@ -769,8 +545,6 @@ pub const Replica = struct { r.* = .{ .gpa = gpa, .id = id, .view = view orelse 0, .t = tape.memory(gpa), .guess = true }; r.t.skips_render = true; r.t.checks = false; - // Its terminals are the session's deltas (Peers sends them). - r.t.screen_state = true; errdefer { tape.release(&r.t); r.epoch.deinit(); @@ -834,7 +608,6 @@ pub const Replica = struct { } pub fn deinit(r: *Replica) void { - for (&r.screens) |*slot| if (slot.*) |*sc| Term.replicaFree(sc.rep, pardes.panes.emulator_gpa); if (r.t.core) |c| { const was = Stepping.begin(&r.t, &r.epoch); // The state it ends on is whole as it is: the copy let go, its @@ -854,7 +627,6 @@ pub const Replica = struct { for (r.since.items) |u| r.gpa.free(u); r.since.deinit(r.gpa); r.out.deinit(r.gpa); - r.screen_out.deinit(r.gpa); r.last_digest.deinit(r.gpa); r.stats.deinit(r.gpa); tape.release(&r.t); @@ -923,8 +695,8 @@ pub const Replica = struct { r.since_check +|= 1; if (u.origin == r.id) if (r.t.core) |c| r.echo.confirmed(c, u.seq); // The pty's bytes fed its emulators: its predicted echo judged - // against them, as a screen-state delta judges it (`screen`). - defer if (!r.t.screen_state and r.diverged == null and tape.feedsTerminal(u.tape)) if (r.t.core) |c| if (c.echo != null) r.echo.fed(c); + // against them. + defer if (r.diverged == null and tape.feedsTerminal(u.tape)) if (r.t.core) |c| if (c.echo != null) r.echo.fed(c); // A copy taken ahead (`ready`), nothing on top: it stays the point a // rollback goes back to, the unit replayed on it and kept in `since`, // not let go and taken again (a megabyte walked) for each unit of @@ -948,11 +720,12 @@ pub const Replica = struct { // nothing ends on again (`neutral`); none, not known. r.last_digest.clearRetainingCapacity(); if (lastDigest(u.tape)) |d| r.last_digest.appendSlice(r.gpa, d) catch {}; - if (r.pending.items[0].terminal and (r.applied > 1 or !r.t.screen_state)) { - // Right, but what it did read a terminal: replayed later (a - // rollback's `since`) it would read the deltas that came - // after it. So it is taken now, over the emulator its step - // read, and the ones on top applied again over it. + if (r.pending.items[0].terminal) { + // Right, but what it did wrote an emulator (or owes one a + // write: a grid's size): replayed later (a rollback's + // `since`) it would write it again. So it is taken now, over + // the emulator its step read, and the ones on top applied + // again over it. r.toConfirmed(); if (tape.replayUnit(&r.t, u.tape)) |why| return r.fail(why); r.freePending(r.pending.orderedRemove(0)); @@ -1007,7 +780,7 @@ pub const Replica = struct { // place, and much of it no digest covers (a colour set, a mode, the // pages a reload remakes). if (r.applied > 0 and u.origin != r.id and ends != null and std.mem.eql(u8, ends.?, r.last_digest.items) and - (r.t.screen_state or !tape.feedsTerminal(u.tape))) + !tape.feedsTerminal(u.tape)) { // Nothing a digest covers moved: what was applied on top is // what the session will apply on top of it. Replayed when the @@ -1076,7 +849,7 @@ pub const Replica = struct { const c = r.core(); for (c.retired_panes.current, c.retired_panes.previous) |x, y| retiring = retiring or x != null or y != null; for (c.panes, serials) |slot, n| retiring = retiring or (if (slot) |pane| pane.serial else 0) != n; - if (retiring or (!r.t.screen_state and Term.writes != writes)) { + if (retiring or Term.writes != writes) { r.copy.release(); rollback.Epoch.select(null); return r.clearSince(); @@ -1189,18 +962,14 @@ pub const Replica = struct { c.toView(.at(r.view)); // Input into a terminal: what reaches its program (a key in tty // mode, a paste, a mouse report) is a pty write, the authority's, - // and stops here (phase 6 predicts its echo). The rest (pardes's - // own keys over it, the wheel) reads its emulator, here the last - // delta's and there what the pty has said since: it is applied, - // and applied again over each delta while it waits (`screen`), so - // what the authority's unit confirms read the emulator its step - // read (the deltas come before it). - const keyboard = if (c.panes[c.view().active]) |pane| pane.terminal != null else false; + // and stops here (core/echo.zig predicts its echo). The rest + // (pardes's own keys over it, the wheel) reads its emulator, fed + // the same bytes in the same order as the session's: it is applied. c.update(in.event); c.step(); - // Under bytes: it owes an emulator a write it skipped (a grid's - // size), replayed when confirmed. - p.terminal = if (r.t.screen_state) keyboard or r.t.touched else r.t.touched; + // It owes an emulator a write it skipped (a grid's size): replayed + // when confirmed. + p.terminal = r.t.touched; const clean = tape.endSpeculation(&r.t); const dt = nowNs() - t0; // Where a blob was written, should one be: the input that did. @@ -1315,134 +1084,6 @@ pub const Replica = struct { return pardes.views.drawOne(c, r.view, present) catch true; } - /// One of the authority's terminal messages (`Screens.flush`, or an - /// answer to `screenRequests`), taken between units in stream order: a - /// delta written into its pane's emulator, or fetched rows. The - /// message for the authority (an acknowledgement, or a request to start - /// afresh), valid until the next call, or null. - pub fn screen(r: *Replica, msg: []const u8) ?[]const u8 { - const m = parseScreen(msg) orelse return null; - const c = r.t.core orelse return null; - const pane = c.panes[m.pane] orelse return null; - if (pane.serial != m.serial) return null; // a pane gone: its slot's next is another - const state = pane.terminal orelse return null; - const slot = &r.screens[m.pane]; - if (slot.* == null or slot.*.?.serial != m.serial) { - if (slot.*) |*old| Term.replicaFree(old.rep, pardes.panes.emulator_gpa); - slot.* = null; - const rep = Term.replica(pardes.panes.emulator_gpa) catch { - r.fail("no memory for a terminal's replica"); - return null; - }; - slot.* = .{ .serial = m.serial, .rep = rep }; - } - const sc = &slot.*.?; - // The emulator is the authority's: on the C heap, outside the - // rollback epoch, so a copy held now never saves or puts back any - // of what this writes (State.gpa). - switch (m.kind) { - kind_delta => { - // A unit kept to replay (`since`) read the emulator as it is - // now, and its step may have read it (a key over a shell's - // text reads its rows, an output its prompt): replayed over - // this delta it would read another (the soak, a copy taken - // ahead, three clients: another's key that read the rows, - // replayed by a rollback after the full-screen program - // redrew them, came to another state). So the units since go - // before it: let go with the copy when nothing is on top (the - // state is the confirmed one), else replayed now. - if (r.copy.held and r.since.items.len > 0) { - const was = Stepping.begin(&r.t, &r.epoch); - defer was.end(); - if (r.applied == 0) { - r.copy.release(); - rollback.Epoch.select(null); - r.clearSince(); - } else { - r.toConfirmed(); - r.dirty = true; - } - } - const t0 = nowNs(); - const applied = Term.apply(state, sc.rep, m.payload) catch |err| { - if (err != error.BaseMismatch) r.fail("a terminal's delta did not apply"); - if (sc.refused) return null; - sc.refused = true; - return r.screenMessage(m.pane, m.serial, kind_reset, &.{}); - }; - if (r.stats.samples) r.stats.apply_ns.append(r.gpa, nowNs() - t0) catch {}; - sc.refused = false; - r.echo.delta(c, m.pane, Term.replicaTop(sc.rep)); - // Its rows as the core keeps them read are another grid's. - c.shell_rows.markStale(pane); - // Its view is the authority's now: a rollback puts it back - // here, and what was applied over a terminal goes on top. - if (r.copy.held) r.views[m.pane] = pardes.Term.grid(state).view; - r.overTerminals(); - var seq: [4]u8 = undefined; - std.mem.writeInt(u32, &seq, applied.seq, .little); - return r.screenMessage(m.pane, m.serial, kind_ack, &seq); - }, - kind_rows => { - sc.asked = null; - Term.applyRows(state, sc.rep, m.payload) catch r.fail("a terminal's rows did not apply"); - c.shell_rows.markStale(pane); - r.overTerminals(); - return null; - }, - else => return null, - } - } - - /// A terminal was written (a delta, rows): what is applied over the - /// emulator (`Pending.terminal`) read the one before it, and the - /// authority's step reads this one (it comes before that step's unit). - /// Back to the confirmed position, to be applied again over it. - fn overTerminals(r: *Replica) void { - const any = for (r.pending.items[0..r.applied]) |p| { - if (p.terminal) break true; - } else false; - if (!any) return; - const was = Stepping.begin(&r.t, &r.epoch); - defer was.end(); - r.toConfirmed(); - r.dirty = true; - } - - /// A request for the rows a terminal shows here and does not hold (its - /// holes in view, after a scroll back), one a terminal at a time; null - /// when none is owed. Until the answer, a hole shows blank. - pub fn screenRequest(r: *Replica) ?[]const u8 { - const c = r.t.core orelse return null; - for (&r.screens, 0..) |*slot, id| { - const sc: *ScreenOf = if (slot.*) |*x| x else continue; - if (sc.asked != null) continue; - const pane = c.panes[id] orelse continue; - if (pane.serial != sc.serial) continue; - const state = pane.terminal orelse continue; - const shown = Term.shown(state, sc.rep); - var holes: std.ArrayList([2]u64) = .empty; - defer holes.deinit(r.gpa); - Term.missing(sc.rep, shown[0], shown[1], &holes, r.gpa) catch return null; - if (holes.items.len == 0) continue; - const want: [2]u64 = .{ holes.items[0][0], holes.items[holes.items.len - 1][1] }; - Term.blank(state, sc.rep, want[0], want[1]); - sc.asked = want; - var range: [16]u8 = undefined; - std.mem.writeInt(u64, range[0..8], want[0], .little); - std.mem.writeInt(u64, range[8..16], want[1], .little); - return r.screenMessage(@intCast(id), sc.serial, kind_rows, &range); - } - return null; - } - - fn screenMessage(r: *Replica, pane: u8, serial: u32, kind: u8, payload: []const u8) ?[]const u8 { - r.screen_out.clearRetainingCapacity(); - writeScreenHead(&r.screen_out, r.gpa, pane, serial, kind) catch return null; - r.screen_out.appendSlice(r.gpa, payload) catch return null; - return r.screen_out.items; - } - /// A piece of a record's bytes by hash (Peer.blob): whole and checked /// against its hash, kept for the unit that names it (tape.keepFile), /// and a file's, a far client's, on disk (`cache`) for its next join. @@ -1720,8 +1361,6 @@ pub const Peer = struct { again: bool = false, /// ...or that its window was closed (Peers.closed). close: bool = false, - /// Its number in the session's `Screens`. - sid: u16 = 0, /// Inputs read (each one's seq, as the client numbered them). seq: u32 = 0, /// The `stamp` frame its next input came with (its reader's). @@ -2010,13 +1649,6 @@ pub const Peer = struct { peer.send(&.{pong}); return true; }, - // Its word about a terminal (an ack, rows asked, a reset), to - // the session's Screens at the next boundary. - .screen_ack => { - const msg = peer.peers.gpa.dupe(u8, payload) catch return false; - peer.peers.post(.{ .screen = .{ .peer = peer, .msg = msg } }); - return true; - }, .check => { peer.peers.post(.{ .check = peer }); return true; @@ -2152,25 +1784,18 @@ pub const Peers = struct { boundary_ns: std.ArrayListUnmanaged(u64) = .empty, cut: u32 = 0, head: [unit_head]u8 = undefined, - /// Its clients' terminals as screen state (core/term/screen_state.zig), while - /// it records: what each was sent. - screens: Screens = undefined, - msgs: std.ArrayListUnmanaged([]u8) = .empty, /// False: its clients' links are in this process's memory, a thread /// for none of them (the soak's, test/replicas.zig): what a client's /// writer would write (its join, then `out`) and its reader read /// (`Peer.take`, then `.gone` posted) are its driver's to do. threads: bool = true, - /// After each flush of a client's terminals, told: the soak's record - /// of each terminal as each version left it (test/replicas.zig). - flushed: ?struct { ctx: *anyopaque, f: *const fn (*anyopaque, *Pardes, *Screens) void } = null, /// Its clients' terminals cross as the pty's bytes in its units, each /// client's emulator its own (P29, P32), not as screen state: every /// session's (runtime/session.zig) but under PARDES_TERM_SCREEN, the /// soak's `--bytes`; its welcome says so to each client. bytes: bool = false, - pub const Note = union(enum) { join: Joining, input: Msg, screen: Msg, gone: *Peer, check: *Peer, joined: *Peer }; + pub const Note = union(enum) { join: Joining, input: Msg, gone: *Peer, check: *Peer, joined: *Peer }; /// A connection to join, and the view it joins again for, if it does. pub const Joining = daemon.Joining; pub const Msg = struct { peer: *Peer, msg: []u8 }; @@ -2191,13 +1816,13 @@ pub const Peers = struct { ps.lock.unlock(ps.io); switch (note) { .join => |j| _ = libc.close(j.fd), - .input, .screen => |in| ps.gpa.free(in.msg), + .input => |in| ps.gpa.free(in.msg), .gone, .check, .joined => {}, } return; }; ps.mail.store(true, .release); - if (note != .screen) ps.urgent.store(true, .release); + ps.urgent.store(true, .release); ps.lock.unlock(ps.io); if (ps.wake) |w| w(ps.wake_ctx); } @@ -2227,8 +1852,6 @@ pub const Peers = struct { const head = wire.header(@backingInt(wire.ServerTag.unit), unit_head + bytes.len); for (ps.list) |slot| if (slot) |peer| peer.send(&.{ &head, &ps.head, bytes }); ps.t.buf.clearRetainingCapacity(); - // The sizes its steps gave terminals, now: the next flush says so. - if (ps.t.core) |core| pardes.panes.resizeDeferred(core); } /// After each of the session's pumps: its unit sent, the clients that @@ -2239,12 +1862,8 @@ pub const Peers = struct { const t0 = nowNs(); defer if (ps.recording and ps.samples) ps.boundary_ns.append(ps.gpa, nowNs() - t0) catch {}; if (ps.recording) { - // The rows the pump's steps read, then its unit, then what the - // terminals came to (the next steps read that). - ps.screensOut(core, .fill); ps.seq += 1; ps.unit(0, ps.seq); - ps.screensOut(core, .flush); } if (!ps.mail.load(.acquire)) return; ps.lock.lockUncancelable(ps.io); @@ -2257,20 +1876,6 @@ pub const Peers = struct { ps.input(core, in.peer, in.msg); ps.gpa.free(in.msg); }, - .screen => |in| { - defer ps.gpa.free(in.msg); - // An acknowledgement (or a reset): room again in its flight - // for what its terminals came to since. Its flush at this - // boundary came before it, and at the bound sent nothing: - // with no step after it, that client kept an old screen. - const reply = (ps.screens.take(core, in.peer.sid, in.msg) catch null) orelse { - ps.screensTo(core, in.peer, .flush); - continue; - }; - defer ps.gpa.free(reply); - const head = wire.header(@backingInt(wire.ServerTag.screen), reply.len); - in.peer.send(&.{ &head, reply }); - }, .gone => |peer| ps.leave(core, peer), .joined => |peer| released(peer), .check => |peer| { @@ -2285,20 +1890,12 @@ pub const Peers = struct { const in = parseInput(msg) orelse return; const t0 = nowNs(); defer if (ps.samples) ps.input_ns.append(ps.gpa, nowNs() - t0) catch {}; - // The terminals as this step reads them, then the step, the rows - // it read, its unit (part B terminal notes' order). - ps.screensOut(core, .flush); core.toView(peer.view); ps.t.stamp = stampOf(in); core.update(in.event); core.step(); ps.t.stamp = null; - ps.screensOut(core, .fill); ps.unit(peer.id, in.seq); - // What the step made of a kind's pane (the tick after a key or a - // click into it: another layout) goes now, not at the next pump's: - // one may not come before the client looks. - ps.screensOut(core, .flush); } /// What its steps recorded passed a unit's bound (`tape.unit_max`): a @@ -2309,33 +1906,6 @@ pub const Peers = struct { ps.unit(0, ps.seq); } - const ScreensOut = enum { flush, fill }; - - /// What each client is owed of the terminals (`Screens.flush`), or the - /// rows a step read that it lacks (`Screens.fill`, then `filled`), each - /// a screen message queued for it. - fn screensOut(ps: *Peers, core: *Pardes, comptime what: ScreensOut) void { - for (ps.list) |slot| if (slot) |peer| ps.screensTo(core, peer, what); - if (what == .fill) ps.screens.filled(core); - } - - fn screensTo(ps: *Peers, core: *Pardes, peer: *Peer, comptime what: ScreensOut) void { - if (ps.bytes) return; - defer { - for (ps.msgs.items) |m| ps.gpa.free(m); - ps.msgs.clearRetainingCapacity(); - } - (switch (what) { - .flush => ps.screens.flush(core, peer.sid, &ps.msgs), - .fill => ps.screens.fill(core, peer.sid, &ps.msgs), - }) catch return; - if (what == .flush) if (ps.flushed) |h| h.f(h.ctx, core, &ps.screens); - for (ps.msgs.items) |m| { - const head = wire.header(@backingInt(wire.ServerTag.screen), m.len); - peer.send(&.{ &head, m }); - } - } - /// A client on `joining.fd` joined: a dump of the session now, its /// threads started. At a step boundary (`boundary`), or a session's /// first client before its first effects (runtime/session.zig). @@ -2355,12 +1925,9 @@ pub const Peers = struct { if (tape.on != null) return daemon.refuseReplica(fd, "that session records a tape of its own (PARDES_RECORD)"); ps.t = tape.memory(ps.gpa); ps.t.unit_digests = true; - // Terminals cross as screen state: a unit carries no pty bytes, - // and its digest is a word (PARDES_REPLICA_TRACE: one a field). - ps.t.screen_state = !ps.bytes; + // A unit's digest is a word (PARDES_REPLICA_TRACE: one a field). ps.t.whole_digest = std.c.getenv("PARDES_REPLICA_TRACE") == null; ps.t.cut = .{ .ctx = ps, .f = cutUnit }; - ps.screens = .init(ps.gpa); tape.on = &ps.t; core.tape = &ps.t; ps.recording = true; @@ -2438,11 +2005,6 @@ pub const Peers = struct { slot.* = peer; peer.pid = peerPid(fd); ps.tellClients(); - // Its terminals afresh, after its dump and before any unit. - if (ps.screens.addPeer()) |sid| { - peer.sid = sid; - ps.screensTo(core, peer, .flush); - } else |_| _ = libc.shutdown(fd, 2); log.info("client {d} joined '{s}' as view {d}: a {d} KB dump ({d} KB of state) in {d} us", .{ peer.id, ps.name, k, whole >> 10, bytes.len >> 10, (nowNs() - t0) / 1000 }); if (std.c.getenv("PARDES_REPLICA_TRACE") != null) std.debug.print("session: client {d} joined after unit {d}\n", .{ peer.id, ps.seq }); } @@ -2492,7 +2054,6 @@ pub const Peers = struct { }; log.info("client {d} left '{s}'", .{ peer.id, ps.name }); ps.tellClients(); - ps.screens.dropPeer(peer.sid); core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view.index())); // Cut off, it joins again after the words why (`send`); its reader // has ended and no other thread sets `cut` now. @@ -2535,7 +2096,7 @@ pub const Peers = struct { var i: usize = 0; while (i < ps.inbox.items.len) { const mine = switch (ps.inbox.items[i]) { - .input, .screen => |in| in.peer == peer, + .input => |in| in.peer == peer, .gone, .check, .joined => |p| p == peer, .join => false, }; @@ -2544,7 +2105,7 @@ pub const Peers = struct { continue; } switch (ps.inbox.items[i]) { - .input, .screen => |in| ps.gpa.free(in.msg), + .input => |in| ps.gpa.free(in.msg), else => {}, } _ = ps.inbox.orderedRemove(i); @@ -2662,8 +2223,6 @@ pub const Peers = struct { fn stop(ps: *Peers, core: *Pardes) void { if (!ps.recording) return; - pardes.panes.resizeDeferred(core); - ps.screens.deinit(core); tape.on = null; core.tape = core.opts.tape orelse &tape.none; tape.release(&ps.t); @@ -2682,7 +2241,6 @@ pub const Peers = struct { slot.* = null; core.undrawn &= ~(@as(u8, 1) << @intCast(peer.view.index())); ps.closeViewOf(core, peer, again); - ps.screens.dropPeer(peer.sid); ps.letGo(peer); }; ps.tellClients(); @@ -2690,7 +2248,7 @@ pub const Peers = struct { ps.lock.lockUncancelable(ps.io); for (ps.inbox.items) |note| switch (note) { .join => |j| _ = libc.close(j.fd), - .input, .screen => |in| ps.gpa.free(in.msg), + .input => |in| ps.gpa.free(in.msg), .gone, .check, .joined => {}, }; ps.inbox.clearRetainingCapacity(); @@ -2704,7 +2262,6 @@ pub const Peers = struct { ps.taken.deinit(ps.gpa); ps.input_ns.deinit(ps.gpa); ps.boundary_ns.deinit(ps.gpa); - ps.msgs.deinit(ps.gpa); ps.each_join.deinit(ps.gpa); } @@ -3110,18 +2667,6 @@ pub fn sendInput(fd: c_int, msg: []const u8) bool { return writeAll(fd, msg[head_len..]); } -/// A message `Replica.screen` or `screenRequest` made, to the session. -pub fn sendScreen(fd: c_int, msg: []const u8) bool { - var buf: [64]u8 = undefined; - if (wire.header_len + msg.len > buf.len) { - const head = wire.header(@backingInt(wire.ClientTag.screen_ack), msg.len); - return writeAll(fd, &head) and writeAll(fd, msg); - } - buf[0..wire.header_len].* = wire.header(@backingInt(wire.ClientTag.screen_ack), msg.len); - @memcpy(buf[wire.header_len..][0..msg.len], msg); - return writeAll(fd, buf[0 .. wire.header_len + msg.len]); -} - /// Asks the session's digest, answered in stream order. pub fn askCheck(fd: c_int) bool { var out: [16]u8 = undefined; @@ -3136,9 +2681,9 @@ pub fn bye(fd: c_int, how: @FieldType(wire.ClientMsg, "bye")) void { } /// What the session streams a client after its dump, as its frontend's loop -/// takes it: a unit's and a terminal message's bytes and a refusal's words -/// on the C heap, the loop's to free. -pub const Said = union(enum) { unit: []u8, screen: []u8, checked: u64, refused: []u8, blob: []u8, ended: u8, left }; +/// takes it: a unit's bytes and a refusal's words on the C heap, the loop's +/// to free. +pub const Said = union(enum) { unit: []u8, checked: u64, refused: []u8, blob: []u8, ended: u8, left }; /// The session's stream off `fd`, each message handed to `post` until the /// link ends (a refusal ends it too); `post` says whether it took it (one @@ -3149,7 +2694,6 @@ pub fn readLink(gpa: Allocator, fd: c_int, rest: *Framer, ctx: anytype, comptime const t = std.enums.fromInt(wire.ServerTag, tag) orelse return false; const msg: Said = switch (t) { .unit => .{ .unit = std.heap.c_allocator.dupe(u8, payload) catch return false }, - .screen => .{ .screen = std.heap.c_allocator.dupe(u8, payload) catch return false }, .blob => .{ .blob = std.heap.c_allocator.dupe(u8, payload) catch return false }, .check => .{ .checked = (wire.decodeServer(tag, payload) catch return false).check }, .refused => .{ .refused = std.heap.c_allocator.dupe(u8, (wire.decodeServer(tag, payload) catch return false).refused) catch return false }, @@ -3158,11 +2702,11 @@ pub fn readLink(gpa: Allocator, fd: c_int, rest: *Framer, ctx: anytype, comptime .pong, .welcome, .dump, .blobs, .zstd => return true, }; if (!post(x, msg)) switch (msg) { - .unit, .screen, .refused, .blob => |b| std.heap.c_allocator.free(b), + .unit, .refused, .blob => |b| std.heap.c_allocator.free(b), .checked, .ended, .left => {}, }; // A last word ends the stream. - return msg == .unit or msg == .screen or msg == .checked or msg == .blob; + return msg == .unit or msg == .checked or msg == .blob; } }; rest.run(gpa, fd, ctx, Take.take); @@ -3576,11 +3120,6 @@ pub const Link = struct { // after it in the stream and its digest covers it. if (!c.asked) c.changed = true; }, - .screen => |bytes| { - defer std.heap.c_allocator.free(bytes); - if (c.r.screen(bytes)) |reply| if (!sendScreen(c.fd, reply)) c.cut(); - c.dirty = true; - }, .blob => |bytes| { defer std.heap.c_allocator.free(bytes); c.r.blobPiece(bytes); @@ -3604,9 +3143,7 @@ pub const Link = struct { } /// Its own view drawn, by the frontend (`drew` is whether anything was - /// written to it): a rollback it may have shown counted, and the - /// history rows it shows and does not hold (a scroll back) asked for, - /// blank until they come. + /// written to it): a rollback it may have shown counted. pub fn drawn(c: *Link, drew: bool) void { if (c.r.stats.mispredicted > c.mispredicted) { c.mispredicted = c.r.stats.mispredicted; @@ -3617,10 +3154,6 @@ pub const Link = struct { // What moved before this frame is in it: not drawn again at the // next unit (a stopped input's rollback, under its own frame). c.r.moved = false; - while (c.r.screenRequest()) |req| if (!sendScreen(c.fd, req)) { - c.cut(); - break; - }; } /// The session's unit `bytes`, taken now: how far behind it is. Past @@ -3817,29 +3350,6 @@ fn key(r: *Replica, cp: u21, sent: *std.ArrayListUnmanaged([]u8)) !void { try sent.append(std.testing.allocator, try std.testing.allocator.dupe(u8, msg)); } -/// What the session sends a peer: its terminals' changes (`.flush`), or, -/// around a step's unit (Peers.input), the rows the step read that the -/// peer lacks (`.fill`), after which the caller gives terminals the sizes -/// the step gave them (`panes.resizeDeferred`), then the unit. -fn deliver(a: *Authority, screens: *Screens, peer: u16, r: *Replica, comptime what: enum { flush, fill }) !void { - const gpa = std.testing.allocator; - var msgs: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (msgs.items) |m| gpa.free(m); - msgs.deinit(gpa); - } - switch (what) { - .flush => try screens.flush(a.core, peer, &msgs), - .fill => { - try screens.fill(a.core, peer, &msgs); - screens.filled(a.core); - }, - } - for (msgs.items) |m| if (r.screen(m)) |reply| { - _ = try screens.take(a.core, peer, reply); - }; -} - /// The blob cache of a test, in its own directory (never the user's). fn testCache(tmp: *std.testing.TmpDir, buf: *[4200]u8, cap: u64) !Cache { var dir_buf: [std.Io.Dir.max_path_bytes]u8 = undefined; @@ -3935,34 +3445,21 @@ fn inputOf(buf: []u8, client: u16, seq: u32, ev: pardes.Event) ![]const u8 { } /// 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 { +/// it: the step, then its unit to every replica. +fn takeAll(a: *Authority, rs: []const *Replica, msg: []const u8) !void { const gpa = std.testing.allocator; - for (rs, ps) |r, peer| try deliver(a, screens, peer, r, .flush); 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 { +fn sendAs(r: *Replica, a: *Authority, rs: []const *Replica, 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); + try takeAll(a, rs, msg); } fn shows(p: *Pardes, text: []const u8) !bool { @@ -4044,9 +3541,9 @@ test "an Upgrade tells a client handed to the session and not joined yet that it test "a replica's own keys apply at once, confirm on the fast path, and end at the authority's digest" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); try std.testing.expectEqual(digestOf(a), r.digest()); var sent: std.ArrayListUnmanaged([]u8) = .empty; @@ -4071,9 +3568,9 @@ test "a replica's own keys apply at once, confirm on the fast path, and end at t test "an input's time is its client's: an edit's second confirms on the fast path though the authority takes it in the next" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); var sent: std.ArrayListUnmanaged([]u8) = .empty; defer { @@ -4108,13 +3605,13 @@ test "an input's time is its client's: an edit's second confirms on the fast pat test "another client's input first: a replica rolls back, replays it and applies its own again" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const r1 = try Replica.init(gpa, 1, first, false); + const r1 = try Replica.init(gpa, 1, first); defer r1.deinit(); - const r2 = try Replica.init(gpa, 2, first, false); + const r2 = try Replica.init(gpa, 2, first); defer r2.deinit(); var s1: std.ArrayListUnmanaged([]u8) = .empty; var s2: std.ArrayListUnmanaged([]u8) = .empty; @@ -4149,11 +3646,11 @@ test "another client's input first: a replica rolls back, replays it and applies test "the copy taken for an input of its own stays once the input is confirmed: the next takes none, and a rollback replays the first over it" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const r = try Replica.init(gpa, 1, first, false); + const r = try Replica.init(gpa, 1, first); defer r.deinit(); var sent: std.ArrayListUnmanaged([]u8) = .empty; defer { @@ -4182,7 +3679,7 @@ test "a client marks its view moved for a unit of the session's whose steps aske // clock, or a ctl write's close, draws nothing; a client presented it // again (the corpus's pet: one picture twice). const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); // A client as a dial joins it: it draws none of its replay. const r = try joinedNow(a, 1, 0); @@ -4207,9 +3704,9 @@ test "the session's pump units that moved nothing, kept under a key applied on t // of them is the bound's is the arrivals' parity, and a pump's unit // while idle turns it. const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); var sent: std.ArrayListUnmanaged([]u8) = .empty; defer { @@ -4255,11 +3752,11 @@ test "a rollback over a Tab it applied measures tabs as its core has them again" // a Tab undone left it, and the next replayed step measured the files' // tabs otherwise (the soak, five clients). const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const r = try Replica.init(gpa, 1, first, false); + const r = try Replica.init(gpa, 1, first); defer r.deinit(); const was = r.core().settings.tab; const msg = try gpa.dupe(u8, try r.input(.{ .command = "Tab 2" })); @@ -4275,101 +3772,12 @@ test "a rollback over a Tab it applied measures tabs as its core has them again" try agrees(a, r); } -test "a delta applied under a speculation outlives its rollback: the terminal stays the authority's newest" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.deinit(); - const shell: u8 = for (a.core.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.isTerminal()) break @intCast(id); - } else return error.NoShell; - // Typing goes to the text pane under the shell (the host's write of - // `active`, taped). - a.core.view().active = for (a.core.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.file != null) break id; - } else return error.NoTextPane; - r.confirm(try a.local(.{ .focus = true })); - try deliver(a, &screens, peer, r, .flush); - var sent: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (sent.items) |m| gpa.free(m); - sent.deinit(gpa); - } - // Typed into the file, at once: a copy is held. - try key(r, 'o', &sent); - try std.testing.expect(r.copy.held); - var line: [64]u8 = undefined; - for (0..3) |round| { - // The shell prints: its unit rolls the replica back and applies the - // key again; then its delta lands, under the new copy. - for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "round {d} line {d}\r\n", .{ round, i }) } }); - r.confirm((try a.pending()).?); - r.settle(); - try std.testing.expect(r.copy.held); - try deliver(a, &screens, peer, r, .flush); - // The rows the core keeps, read once under the copy. - _ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); - } - for (sent.items) |m| { - r.confirm(try a.take(m)); - r.settle(); - gpa.free(m); - } - sent.clearRetainingCapacity(); - try deliver(a, &screens, peer, r, .flush); - // Drawn (its rows read, between steps), then typed into: the copy keeps - // those rows. The shell prints, its delta lands under the copy, and then - // another's unit puts the copy back: the rows it kept are of an older - // grid and must not be read. - r.confirm(try a.local(.{ .focus = false })); - _ = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); - try key(r, 'x', &sent); - for (0..40) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "last line {d}\r\n", .{i}) } }); - r.confirm((try a.pending()).?); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - r.confirm(try a.local(.{ .focus = true })); - r.settle(); - const n = a.core.panes[shell].?.rows; - const back = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); - const now = try pardes.edit.shellRows(a.core, a.core.panes[shell].?); - for (now[now.len - n ..], back[back.len - n ..]) |x, y| try std.testing.expectEqualStrings(x, y); - for (sent.items) |m| { - r.confirm(try a.take(m)); - r.settle(); - } - try deliver(a, &screens, peer, r, .flush); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try std.testing.expectEqual(digestOf(a), r.digest()); - var dump_a: std.Io.Writer.Allocating = .init(gpa); - defer dump_a.deinit(); - var dump_r: std.Io.Writer.Allocating = .init(gpa); - defer dump_r.deinit(); - try Term.dumpScreen(a.core.panes[shell].?.terminal.?, &dump_a.writer); - try Term.dumpScreen(r.core().panes[shell].?.terminal.?, &dump_r.writer); - try std.testing.expectEqualStrings(dump_a.written(), dump_r.written()); - const rows_a = try pardes.edit.shellRows(a.core, a.core.panes[shell].?); - const rows_r = try pardes.edit.shellRows(r.core(), r.core().panes[shell].?); - // As many rows (the history is the authority's to the row), the screen's - // the same; above it, rows scrolled past more than a screen at once are - // holes until fetched. - try std.testing.expectEqual(rows_a.len, rows_r.len); - const shown = a.core.panes[shell].?.rows; - for (rows_a[rows_a.len - shown ..], rows_r[rows_r.len - shown ..]) |x, y| try std.testing.expectEqualStrings(x, y); -} - test "a closed terminal brought back on a screen-state replica: its emulator on the C heap, never the rollback epoch's" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -4392,13 +3800,13 @@ test "a closed terminal brought back on a screen-state replica: its emulator on test "a view that sized a terminal closing leaves nothing queued: the others' replicas copy, type and agree" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 100, .rows = 30, .boot = .tty }, TestHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const r1 = try Replica.init(gpa, 1, first, true); + const r1 = try Replica.init(gpa, 1, first); defer r1.deinit(); - const r2 = try Replica.init(gpa, 2, first, true); + const r2 = try Replica.init(gpa, 2, first); defer r2.deinit(); a.core.view().active = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break id; @@ -4436,244 +3844,12 @@ test "a view that sized a terminal closing leaves nothing queued: the others' re try std.testing.expectEqual(digestOf(a), r1.digest()); } -test "a terminal sized again by a client's key: the step reads the grid it had, on both sides" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 50, .rows = 20, .boot = .tty }, TestHost.host(), true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.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.view().active = shell; - // History the replica holds as holes, of lines a narrow grid wraps in - // two, which a wider one unwraps. - var line: [96]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d:0>4} xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n", .{i}) } }); - r.confirm((try a.pending()).?); - // Out of terminal mode in the session's view, which sizes it; then a - // client's own view (a copy of it), wider: its first key sizes the - // terminal again, in that key's step (the soak's tty and window at two - // sizes, 2026-10-30: the client's replay read holes the session's step - // had read as text, and the fill came in the new grid's numbers). - r.confirm(try a.local(.{ .key = .{ .cp = 'b', .ctrl = true } })); - for ([_]u21{ 'g', 'g' }) |cp| r.confirm(try a.local(.{ .key = .{ .cp = cp, .text = &.{@intCast(cp)} } })); - const opened = try a.openView(1); - r.view = opened.view; - r.confirm(opened.unit); - try deliver(a, &screens, peer, r, .flush); - var sent: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (sent.items) |m| gpa.free(m); - sent.deinit(gpa); - } - const Step = struct { - fn take(au: *Authority, sc: *Screens, pe: u16, rr: *Replica, msg: []const u8) !void { - try deliver(au, sc, pe, rr, .flush); - const u = try std.testing.allocator.dupe(u8, try au.take(msg)); - defer std.testing.allocator.free(u); - try deliver(au, sc, pe, rr, .fill); - pardes.panes.resizeDeferred(au.core); - rr.confirm(u); - rr.settle(); - } - }; - try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .resize = .{ .cols = 120, .rows = 30 } }))); - try key(r, 'g', &sent); - try key(r, 'g', &sent); - for (sent.items) |m| try Step.take(a, &screens, peer, r, m); - for (sent.items) |m| gpa.free(m); - sent.clearRetainingCapacity(); - // The session's view types into it, which sizes it back (the client's - // copy of its history all holes again, a new numbering); then the - // client's key that reads all of it, and sizes it again. - try deliver(a, &screens, peer, r, .flush); - { - const was = Stepping.begin(&a.t, null); - a.core.toView(.at(0)); - a.core.update(.{ .key = .{ .cp = 'k', .text = "k" } }); - a.core.step(); - was.end(); - } - a.seq += 1; - const back = try gpa.dupe(u8, try a.unit(0, a.seq)); - defer gpa.free(back); - try deliver(a, &screens, peer, r, .fill); - pardes.panes.resizeDeferred(a.core); - r.confirm(back); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - try key(r, 'w', &sent); - try key(r, 'w', &sent); - for (sent.items) |m| try Step.take(a, &screens, peer, r, m); - try deliver(a, &screens, peer, r, .flush); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try std.testing.expectEqual(digestOf(a), r.digest()); -} - -test "pardes's own keys over a terminal's history apply at once: its view moves here, a delta while they wait puts them on top again, the authority's ends the same" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.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.view().active = shell; - r.confirm(try a.local(.{ .focus = true })); - var line: [64]u8 = undefined; - for (0..200) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "history line {d}\r\n", .{i}) } }); - r.confirm((try a.pending()).?); - try deliver(a, &screens, peer, r, .flush); - r.settle(); - var sent: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (sent.items) |m| gpa.free(m); - sent.deinit(gpa); - } - // Normal mode in the shell, up a few rows, then half a screen and more: - // the cursor leaves the view, and the view follows it back. - const keys = [_]pardes.Key{ - .{ .cp = a.core.opts.tty_toggle, .ctrl = true }, .{ .cp = 'k', .text = "k" }, .{ .cp = 'k', .text = "k" }, - .{ .cp = 'u', .ctrl = true }, .{ .cp = 'u', .ctrl = true }, .{ .cp = 'k', .text = "k" }, - }; - for (keys) |k| try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = k }))); - try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); - try std.testing.expectEqual(sent.items.len, r.applied); - const here = r.core().panes[shell].?; - try std.testing.expect(pardes.Term.grid(here.terminal).view != null); - // The shell prints while they wait: its unit, then its delta, which - // sets the view the authority's (at the bottom still): what was applied - // goes on top of it again. - for (0..5) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "late line {d}\r\n", .{i}) } }); - r.confirm((try a.pending()).?); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - r.settle(); - try std.testing.expectEqual(sent.items.len, r.applied); - try std.testing.expect(pardes.Term.grid(r.core().panes[shell].?.terminal).view != null); - // The authority takes them in order, the terminal sent before each and - // the rows its step read after, as the session's loop does. - for (sent.items) |m| { - try deliver(a, &screens, peer, r, .flush); - r.settle(); - const u = try gpa.dupe(u8, try a.take(m)); - defer gpa.free(u); - try deliver(a, &screens, peer, r, .fill); - r.confirm(u); - r.settle(); - } - try deliver(a, &screens, peer, r, .flush); - r.settle(); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try std.testing.expectEqual(@as(u32, 0), r.stats.mispredicted); - try std.testing.expectEqual(digestOf(a), r.digest()); - try std.testing.expect(pardes.Term.grid(a.core.panes[shell].?.terminal).view != null); - try std.testing.expectEqual(pardes.Term.grid(a.core.panes[shell].?.terminal).view, pardes.Term.grid(r.core().panes[shell].?.terminal).view); - // A rollback with nothing confirmed on top puts the view back: one more - // key up, and another's unit first. - try sent.append(gpa, try gpa.dupe(u8, try r.input(.{ .key = .{ .cp = 'u', .ctrl = true } }))); - const before = pardes.Term.grid(a.core.panes[shell].?.terminal).view; - try std.testing.expect(pardes.Term.grid(r.core().panes[shell].?.terminal).view.? < before.?); - r.confirm(try a.local(.{ .focus = false })); - r.settle(); - const last = try gpa.dupe(u8, try a.take(sent.items[sent.items.len - 1])); - defer gpa.free(last); - r.toConfirmed(); - try std.testing.expectEqual(before, pardes.Term.grid(r.core().panes[shell].?.terminal).view); - r.dirty = true; - r.settle(); - try deliver(a, &screens, peer, r, .fill); - r.confirm(last); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - r.settle(); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try std.testing.expectEqual(digestOf(a), r.digest()); - try std.testing.expectEqual(pardes.Term.grid(a.core.panes[shell].?.terminal).view, pardes.Term.grid(r.core().panes[shell].?.terminal).view); -} - -test "a unit kept over a copy taken ahead is never replayed over a delta that came after it: the session's key read a shell's rows, the program redrew them" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.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.view().active = shell; - r.confirm(try a.local(.{ .focus = true })); - var line: [96]u8 = undefined; - for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "line {d} {s}\r\n", .{ i, "words of a length its own"[0 .. i % 20 + 4] }) } }); - r.confirm((try a.pending()).?); - try deliver(a, &screens, peer, r, .flush); - // Out of the shell's tty mode, in the session's view: keys over its text. - r.confirm(try a.local(.{ .key = .{ .cp = a.core.opts.tty_toggle, .ctrl = true } })); - r.settle(); - // The client idle: a copy taken ahead. The session's keys read the rows - // (up, to the line's end): replayed here over the copy, and kept. - r.ready(); - try std.testing.expect(r.copy.held); - for ([_]u21{ 'k', 'k', '$' }) |cp| { - const u = try gpa.dupe(u8, try a.local(.{ .key = .{ .cp = cp, .text = &.{@intCast(cp)} } })); - defer gpa.free(u); - try deliver(a, &screens, peer, r, .fill); - r.confirm(u); - r.settle(); - } - // The program redraws the screen: other rows where those keys read. - a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[H\x1b[2J" } }); - for (0..30) |i| a.output(.{ .output = .{ .pane = .at(shell), .bytes = try std.fmt.bufPrint(&line, "{d}\r\n", .{i}) } }); - r.confirm((try a.pending()).?); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - // The client types, and the session's key comes first: a rollback, which - // must not replay the keys that read the rows over the redrawn ones. - var sent: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (sent.items) |m| gpa.free(m); - sent.deinit(gpa); - } - try key(r, 'h', &sent); - try std.testing.expectEqual(@as(usize, 1), r.applied); - { - const u = try gpa.dupe(u8, try a.local(.{ .key = .{ .cp = '0', .text = "0" } })); - defer gpa.free(u); - try deliver(a, &screens, peer, r, .fill); - r.confirm(u); - r.settle(); - } - try deliver(a, &screens, peer, r, .flush); - r.confirm(try a.take(sent.items[0])); - r.settle(); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try std.testing.expectEqual(digestOf(a), r.digest()); -} - test "a unit that closes or tears down a terminal is never kept over a copy taken ahead: a rollback would close its emulator again" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const text = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.file != null) break id; @@ -4738,9 +3914,9 @@ const BytesPair = struct { fn init() !BytesPair { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host()); errdefer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); var shell: ?pardes.Pane.Id = null; for (a.core.panes, 0..) |slot, id| if (slot) |pane| { if (pane.isTerminal()) shell = .at(id) else if (pane.file != null) a.core.view().active = @intCast(id); @@ -4958,7 +4134,7 @@ test "a Restore tells its clients so before it lets them go (each joins again, s fn post(l: *@This(), msg: Said) bool { switch (msg) { .refused => |w| l.words = w, - .unit, .screen, .blob => |b| std.heap.c_allocator.free(b), + .unit, .blob => |b| std.heap.c_allocator.free(b), .checked, .ended, .left => {}, } return true; @@ -5073,7 +4249,7 @@ fn firstOnPair(bytes: bool) !void { const core = try Pardes.init(gpa, opts); defer core.deinit(); core.host = .{ .ctx = &spawns, .vtable = &Spawns.vtable }; - var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "pair", .bytes = bytes, .detached = true }; + var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "pair", .bytes = true, .detached = true }; defer ps.deinit(); defer live_peers = null; defer ps.dropAll(core); @@ -5123,7 +4299,7 @@ fn firstOnPair(bytes: bool) !void { } else return error.NoShell; core.update(.{ .output = .{ .pane = .at(shell), .bytes = "first$ " } }); ps.boundary(core); - // Its check, answered after every unit and terminal message before it. + // Its check, answered after every unit before it. try std.testing.expect(askCheck(j.fd)); while (!ps.mail.load(.acquire)) std.Thread.yield() catch {}; ps.boundary(core); @@ -5134,9 +4310,6 @@ fn firstOnPair(bytes: bool) !void { fn take(t: *@This(), tag: u8, payload: []const u8) bool { switch (std.enums.fromInt(wire.ServerTag, tag) orelse return false) { .unit => t.r.confirm(payload), - .screen => if (t.r.screen(payload)) |reply| { - _ = sendScreen(t.fd, reply); - }, .check => { t.digest = (wire.decodeServer(tag, payload) catch return false).check; return false; @@ -5357,7 +4530,7 @@ test "bytes: a kitty image shown by a file, a temporary file or shared memory is test "a replica joined from the session's dump replays the units after it" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); _ = try a.local(.{ .key = .{ .cp = 'j', .text = "j" } }); const was = Stepping.begin(&a.t, null); @@ -5393,7 +4566,7 @@ test "a replica joined from a dump replays a step that opens a file's pane and s // No rows for a second pane: the Look's pane of a kind is made, the // placement says it has no room (a message in the step that made the // pane, which was not in /log yet), and the pane goes. - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 5, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 5, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const zon = pardes.Kind.loadedOf(&Zon.ops, "/x/zon.so", @splat(9), &words); @@ -5427,7 +4600,7 @@ const Zon = struct { test "a replica joined from a themed dump paints its taglines in the restored theme" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host()); defer a.deinit(); _ = try a.local(.{ .command = "Theme rose_pine_moon" }); const was = Stepping.begin(&a.t, null); @@ -5460,7 +4633,7 @@ test "a host's Adopt and a terminal reader's failure are inputs: a replica makes if (pardes.Term.ops == null) return error.SkipZigTest; // a shell, opened by a key const gpa = std.testing.allocator; // Its terminals as screen state, as a session's for its clients are. - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const was = Stepping.begin(&a.t, null); const bytes = try pardes.dump.dumpBytes(a.core); @@ -5486,7 +4659,7 @@ test "a host's Adopt and a terminal reader's failure are inputs: a replica makes test "a join's dump, its blobs put back where they go, is the session's dump" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const text = try gpa.alloc(u8, 20000); defer gpa.free(text); @@ -5612,7 +4785,7 @@ test "a far join is sent each blob once: joined again with them on disk or in th const io = std.testing.io; zstd.gpa = gpa; defer zstd.gpa = std.heap.c_allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const text = try gpa.alloc(u8, 30000); defer gpa.free(text); @@ -5707,7 +4880,7 @@ test "a far join is sent each blob once: joined again with them on disk or in th test "a replica joined after a pane closed: the session's jump to it, its Panes and Recent rows, asked by either" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); // A file looked at and closed: a jump to it, Recent's, a closed pane. var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; @@ -5759,7 +4932,7 @@ test "a replica joined after a pane closed: the session's jump to it, its Panes test "a replica's Del of a file its session's Recent knows asks the host what the session asked" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined; @@ -5778,11 +4951,11 @@ test "a replica's Del of a file its session's Recent knows asks the host what th test "a client leaves, and one joins: what the leave queued (a terminal's resize) is done in its unit, on every side, before the join's dump" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, PtyHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, PtyHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const old = try Replica.init(gpa, 1, first, true); + const old = try Replica.init(gpa, 1, first); defer old.deinit(); // A second client, bigger, types into the terminal: it sizes it. const opened = try a.openView(2); @@ -5817,11 +4990,11 @@ test "a client leaves, and one joins: what the leave queued (a terminal's resize test "a client that diverged joins again for its view: kept for it meanwhile, its pane in it again; the other client agrees" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const first = try gpa.dupe(u8, try a.unit(0, 0)); defer gpa.free(first); - const old = try Replica.init(gpa, 1, first, false); + const old = try Replica.init(gpa, 1, first); defer old.deinit(); const opened = try a.openView(2); old.confirm(opened.unit); @@ -5961,9 +5134,9 @@ test "a client cut off for what it left unread is told why and joins again for i test "a client whose session's units come more than two seconds later than its quickest lets its link go, says so once, and joins again; its first unit after a join learns the clocks again" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); var fds: [2]c_int = undefined; if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &fds) != 0) return error.NoSocket; defer for (fds) |fd| { @@ -6061,7 +5234,7 @@ test "a client's writer, the client cut off while it waits on the socket, writes test "a client joined from a dump moves through another view's pane as the session does, its lines not wrapped" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host()); defer a.deinit(); // The first client's Wrap off (SPC t w), and its cursor down into the // file's long lines, near the bottom of its view. @@ -6090,7 +5263,7 @@ test "a client joined from a dump moves through another view's pane as the sessi test "a client joined from a dump makes a `/` query's rows as the session does, though only the session has drawn its owner" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host()); defer a.deinit(); // The session draws: its owner's colours painted for the view (File.refreshHighlights). { @@ -6126,7 +5299,7 @@ test "a client joined from a dump asks a worker for a `/` query's colours as the }; const gpa = std.testing.allocator; // A view as tall as the text: the frame paints every line of it. - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 500, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 500, .file = "build.zig" }, .{ .vtable = &Paints.vtable }); defer a.deinit(); { const was = Stepping.begin(&a.t, null); @@ -6156,7 +5329,7 @@ test "a client joined from a dump asks a worker for a `/` query's colours as the const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .search = search }; }; const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &Paints.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &Paints.vtable }); defer a.deinit(); { const p = a.core; @@ -6177,49 +5350,11 @@ test "a client joined from a dump asks a worker for a `/` query's colours as the } } -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 (pardes.Term.ops == null) return error.SkipZigTest; // a shell - 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.view().active = shell; - var line: [64]u8 = undefined; - for (0..60) |i| a.output(.{ .output = .{ .pane = .at(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); -} - test "a replica with no code for a kind whose state is not plain shows its pane as a line saying so, and its keys go to the authority" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); // What the host read off the library, as the `addon` event: the // replica's core takes the kind's words, never its code. @@ -6277,9 +5412,9 @@ const Placed = struct { test "a kind's place moved in a step of another view's: a replica's key that reads it guesses the authority's" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); @@ -6333,7 +5468,7 @@ const Jobber = struct { test "a client joined from a dump numbers a kind's next job as the session does" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + 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 jobber = pardes.Kind.loadedOf(&Jobber.ops, "/x/jobber.so", @splat(7), &words); @@ -6350,9 +5485,9 @@ test "a client joined from a dump numbers a kind's next job as the session does" test "a replica's word that opens a kind's pane with no file waits for the authority's open: never mispredicted" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); @@ -6371,7 +5506,7 @@ test "a replica's word that opens a kind's pane with no file waits for the autho test "a client joined from a dump tells a kind each view's facts as the session does, the live one's and another's" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + 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 placed = pardes.Kind.loadedOf(&Placed.ops, "/x/placed.so", @splat(7), &words); @@ -6441,10 +5576,10 @@ const BusyHost = struct { 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); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &BusyHost.vtable }); defer a.deinit(); BusyHost.core = a.core; - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); var words: [64]pardes.Kind.LoadedWord = undefined; const asker = pardes.Kind.loadedOf(&Asker.ops, "/x/asker.so", @splat(7), &words); @@ -6465,9 +5600,9 @@ test "a kind's job answered at once inside its host's call (no worker free) is t test "a closed terminal with a kitty image brought back on a client: its image drawn under a speculation, rolled back by another's unit, is drawn again from what the emulator holds" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host()); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -6539,40 +5674,35 @@ fn partsApart(a: *Authority, r: *Replica, arena: std.mem.Allocator) ![]const u8 return if (std.mem.eql(u64, w, g)) "" else tape.partsDiffer(g, w, arena); } -test "a terminal's program shows a kitty image under screen state: the client's emulator never has it, and its tag says what the session's does" { +test "a terminal's program shows a kitty image: the client's emulator has it as the session's does, and its tag says what the session's does" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, TestHost.host()); defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); } else return error.NoShell; - try deliver(a, &screens, peer, r, .flush); try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); - // In the session's order: the pump's unit, then what its terminals came - // to; then a step after both, on every side. + // In the session's order: the pump's unit, its bytes fed on every side; + // then a step after it. a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b_Ga=T,i=7,f=24,s=2,v=2;ESIzESIzESIzESIz\x1b\\" } }); r.confirm((try a.pending()).?); r.settle(); - try deliver(a, &screens, peer, r, .flush); r.confirm(try a.local(.{ .focus = true })); r.settle(); try std.testing.expect(pardes.Term.hasImages(a.core.panes[shell].?.terminal)); - try std.testing.expect(!pardes.Term.hasImages(r.core().panes[shell].?.terminal)); + try std.testing.expect(pardes.Term.hasImages(r.core().panes[shell].?.terminal)); try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); try agrees(a, r); const prefix = try pardes.tagline.prefixIn(r.core(), arena.allocator(), r.core().panes[shell].?); try std.testing.expect(std.mem.indexOf(u8, prefix, " petscii:") != null); } -test "a command typed into a shell with prompt marks under screen state: every side notes it as the session's emulator numbers it, and Kill finds it" { +test "a command typed into a shell with prompt marks: every side notes it as its own emulator, fed the same bytes, numbers it, and Kill finds it" { if (pardes.Term.ops == null) return error.SkipZigTest; // a shell const gpa = std.testing.allocator; var arena: std.heap.ArenaAllocator = .init(gpa); @@ -6584,12 +5714,9 @@ test "a command typed into a shell with prompt marks under screen state: every s fn write(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .tty_taken = taken, .pty_write = write }; }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &ShellHost.vtable }, true); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &ShellHost.vtable }); defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -6599,7 +5726,6 @@ test "a command typed into a shell with prompt marks under screen state: every s a.output(.{ .output = .{ .pane = .at(shell), .bytes = prompt ++ "ls\r\n\x1b]133;C;aid=pardes\x07a b\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt } }); r.confirm((try a.pending()).?); r.settle(); - try deliver(a, &screens, peer, r, .flush); a.core.view().active = shell; r.confirm(try a.local(.{ .focus = true })); r.settle(); @@ -6607,7 +5733,7 @@ test "a command typed into a shell with prompt marks under screen state: every s // Exec'd in the shell: typed at its prompt, the command noted. r.confirm(try a.local(.{ .command = "Exec sleep 9" })); r.settle(); - // Its marks cross with the cells (Term.marksOf): numbered alike. + // Its marks are its bytes' on every side: numbered alike. try std.testing.expectEqual(@as(u32, 2), a.core.panes[shell].?.sent_command.?.seq); try std.testing.expectEqual(@as(u32, 2), r.core().panes[shell].?.sent_command.?.seq); try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); @@ -6615,7 +5741,6 @@ test "a command typed into a shell with prompt marks under screen state: every s a.output(.{ .output = .{ .pane = .at(shell), .bytes = "sleep 9\r\n\x1b]133;C;aid=pardes\x07" } }); r.confirm((try a.pending()).?); r.settle(); - try deliver(a, &screens, peer, r, .flush); r.confirm(try a.local(.{ .command = "Kill" })); r.settle(); try std.testing.expectEqualStrings("", try partsApart(a, r, arena.allocator())); @@ -6680,7 +5805,6 @@ test "a step of the session's own that reads a terminal right after its output, var at: usize = 0; while (try wire.framed(from.out.items[at..])) |m| : (at += m.total) l.take(switch (std.enums.fromInt(wire.ServerTag, m.tag).?) { .unit => .{ .unit = try std.heap.c_allocator.dupe(u8, m.payload) }, - .screen => .{ .screen = try std.heap.c_allocator.dupe(u8, m.payload) }, else => return error.UnexpectedFrame, }); from.out.clearRetainingCapacity(); @@ -6711,7 +5835,7 @@ test "a step of the session's own that reads a terminal right after its output, test "a far client's own Del of a pane whose kind's state is not plain, rolled back by another's unit: the pane comes back whole, and is closed again with the session's order" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + 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 counter = pardes.Kind.loadedOf(&Counter.ops, "/x/counter.so", @splat(7), &words); @@ -6792,7 +5916,7 @@ const SeenHost = struct { test "a client's step that asks the session's host for something that returns nothing goes on at once, and the session's unit confirms it: nothing rolled back" { const gpa = std.testing.allocator; var h: SeenHost = .{}; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host()); defer a.deinit(); h.core = a.core; const r = try joinedFresh(a); @@ -6812,7 +5936,7 @@ test "a client's step that asks the session's host for something that returns no test "a client's step whose session's host says something into the core during the call it made: its speculation rolled back, then the session's state" { const gpa = std.testing.allocator; var h: SeenHost = .{ .tell = true }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host()); defer a.deinit(); h.core = a.core; const r = try joinedFresh(a); @@ -6835,7 +5959,7 @@ test "a client's ThemeFile waits for the session, whose host loads the file into const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; var line: [std.Io.Dir.max_path_bytes + 16]u8 = undefined; var h: SeenHost = .{}; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host()); defer a.deinit(); h.core = a.core; const r = try joinedFresh(a); @@ -6855,7 +5979,7 @@ test "a client's ThemeFile waits for the session, whose host loads the file into test "a client's yank and paste of the system clipboard are its own frontend's: its view counts them, at once and as the session does, and the session's host is asked neither" { const gpa = std.testing.allocator; var h: SeenHost = .{}; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host()); defer a.deinit(); h.core = a.core; _ = try a.unit(0, 0); @@ -6888,7 +6012,7 @@ test "a client's yank and paste of the system clipboard are its own frontend's: test "a client's own Zerox and Del of a file pane are instant: what Recent keeps of the file is what its open learned, not a question to the disk; Recent has its place as the session's always did" { const gpa = std.testing.allocator; var h: SeenHost = .{}; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, h.host()); defer a.deinit(); h.core = a.core; var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; @@ -6931,7 +6055,7 @@ const Still = struct { test "a client's n in a kind's pane is a motion: it steps to the next place a result row holds at once, asking the disk nothing of words that might name files" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; const dir = std.mem.span(@as([*:0]u8, @ptrCast(std.c.getcwd(&cwd, cwd.len) orelse return error.NoCwd))); @@ -7255,7 +6379,7 @@ const Walk = struct { test "a far client's every word and key, on a file's pane, a kind's and a shell's, and the gestures between them beside a shell that asked for focus events: what waits is in may_wait, with why, and nothing else waits" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, FullHost.host(), true); + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, FullHost.host()); defer a.deinit(); var cwd: [std.Io.Dir.max_path_bytes]u8 = undefined; var line: [std.Io.Dir.max_path_bytes + 32]u8 = undefined; @@ -7296,13 +6420,9 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' a.core.view().active = id; _ = a.local(.{ .key = .{ .cp = a.core.opts.tty_toggle, .ctrl = true } }) catch {}; }; - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); const r = try joinedFresh(a); defer r.deinit(); r.core().kinds.ops[r.core().kinds.byName("still").?] = &Still.ops; - try deliver(a, &screens, peer, r, .flush); r.settle(); try std.testing.expectEqual(id, r.core().view().active); if (on == .shell) try std.testing.expect(pardes.Term.modes(r.core().panes[id].?.terminal).focus); @@ -7384,7 +6504,7 @@ test "a far client's click into a shell whose program asked for focus events is const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; }; Told.len = 0; - const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }); defer a.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -7392,12 +6512,8 @@ test "a far client's click into a shell whose program asked for focus events is a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; _ = try a.local(.{ .command = "New" }); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); const r = try joinedFresh(a); defer r.deinit(); - try deliver(a, &screens, peer, r, .flush); r.settle(); Told.len = 0; const rect = r.core().view().rects[shell]; @@ -7411,10 +6527,8 @@ test "a far client's click into a shell whose program asked for focus events is try std.testing.expectEqual(@as(u32, 0), r.stats.stopped); try std.testing.expectEqual(@as(usize, shell), r.core().view().active); for (sent.items) |m| { - try deliver(a, &screens, peer, r, .flush); const u = try gpa.dupe(u8, try a.take(m)); defer gpa.free(u); - try deliver(a, &screens, peer, r, .fill); r.confirm(u); r.settle(); } @@ -7426,7 +6540,7 @@ test "a far client's click into a shell whose program asked for focus events is test "a far client's own Look of ~/x, bare Shell and a word that runs in the session's directory read the session's facts: its speculation asks its own machine's environment nothing" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const r = try joinedFresh(a); defer r.deinit(); @@ -7464,7 +6578,7 @@ test "a far client's replay of the session's DumpDir takes the session's answer // The session's machine: a directory it may not write in. if (std.c.mkdir(ro, 0o500) != 0) return error.NoDir; defer _ = std.c.chmod(ro, 0o700); - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host()); defer a.deinit(); const r = try joinedFresh(a); defer r.deinit(); @@ -7522,7 +6636,7 @@ test "a far client's replay of the session's Fonts and Font takes the session's if (fonts.list(arena.allocator(), null).len == session_faces and client_named.len > 0 and std.mem.eql(u8, client_named[0].path, session_first)) return error.SkipZigTest; _ = Shell.setenv("HOME", session_home, 1); // A window's view: the font words are a window's. - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .windowed = true }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml", .windowed = true }, TestHost.host()); defer a.deinit(); const r = try joinedFresh(a); defer r.deinit(); @@ -7545,7 +6659,7 @@ test "a far client's replay of the session's Fonts and Font takes the session's // cover; an answer let go (not quiet then) covers nothing. test "an idle client's check answered covers the units that came while it was asked: it asks no other until something changes" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host()); defer a.deinit(); const r = try joinedNow(a, 1, 0); defer r.deinit(); @@ -7594,7 +6708,7 @@ test "an idle client's check answered covers the units that came while it was as // to look at, at its own focus-in (upgrade.noticeNewer). test "a far client's window found again is instant: its refocus asks the session's host nothing, and the session's unit confirms it" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, FullHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, FullHost.host()); defer a.deinit(); const r = try joinedFresh(a); defer r.deinit(); @@ -7643,7 +6757,7 @@ const Pointed = struct { // client's speculation). test "a far client's drag in a kind's pane it grabbed, the pane since too short for a row of body: the kind is told its edge, at once and as on the session" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + 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 pointed = pardes.Kind.loadedOf(&Pointed.ops, "/x/pointed.so", @splat(8), &words); @@ -7744,7 +6858,7 @@ test "a far client's frame drawn under a speculation that rolls back asks a pict } }; const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, TestHost.host(), false); + 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 drawn = pardes.Kind.loadedOf(&Drawn.ops, "/x/drawn.so", @splat(9), &words); @@ -7804,7 +6918,7 @@ test "a far client's click into a shell whose queue is backed up: the session's } const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .pty_write = write }; }; - const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }, true); + const a = try Authority.init(gpa, .{ .cols = 120, .rows = 40, .boot = .tty }, .{ .vtable = &Told.vtable }); defer a.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -7812,12 +6926,8 @@ test "a far client's click into a shell whose queue is backed up: the session's a.output(.{ .output = .{ .pane = .at(shell), .bytes = "\x1b[?1004h$ " } }); _ = (try a.pending()).?; _ = try a.local(.{ .command = "New" }); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); const r = try joinedFresh(a); defer r.deinit(); - try deliver(a, &screens, peer, r, .flush); r.settle(); // A 9P write into the shell, past the ring: the rest parked, on both. const big = try gpa.alloc(u8, pardes.memory.limits.effect_cap * pardes.effect_write_cap + 100); @@ -7848,10 +6958,8 @@ test "a far client's click into a shell whose queue is backed up: the session's try std.testing.expectEqual(@as(usize, 0), r.applied); for (r.stats.stops) |st| if (st.n > 0) try std.testing.expectEqualStrings("pty_write", st.name); for (sent.items) |m| { - try deliver(a, &screens, peer, r, .flush); const u = try gpa.dupe(u8, try a.take(m)); defer gpa.free(u); - try deliver(a, &screens, peer, r, .fill); r.confirm(u); r.settle(); } @@ -7912,7 +7020,7 @@ test "a client joined from a dump makes a `/` query's rows as the session does, } }; const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &WorkerSearch.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, .{ .vtable = &WorkerSearch.vtable }); defer a.deinit(); WorkerSearch.init(a); defer WorkerSearch.q.deinit(); @@ -7939,7 +7047,7 @@ test "a client joined from a dump makes a `/` query's rows as the session does, // elsewhere on a core that drew than on one that did not. test "a client joined from a dump lands a click on a rail's tick as the session does, the session's ticks drawn before the places changed" { const gpa = std.testing.allocator; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host(), false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "build.zig" }, TestHost.host()); defer a.deinit(); _ = try a.local(.{ .command = "Search /pub" }); const owner: usize = 0; @@ -8006,7 +7114,7 @@ test "a far client's step that asks for a search goes on at once, and a session const dir = dir_buf[0..try tmp.dir.realPath(std.testing.io, &dir_buf)]; var path_buf: [std.Io.Dir.max_path_bytes + 8]u8 = undefined; const path = try std.fmt.bufPrint(&path_buf, "{s}/a.zig", .{dir}); - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = path }, .{ .vtable = &LoopSearch.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = path }, .{ .vtable = &LoopSearch.vtable }); defer a.deinit(); LoopSearch.core = a.core; const r = try joinedFresh(a); @@ -8053,7 +7161,7 @@ test "a far client's replay of a message its session's host stamped takes the se const was = if (std.c.getenv("PARDES_NOTIME")) |v| try gpa.dupeSentinel(u8, std.mem.span(v), 0) else null; defer if (was) |v| gpa.free(v); defer _ = if (was) |v| Shell.setenv("PARDES_NOTIME", v, 1) else @import("dev").host_io.testUnsetenv("PARDES_NOTIME"); - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &Stamping.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &Stamping.vtable }); defer a.deinit(); Stamping.core = a.core; const r = try joinedFresh(a); @@ -8082,9 +7190,9 @@ test "a client joined from a dump takes a 9P pty/run in a shell as the session d fn write(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .tty_taken = taken, .pty_write = write }; }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &RunHost.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &RunHost.vtable }); defer a.deinit(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const shell: u8 = for (a.core.panes, 0..) |slot, id| { if (slot) |pane| if (pane.isTerminal()) break @intCast(id); @@ -8146,158 +7254,6 @@ test "a client joined from a dump takes a 9P pty/run in a shell as the session d try agrees(a, late); } -// The same run with the terminals crossing as screen state (a session's -// clients', until the switch to bytes): a replica's emulator is the -// deltas', its marks not the session's. -test "a client of screen-state terminals takes a 9P pty/run in a shell as the session does" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const RunHost = struct { - fn taken(_: ?*anyopaque, _: pardes.Pane.Id) bool { - return false; - } - fn write(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} - const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .tty_taken = taken, .pty_write = write }; - }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &RunHost.vtable }, true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.deinit(); - const shell: u8 = for (a.core.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.isTerminal()) break @intCast(id); - } else return error.NoShell; - const Step = struct { - var second: ?*Replica = null; - fn take(s: *Authority, sc: *Screens, p: u16, x: *Replica, u: []const u8) !void { - const gpa_ = std.testing.allocator; - const kept = try gpa_.dupe(u8, u); - defer gpa_.free(kept); - // The unit first, its screens at the frame after (Peers). - x.confirm(kept); - x.settle(); - if (second) |y| { - y.confirm(kept); - y.settle(); - } - try deliver(s, sc, p, x, .flush); - if (second) |y| try deliver(s, sc, p + 1, y, .flush); - } - fn serve(s: *Authority, sc: *Screens, p: u16, x: *Replica, req: pardes.ctlfs.Req) !pardes.ctlfs.Reply { - const was = Stepping.begin(&s.t, null); - const reply = s.core.serveFs(req); - s.core.pump(s.host) catch {}; - was.end(); - s.seq += 1; - try take(s, sc, p, x, try s.unit(0, s.seq)); - return reply; - } - fn output(s: *Authority, sc: *Screens, p: u16, x: *Replica, pane: u8, bytes: []const u8) !void { - s.output(.{ .output = .{ .pane = .at(pane), .bytes = bytes } }); - try take(s, sc, p, x, (try s.pending()).?); - } - }; - const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - try Step.output(a, &screens, peer, r, shell, prompt ++ "ls\r\n\x1b]133;C;aid=pardes\x07a b\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt); - // A second client joins now, from the session's dump. - const joined = (try a.join(2, null)).?; - defer gpa.free(joined.dump); - try Step.take(a, &screens, peer, r, joined.unit); - const late = try Replica.initDump(gpa, 2, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); - defer late.deinit(); - const peer2 = try screens.addPeer(); - try deliver(a, &screens, peer2, late, .flush); - Step.second = late; - defer Step.second = null; - const node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_run); - for (0..2) |_| { - const h = (try Step.serve(a, &screens, peer, r, .{ .tag = 1, .op = .open, .node = node, .omode = 2 })).handle; - _ = try Step.serve(a, &screens, peer, r, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "true\n" }); - try Step.output(a, &screens, peer, r, shell, "true\r\n\x1b]133;C;aid=pardes\x07\x1b]133;D;0;aid=pardes\x07" ++ prompt); - const answer = try Step.serve(a, &screens, peer, r, .{ .tag = 3, .op = .read, .node = node, .handle = h, .size = 64 }); - try std.testing.expectEqualStrings("exit 0\n", a.core.fsPayload(answer)); - _ = try Step.serve(a, &screens, peer, r, .{ .tag = 4, .op = .release, .node = node, .handle = h, .opened = true }); - } - try agrees(a, r); - try agrees(a, late); -} - -// daemon.py --clients' client C (2026-11-20): idle, a copy taken ahead; the -// session's script opens pty/run and its command prints, replayed over the -// copy and kept; the client types into the shell, its speculation stops at -// the pty write, and the rollback replays the open again over a record the -// copy never held (it holds the opens as far as `opens_len`), whose line -// and output the epoch had freed: freed again there, the client's C heap -// was corrupt. -test "a 9P open the session made over a copy taken ahead, replayed after a rollback: the record past the opens the copy holds is written over, never freed again" { - if (pardes.Term.ops == null) return error.SkipZigTest; // a shell - const gpa = std.testing.allocator; - const RunHost = struct { - fn taken(_: ?*anyopaque, _: pardes.Pane.Id) bool { - return false; - } - fn write(_: ?*anyopaque, _: pardes.Pane.Id, _: []const u8) void {} - const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .tty_taken = taken, .pty_write = write }; - }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &RunHost.vtable }, true); - defer a.deinit(); - var screens: Screens = .init(gpa); - defer screens.deinit(a.core); - const peer = try screens.addPeer(); - const r = try Replica.init(gpa, 1, try a.unit(0, 0), true); - defer r.deinit(); - const shell: u8 = for (a.core.panes, 0..) |slot, id| { - if (slot) |pane| if (pane.isTerminal()) break @intCast(id); - } else return error.NoShell; - const prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; - a.output(.{ .output = .{ .pane = .at(shell), .bytes = prompt } }); - r.confirm((try a.pending()).?); - try deliver(a, &screens, peer, r, .flush); - r.ready(); - try std.testing.expect(r.copy.held and r.core().fs.opens_len == 0); - const node = pardes.ctlfs.Node.of(a.core.panes[shell].?.serial, .pty_run); - const Serve = struct { - fn serve(s: *Authority, x: *Replica, req: pardes.ctlfs.Req) !pardes.ctlfs.Reply { - const was = Stepping.begin(&s.t, null); - const reply = s.core.serveFs(req); - s.core.pump(s.host) catch {}; - was.end(); - s.seq += 1; - const u = try std.testing.allocator.dupe(u8, try s.unit(0, s.seq)); - defer std.testing.allocator.free(u); - x.confirm(u); - x.settle(); - return reply; - } - }; - const h = (try Serve.serve(a, r, .{ .tag = 1, .op = .open, .node = node, .omode = 2 })).handle; - _ = try Serve.serve(a, r, .{ .tag = 2, .op = .write, .node = node, .handle = h, .data = "echo x\n" }); - a.output(.{ .output = .{ .pane = .at(shell), .bytes = "echo x\r\n\x1b]133;C;aid=pardes\x07x\r\n\x1b]133;D;0;aid=pardes\x07" ++ prompt } }); - r.confirm((try a.pending()).?); - r.settle(); - // Kept over the copy: the record past its opens holds the run's output. - try std.testing.expect(r.copy.held and r.since.items.len > 0); - try std.testing.expectEqualStrings("x\n", r.core().fs.opens[h - 1].what.run.output); - var sent: std.ArrayListUnmanaged([]u8) = .empty; - defer { - for (sent.items) |m| gpa.free(m); - sent.deinit(gpa); - } - // A key into the shell: its speculation stops at the pty write, and - // the copy is put back, the units since replayed (the open again). - try key(r, 'e', &sent); - try std.testing.expect(r.applied == 0 and r.stats.stopped > 0); - r.confirm(try a.take(sent.items[0])); - r.settle(); - try deliver(a, &screens, peer, r, .flush); - _ = try Serve.serve(a, r, .{ .tag = 3, .op = .release, .node = node, .handle = h, .opened = true }); - if (r.diverged) |why| std.debug.print("diverged: {s}\n", .{why}); - try std.testing.expect(r.diverged == null and r.quiet()); - try agrees(a, r); -} - test "a script's half line held over a copy taken ahead, its next write run and its rest moved to the front in place, put back by a rollback: the line replayed is the session's" { var n = try NinepJoin.init("one\n", TestHost.host()); defer n.deinit(); @@ -8341,7 +7297,7 @@ test "a far client's Del with panes above and below is applied at once, and its } const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .now = now }; }; - const a = try Authority.init(gpa, .{ .cols = 80, .rows = 30, .file = "mise.toml" }, .{ .vtable = &Clocked.vtable }, false); + const a = try Authority.init(gpa, .{ .cols = 80, .rows = 30, .file = "mise.toml" }, .{ .vtable = &Clocked.vtable }); defer a.deinit(); _ = try a.local(.{ .command = "New" }); const mid = a.core.view().active; @@ -8393,7 +7349,7 @@ const NinepJoin = struct { serial: u32, fn init(text: []const u8, host: pardes.Host) !NinepJoin { - const a = try Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, host, false); + const a = try Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, host); errdefer a.deinit(); const was = Stepping.begin(&a.t, null); const pane = try a.core.setTestFile(text); @@ -8691,7 +7647,7 @@ const RunJoin = struct { /// The session at its shell's first prompt, and the shell's slot. fn init(n: *NinepJoin) !u8 { - const a = try Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &vtable }, false); + const a = try Authority.init(std.testing.allocator, .{ .cols = 80, .rows = 24, .boot = .tty }, .{ .vtable = &vtable }); n.* = .{ .a = a, .serial = 0 }; _ = try a.unit(0, 0); const shell: u8 = for (a.core.panes, 0..) |slot, id| { diff --git a/core/root.zig b/core/root.zig index e29e70d8..66630b2d 100644 --- a/core/root.zig +++ b/core/root.zig @@ -632,7 +632,7 @@ const machine_lines = [_]struct { []const u8, usize, []const u8 }{ .{ "jj.zig", 11, "jj run under tape.site(.jj) on an io of its own (the tape's spawns nothing) with this process's environment, the signal mask cleared as Stream's children's: the session's, a replica replays its answer; or on a worker for `Changes`, its answer an input, with the wall clock it was made at (tape.value(.clock) on the loop) for its descriptions' ages; a test's shell inbox (dev)" }, .{ "look.zig", 6, "openLink's fork (the host's: a view's frontend opens a link) and a remote's error name" }, .{ "memory.zig", 7, "the memory regions themselves (mmap, madvise, their locks)" }, - .{ "replica.zig", 76, "the client and session engines: sockets, threads, clocks, the blob cache, traces" }, + .{ "replica.zig", 74, "the client and session engines: sockets, threads, clocks, the blob cache, traces" }, .{ "rollback.zig", 1, "a test helper's directory" }, .{ "root.zig", 4, "dev's modules re-exported (host_io, file_watch, glide, fonts)" }, .{ "selection_pipe.zig", 14, "a pipe's child processes and their files: the host's `pipe` entry" }, diff --git a/core/tape.zig b/core/tape.zig index f231831d..5056f225 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -1153,7 +1153,8 @@ fn tagOf(comptime entry: anytype, comptime Made: type) [:0]const u8 { /// The entries that answer stop by nature: the answer is the session's. const keeps_stopping = [_]Host.Fn{ // A shell's input: a device by the user's line (a far shell may feel - // like ssh), and off the tape with screen-state terminals. + // like ssh; core/echo.zig predicts its echo), and off the tape outside + // a speculation. .pty_write, // Its host says into the core on every call that the shell started // and where (host_io.forkShell: acknowledgeShell, setCwd), and gives @@ -1197,8 +1198,10 @@ fn hostCall(t: *Tape, p: *const Pardes, comptime f: Host.Fn, args: Host.Args(f)) const R = Host.Ret(f); const name = @tagName(f); // A terminal's answers and what is typed at it from its output are the - // authority's to write, never a replica's: off the tape on both sides. - if (comptime std.mem.eql(u8, name, "pty_write")) if (t.screen_state and !t.speculating) { + // authority's to write, never a replica's: off the tape on both sides + // (a replica's replay of the step writes nothing, and checks nothing: + // a write returns nothing a step reads). + if (comptime std.mem.eql(u8, name, "pty_write")) if (!t.speculating) { if (!t.replay) _ = p.host.call(f, args); return; }; @@ -1832,11 +1835,11 @@ test "a core pumped twice with one host and once with another: which functions i const R = pardes.replica; var first: Pumped = .{ .ns = 0 }; var second: Pumped = .{ .ns = 1 << 40 }; - const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{ .ctx = &first, .vtable = &Pumped.one }, false); + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24 }, .{ .ctx = &first, .vtable = &Pumped.one }); defer a.deinit(); const boot = Pumped.said(a.t.buf.items); try std.testing.expectEqual(Host.mask(.{ .vtable = &Pumped.one }), boot.mask); - const r = try R.Replica.init(gpa, 1, try a.unit(0, 0), false); + const r = try R.Replica.init(gpa, 1, try a.unit(0, 0)); defer r.deinit(); const hosts = [_]Host{ .{ .ctx = &first, .vtable = &Pumped.one }, .{ .ctx = &second, .vtable = &Pumped.more } }; for (hosts, [_]usize{ 0, 1 }, 1..) |h, sets, seq| { |
