From 774efcc950662cd20c1b4a41d002ce421067564f Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Fri, 20 Nov 2026 15:49:10 -0300 Subject: pair: the boot as input zero (the last step's design 3, way a2): under PARDES_PAIR the client no longer waits for its session's init, dump and socket before its first frame: it makes its own core from the same options and arguments (replica.ownBoot, Replica.initBoot: Pardes.init on no tape, as the session's start, its file read on its own machine, then the view the session's join opens for it, Peers.viewFor, shared by both), draws it, and says its digest before its `far` (a new client word, `boot`, 0x0a: 0x09 is the server's zstd envelope, which a stream's reader unpacks whichever way it runs; wire protocol 26, after the other line's 25); the session's writer sends no dump when the joiner's boot digest is its own at the join, and the client, reading the welcome once its first frame is drawn (replica.confirmBoot, client.zig `confirm`, the start's inputs held until then: Link.held, Link.release), goes on from its own core, or, unequal (the file edited between the two reads, anything else a start reads otherwise), loads the dump in its place and starts again; what made boots unequal by construction, found by the digest's parts compared in a scratch build: a join's view settled the session's first effects (Pardes.settle in openView: its boot shell spawned and acknowledged inside the join), which a client cannot perform; the effects queued before a join are now performed after it, on the tape the client is sent (viewFor, queueFirst), so the boot shell's spawn and first bytes reach the client as units, as P32 asked, and the dump path gets them so too; and a boot stepped on the replica's own tape read the machine as a replica's step would (the shell, the directory): Pardes.init runs on no tape, the view on the replica's tape (no terminal reloaded there, as on the session's screen-state tape); confirmed over 100 starts of a file and 100 of a shell (see the report); a boot's terminals are made on the C heap (panes.emulatorGpa reads dump.terminal_gpa); a window's pair's client boots unwindowed, as the terminal binary its session execs (main.zig `pair`, Options.windowed); tests: core/replica.zig "a pair's client makes its own core ...: no dump is sent" and "... the file edited between ...: the dump is sent, loaded in its place, and the client shows the session's file", and firstOnPair's screen-state client now its own boot, confirmed with no dump, the boot shell's spawn and first bytes after, digests equal, no reload; the start (ReleaseFast, medium.zig, one build alternated, NOT quiet: loads 8-16): the pair's first frame best 9.5 ms against the own path's 9.9 (median 10.2 against 11.4), the client 45.0-53.8M instructions:u (the bar 56.7M), its session 17.2-17.6M beside it, the own path 53.5M bit-equal to the base's; confirmed 100 of 100 starts of a file and 100 of 100 of a shell, a window pair 17 of 17; tui core-test 863/1018 (155 skipped), shell-test 1060/1063, term 17/17, pane 183/184, kitty 45/45, behaviour-test and --replay 275/275, process-test 0 of 144 failed, as a pair (PARDES_PAIR=1) 16 of 144 failed (the base 17), both soaks diverged 0, unequal 0, checked/wrong 0, unlisted 0, corpus 22 of 22, no leak, daemon.py plain, --far, --pair, --relink, --launch, --games, --window-clients, --gui, --upgrade both ways (new->old failed once on a client's key under load, then passed twice) pass, an idle pair 0 and 0 wakeups in 2 s, gui unit-test 1656/1660 with only BaselineHarnessMismatch, the frame and perf gate against tree2 PASS (77/77 frames, corpus2x -0.008%, 121 per-operation counts within 0.1%), macOS lib (Linux host), aarch64-macos and FreeBSD build (loads 5-23) Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- runtime/client.zig | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'runtime/client.zig') diff --git a/runtime/client.zig b/runtime/client.zig index 329bdab3..d20e64d1 100644 --- a/runtime/client.zig +++ b/runtime/client.zig @@ -185,7 +185,9 @@ pub fn Loop(comptime Frontend: type) type { upgrade.locate(); while (true) { link.reset(s.r, &s.joined); - l.fe.start(l); + if (s.joined.booted) { + if (!l.confirm(s)) return .failed; + } else l.fe.start(l); var done: std.atomic.Value(bool) = .init(false); const reader = try std.Thread.spawn(.{}, read, .{ l, s, &done }); while (!link.quit) { @@ -226,6 +228,28 @@ pub fn Loop(comptime Frontend: type) type { } } + /// A pair's first join, its replica its own boot (replica.ownBoot): its + /// start's inputs held and its first pass drawn, then the session's + /// welcome read: the same core, what was held is sent; another (the + /// dump came), the dump's replica in place of the boot's, started + /// again. False, and why in `s.why`: no session to go on with. + fn confirm(l: *L, s: *Start) bool { + const link = &l.link; + link.held = .empty; + l.fe.start(l); + _ = l.before(); + const r = replica.confirmBoot(s.gpa, &s.joined, s.r, s.o, &s.why) orelse { + link.release(s.gpa, false); + return false; + }; + link.release(s.gpa, r == s.r); + if (r == s.r) return true; + s.r = r; + link.reset(r, &s.joined); + l.fe.start(l); + return true; + } + /// The session's stream, onto the frontend's queue: its messages, /// and its end. fn read(l: *L, s: *Start, done: *std.atomic.Value(bool)) void { -- cgit v1.3 From fe0aa07c18a9fd5ca6bdcb78e9354a2745e32298 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Sat, 21 Nov 2026 03:29:45 -0300 Subject: client: what the pair's last rounds left, each a test first: a window client exec'd at its session's Upgrade comes back the size it was, not the default (runtime/client.zig `execAgain` passed `--attach=` alone, so the new process made a 1120x720 window: a `--geometry=900x560` pair's session went from 56x16 to 70x20 after an Upgrade to another build, with the variable or without (any `pardes-gui attach`); now the window's size at the exec, SDL_GetWindowSize, as `--geometry=WxH`); a pair's client exec'd at an Upgrade waits for its session at `ended` as before the exec (tui.zig and gui.zig `runClient` asked `opts.pair`, which the exec'd `--attach=` client has not: now every near client waits, a non-child answers ECHILD at once; not seen to fail here: the subreaper took the session first); tests in test/daemon.py: `pair_upgrade_views` (plain, --pair: two clients' own views, the pair's scroll and the attach's focus, the same after a same-build Upgrade: the screens by pyte, the focus by where typing lands: passed before this change too), `pair_exec_reaps`, `far_exec` (a far client, PARDES_REPLICA_FAR by the socket's path, execs the build at its start path and agrees after: passed before too), `pair_window_geometry` (offscreen, not test mode: failed before), the last three in --upgrade OLD NEW Co-Authored-By: Claude Opus Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T --- dev/gui/gui.zig | 14 ++- dev/tui/tui.zig | 10 +- runtime/client.zig | 7 +- test/daemon.py | 324 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 341 insertions(+), 14 deletions(-) (limited to 'runtime/client.zig') diff --git a/dev/gui/gui.zig b/dev/gui/gui.zig index d10173b4..d779cf47 100644 --- a/dev/gui/gui.zig +++ b/dev/gui/gui.zig @@ -1429,16 +1429,22 @@ fn clientSession(init: std.process.Init, g: *Gui, opts_in: pardes.Options, test_ .gone => Said.no(io, "'{s}' let this client go (a Detach in it, or the session's end)", .{to.session}), .failed => Said.no(io, "{s}", .{start.said()}), // A new process's window: the build at its start path, exec'd. - .upgrade => |view| Said.no(io, "{s}", .{client_loop.execAgain(&start, view)}), + .upgrade => |view| { + // Its new window the size this one has now. + var size: [2]c_int = .{ 0, 0 }; + _ = c.SDL_GetWindowSize(g.window, &size[0], &size[1]); + Said.no(io, "{s}", .{client_loop.execAgain(&start, view, size)}); + }, .left => { var said: [600]u8 = undefined; std.Io.File.stderr().writeStreamingAll(io, std.fmt.bufPrint(&said, "pardes-gui: detached from '{s}', which is still running; come back with `pardes-gui attach {s}`\n", .{ to.session, to.session }) catch "pardes-gui: detached\n") catch {}; std.process.exit(0); }, .ended => |code| { - // A pair's window is its session's parent: its status once it - // is gone, as the terminal's (tui.zig `runClient`). - if (opts_in.pair != null) { + // A pair's window is its session's parent, an exec'd one too: + // its status once it is gone, as the terminal's (tui.zig + // `runClient`). + if (!to.far) { var status: c_int = 0; while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} } diff --git a/dev/tui/tui.zig b/dev/tui/tui.zig index a6d2216d..09704424 100644 --- a/dev/tui/tui.zig +++ b/dev/tui/tui.zig @@ -800,9 +800,11 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, }, .ended => |code| { screen.leave(); - // A pair's client is its session's parent: its status once it - // is gone, as a terminal's job ends with its program. - if (opts.pair != null) { + // A pair's client is its session's parent, an exec'd one too + // (an Upgrade's, which `opts.pair` no longer says): its status + // once it is gone, as a terminal's job ends with its program. + // Not its child: no wait (ECHILD at once). + if (!far_link) { var status: c_int = 0; while (libc.waitpid(@intCast(start.joined.pid), &status, 0) < 0 and libc.errno(-1) == .INTR) {} } @@ -816,7 +818,7 @@ pub fn runClient(init: std.process.Init, opts: pardes.Options, path: []const u8, // The blink: its screen left, the build at its start path // exec'd, which enters it again. screen.leave(); - Said.no(io, "{s}", .{client_loop.execAgain(&start, view)}); + Said.no(io, "{s}", .{client_loop.execAgain(&start, view, null)}); }, } } diff --git a/runtime/client.zig b/runtime/client.zig index c550b0fa..22e60fc1 100644 --- a/runtime/client.zig +++ b/runtime/client.zig @@ -125,11 +125,14 @@ pub const Ended = union(enum) { done, gone, failed, left, ended: u8, upgrade: u8 /// process's child still), joining for `view` (PARDES_JOIN_VIEW; far, /// PARDES_REPLICA_FAR). The terminal's blink: no record crosses the exec. /// Returns only when the exec failed: why. -pub fn execAgain(s: *Start, view: u8) []const u8 { +pub fn execAgain(s: *Start, view: u8, size: ?[2]c_int) []const u8 { const path = upgrade.exe() orelse return "Upgrade: this client does not know the path it was started from"; var at_buf: [4200]u8 = undefined; const at = std.fmt.bufPrintSentinel(&at_buf, "--attach={s}:{s}", .{ s.dial.path, s.dial.session }, 0) catch return "Upgrade: the session's socket's path is too long to attach again by"; - const argv = [_:null]?[*:0]const u8{ path, at }; + // A window's new window the size it had (`--geometry`), not the default. + var size_buf: [48]u8 = undefined; + const geometry: ?[*:0]const u8 = if (size) |wh| (std.fmt.bufPrintSentinel(&size_buf, "--geometry={d}x{d}", .{ wh[0], wh[1] }, 0) catch unreachable).ptr else null; // two c_ints fit 48 + const argv = [_:null]?[*:0]const u8{ path, at, geometry }; var view_buf: [32]u8 = undefined; const joining = std.fmt.bufPrintSentinel(&view_buf, "PARDES_JOIN_VIEW={d}", .{view}, 0) catch unreachable; // a u8 fits 32 var n: usize = 0; diff --git a/test/daemon.py b/test/daemon.py index 5744b099..7a600048 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -30,7 +30,8 @@ private HOME and runtime directory: python3 -B test/daemon.py --pair PARDES_PAIR: a terminal's session and its first client python3 -B test/daemon.py --attach-upgrading - an attach started as its session upgrades (in plain and --pair too) + an attach started as its session upgrades, and two clients' views + across an Upgrade (in plain and --pair too) python3 -B test/daemon.py --relink the daemon killed: its sessions register again with the next; and one stopped: an Adopt waits for its answer to the hello @@ -44,6 +45,7 @@ private HOME and runtime directory: at 0/30/80/207 ms, and a window's session serving replicas """ import fcntl +import json import os import random import re @@ -925,6 +927,312 @@ def attach_upgrading(binary, rounds=6): 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 + down a long file a page at a time, the attach's focus on a pane of its + own (New); an Upgrade lets both go and each joins again for its view + (views.away): the same lines shown, the cursor where it was, in each.""" + import pyte + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rv-', 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', PARDES_PAIR='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(300))) + terms = [] + + def screen(t): + s = pyte.Screen(100, 30) + # Its colours (SGR with colons, which pyte misreads) left out. + pyte.ByteStream(s).feed(re.sub(rb'\x1b\[[0-9:;]*m', b'', t.text())) + return s + + def shown(t): + """The notes' lines it shows, and its cursor.""" + s = screen(t) + return sorted(int(m.group(1)) for row in s.display for m in re.finditer(r'line (\d+) of the notes', row)), (s.cursor.x, s.cursor.y) + + def settled(t): + last = [None, 0] + + def same(): + now = shown(t) + if now != last[0]: + last[0], last[1] = now, time.monotonic() + return time.monotonic() - last[1] > 1.5 and now + return wait_for('its screen settled', same, timeout=30) + + try: + t = Term(30, 100) + terms.append(t) + c = t.spawn([binary, '--9p=pv', str(notes)], env) + sock = root / 'pardes-9p-pv.sock' + wait_for('the socket', sock.exists) + nine = Client(sock) + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + wait_for('drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) + for _ in range(3): + os.write(t.master, b'\x1b[6~') + time.sleep(.2) + tt = Term(30, 100) + terms.append(tt) + a = tt.spawn([binary, 'attach', 'pv'], env) + wait_for('the attach drawn', lambda: b'\x1b[?1049h' in tt.text(), timeout=30) + os.write(tt.master, b'j') + time.sleep(.3) + before_panes = view_panes(nine) + nine.write('/exec', b'New\n') + wait_for('a pane in the attach\'s view', lambda: view_panes(nine) - before_panes) + + def focus(): + """Each client's focus: its view live (a key that moves nothing).""" + got = [] + for term in (t, tt): + os.write(term.master, b'\x1b') + time.sleep(.6) + got.append(nine.read('/focus')) + return got + focused = focus() + before = settled(t), settled(tt) + assert before[0][0] and before[0][0][0] >= 40, ('the pair scrolled', before[0]) + marks = len(t.text()), len(tt.text()) + ino = sock.stat().st_ino + nine.write('/ctl', b'Upgrade\n') + nine.socket.close() + wait_for('the session exec\'d', lambda: sock.stat().st_ino != ino, timeout=60) + nine = reconnect(sock) + for term, mark in zip((t, tt), marks): + wait_for('joined again', lambda: b'joined again' in term.text()[mark:], timeout=30) + after = settled(t), settled(tt) + assert after == before, ('each client\'s lines and cursor as they were', before, after) + # Its focus: what it types lands in the pane it had the keyboard in + # (/focus, read after a key, is which view is live then: not a + # client's own). + for term, pane, word in zip((t, tt), focused, (b'PAIRTYPED', b'ATTACHTYPED')): + os.write(term.master, b'i' + word + b'\x1b') + wait_for('typed into its pane', lambda: word in nine.read(f'/pane/{int(pane)}/body'), timeout=10) + print('pair upgrade views: two clients, each its own view: the pair\'s scroll and the attach\'s focus as they were after an Upgrade') + nine.socket.close() + a.terminate() + a.wait(timeout=20) + os.kill(c.pid, signal.SIGTERM) + c.wait(timeout=20) + wait_for('the session ended', lambda: not alive(session), timeout=30) + finally: + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + for t in terms: + t.close() + shutil.rmtree(root, ignore_errors=True) + + +def pair_exec_reaps(old, new): + """PARDES_PAIR across builds: a pair started from `root/bin` (old), its + session upgraded to the build installed there since (new): its client, + the session's parent, execs that build (the blink) and is still its + parent; Exit typed then: the client returns once the session is gone, + reaped, its status the session's (0), as before the exec.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rpx-', 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', PARDES_PAIR='1') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + (root / 'bin').mkdir() + binary = root / 'bin' / 'pardes' + install(old, binary) + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(30))) + terms = [] + try: + t = Term(30, 100) + terms.append(t) + c = t.spawn([str(binary), '--9p=px', str(notes)], env) + sock = root / 'pardes-9p-px.sock' + wait_for('the socket', sock.exists) + nine = Client(sock) + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + assert ppid(session) == c.pid + wait_for('drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) + install(new, binary) + ino = sock.stat().st_ino + 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) + nine.write('/ctl', b'Exit\n') + nine.socket.close() + assert c.wait(timeout=30) == 0, c.returncode + # Its parent's wait returned: the session reaped, not a zombie left + # to whoever takes it in. + assert not os.path.exists(f'/proc/{session}') if procfs else not alive(session), open(f'/proc/{session}/stat').read() + print('pair exec reaps: a pair\'s client exec\'d at its session\'s Upgrade still reaps it at Exit, status 0') + finally: + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + for t in terms: + t.close() + shutil.rmtree(root, ignore_errors=True) + + +def far_exec(old, new): + """A far client (PARDES_REPLICA_FAR, as through ssh's forward) of a + session started from `root/bin` (old), the session upgraded to the build + installed there since (new): the far client execs the build at its own + start path (its install holds the session's build now), the same + process, far still, and is back in its view: its key steps the session + and its digest agrees. Not through ssh: its forward's own end is not + here (its socket file left behind at the exec, the far install holding + another build: not covered).""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rfx-', 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') + (root / 'bin').mkdir() + binary = root / 'bin' / 'pardes' + install(old, binary) + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(30))) + terms = [] + try: + out = subprocess.run([str(binary), 'new', '--detach=fx', str(notes)], env=env, cwd=root, capture_output=True, timeout=30) + assert out.returncode == 0, out + sock = root / 'pardes-9p-fx.sock' + nine = Client(sock) + session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + t = Term(30, 100) + terms.append(t) + check = root / 'f.check' + c = t.spawn([str(binary), f'--attach={root / "pardes-replica.sock"}:fx'], + dict(env, PARDES_REPLICA_FAR='1', PARDES_REPLICA_CHECK=str(check))) + wait_for('the far client drawn', lambda: b'line 3 of the notes' in t.text(), timeout=30) + key = lambda b: os.write(t.master, b) # noqa: E731 + seen = len(checks(check)) + key(b'gg') + wait_for('its key stepped', lambda: agreed(check, seen + 1), timeout=30) + install(new, binary) + mark = len(t.text()) + ino = sock.stat().st_ino + nine.write('/ctl', b'Upgrade\n') + nine.socket.close() + wait_for('the session exec\'d', lambda: sock.stat().st_ino != ino, timeout=60) + nine = reconnect(sock) + wait_for('the far client on the new build', lambda: exe_of(c.pid) == (str(binary), True), timeout=30) + assert b'PARDES_REPLICA_FAR=1' in open(f'/proc/{c.pid}/environ', 'rb').read().split(b'\0') if procfs else True + wait_for('the terminal entered again', lambda: t.text().rfind(b'\x1b[?1049h') > t.text().rfind(b'\x1b[?1049l') > mark, timeout=30) + seen = len(checks(check)) + key(b'j') + wait_for('its key stepped after', lambda: agreed(check, seen + 1), timeout=30) + assert c.poll() is None + print('far exec: a far client exec\'d the build at its start path at its session\'s Upgrade, far still, and agrees') + c.terminate() + c.wait(timeout=20) + nine.socket.close() + assert subprocess.run([str(binary), 'kill', 'fx'], env=env, capture_output=True, timeout=30).returncode == 0 + wait_for('the session ended', lambda: not alive(session), timeout=30) + finally: + for p in processes(root): + try: + os.kill(p, signal.SIGKILL) + except OSError: + pass + for t in terms: + t.close() + shutil.rmtree(root, ignore_errors=True) + + +def pair_window_geometry(gui_binary, new_gui): + """PARDES_PAIR, a window with `--geometry=WxH` (offscreen, not test + mode: its grid is its window's): another build at its start path, its + session upgraded: the window client execs it, and its new window is the + size it had (the session's grid as before), not the default's.""" + scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' + scratch.mkdir(parents=True, exist_ok=True) + root = Path(tempfile.mkdtemp(prefix='rgg-', 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'), + SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_DAEMON='on', TERM='xterm-256color', PARDES_PAIR='1', + SDL_VIDEO_DRIVER='offscreen') + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + notes = root / 'notes.txt' + notes.write_text(''.join(f'line {i} of the notes\n' for i in range(30))) + (root / 'bin').mkdir() + gui = root / 'bin' / 'pardes-gui' + install(Path(gui_binary), gui) + install(Path(gui_binary).with_name('pardes'), gui.with_name('pardes')) + procs = [] + + def grid(nine): + s = json.loads(nine.read('/screen')) + return s['cols'], s['rows'] + + def started(name, *flags): + p = subprocess.Popen([str(gui), f'--9p={name}', *flags, str(notes)], env=env, cwd=root, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=open(root / f'{name}.err', 'w'), start_new_session=True) + procs.append(p) + sock = root / f'pardes-9p-{name}.sock' + wait_for(f'session {name}\'s 9P socket', sock.exists, timeout=30) + nine = Client(sock) + wait_for('its window\'s grid', lambda: grid(nine) != (80, 24), timeout=30) + time.sleep(1) + return p, nine, grid(nine) + + try: + p0, n0, plain = started('plain') + n0.write('/ctl', b'Exit\n') + n0.socket.close() + p0.wait(timeout=30) + p, nine, sized = started('sized', '--geometry=900x560') + assert sized != plain, ('--geometry makes its own grid', sized, plain) + install(Path(new_gui), gui) + install(Path(new_gui).with_name('pardes'), gui.with_name('pardes')) + sock = root / 'pardes-9p-sized.sock' + ino = sock.stat().st_ino + 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 window on the new build', lambda: exe_of(p.pid) == (str(gui), True), timeout=30) + nine = reconnect(sock) + time.sleep(3) + assert grid(nine) == sized, ('the exec\'d window the size it had', grid(nine), sized, plain) + print(f'pair window geometry: --geometry=900x560 ({sized[0]}x{sized[1]}, the default {plain[0]}x{plain[1]}): the window exec\'d at an Upgrade the size it had') + nine.write('/ctl', b'Exit\n') + nine.socket.close() + p.wait(timeout=30) + finally: + for p in procs: + if p.poll() is None: + p.kill() + for q in processes(root): + try: + os.kill(q, signal.SIGKILL) + except OSError: + pass + shutil.rmtree(root, ignore_errors=True) + + def manage(binary): """`pardes --ps`, `--kill=NAME` and `--kill-all`: two detached sessions and their shells listed, one session killed outright and its shell @@ -2132,6 +2440,7 @@ def main(binary, cycles): pair(binary) pair_rows(binary) attach_upgrading(binary) + pair_upgrade_views(binary) manage(binary) relink(binary) answer_late(binary) @@ -3070,10 +3379,16 @@ if __name__ == '__main__': if sys.argv[1:3] == ['--upgrade', '--gui']: gui_upgrades(Path(sys.argv[3]).resolve(), Path(sys.argv[4]).resolve()) elif sys.argv[1:2] == ['--upgrade']: - upgrades(Path(sys.argv[2]).resolve(), Path(sys.argv[3]).resolve()) + old, new = Path(sys.argv[2]).resolve(), Path(sys.argv[3]).resolve() + upgrades(old, new) + if knows_exec(old): + pair_exec_reaps(old, new) + far_exec(old, new) # With a pardes-gui beside each: the clients carried too. - if all(Path(a).resolve().with_name('pardes-gui').exists() for a in sys.argv[2:4]): - upgrade_clients(Path(sys.argv[2]).resolve(), Path(sys.argv[3]).resolve()) + if all(a.with_name('pardes-gui').exists() for a in (old, new)): + upgrade_clients(old, new) + if knows_exec(old): + pair_window_geometry(old.with_name('pardes-gui'), new.with_name('pardes-gui')) elif sys.argv[1:2] == ['--upgrade-clients']: upgrade_clients(Path(sys.argv[2]).resolve(), Path(sys.argv[3]).resolve()) elif sys.argv[1:2] == ['--clients']: @@ -3086,6 +3401,7 @@ if __name__ == '__main__': pair(sys.argv[2]) pair_rows(sys.argv[2]) attach_upgrading(sys.argv[2]) + pair_upgrade_views(sys.argv[2]) elif sys.argv[1:2] == ['--attach-upgrading']: attach_upgrading(sys.argv[2]) elif sys.argv[1:2] == ['--relink']: -- cgit v1.3