From 90ba0ef908dd65b322676f7a0f6edc5b7b976242 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 07:18:40 -0300 Subject: replica: the tests first: a client that joins a session holding a script's 9P state made before the join steps the request after it otherwise than its session, one test a group of the earlier audit's rows (reports/pardes-faults-3.md 1b), each a session with a file pane (or a shell) and its 9P server (NinepJoin: a request is the session's step, then its loop's pass; a client joined from the session's dump takes every unit after), on this base: an open of a pane's exec holding half a line ("Ne", then "w\n" after the join): unequal (the session made a pane); two writes of one open to a body, then Undo: unequal (the client's second write its own step); a ctl open's lock, another open's lock after the join: the session refused it, the client gave it the lock ("expected 1, found 2": no digest covered the lock); addr: unequal; limit: diverged ("the core called mtime where the tape has a done (0) (tape byte 78, in serve_fs)"); dot truncated, released after: unequal; two writes of one open to sel: unequal; nomark, then two opens' writes and Undo: unequal; noscroll, then a long write: unequal; a tag truncated, written after: unequal; a chorded exec told to an event reader, its record written back after: unequal; writes to a body held to go in as one edit (a host with a clock, the join before the pause): unequal; a pty/run's line sent before the join, its end after, then the open's next line: unequal (shell-test); a shell found to have no prompt marks before the join, a pty/run after: diverged ("the core called prompt where the tape has a done (0) (tape byte 112, in serve_fs)") (shell-test); the audit's /pager text and last line of a closed open are no fault: the join's step settles first (Core.zig openView and rejoinView), so no test; on this base tui core-test runs the nine without a shell, all failing (the two with one skip), shell-test all eleven failing (load 35-47) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- core/replica.zig | 325 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 325 insertions(+) (limited to 'core/replica.zig') diff --git a/core/replica.zig b/core/replica.zig index 3f92603c..50615fc0 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -6923,3 +6923,328 @@ test "a far client's Del with panes above and below is applied at once, and its try agrees(a, r); try std.testing.expectEqual(Clocked.now_ns + pardes.config.del_question_delay_ns, r.core().panes[mid].?.question_due_ns); } + +// ---- a client that joins a session with 9P work under way ---- +// +// A 9P request is an input every replica replays, so the state the 9P +// tree builds from the requests (the open records, each pane's `fs`) is +// a client's for everything after its join: what was made before it +// comes in the join's dump, or the client steps the next request +// otherwise than its session. + +/// A session with a file pane and its 9P server, and a client joined +/// from its dump (`join`) that takes every unit after. +const NinepJoin = struct { + a: *Authority, + late: ?*Replica = null, + 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); + errdefer a.deinit(); + const was = Stepping.begin(&a.t, null); + const pane = try a.core.setTestFile(text); + was.end(); + _ = try a.unit(0, 0); + return .{ .a = a, .serial = pane.serial }; + } + + fn deinit(n: *NinepJoin) void { + if (n.late) |r| r.deinit(); + n.a.deinit(); + } + + fn node(n: *const NinepJoin, file: pardes.ctlfs.PaneFile) u64 { + return pardes.ctlfs.Node.of(n.serial, file); + } + + /// One request as the session's 9P server serves it, a step of its + /// own, then (`pumped`) its loop's pass: a join can come between the + /// two, the session's loop being elsewhere. Its unit to the client. + fn serve(n: *NinepJoin, req: pardes.ctlfs.Req, pumped: bool) !pardes.ctlfs.Reply { + const a = n.a; + const was = Stepping.begin(&a.t, null); + const reply = a.core.serveFs(req); + if (pumped) a.core.pump(a.host) catch {}; + was.end(); + a.seq += 1; + try n.send(try a.unit(0, a.seq)); + return reply; + } + + /// A pass of the session's loop with no request: its unit. + fn pump(n: *NinepJoin) !void { + n.a.pump(); + try n.send((try n.a.pending()).?); + } + + fn send(n: *NinepJoin, u: []const u8) !void { + const r = n.late orelse return; + const kept = try std.testing.allocator.dupe(u8, u); + defer std.testing.allocator.free(kept); + r.confirm(kept); + r.settle(); + } + + /// A client joins now, from the session's dump, at the digest the + /// session had. + fn join(n: *NinepJoin) !void { + const joined = (try n.a.join(1, null)).?; + defer std.testing.allocator.free(joined.dump); + const r = try Replica.initDump(std.testing.allocator, 1, joined.view, joined.dump, .{ .cols = 80, .rows = 24 }); + r.t.screen_state = false; + r.core().echo = null; + n.late = r; + try std.testing.expectEqual(joined.digest, r.digest()); + } + + fn agree(n: *NinepJoin) !void { + try agrees(n.a, n.late.?); + } +}; + +test "a client joined while a script's open of a pane's exec holds half a line runs the line its session runs" { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const exec = n.node(.exec); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = exec, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = exec, .handle = h, .data = "Ne" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = exec, .handle = h, .data = "w\n" }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = exec, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined between two writes of one open to a body makes them one undo step, as its session does" { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const body = n.node(.body); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = body, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = body, .handle = h, .data = "a\n" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = body, .handle = h, .data = "b\n" }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true }, true); + _ = try n.serve(.{ .tag = 5, .op = .write, .node = n.node(.ctl), .data = "Undo" }, true); + try n.agree(); +} + +test "a client joined while a script's ctl open holds a pane's lock refuses another open's lock, as its session does" { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const ctl = n.node(.ctl); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = ctl, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = ctl, .handle = h, .data = "lock\n" }, true); + try n.join(); + const g = (try n.serve(.{ .tag = 3, .op = .open, .node = ctl, .omode = 1 }, true)).handle; + try std.testing.expectEqual(pardes.ctlfs.Status.err, (try n.serve(.{ .tag = 4, .op = .write, .node = ctl, .handle = g, .data = "lock\n" }, true)).status); + // Who holds it, by name: on the base no digest covered it. + const id = n.a.core.paneBySerial(n.serial).?; + try std.testing.expectEqual(n.a.core.panes[id].?.fs.lock, n.late.?.core().panes[id].?.fs.lock); + try n.agree(); + _ = try n.serve(.{ .tag = 5, .op = .release, .node = ctl, .handle = g, .opened = true }, true); + _ = try n.serve(.{ .tag = 6, .op = .release, .node = ctl, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined after a script set a pane's addr, its limit, or truncated its dot writes where its session writes" { + // addr: the next data write replaces what it says. + { + var n = try NinepJoin.init("one two\nthree\n", TestHost.host()); + defer n.deinit(); + _ = try n.serve(.{ .tag = 1, .op = .write, .node = n.node(.addr), .data = "/two/" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 2, .op = .write, .node = n.node(.data), .data = "2" }, true); + try n.agree(); + } + // limit: an address is looked for inside it. + { + var n = try NinepJoin.init("one two\nthree\n", TestHost.host()); + defer n.deinit(); + _ = try n.serve(.{ .tag = 1, .op = .write, .node = n.node(.limit), .data = "#0,#3" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 2, .op = .write, .node = n.node(.addr), .data = "/two/" }, true); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = n.node(.data), .data = "2" }, true); + try n.agree(); + } + // dot truncated: its open's release with no write empties it. + { + var n = try NinepJoin.init("one two\nthree\n", TestHost.host()); + defer n.deinit(); + const dot = n.node(.dot); + _ = try n.serve(.{ .tag = 1, .op = .write, .node = dot, .data = "#0,#3" }, true); + const h = (try n.serve(.{ .tag = 2, .op = .open, .node = dot, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 3, .op = .setattr, .node = dot, .handle = h, .truncate = true }, true); + try n.join(); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = dot, .handle = h, .opened = true }, true); + try n.agree(); + } +} + +test "a client joined between two writes of one open to a pane's sel runs the second on from the first, as its session does" { + var n = try NinepJoin.init("one two\n", TestHost.host()); + defer n.deinit(); + const sel = n.node(.sel); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = sel, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = sel, .handle = h, .data = "a" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = sel, .handle = h, .data = "b" }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = sel, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined after a script's nomark or noscroll writes as its session does" { + // nomark: writes under it are one undo step. + { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + _ = try n.serve(.{ .tag = 1, .op = .write, .node = n.node(.ctl), .data = "nomark" }, true); + try n.join(); + // Two opens' writes, each its own undo step but for nomark. + const body = n.node(.body); + for ([_][]const u8{ "two\n", "three\n" }) |text| { + const h = (try n.serve(.{ .tag = 2, .op = .open, .node = body, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 3, .op = .write, .node = body, .handle = h, .data = text }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = body, .handle = h, .opened = true }, true); + } + _ = try n.serve(.{ .tag = 5, .op = .write, .node = n.node(.ctl), .data = "mark" }, true); + _ = try n.serve(.{ .tag = 6, .op = .write, .node = n.node(.ctl), .data = "Undo" }, true); + try n.agree(); + } + // noscroll: a write past the screen leaves the view where it was. + { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + _ = try n.serve(.{ .tag = 1, .op = .write, .node = n.node(.scroll), .data = "0" }, true); + try n.join(); + _ = try n.serve(.{ .tag = 2, .op = .write, .node = n.node(.body), .data = &@as([100]u8, @splat('\n')) }, true); + try n.agree(); + } +} + +test "a client joined after a script truncated a pane's tag writes the tag its session writes" { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const tag = n.node(.tag); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = tag, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .setattr, .node = tag, .handle = h, .truncate = true }, true); + try n.join(); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = tag, .handle = h, .data = "Get Put\n" }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = tag, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined while a chorded exec waits for its event reader's write-back runs it with its argument, as its session does" { + var n = try NinepJoin.init("Msg said\narg-text\n", TestHost.host()); + defer n.deinit(); + const event = n.node(.event); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = event, .omode = 2 }, true)).handle; + // The session's chorded click, told to the reader, its argument kept. + { + const was = Stepping.begin(&n.a.t, null); + const id = n.a.core.paneBySerial(n.serial).?; + try std.testing.expect(pardes.mouse.reportRange(n.a.core, id, pardes.config.exec_cmd, "Msg", false, .{ .q0 = 0, .q1 = 3 }, "arg-text")); + was.end(); + n.a.seq += 1; + _ = try n.a.unit(0, n.a.seq); + } + try n.join(); + // The command's record written back alone: its argument is the one kept. + _ = try n.serve(.{ .tag = 2, .op = .write, .node = event, .handle = h, .data = "MX0 3 9 3 Msg\n" }, true); + _ = try n.serve(.{ .tag = 3, .op = .release, .node = event, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined while a script's writes to a body are held to go in as one edit puts them in as its session does" { + // A host with a clock: held writes go in once they have paused + // (pane.batch_pause_ns), and the join came before that. + const Clock = struct { + var now_ns: u64 = 5 * std.time.ns_per_s; + fn now(_: ?*anyopaque) u64 { + return now_ns; + } + const vtable: pardes.Host.VTable = .{ .watched = TestHost.watched, .now = now }; + }; + var n = try NinepJoin.init("one\n", .{ .vtable = &Clock.vtable }); + defer n.deinit(); + const body = n.node(.body); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = body, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = body, .handle = h, .data = "two\n" }, true); + try std.testing.expect(n.a.core.fs.batch.bytes.items.len > 0); + try n.join(); + Clock.now_ns += std.time.ns_per_s; + try n.pump(); + try n.agree(); + _ = try n.serve(.{ .tag = 3, .op = .release, .node = body, .handle = h, .opened = true }, true); + try n.agree(); +} + +/// A session with a shell, for a run's 9P state across a join: a host +/// whose pty takes the line and whose tty nobody else holds. +const RunJoin = 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 prompt = "\x1b]133;A;cl=line;aid=pardes\x07$ \x1b]133;B;aid=pardes\x07"; + + /// 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); + n.* = .{ .a = a, .serial = 0 }; + _ = try a.unit(0, 0); + const shell: u8 = for (a.core.panes, 0..) |slot, id| { + if (slot) |pane| if (pane.isTerminal()) break @intCast(id); + } else return error.NoShell; + n.serial = a.core.panes[shell].?.serial; + return shell; + } + + fn output(n: *NinepJoin, shell: u8, bytes: []const u8) !void { + n.a.output(.{ .output = .{ .pane = .at(shell), .bytes = bytes } }); + try n.send((try n.a.pending()).?); + } +}; + +test "a client joined while a script's pty/run waits on the command it sent ends the run as its session does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + var n: NinepJoin = undefined; + const shell = try RunJoin.init(&n); + defer n.deinit(); + // The shell's greeting (`ls`) run at its first prompt, done. + try RunJoin.output(&n, shell, RunJoin.prompt ++ "ls\r\n\x1b]133;C;aid=pardes\x07a b\r\n\x1b]133;D;0;aid=pardes\x07" ++ RunJoin.prompt); + const run = n.node(.pty_run); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = run, .omode = 2 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = run, .handle = h, .data = "true\n" }, true); + try n.join(); + try RunJoin.output(&n, shell, "true\r\n\x1b]133;C;aid=pardes\x07\x1b]133;D;0;aid=pardes\x07" ++ RunJoin.prompt); + const answer = try n.serve(.{ .tag = 3, .op = .read, .node = run, .handle = h, .size = 64 }, true); + try std.testing.expectEqualStrings("exit 0\n", n.a.core.fsPayload(answer)); + // The open's next line, sent at the prompt the first left. + _ = try n.serve(.{ .tag = 4, .op = .write, .node = run, .handle = h, .data = "false\n" }, true); + try RunJoin.output(&n, shell, "false\r\n\x1b]133;C;aid=pardes\x07\x1b]133;D;1;aid=pardes\x07" ++ RunJoin.prompt); + _ = try n.serve(.{ .tag = 5, .op = .release, .node = run, .handle = h, .opened = true }, true); + try n.agree(); +} + +test "a client joined after its session's shell was found to have no prompt marks answers a pty/run as its session does" { + if (pardes.Term.ops == null) return error.SkipZigTest; // a shell + var n: NinepJoin = undefined; + const shell = try RunJoin.init(&n); + defer n.deinit(); + { + const was = Stepping.begin(&n.a.t, null); + n.a.core.acknowledgeShell(.at(shell), "/bin/sh", false); + was.end(); + n.a.seq += 1; + _ = try n.a.unit(0, n.a.seq); + } + try n.join(); + const run = n.node(.pty_run); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = run, .omode = 2 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .write, .node = run, .handle = h, .data = "true\n" }, true); + const answer = try n.serve(.{ .tag = 3, .op = .read, .node = run, .handle = h, .size = 64 }, true); + try std.testing.expectEqualStrings("error no prompt marks\n", n.a.core.fsPayload(answer)); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = run, .handle = h, .opened = true }, true); + try n.agree(); +} -- cgit v1.3 From 27837e6345b51ceb2ceaaee58fd593024feb07c8 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 08:13:35 -0300 Subject: ninep: the audit's two more finds ride with the rest: the panes the last look or exec touched (fs.results and each open's) and a column's or the workspace's tag truncation (fs.header_rewrite, header_trunc_pending, header_held) are digested and dumped, dropped at a revive as the opens are; found by reading the namespace field by field (reports/pardes-faults-4.md section 3): exec.leased reads an open's results to keep a done command pane a script reads from being taken again, and a new open's results are the session's last (no test: it needs a finished command pane read by a script); a header's truncation is the pane tag's twin: test "a client joined after a script truncated the workspace's tag writes the tag its session writes" (unequal on the base); the rest of the namespace is no fault (set and read in one request's step, or replies, the log, the listener) but edit_hold (listed: the session's listener sets it between steps); gate on this tip (load 5-18): tui core-test 868/1023 (155 skipped), shell-test 1063/1066, pane-test 183/184, behaviour-test 275/275 and --replay 275/275, term-test 17/17, kitty-test 45/45, addon-test 5/5, process-test 1 of 144 (pty/run's "busy while a job holds the tty", at load 18; 3 of 3 alone), replicas --clients 5, --bytes --clients 5 and both with --seeds 8: diverged 0, unequal 0, unlisted stops 0, corpus 22 of 22, no leak; attach probe 0 of 6; cross_replay 29 digests agree on each replica; daemon.py plain, --far, --games, --window-clients, --upgrade base -> this and this -> base pass; the macOS (Linux host), macOS arm and FreeBSD builds; the frame and perf gate against tree2 PASS: 77/77 frames, gui unit-test 1660/1664, perfab corpus2x +0.009%, perfops 121 within 0.1% (largest client-key-down on medium +0.054%) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- abi/wire.zig | 3 ++- core/fs.zig | 23 ++++++++++++++++++----- core/ninep/tree.zig | 5 +++-- core/replica.zig | 12 ++++++++++++ 4 files changed, 35 insertions(+), 8 deletions(-) (limited to 'core/replica.zig') diff --git a/abi/wire.zig b/abi/wire.zig index 4055e42d..e68e8462 100644 --- a/abi/wire.zig +++ b/abi/wire.zig @@ -11,7 +11,8 @@ const config = @import("pardes_options"); const build_info = @import("build_info"); /// 24: the 9P state a session's requests made (its open records, each -/// pane's) is in its join's dump and its digest (core/fs.zig Namespace); +/// pane's, the panes the last look or exec touched, a header's +/// truncation) is in its join's dump and its digest (core/fs.zig Namespace); /// 23: a pane of a kind's frame names its rasters by key, their pixels /// crossing before it as strips of 4 MiB at most over the rows it shows /// (screen kind 5), and a replica lacking one asks for its pane again diff --git a/core/fs.zig b/core/fs.zig index dcc33cd6..eadb7c19 100644 --- a/core/fs.zig +++ b/core/fs.zig @@ -843,7 +843,10 @@ pub const EditHold = struct { pub const Namespace = struct { /// What a step reads that 9P requests made (every request an input /// each replica replays) is the core's like any state: the open - /// records and the writes held to go in as one edit, digested and dumped (a client's join takes them from + /// records (a command pane a script reads is not taken again: + /// exec.leased), the panes the last look or exec touched (a new open's + /// own), the writes held to go in as one edit and a header tag's + /// truncation, digested and dumped (a client's join takes them from /// the dump; a session revived from one drops the opens with the /// connections that held them: dump.zig `loadAndRevive`). The rest is /// the server's (core/walk.zig): its sockets and the mounts (dumped @@ -861,9 +864,9 @@ pub const Namespace = struct { "lsp_answer_at", "edit_started", "edit_hold", "edit_said", "lsp_result", "write_room", "write_waits", "log_full_hash", "pages", "closed_lines", "ran_at", "refilled", "failures", "ename", "news", "hanging_up", "log", "plumb_held", - "results", "results_len", "started", "header_rewrite", "header_trunc_pending", "header_held", + "started", }, - .len = .{.{ "opens", "opens_len" }}, + .len = .{ .{ "opens", "opens_len" }, .{ "results", "results_len" } }, }; socket_path: []const u8 = "", tcp_address: ?std.Io.net.IpAddress = null, @@ -1025,11 +1028,17 @@ pub const Namespace = struct { /// Its digest (core/walk.zig): the opens in use, and writes held by /// their length (their bytes are the same writes on every side; a /// stream of 8 KB appends hashed whole cost each its length again; - /// none held, the rest of `batch` is nothing a step reads). Nothing at + /// none held, the rest of `batch` is nothing a step reads), the panes + /// the last look or exec touched, a header's truncation. Nothing at /// all for a session no script holds anything of. pub fn digest(st: *const Namespace, h: *pardes.walk.Hasher) void { - comptime if (pardes.walk.fieldNames(Namespace).len != 3) @compileError("Namespace.digest: hash every field the walk does not leave out"); + comptime if (pardes.walk.fieldNames(Namespace).len != 8) @compileError("Namespace.digest: hash every field the walk does not leave out"); for (st.opens[0..st.opens_len]) |*o| pardes.walk.hash(tree.Open, o, h); + h.update(std.mem.sliceAsBytes(st.results[0..st.results_len])); + if (st.header_rewrite != null or st.header_trunc_pending != null or st.header_held) { + const words = [_]u64{ st.header_rewrite orelse std.math.maxInt(u64), st.header_trunc_pending orelse std.math.maxInt(u64), @intFromBool(st.header_held) }; + h.update(std.mem.asBytes(&words)); + } const b = &st.batch; if (b.bytes.items.len == 0) return; const words = [_]u64{ b.serial, b.node, b.handle, b.at, b.bytes.items.len, b.last_ns }; @@ -1041,8 +1050,12 @@ pub const Namespace = struct { pub fn forget(st: *Namespace, gpa: std.mem.Allocator) void { for (&st.opens) |*o| o.deinit(gpa); st.opens_len = 0; + st.results_len = 0; st.batch.bytes.deinit(gpa); st.batch = .{}; + st.header_rewrite = null; + st.header_trunc_pending = null; + st.header_held = false; } pub fn mount(st: *Namespace, gpa: std.mem.Allocator, name: []const u8, dial: []const u8) !void { diff --git a/core/ninep/tree.zig b/core/ninep/tree.zig index 107479f6..3eeb5d3f 100644 --- a/core/ninep/tree.zig +++ b/core/ninep/tree.zig @@ -126,8 +126,8 @@ pub const out_reserve = 4 * 1024; pub const Open = struct { /// A client's join carries it and the digest covers it (fs.Namespace), /// but what only its reader is answered with: the listener's held - /// read, the stream's last answer, the panes a look or exec touched. - pub const replica = .{ .authority = .{ "results", "held", "replay" } }; + /// read and the stream's last answer. + pub const replica = .{ .authority = .{ "held", "replay" } }; /// The node it was opened on, which every use checks; 0 is a free record. node: u64 = 0, what: What = .{ .snapshot = null }, @@ -216,6 +216,7 @@ pub const Open = struct { pub const Replay = struct { off: u64, bytes: []u8 }; pub const Results = struct { + pub const replica = .{ .len = .{.{ "list", "len" }} }; list: [pardes.MAX_PANES]u32 = undefined, len: u8 = 0, /// Written on: reads are a stream from the write on, whatever diff --git a/core/replica.zig b/core/replica.zig index 50615fc0..4d1a635c 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -7133,6 +7133,18 @@ test "a client joined after a script truncated a pane's tag writes the tag its s try n.agree(); } +test "a client joined after a script truncated the workspace's tag writes the tag its session writes" { + var n = try NinepJoin.init("one\n", TestHost.host()); + defer n.deinit(); + const tag: u64 = @backingInt(pardes.ctlfs.TopFile.tag); + const h = (try n.serve(.{ .tag = 1, .op = .open, .node = tag, .omode = 1 }, true)).handle; + _ = try n.serve(.{ .tag = 2, .op = .setattr, .node = tag, .handle = h, .truncate = true }, true); + try n.join(); + _ = try n.serve(.{ .tag = 3, .op = .write, .node = tag, .handle = h, .data = "Exit\n" }, true); + _ = try n.serve(.{ .tag = 4, .op = .release, .node = tag, .handle = h, .opened = true }, true); + try n.agree(); +} + test "a client joined while a chorded exec waits for its event reader's write-back runs it with its argument, as its session does" { var n = try NinepJoin.init("Msg said\narg-text\n", TestHost.host()); defer n.deinit(); -- cgit v1.3