diff options
| -rw-r--r-- | core/replica.zig | 185 | ||||
| -rw-r--r-- | core/tape.zig | 7 | ||||
| -rw-r--r-- | dev/host_io.zig | 2 | ||||
| -rw-r--r-- | dev/tui/tui.zig | 22 | ||||
| -rw-r--r-- | runtime/daemon.zig | 3 | ||||
| -rw-r--r-- | runtime/session.zig | 6 | ||||
| -rw-r--r-- | test/daemon.py | 127 | ||||
| -rw-r--r-- | test/replicas.zig | 126 | ||||
| -rw-r--r-- | test/tty.zig | 6 |
9 files changed, 438 insertions, 46 deletions
diff --git a/core/replica.zig b/core/replica.zig index dd3f13d1..10eba502 100644 --- a/core/replica.zig +++ b/core/replica.zig @@ -806,7 +806,7 @@ pub const Replica = struct { tape.adoptCore(&r.t, c); const was = Stepping.begin(&r.t, &r.epoch); defer was.end(); - r.view = Peers.viewFor(c, null) orelse return error.NoView; + r.view = Peers.viewFor(c, null, true) orelse return error.NoView; break :boot c; }; // The chrome's colours are local, never dumped: the restored theme's. @@ -2117,6 +2117,9 @@ pub const Peers = struct { /// No frontend of its own (the host says): with no client either, the /// session is unattended. detached: bool = false, + /// A Restore let every client go (`restoring`): the restored core's one + /// view (views.only) is the first to join again's. + restored: bool = false, /// Its last client left with a close (its window closed, its terminal /// hung up) and the session is a pair's not kept (daemon.sessionState): it /// ends there (runtime/session.zig). @@ -2246,7 +2249,14 @@ pub const Peers = struct { }, .screen => |in| { defer ps.gpa.free(in.msg); - const reply = (ps.screens.take(core, in.peer.sid, in.msg) catch null) orelse continue; + // 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 }); @@ -2346,10 +2356,26 @@ pub const Peers = struct { ps.recording = true; ps.samples = std.c.getenv("PARDES_REPLICA_STATS") != null; } - const k = viewFor(core, joining.view) orelse { + // A join with no room lets go a view kept past its bound by the + // core's clock (Core.openView), which a wake by mail alone, as this + // join's, does not move (tui.zig `clockNow`): moved now, on the tape. + if (@popCount(core.views_open) == pardes.views.max) if (core.host.call(.now, .{})) |now| core.advance(now); + // A pair's first client, or the first back after a Restore with no + // client and no view kept for one: the view the session has is the + // joiner's. Any other attach (a detached session's too) opens one. + const own = joining.own or (ps.restored and ps.count() == 0 and core.views_away == 0); + ps.restored = false; + const k = viewFor(core, joining.view, own) orelse { core.unattended = ps.count() == 0 and ps.detached; if (ps.count() == 0) ps.stop(core); - return daemon.refuseReplica(fd, "that session has as many views as it takes"); + const full = "that session has as many views as it takes"; + var left: u64 = 0; + for (0..pardes.views.max) |i| if (pardes.views.isAway(core, @intCast(i))) { + const n = (core.views[i].?.away_ns + pardes.views.away_kept_ns) -| core.clock.now_ns; + left = if (left == 0) n else @min(left, n); + }; + var why: [128]u8 = undefined; + return daemon.refuseReplica(fd, if (left == 0) full else std.fmt.bufPrint(&why, full ++ " (one is kept {d} s more for a client joining again)", .{(left + std.time.ns_per_s - 1) / std.time.ns_per_s}) catch full); }; ps.seq += 1; ps.unit(0, ps.seq); @@ -2420,18 +2446,22 @@ pub const Peers = struct { /// boot shell's spawn among them) is performed after it, on the tape /// its client is sent, not by the view's settle, as a client that made /// its core itself performs none of them. + /// `own`: the live view is the joiner's, in a session nobody looks at + /// (a pair's first client, Options.pair; the first back after a + /// Restore): not one beside it nobody looks at, which would size its + /// terminals (Pardes.sizes). /// ponytail: a divergence's redial that came before its old link's end /// (posted by that link's reader, microseconds after the bye; the /// redial is a dial and the daemon's hand-over later) finds its view /// not kept yet, and takes a new one. - fn viewFor(core: *Pardes, back: ?u8) ?u8 { + fn viewFor(core: *Pardes, back: ?u8, own: bool) ?u8 { const held = core.gpa.alloc(pardes.Effect, core.effects_len) catch return null; defer core.gpa.free(held); for (held, 0..) |*e, i| e.* = core.effects[(core.effects_head + i) % core.effects.len]; core.effects_len = 0; defer queueFirst(core, held); core.unattended = false; - const k = (if (back) |v| (if (core.rejoinView(.at(v))) v else null) else null) orelse (core.openView() orelse return null).index(); + const k = if (own) core.live else (if (back) |v| (if (core.rejoinView(.at(v))) v else null) else null) orelse (core.openView() orelse return null).index(); core.undrawn |= @as(u8, 1) << @intCast(k); return k; } @@ -2536,6 +2566,36 @@ pub const Peers = struct { ps.drop(core, true); } + /// Every client told the session is restoring a dump and let go: each + /// joins again at once (host_io.restoreCore), as at an Upgrade, not + /// asking the daemon whether a link cut with no word was its + /// session's end (`cutListed`). + pub fn restoring(ps: *Peers, core: *Pardes) void { + var out: [600]u8 = undefined; + const words = wire.encodeServer(&out, .{ .refused = restore_words }) catch unreachable; // the words fit + for (ps.list) |slot| if (slot) |peer| peer.last(words); + ps.flushed200(); + // One dialling again already (handed over meanwhile) joins the + // restored core at the next boundary, not hung up on: its redial + // would wait 100 ms for the next dial. + var again: std.ArrayListUnmanaged(Joining) = .empty; + defer again.deinit(ps.gpa); + ps.lock.lockUncancelable(ps.io); + var i: usize = 0; + while (i < ps.inbox.items.len) { + if (ps.inbox.items[i] != .join) { + i += 1; + continue; + } + again.append(ps.gpa, ps.inbox.items[i].join) catch break; + _ = ps.inbox.orderedRemove(i); + } + ps.lock.unlock(ps.io); + ps.drop(core, false); + ps.restored = true; + for (again.items) |j| ps.post(.{ .join = j }); + } + /// What each client was sent goes first, for up to 200 ms. fn flushed200(ps: *Peers) void { const until = nowNs() + 200 * std.time.ns_per_ms; @@ -3112,6 +3172,10 @@ pub fn ended(why: []const u8) bool { /// What an Upgrade tells its clients (`Peers.refuseAll`): each dials again. pub const upgrading = "the session is upgrading to another build of pardes"; +/// What a Restore tells its clients (`Peers.restoring`): each joins again, +/// saying nothing (the own frontend's Restore shows nothing either). +pub const restore_words = "the session is restoring a dump"; + /// A link cut with no last word (`why` its hang-up) whose session its /// daemon lists still: an Upgrade's exec cut it, a dump on the way past the /// clients' flush (`Peers.refuseAll`), whichever build the session is, not @@ -3639,7 +3703,7 @@ pub const Link = struct { return true; } if (c.refused) |words| { - c.notify("joined again: {s}", .{words}); + if (!std.mem.eql(u8, words, restore_words)) c.notify("joined again: {s}", .{words}); std.heap.c_allocator.free(words); c.refused = null; return true; @@ -4772,7 +4836,7 @@ test "a session's first client on the socket it starts with (Options.pair), join try firstOnPair(false); } -test "bytes: a session's first client on its pair, taken before its first effects, has the boot shell's first bytes with no reload of them (the session's one at the join is of its emulator before any byte, the client's none); a client after them makes every side reload" { +test "bytes: a session's first client on its pair, taken before its first effects, has the boot shell's first bytes with no reload at all (its view is the session's, none opened for it); a client after them makes every side reload" { try firstOnPair(true); } @@ -4784,6 +4848,79 @@ test "a pair's client's own core, the file edited between the session's read and try ownBootAgainst(true); } +test "a Restore tells its clients so before it lets them go (each joins again, saying nothing), and one handed over meanwhile is joined to the restored core at the next boundary, not hung up on" { + const gpa = std.testing.allocator; + 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 _ = libc.close(fds[1]); + var late: [2]c_int = undefined; + if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &late) != 0) return error.NoSocket; + defer _ = libc.close(late[1]); + const core = try Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); + defer core.deinit(); + core.host = TestHost.host(); + var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "restore", .detached = true }; + defer ps.deinit(); + defer live_peers = null; + defer ps.dropAll(core); + ps.join(core, .{ .fd = fds[0] }); + var why: [600]u8 = @splat(0); + var j = joinOn(gpa, fds[1], null, &why, null, null, null) orelse return error.JoinFailed; + gpa.free(j.dump); + defer j.rest.deinit(gpa); + // A client dialling again, handed over before the Restore lets the first go. + ps.handed(late[0], null); + ps.restoring(core); + const Last = struct { + words: ?[]u8 = null, + fn post(l: *@This(), msg: Said) bool { + switch (msg) { + .refused => |w| l.words = w, + .unit, .screen, .blob => |b| std.heap.c_allocator.free(b), + .checked, .ended, .left => {}, + } + return true; + } + }; + var last: Last = .{}; + readLink(gpa, fds[1], &j.rest, &last, Last.post); + const words = last.words orelse return error.NoLastWord; + defer std.heap.c_allocator.free(words); + try std.testing.expectEqualStrings(restore_words, words); + try std.testing.expectEqual(1, ps.inbox.items.len); +} + +test "a detached session's first attach opens a view of its own beside the session's; the first back after a Restore takes the session's" { + const gpa = std.testing.allocator; + const core = try Pardes.init(gpa, .{ .cols = 80, .rows = 24 }); + defer core.deinit(); + core.host = TestHost.host(); + var ps: Peers = .{ .gpa = gpa, .io = std.testing.io, .name = "attach", .detached = true }; + defer ps.deinit(); + defer live_peers = null; + defer ps.dropAll(core); + const session_view = core.live; + 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 _ = libc.close(fds[1]); + ps.join(core, .{ .fd = fds[0] }); + const first = for (ps.list) |slot| { + if (slot) |peer| break peer; + } else return error.NotJoined; + try std.testing.expect(first.view.index() != session_view); + try std.testing.expect(pardes.views.isOpen(core, session_view)); + ps.restoring(core); + var again: [2]c_int = undefined; + if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &again) != 0) return error.NoSocket; + defer _ = libc.close(again[1]); + ps.join(core, .{ .fd = again[0] }); + const back = for (ps.list) |slot| { + if (slot) |peer| break peer; + } else return error.NotJoined; + try std.testing.expectEqual(core.live, back.view.index()); + try std.testing.expectEqual(1, pardes.views.count(core)); +} + /// A session's first client on its pair making its core itself /// (`ownBoot`), the file it opens `edited` after the session read it. fn ownBootAgainst(edited: bool) !void { @@ -4805,7 +4942,7 @@ fn ownBootAgainst(edited: bool) !void { defer ps.deinit(); defer live_peers = null; defer ps.dropAll(core); - ps.join(core, .{ .fd = fds[0] }); + ps.join(core, .{ .fd = fds[0], .own = true }); // Edited after the session read it, before its client does. if (edited) try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "a.txt", .data = "edited between\n" }); var o = opts; @@ -4824,6 +4961,10 @@ fn ownBootAgainst(edited: bool) !void { } try std.testing.expectEqual(!edited, r == booted); try std.testing.expectEqual(tape.digestOf(core), r.digest()); + // The session's one view is its client's: none beside it, nobody's, + // sizes its terminals. + try std.testing.expectEqual(@as(u8, 1), core.views_open); + try std.testing.expectEqual(@as(u8, 0), r.view); // What the client shows is the session's file as the session read it. try std.testing.expectEqualStrings("the session's start\n", r.core().panes[0].?.file.?.content); } @@ -4855,7 +4996,7 @@ fn firstOnPair(bytes: bool) !void { defer live_peers = null; defer ps.dropAll(core); const reloads = pardes.Term.reloads.n; - ps.join(core, .{ .fd = fds[0] }); + ps.join(core, .{ .fd = fds[0], .own = true }); var j: Joined = undefined; var why: [600]u8 = @splat(0); const r = if (bytes) r: { @@ -4926,10 +5067,10 @@ fn firstOnPair(bytes: bool) !void { if (r.diverged) |w| std.debug.print("diverged: {s}\n", .{w}); try std.testing.expect(r.diverged == null); try std.testing.expectEqual(take.digest.?, r.digest()); - // Bytes: the session's reload at the join, of an emulator that held - // nothing yet (Pardes.init made it, the spawn is a first effect); the - // client loaded it from the dump and replayed every byte since. - try std.testing.expectEqual(reloads + @intFromBool(bytes), pardes.Term.reloads.n); + // No reload at the join: the session's view is its first client's, none + // opened for it (Peers.viewFor); the client loaded the terminal from the + // dump and replayed every byte since. + try std.testing.expectEqual(reloads, pardes.Term.reloads.n); var arena: std.heap.ArenaAllocator = .init(gpa); defer arena.deinit(); const rows = try pardes.Term.viewport(r.core().panes[shell].?.terminal.?, arena.allocator(), false); @@ -4940,7 +5081,7 @@ fn firstOnPair(bytes: bool) !void { if (libc.socketpair(libc.AF.UNIX, libc.SOCK.STREAM | libc.SOCK.CLOEXEC, 0, &late) != 0) return error.NoSocket; defer _ = libc.close(late[1]); ps.join(core, .{ .fd = late[0] }); - try std.testing.expectEqual(reloads + 2, pardes.Term.reloads.n); + try std.testing.expectEqual(reloads + 1, pardes.Term.reloads.n); } test "bytes: a join refused for want of a view reloads nothing on any side: a client with a key on top stays the session's" { @@ -6561,7 +6702,7 @@ test "a client's n in a kind's pane is a motion: it steps to the next place a re /// `addon`: a kind whose state is its own on the session (a PDF's), which /// the walk does not stand in (its Still has no search, place or word): /// the soak's (test/replicas.zig) PDF and pictures are, judged by name. -const On = enum { any, file, kind, shell, shell_normal, addon }; +const On = enum { any, file, kind, shell, shell_normal, addon, dir }; /// What a far client may wait a round trip for (the user's line, P14: a /// side effect on the system may be slow; motions, edits and layout are @@ -6582,6 +6723,12 @@ const may_wait = [_]Wait{ .{ .what = "LookPrev", .on = .any, .stop = "resolve", .why = "a Look's walk: each word asked of the disk" }, .{ .what = "Mini *", .on = .any, .stop = "resolve", .why = "a file opened by name, from the session's disk" }, .{ .what = "Get", .on = .any, .stop = "read_file", .why = "the file read again from the session's disk" }, + .{ .what = "Get", .on = .dir, .stop = "dir_listing", .why = "a directory listed again from the session's disk" }, + // A directory's pane (Dir.zig): its entries are names on the session's disk. + .{ .what = "Enter", .on = .dir, .stop = "resolve", .why = "the entry under the cursor opened, from the session's disk" }, + .{ .what = "* Enter", .on = .dir, .stop = "resolve", .why = "the entry opened (Enter after a prefix still opens it)" }, + .{ .what = "Tab", .on = .dir, .stop = "kind", .why = "what the entry under the cursor is, asked of the session's disk" }, + .{ .what = "* Tab", .on = .dir, .stop = "kind", .why = "what the entry is (Tab after a prefix still asks)" }, .{ .what = "Save", .on = .any, .stop = "write_file", .why = "a save" }, .{ .what = "Changes", .on = .any, .stop = "jj", .why = "what jj says of the pinned changes, the session's (P14: a word typed may take a moment once)" }, // A program run, a shell opened or closed: the session's processes. @@ -6858,12 +7005,16 @@ test "a far client's every word and key, on a file's pane, a kind's and a shell' _ = try a.local(.{ .command = "Still" }); const kind = a.core.view().active; try std.testing.expect(file != kind and a.core.panes[file].?.file != null and a.core.panes[kind].?.addon != null); + // A directory's pane (Dir.zig), listed from the disk. + _ = try a.local(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/", .{dir}) }); + const listing = a.core.view().active; + try std.testing.expect(a.core.panes[listing].?.file.?.listing != null); var seen: [may_wait.len]bool = @splat(false); var hit: [may_wait.len]bool = @splat(false); var unlisted: u32 = 0; var tried: u32 = 0; - const stands = [_]struct { On, ?usize }{ .{ .file, file }, .{ .kind, kind }, .{ .shell, shell }, .{ .shell_normal, shell } }; + const stands = [_]struct { On, ?usize }{ .{ .file, file }, .{ .kind, kind }, .{ .shell, shell }, .{ .shell_normal, shell }, .{ .dir, listing } }; for (stands) |stand| { const on, const at = stand; const id = at orelse continue; diff --git a/core/tape.zig b/core/tape.zig index d1e0527c..d32f8dd8 100644 --- a/core/tape.zig +++ b/core/tape.zig @@ -948,11 +948,11 @@ const pane_fields = walk.fieldNames(pardes.Pane); const file_fields = walk.fieldNames(pardes.panes.File.State); const places_fields = walk.fieldNames(pardes.panes.Places); const view_fields = walk.fieldNames(Pardes.View); -const Parts = [pardes_fields.len + stream_fields.len + pardes.views.max * view_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64; +pub const Parts = [pardes_fields.len + stream_fields.len + pardes.views.max * view_fields.len + pardes.MAX_PANES * (2 + pane_fields.len + file_fields.len + places_fields.len)]u64; /// The session's digest as one per field of the core's, its stream's, and /// each pane's and its file's, so a divergence says where it is. -fn digestParts(p: *const Pardes, parts: *Parts) []const u64 { +pub fn digestParts(p: *const Pardes, parts: *Parts) []const u64 { var n = walk.fieldDigests(Pardes, p, parts[0..pardes_fields.len]).len; n += walk.fieldDigests(pardes.Stream, &p.stream, parts[n..][0..stream_fields.len]).len; for (&p.views) |*slot| if (slot.*) |*v| { @@ -974,7 +974,7 @@ fn digestParts(p: *const Pardes, parts: *Parts) []const u64 { } /// The fields whose digests differ, named. -fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []const u8 { +pub fn partsDiffer(got: []const u64, want: []const u64, a: std.mem.Allocator) []const u8 { var said: std.ArrayList(u8) = .empty; if (got.len != want.len) said.print(a, "the panes there are ({d} parts, {d} recorded); ", .{ got.len, want.len }) catch {}; const n = @min(got.len, want.len); @@ -1312,6 +1312,7 @@ pub fn recordDigest(t: *Tape) void { t.record(.digest, []const u64, &d); } + /// A core made outside the tape (a replica client's, from a dump) is the /// one it replays into. pub fn adoptCore(t: *Tape, p: *Pardes) void { diff --git a/dev/host_io.zig b/dev/host_io.zig index a22bf5ce..419c4570 100644 --- a/dev/host_io.zig +++ b/dev/host_io.zig @@ -52,7 +52,7 @@ pub fn stopWorkers() void { /// session is one view, the live one's (the tty's terminal, the window's /// window): the others are let go, as a detach of each. pub fn restoreCore(gpa: std.mem.Allocator, core: *pardes.Pardes, path: []const u8, peers: *replica.Peers, inotify_fd: c_int, watches: *file_watch.Table) ?*pardes.Pardes { - peers.dropAll(core); + peers.restoring(core); const bytes = pardes.dump.restoreBytes(core, gpa, path) catch |err| { core.reportError(.at(core.view().active), "Restore", err); return null; diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index 7e5a75fb..92ac6a0c 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -738,14 +738,23 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, if (comptime builtin.os.tag == .freebsd) posix.sigaction(.WINCH, &.{ .handler = .{ .handler = keepSignal }, .mask = posix.sigemptyset(), .flags = 0 }, null); posix.sigprocmask(posix.SIG.BLOCK, &winch_set, null); - var start: client_loop.Start = undefined; - if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) Said.no(io, "{s}", .{start.said()}); - defer start.close(); var tty_buf: [0x10000]u8 = undefined; var screen: Screen = .{ .io = io, .gpa = gpa, .env = init.environ_map, .buf = &tty_buf, .kitty = .init(gpa) }; defer screen.kitty.deinit(); - try screen.enter(try vaxis.Tty.init(io, &tty_buf)); + // A pair's terminal is its own before its join, as the own frontend's + // is before its core: that join is the pair's whole start (its own + // boot, replica.ownBoot), and keys typed meanwhile are its input, not + // echoed by the line discipline and lost as it enters. An attach enters + // once joined, a refusal said on the terminal as it was. + if (opts.pair != null) try screen.enter(try vaxis.Tty.init(io, &tty_buf)); defer screen.leave(); + var start: client_loop.Start = undefined; + if (!start.open(init, opts, .{ .path = path, .session = session, .far = far_link })) { + screen.leave(); + Said.no(io, "{s}", .{start.said()}); + } + defer start.close(); + if (opts.pair == null) try screen.enter(try vaxis.Tty.init(io, &tty_buf)); defer screen.glide.deinit(gpa); defer screen.art.deinit(gpa); var paste_buf: std.Io.Writer.Allocating = .init(gpa); @@ -1631,9 +1640,12 @@ const Shell = struct { return false; } - /// Terminal `screen` (its view live) is `ws` big. + /// Terminal `screen` (its view live) is `ws` big; the size it has is no + /// resize (a client's start takes its size before its input thread's + /// first one comes: Tty.start). fn resized(s: *Shell, screen: ?*Screen, ws: vaxis.Winsize) void { if (screen) |sc| { + if (sc.size) |was| if (std.meta.eql(was, ws)) return; sc.size = ws; sc.vx.resize(s.gpa, sc.tty.writer(), ws) catch {}; } diff --git a/runtime/daemon.zig b/runtime/daemon.zig index 7ae0d8b5..595d5107 100644 --- a/runtime/daemon.zig +++ b/runtime/daemon.zig @@ -466,7 +466,8 @@ pub const Note = union(enum) { replica: Joining, }; -pub const Joining = struct { fd: c_int, view: ?u8 = null }; +/// `own`: a pair's first client, taking the session's view (Peers.viewFor). +pub const Joining = struct { fd: c_int, view: ?u8 = null, own: bool = false }; /// Where every note the daemon sends goes, once `watch` has started the /// reader: the session loop's, before its first step, until its state diff --git a/runtime/session.zig b/runtime/session.zig index 5e99384e..75e8efcc 100644 --- a/runtime/session.zig +++ b/runtime/session.zig @@ -111,7 +111,7 @@ pub fn Loop(comptime Frontend: type) type { // A first client on the socket it was started with, before its // first effects: it has every terminal from its first byte, and // no reload (Core.openView). - if (o.pair) |fd| l.peers.join(l.core, .{ .fd = fd }); + if (o.pair) |fd| l.peers.join(l.core, .{ .fd = fd, .own = true }); l.effects(); // ...and its shells, once a fresh session's own has a directory // to adopt them in. @@ -192,8 +192,12 @@ pub fn Loop(comptime Frontend: type) type { // go, and its one could not join it again (no socket finds it): // refused, as its Upgrade is (tui.zig `upgradeNow`). if (l.peers.count() > 0 and daemon.link < 0) return l.core.reportFailure(l.core.view().active, "Restore: no daemon keeps this session, so its client could not join it again; this session stays as it is"); + const watched = l.peers.count() > 0; const nc = host_io.restoreCore(l.gpa, l.core, path, &l.peers, l.watches.fd, &l.watches.table) orelse return; l.fe.restoring(nc); + // Its clients join again at once: the dump's messages are not + // put on the clock meanwhile (Messages.expireUnattended). + if (watched) nc.unattended = false; // The old core's pipes end, and an answer to its query is // turned away. l.inbox.pipe_tasks.cancelAll(l.io); diff --git a/test/daemon.py b/test/daemon.py index 5c075520..c6ff6256 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -143,6 +143,16 @@ def run(client, serial, line): client.close(fid) +def adopted_pid(client, pane): + """An adopted shell's `echo $$`, once it answers: sized twice at its + adoption (dev/Ptys.zig `take`), it draws its prompt again, and a run + sent into a prompt redrawn under it reads as not run (core/ninep/pty.zig + `noteMarks`).""" + wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n') + said = run(client, pane, b'echo $$\n') + return said.split(b'\n')[1], said + + # FreeBSD has no /proc: ps and procstat answer instead. procfs = os.path.isdir('/proc/self') @@ -978,6 +988,65 @@ def attach_upgrading(binary, rounds=6, dump=True): shutil.rmtree(root, ignore_errors=True) +def kept_views(binary): + """A view kept for its client's rejoin (views.away: a bye that says it + joins again, a client cut off behind, every client at an Upgrade) is + that client's for 30 s, then a join with no room takes it, in a session + nobody types in: a `new --detach` session at its four views (a client + attached, idle; raw replicas), two of them leaving to join again and + never coming back; a join at once is refused and told for how long, one + 31 s later, nothing typed in between, is welcomed.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rk-', dir=scratch)) + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), + TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + t = Term(30, 100) + rs = [] + try: + out = subprocess.run([binary, 'new', '--detach=kv'], env=env, cwd=root, capture_output=True, timeout=30, stdin=subprocess.DEVNULL) + assert out.returncode == 0, out + a = t.spawn([binary, 'attach', 'kv'], env) + wait_for('the client drawn', lambda: b'\x1b[?1049h' in t.text(), timeout=30) + sock, build = root / 'pardes-replica.sock', semantics(binary) + while True: + r = Replica(sock) + said = r.hello('kv', build) + if said[0] != 'welcome': + break + rs.append(r) + assert said[0] == 'refused' and 'as many views' in said[1] and len(rs) >= 2, (said, len(rs)) + for r in rs[:2]: + r.send(0x02, b'\x01') + r.close() + left = time.monotonic() + said = Replica(sock).hello('kv', build) + assert said[0] == 'refused' and re.search(r'as many views as it takes \(one is kept (\d+) s more for a client joining again\)', said[1]), said + print(f'kept views: {len(rs)} replicas and a client at the cap; two left to join again; a join at once refused: "{said[1]}"') + time.sleep(max(0, left + 31 - time.monotonic())) + said = Replica(sock).hello('kv', build) + assert said[0] == 'welcome', ('a view kept 31 s in an idle session, still kept', said) + assert a.poll() is None + print('kept views: a join 31 s after, nothing typed in between, took a kept view') + a.terminate() + a.wait(timeout=20) + assert subprocess.run([binary, 'kill', 'kv'], env=env, capture_output=True, timeout=30).returncode == 0 + wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=20) + finally: + for r in rs: + r.close() + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + t.close() + shutil.rmtree(root, ignore_errors=True) + + def pair_upgrade_views(binary): """PARDES_PAIR, two clients each in its own view (the pair's own terminal and an attach), each with its own scroll and focus: the pair's scrolled @@ -1117,14 +1186,17 @@ def pair_exec_reaps(old, new): wait_for('drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) install(new, binary) ino = sock.stat().st_ino + # Before the Upgrade: the exec'd client can draw before its exec is seen. + mark = len(t.text()) nine.write('/ctl', b'Upgrade\n') nine.socket.close() wait_for('the session exec\'d', lambda: sock.stat().st_ino != ino, timeout=60) wait_for('the client on the new build', lambda: exe_of(c.pid) == (str(binary), True), timeout=30) nine = reconnect(sock) assert ppid(session) == c.pid - mark = len(t.text()) - wait_for('drawn again', lambda: b'line 3 of the notes' in t.text()[mark:], timeout=30) + # The blink: its screen left and entered again, the notes drawn there. + wait_for('drawn again', lambda: (lambda x: x.rfind(b'\x1b[?1049h') > x.rfind(b'\x1b[?1049l') > mark + and b'line 3 of the notes' in x[x.rfind(b'\x1b[?1049h'):])(t.text()), timeout=30) nine.write('/ctl', b'Exit\n') nine.socket.close() assert c.wait(timeout=30) == 0, c.returncode @@ -1469,7 +1541,8 @@ def relink(binary): before = set(terminals(own)) own.write(f'/pane/{min(before)}/exec', b'Adopt\n') pane = wait_for('the adopted pane', lambda: set(terminals(own)) - before).pop() - assert run(own, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(own, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'relink: a client attached to the session through the new daemon; killed outright, its shell {shell_pid} was adopted') exit_session(own, pane) stub.wait(timeout=10) @@ -1543,7 +1616,8 @@ def answer_late(binary): two.write(f'/pane/{min(before)}/exec', b'Adopt\n') took = time.monotonic() - asked pane = wait_for('the adopted pane', lambda: set(terminals(two)) - before).pop() - assert run(two, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(two, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'answer late: an Adopt asked while the daemon was stopped waited {took:.1f} s for its answer, ' f'and shell {shell_pid} was adopted') exit_session(two, pane) @@ -2035,7 +2109,10 @@ def far(binary): time.sleep(.3) os.write(ts.master, b' sD') wait_for(f'the client through ssh ends ({name})', lambda: sc.poll() is not None, timeout=30) - assert name == 'files' or b"no session called 'nobody'" in ts.text(), ts.text()[-300:] + # Its words are read off its terminal by a thread of the Term's: + # the process can be gone before they are in `text()`. + if name == 'nobody': + wait_for('the refusal said through ssh', lambda: b"no session called 'nobody'" in ts.text(), timeout=5) wait_for(f'its ssh and socket gone ({name})', lambda: not forwarded(), timeout=10) body = texts() for words in (b'from-A', b'from-B', b'again-A', b'from-C', b'from-D', b'from-E', b'from-F'): @@ -2566,6 +2643,7 @@ def main(binary, cycles): pair(binary) pair_rows(binary) attach_upgrading(binary) + kept_views(binary) pair_upgrade_views(binary) manage(binary) relink(binary) @@ -2712,11 +2790,8 @@ def main(binary, cycles): client.write(f'/pane/{min(before)}/exec', b'Adopt\n') adopted = wait_for('the adopted pane', lambda: set(terminals(client)) - before) pane = adopted.pop() - # Sized twice (Ptys.take): a run into a prompt redrawn under it - # reads as not run (core/ninep/pty.zig). - wait_for('the adopted shell answers', lambda: run(client, pane, b'true\n') == b'exit 0\n') - said = run(client, pane, b'echo $$\n') - assert said.split(b'\n')[1] == str(shell_pid).encode(), said + pid, said = adopted_pid(client, pane) + assert pid == str(shell_pid).encode(), said print(f'daemon: shell {shell_pid} outlived kill -9 of its session and was adopted') # Attached again: a client. (After the runs: a pty/run under a # client puts it off the session's state, and it joins again; one @@ -3159,6 +3234,16 @@ def upgrades(old, new): or b'run the same pardes at both ends' in term2.text())), timeout=30) wait_for('the word said', lambda: 'Upgrade: now pardes' in screen_text(client)) + # Two clients' views kept at the Upgrade, with the time (views.away), + # whose clients never come back (the raw replica, the old build's): + # each its client's for 30 s, and the session's views all taken. + # The first join waits as long as its refusal says. + if keeps_views(old): + said = Replica(root / 'pardes-replica.sock').hello('work', new_build) + kept = re.search(r'one is kept (\d+) s more', said[1]) if said[0] == 'refused' else None + if kept: + time.sleep(int(kept.group(1)) + .5) + print(f'upgrade: two views kept for clients that never came back; the join waited {kept.group(1)} s for one, as its refusal said') # The daemon lists the session under its new build. said = Replica(root / 'pardes-replica.sock').hello('work', new_build) assert said == ('welcome', session, 'work'), said @@ -3272,7 +3357,8 @@ def upgrades(old, new): before = set(terminals(client)) client.write(f'/pane/{min(before)}/exec', b'Adopt\n') pane = wait_for('the adopted pane', lambda: set(terminals(client)) - before).pop() - assert run(client, pane, b'echo $$\n').split(b'\n')[1] == str(shell_pid).encode() + pid, said = adopted_pid(client, pane) + assert pid == str(shell_pid).encode(), (said, shell_pid) print(f'upgrade: the upgraded daemon kept shell {shell_pid} through kill -9 of its session, and it was adopted') client.write(f'/pane/{pane}/exec', b'Exit\n') stub.wait(timeout=10) @@ -3298,6 +3384,20 @@ def knows_size(gui_binary): return b'PARDES_JOIN_SIZE' in Path(gui_binary).read_bytes() +def keeps_views(binary): + """Whether a build keeps its clients' views at an Upgrade with the time + each was kept (View.away_ns), so that the build after holds them.""" + return b'away_ns' in Path(binary).read_bytes() + + +def redials_far(binary): + """Whether a build's far client whose link an Upgrade cuts with no last + word dials again (core/replica.zig `cutListed`'s `far`) rather than take + it for its session's end: the change that made it gave the window its + size at its exec too (PARDES_JOIN_SIZE), the string that says so.""" + return b'PARDES_JOIN_SIZE' in Path(binary).read_bytes() + + def knows_exec(binary): """Whether a build's client execs the build at its start path at an Upgrade, for the view it is handed (PARDES_JOIN_VIEW).""" @@ -3523,7 +3623,10 @@ if __name__ == '__main__': upgrades(old, new) if knows_exec(old): pair_exec_reaps(old, new) - far_exec(old, new) + if redials_far(old): + far_exec(old, new) + else: + print('far exec: skipped: the old build\'s far client, cut at the Upgrade with no last word, takes it for its session\'s end (no PARDES_JOIN_SIZE)') # With a pardes-gui beside each: the clients carried too. if all(a.with_name('pardes-gui').exists() for a in (old, new)): upgrade_clients(old, new) diff --git a/test/replicas.zig b/test/replicas.zig index e5e719b3..48eaa857 100644 --- a/test/replicas.zig +++ b/test/replicas.zig @@ -336,7 +336,7 @@ const Totals = struct { /// search (`/`, a pattern, Enter), a sweep of B1 over the PDF and its /// wheel; a yank to the system clipboard and a paste from it; now and /// then a client's Detach. -fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const u8, script: *Script, far: bool) pardes.Event { +fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const u8, script: *Script, far: bool, spare: bool) pardes.Event { const typed = "abcdefghijklmnopqrstuvwxyz0123456789 -_=+,:;()"; const normal = "hjklwbe0$xpuyoOiaAIdcv.nN%sC"; if (script.at < script.n) { @@ -346,13 +346,19 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const switch (random.uintLessThan(u8, 46)) { 0...15 => { buf[0] = typed[random.uintLessThan(usize, typed.len)]; + if (buf[0] == 'q' and script.space) buf[0] = 'r'; + script.space = buf[0] == ' '; return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } }; }, 16...27 => { buf[0] = normal[random.uintLessThan(usize, normal.len)]; + script.space = false; return .{ .key = .{ .cp = buf[0], .text = buf[0..1] } }; }, - 28...31 => return .{ .key = .{ .cp = Key.escape } }, + 28...31 => { + script.space = false; + return .{ .key = .{ .cp = Key.escape } }; + }, 32 => return .{ .key = .{ .cp = Key.enter } }, 33 => return .{ .key = .{ .cp = Key.backspace } }, 34 => return .{ .key = .{ .cp = switch (random.uintLessThan(u8, 4)) { @@ -374,7 +380,9 @@ fn nextEvent(random: std.Random, buf: *[64]u8, aim: Aim, looks: []const []const 4 => "Search Panes", 5 => "Search Recent", 6, 7 => looks[random.uintLessThan(usize, looks.len)], - 8 => "Del", + // Not the session's last panes: a Del of its last ends it, and + // the run with it (`Soak.spare`). + 8 => if (spare) "Del" else "Undo", // A tab's width: every pane's layout. 9 => "Tab 2", 10 => "Tab 8", @@ -431,6 +439,9 @@ const Script = struct { evs: [3]pardes.Event = undefined, n: u8 = 0, at: u8 = 0, + /// Its last key was a space: Space then q is Exit (config.zig's + /// leader), which ends the session and the run with it. + space: bool = false, }; fn writeFile(path: [:0]const u8, lines: usize) !void { @@ -873,6 +884,62 @@ const Watchdog = struct { } }; +/// At a client's mismatch only: its digest of every field, as the mismatch +/// left its core, and the unit it parted on. The witness names the fields +/// when its own replay of the kept stream comes to that unit (`judge`): +/// nothing more on the session's step or the wire, so the run's timing is +/// the untraced one. +const Named = struct { + const Parted = struct { c: usize, origin: u16, seq: u32, parts: []u64, terms: [pardes.MAX_PANES]Term }; + /// A terminal pane's: its screen's digest without its view and with + /// it, and where its view and cursor stand. + const Term = struct { content: u64 = 0, viewed: u64 = 0, grid: pardes.Term.Grid = .{} }; + + fn terms(p: *const pardes.Pardes) [pardes.MAX_PANES]Term { + var out: [pardes.MAX_PANES]Term = @splat(.{}); + for (p.panes, &out) |slot, *t| { + const state = (slot orelse continue).terminal orelse continue; + var a = pardes.walk.Hasher.init(0); + state.digestScreen(&a, false); + var b = pardes.walk.Hasher.init(0); + state.digestScreen(&b, true); + t.* = .{ .content = a.final(), .viewed = b.final(), .grid = pardes.Term.grid(state) }; + } + return out; + } + var parted: std.ArrayListUnmanaged(Parted) = .empty; + + fn reset() void { + for (parted.items) |x| gpa.free(x.parts); + parted.clearRetainingCapacity(); + } + + /// Client `c` parted on `unit`: kept for the witness, said once. + fn say(r: Run, c: usize, rp: *replica.Replica, unit: []const u8) void { + const u = replica.parseUnit(unit) orelse return; + const mine = gpa.create(pardes.tape.Parts) catch return; + defer gpa.destroy(mine); + const got = pardes.tape.digestParts(rp.core(), mine); + parted.append(gpa, .{ .c = c, .origin = u.origin, .seq = u.seq, .parts = gpa.dupe(u64, got) catch return, .terms = terms(rp.core()) }) catch return; + std.debug.print("seed {d} rtt {d} ms: client {d} parted on unit {d}/{d} ({d} bytes; {d} applied on top, {d} pending): its fields kept for the witness\n", .{ r.seed, r.rtt_ms, c + 1, u.origin, u.seq, u.tape.len, rp.applied, rp.pending.items.len }); + } + + /// The witness at the end of unit `u`: each client that parted there, + /// its fields against the witness's (the session's stream replayed). + fn atUnit(tag: anytype, u: replica.Unit, rp: *replica.Replica, w: *std.Io.Writer) void { + for (parted.items) |x| if (x.origin == u.origin and x.seq == u.seq) { + var arena = std.heap.ArenaAllocator.init(gpa); + defer arena.deinit(); + const theirs = arena.allocator().create(pardes.tape.Parts) catch return; + const want = pardes.tape.digestParts(rp.core(), theirs); + w.print("seed {d} rtt {d} ms: client {d} names: at unit {d}/{d}, against the witness's replay: {s}\n", tag ++ .{ x.c + 1, u.origin, u.seq, pardes.tape.partsDiffer(x.parts, want, arena.allocator()) }) catch {}; + for (x.terms, terms(rp.core()), 0..) |a, b, id| if (a.viewed != b.viewed or a.content != b.content) { + w.print(" pane {d}'s terminal: content {s}, view {s}; the client's {any}; the witness's {any}\n", .{ id, if (a.content == b.content) "equal" else "DIFFERS", if (a.viewed == b.viewed) "equal" else "DIFFERS", a.grid, b.grid }) catch {}; + }; + }; + } +}; + const Witness = struct { const Sent = struct { blob: bool, bytes: []u8 }; const Dump = struct { c: usize, id: u16, view: u8, cols: u16, rows: u16, join_seq: u32, bytes: []u8, start: ?usize = null }; @@ -1050,6 +1117,7 @@ const Witness = struct { if (u.origin == 0) last0 = u.seq; rp.since_check = if (parted == null) 1 << 20 else 0; rp.confirm(m.bytes); + if (parted == null) Named.atUnit(tag, u, rp, w); if (rp.diverged) |why| { if (parted == null) { parted = i; @@ -1123,6 +1191,15 @@ const Soak = struct { l: *SessionLoop = undefined, /// What failed inside the loop (its wait returns nothing): the run's. err: ?anyerror = null, + /// `finish` ran: the session's loop ended at the run's end, not before. + finished: bool = false, + /// The session's `quit` after its last step (`sent`): an Exit's end. + quit: bool = false, + /// The last inputs the typists drew (who, as `describe` says them), + /// said with an early end. + drawn: [8]struct { who: u16 = 0, text: [48]u8 = undefined, len: u8 = 0 } = @splat(.{}), + drawn_n: usize = 0, + // ---- its host ---- /// A pty that echoes what it is written, 2 ms later, as a shell's. @@ -1354,7 +1431,22 @@ const Soak = struct { /// clients' inputs, joins and leaves taken in): what a Peer's writer /// would write, down each link; a join taken or refused; a link the /// session shut; the echoes its steps asked of the shell. + fn drew(s: *Soak, who: u16, ev: pardes.Event) void { + const d = &s.drawn[s.drawn_n % s.drawn.len]; + s.drawn_n += 1; + d.who = who; + d.len = @intCast(describe(&d.text, ev).len); + } + + /// Panes enough that the Dels in flight (a typist's each) leave one. + fn spare(s: *const Soak) bool { + var n: usize = 0; + for (s.l.core.panes) |slot| n += @intFromBool(slot != null); + return n > 3; + } + pub fn sent(s: *Soak) void { + defer s.quit = s.l.core.quit; s.sentOrFail() catch |err| { if (s.err == null) s.err = err; s.l.core.quit = true; @@ -1811,7 +1903,8 @@ const Soak = struct { switch (m.kind) { .input => { var buf: [64]u8 = undefined; - const ev = nextEvent(s.random, &buf, s.aim, s.looks, &cl.script, net.throttled == @as(?usize, c)); + const ev = nextEvent(s.random, &buf, s.aim, s.looks, &cl.script, net.throttled == @as(?usize, c), s.spare()); + s.drew(@intCast(c + 1), ev); cl.loop.input(ev); cl.left -= 1; if (cl.left > 0) try net.send(.{ .at = m.at + typistGap(s.random), .n = 0, .kind = .input, .who = m.who, .bytes = &.{} }) else { @@ -1829,7 +1922,9 @@ const Soak = struct { // what its unit cost, on this process's clock. const reloads = pardes.Term.reloads.n; const t0 = monoNs(); + const whole = rp.diverged == null; cl.loop.take(.{ .unit = try std.heap.c_allocator.dupe(u8, m.bytes) }); + if (whole and rp.diverged != null and !cl.loop.link.put_off) Named.say(s.r, c, rp, m.bytes); if (pardes.Term.reloads.n != reloads) try s.totals.join_client_ns.append(gpa, monoNs() - t0); const behind = if (net.throttled == @as(?usize, c)) &s.totals.far_behind else &s.totals.near_behind; behind.* = @max(behind.*, cl.loop.link.behind); @@ -1890,7 +1985,8 @@ const Soak = struct { s.moved_at = s.now; return; } - if (s.now - s.moved_at < stuck_us) return; + // The soak's clock is a message's time: one due before it steps it back. + if (s.now -| s.moved_at < stuck_us) return; std.debug.print("seed {d} rtt {d} ms: watchdog: nothing stepped or checked for {d} s of the soak's clock (since {d} us)\n", .{ s.r.seed, s.r.rtt_ms, stuck_us / std.time.us_per_s, s.moved_at }); s.report(); return error.Hung; @@ -1918,7 +2014,8 @@ const Soak = struct { const core = s.l.core; s.clock(); var buf: [64]u8 = undefined; - const ev = nextEvent(s.random, &buf, s.aim, s.looks, &s.own_script, false); + const ev = nextEvent(s.random, &buf, s.aim, s.looks, &s.own_script, false, s.spare()); + s.drew(0, ev); core.toView(.at(0)); core.update(ev); s.own_left -= 1; @@ -1988,6 +2085,7 @@ const Soak = struct { /// At quiescence: every client's digest the session's, its terminals /// the session's cell for cell, its files' texts byte for byte. fn finish(s: *Soak) !void { + s.finished = true; const totals = s.totals; const core = s.l.core; totals.flood_us += s.flood_end -| flood_at; @@ -2073,6 +2171,8 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { if (trace) std.debug.print("seed {d} rtt {d} ms\n", .{ r.seed, r.rtt_ms }); Witness.reset(); defer Witness.reset(); + Named.reset(); + defer Named.reset(); var prng = std.Random.DefaultPrng.init(r.seed *% 0x9e3779b97f4a7c15 +% r.rtt_ms); const random = prng.random(); var paths: [3][256:0]u8 = undefined; @@ -2168,6 +2268,20 @@ fn run(init: std.process.Init, r: Run, dir: []const u8, totals: *Totals) !void { // The session: THE session loop, from its start to its end. try SessionLoop.run(init, .{ .cols = 100, .rows = 30, .boot = .tty }, &soak); if (soak.err) |err| return err; + // The loop ends without the run's end too (runtime/session.zig): every + // client gone at a boundary, the last by a close; or the session ended + // (Exit, the last pane's Del). Said, and the run failed. + if (!soak.finished) { + std.debug.print("seed {d} rtt {d} ms: the session's loop ended before the run did: {s}; the clients:", .{ r.seed, r.rtt_ms, if (soak.quit) "the session ended (Exit, the last pane's Del)" else "every client gone at a boundary, the last by a close" }); + for (soak.clients, 1..) |cl, k| std.debug.print(" {d} {s}{s}{s};", .{ k, if (cl.r == null) "none" else "joined", if (cl.dialling) " dialling" else "", if (cl.shut) " shut" else "" }); + std.debug.print(" typing {d}, at {d} us; the last drawn (0 the session's own):", .{ soak.typing, soak.now }); + for (0..@min(soak.drawn_n, soak.drawn.len)) |k| { + const d = soak.drawn[(soak.drawn_n - 1 - k) % soak.drawn.len]; + std.debug.print(" {d}: {s};", .{ d.who, d.text[0..d.len] }); + } + std.debug.print("\n", .{}); + return error.EndedEarly; + } } /// What `questions`'s kitty query and `images`'s four are answered with. diff --git a/test/tty.zig b/test/tty.zig index 5cd92887..97b64b7c 100644 --- a/test/tty.zig +++ b/test/tty.zig @@ -146,6 +146,12 @@ pub const Tty = struct { // Set back, not unset: an unsetenv compacts the environment block // the runner's std.Io holds (host_io.testUnsetenv's reason). if (runtime_dir) |was| { + // Its pair's session and their daemon, the case's own, ended: a + // session whose client went with no goodbye (let go at a + // Restore, killed) is kept by that daemon, and outlived the run. + if (std.fmt.allocPrintSentinel(t.arena, "'{s}' --kill-all > /dev/null 2>&1", .{t.exe}, 0)) |cmd| { + _ = system(cmd); + } else |_| {} _ = setenv("PARDES_HARNESS_DAEMON", "", 1); _ = setenv("XDG_RUNTIME_DIR", was, 1); runtime_dir = null; |
