diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-22 16:57:59 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-22 18:52:03 -0300 |
| commit | b3c38ea198e1fe915f029d7e41b469b8a53d2338 (patch) | |
| tree | d6db809889ae1412146ca9dc806fb7d61f8e2bd2 /test | |
| parent | 9863a63b614d200852853825031189364dcacfdc (diff) | |
| parent | 6401b327a217c144895e22fb7ad24d986af97d86 (diff) | |
| download | pardes-b3c38ea198e1fe915f029d7e41b469b8a53d2338.tar.gz pardes-b3c38ea198e1fe915f029d7e41b469b8a53d2338.zip | |
integration: the pair's chain on the gathered line: pardes-pair-10 (`vxutwuwz`, the pair's ten changes on pardes-merge50 past the four already gathered: a window's facts its client's (P47: WindowOpacity applied by a client window, `Font` gated by the desktop builds' capabilities, not the frontend's build), a window pair's session listed as a window's (P49), the user's terminal put back when a pair's client dies with no word (P48), a pair's user told a newer build is installed, an addon's landing on the tape and a client on the session's machine running a kind loaded by path (`Site.landing`, P51), an upgraded pair's session attended until its client is back, and test/daemon.py's `--with-pair`, `base_env`, `listed_as` and the Restore test as P44) on pardes-merge57 (the terminals' old road deleted, the wire at 30); two textual conflicts: core/replica.zig `Peer`'s fields (the pair's `bye` and `pair` kept, the deletion's removal of `sid` with its `Screens` kept) and test/daemon.py's head (the pair's `WITH_PAIR`, `base_env` and `listed_as` kept where the deletion had removed `KEEP`); the semantic ones the text did not show: the pair's `zwrkukrx` (`PARDES_TERM_BYTES`, its switch to the bytes road) merged without a conflict into core/replica.zig `takeJoined` (setting `r.t.screen_state`, a field the deletion removed), runtime/session.zig (`Peers.bytes`, removed) and test/process.zig (its passthrough): all three taken out, the gathered line's text there exactly, no road to choose (core/root.zig's machine_lines for replica.zig stays at the gathered line's 76: the pair's +1 was that getenv); test/daemon.py's two functions the gathered line added after the pair's base (`kept_views`, `kitty_image`) built their environment in the idiom `base_env()` replaced at every other site: now `base_env()` (the same without `--with-pair`; with it they run as a user who exported PARDES_PAIR, as every other mode does); the pair's `Peers.input` focus line, written after `screensOut` (deleted), stands alone before the step; `Site.landing` stays at the enum's end after `medium` (`images` gone): `wire.semantics` moves as any tape change does, no version line; and found by the gate: test/panes.zig's P51 test (the pair's, written on its old base) called `Authority.init` and `Replica.init` with the road's flag the deletion removed (pane-test did not compile): the argument removed, as merge57 did in core/jj.zig; nothing in core/tape.zig, abi/wire.zig or core/views.zig resolved by hand; gate (Debug tui in the workspace, loads 2-10): core-test 916/1073 (157 skipped), shell-test 1115/1118 (3 skipped), pane-test 182/183 (1 skipped: the base's + the P51 test), term-test 15/15, kitty-test 45/45, addon-test 5/5, behaviour-test and --replay 275/275, consumer-test, process-test own 0 of 146 and as pairs 0 of 146 (themesel first time as a pair, alone 0 of 5 first time and 5 of 5 on the runner's retry: pair-8's open case); the soak --clients 5 diverged 0, unequal 0 at 30/80/207 ms, unlisted 0, the corpus 22 of 22, no leak; daemon.py on Debug and ReleaseSafe: plain 3 of 3 each, --restore PASS each (P44's test, failing on the base), --pair, --attach-upgrading, --clients 3 of 3 each, --far PASS on ReleaseSafe and on Debug 3 of 3 alone (once at load 10 by_hash saw a client join again); --upgrade from the installed build PASS; with --with-pair every mode passes on both builds (plain, clients, manage, launch, relink, far, restore, attach-upgrading, pair, window-clients, gui, games, kitty-image), its --upgrade both ways past pair-10's wall and failing later (far_exec; a client's check differing after a ReleaseSafe-to-Debug Upgrade); the frame and perf gate against tree3 (gpu/pp11-g): 77/77 frames, perfab corpus2x +0.105% (noise 0.048%), 121 counts within 0.1% (largest terminal-on-all +0.085%)
Co-Authored-By: Claude Opus <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 177 | ||||
| -rw-r--r-- | test/panes.zig | 55 |
2 files changed, 172 insertions, 60 deletions
diff --git a/test/daemon.py b/test/daemon.py index 55cffaf4..9e0047e5 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -29,6 +29,8 @@ private HOME and runtime directory: `pardes new --detach` returns once its session runs python3 -B test/daemon.py --pair <pardes> PARDES_PAIR: a terminal's session and its first client + python3 -B test/daemon.py --with-pair <mode> ... + any mode with PARDES_PAIR set in every process it starts python3 -B test/daemon.py --attach-upgrading <pardes> an attach started as its session upgrades, and two clients' views across an Upgrade (in plain and --pair too) @@ -69,6 +71,29 @@ from pathlib import Path sys.path.insert(0, str(Path(__file__).parent)) from ninep import Client # noqa: E402 +# `--with-pair` before a mode: that mode as a user who exported PARDES_PAIR. +WITH_PAIR = False + + +def base_env(): + """This process's environment without the caller's PARDES_* (a session + of the user's) or a pager; under `--with-pair`, PARDES_PAIR set in it, as + for a user who exported it: every mode run with the variable.""" + env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + if WITH_PAIR: + env['PARDES_PAIR'] = '1' + return env + + +def listed_as(word, kind='tty'): + """How `--ps` lists a session `detached` (started so, or Detached in its + own frontend) or that `has a frontend`: under the variable the first is + kept (from birth, or at the Detach) and the second a pair (P36).""" + if WITH_PAIR: + return f'({kind}, kept)' if word == 'detached' else f'({kind})' + return f'({kind}, {word})' + + def wait_for(what, check, timeout=10): deadline = time.monotonic() + timeout while True: @@ -454,7 +479,7 @@ def clients(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rc-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -596,7 +621,7 @@ def launch(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rl-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -623,12 +648,12 @@ def launch(binary): assert (root / 'pardes-9p-work.sock').exists(), list(root.iterdir()) pid = status_pid('work') listed = cli('ps').stdout.decode() - assert f'session work {pid} (tty, detached)' in listed, listed + assert f'session work {pid} {listed_as('detached')}' in listed, listed assert alive(pid) and os.getsid(pid) == pid, (pid, os.getsid(pid)) out = cli('new', '--detach') assert out.returncode == 0 and out.stdout.strip().isdigit(), out unnamed = int(out.stdout) - assert status_pid(str(unnamed)) == unnamed and f'session {unnamed} {unnamed} (tty, detached)' in cli('ps').stdout.decode() + assert status_pid(str(unnamed)) == unnamed and f'session {unnamed} {unnamed} {listed_as('detached')}' in cli('ps').stdout.decode() taken = cli('new', '--detach=work') assert taken.returncode == 1 and taken.stderr == b'pardes: a session named work is already running\n', taken # The flag alone runs the session in this process, as a supervisor @@ -664,7 +689,7 @@ def pair(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rp-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -738,7 +763,7 @@ def pair_rows(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -928,7 +953,7 @@ def attach_upgrading(binary, rounds=6, dump=True): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ru-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -1019,7 +1044,7 @@ def kept_views(binary): 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 = base_env() 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) @@ -1091,7 +1116,7 @@ def pair_upgrade_views(binary): 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 = base_env() 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) @@ -1197,7 +1222,7 @@ def pair_exec_reaps(old, new): 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 = base_env() 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) @@ -1261,7 +1286,7 @@ def far_exec(old, new): 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 = base_env() 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) @@ -1327,7 +1352,7 @@ def pair_window_geometry(gui_binary, new_gui): 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 = base_env() 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') @@ -1399,7 +1424,7 @@ def manage(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rm-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -1435,14 +1460,14 @@ def manage(binary): listed = out.stdout.decode() assert f'pardes daemon {daemon}' in listed, listed for name in ('one', 'two'): - assert f'session {name} {sessions[name]} (tty, detached)' in listed, listed + assert f'session {name} {sessions[name]} {listed_as('detached')}' in listed, listed assert f'shell {shells[name]}' in listed, listed # The same, a record a line, in each session's /sessions. with Client(root / 'pardes-9p-one.sock') as c: records = c.read('/sessions').decode().splitlines() assert records[0] == f'daemon {daemon}', records for name in ('one', 'two'): - at = records.index(f'session {sessions[name]} tty detached {name}') + at = records.index(f'session {sessions[name]} tty {"kept" if WITH_PAIR else "detached"} {name}') assert records[at + 1] == f'shell {shells[name]}', records print('manage: /sessions read over 9P listed the daemon, both sessions and their shells') os.kill(sessions['two'], signal.SIGKILL) @@ -1503,7 +1528,7 @@ def relink(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -1545,7 +1570,7 @@ def relink(binary): own_shell = terminals(own)[0] own_shell_pid = int(run(own, own_shell, b'echo $$\n').split(b'\n')[1]) started.append(own_shell_pid) - expected = [f'session work {session} (tty, detached)', f'session own {own_pid} (tty, has a frontend)', + expected = [f'session work {session} {listed_as("detached")}', f'session own {own_pid} {listed_as("has a frontend")}', f'shell {shell_pid}', f'shell {own_shell_pid}'] assert all(row in listed() for row in expected), listed() daemon = daemons()[0] @@ -1609,7 +1634,7 @@ def answer_late(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ra-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -1727,7 +1752,7 @@ def pdf_window(binary, gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='pdfw-', dir=os.environ.get('TMPDIR') or scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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') env.pop('XDG_DATA_HOME', None) @@ -1793,7 +1818,7 @@ def window_clients(binary, gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='wc-', dir=os.environ.get('TMPDIR') or scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -1845,7 +1870,7 @@ def window_clients(binary, gui_binary): if not rtt: # Its clients are no sessions of the daemon's. listed = sessions_listed(binary, env, root) - assert [(n, k) for n, _, k in listed] == [('files', '(tty, detached)')], listed + assert [(n, k) for n, _, k in listed] == [('files', listed_as('detached'))], listed # Moved and scrolled, its own view only: agreed again. n = len(checks(check)) w.keys(b'jjjjjkkk\x06\x06\x02') @@ -1951,15 +1976,19 @@ def window_clients(binary, gui_binary): wait_for('the terminal client agrees with the window', lambda: agreed(root / 'b.check', nb), timeout=30) wait_for('the window client agrees with the window', lambda: agreed(root / 'g.check', ng), timeout=30) listed = sessions_listed(binary, env, root) - assert [(n, k) for n, _, k in listed] == [('win', '(gui, has a frontend)')], listed + assert [(n, k) for n, _, k in listed] == [('win', listed_as('has a frontend', 'gui'))], listed assert wg.close() == 0, wg.said()[-800:] os.write(tb.master, b' sD') wait_for('the terminal client let go', lambda: b.poll() is not None, timeout=10) assert win.p.poll() is None print(f'daemon: a window\'s session served a terminal\'s client and a window\'s, digests agreed ' - f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times; --ps listed it alone, (gui, has a frontend)') + f'{len(checks(root / "b.check"))} and {len(checks(root / "g.check"))} times; --ps listed it alone, {listed_as("has a frontend", "gui")}') win.close() nine.socket.close() + # Under the variable the window is its session's client, and the + # terminal client's Detach kept that session (P36): ended by name. + if WITH_PAIR: + subprocess.run([binary, '--kill=win'], env=dict(env, PARDES_DAEMON='on'), cwd=root, capture_output=True, timeout=30) wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=15) print('daemon: window clients\' sessions ended, nothing left behind') finally: @@ -2015,7 +2044,7 @@ def far(binary): scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rf-', dir=scratch)) cache = root / 'cache' - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_CACHE_HOME=str(cache), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_REPLICA_FAR='1') @@ -2185,7 +2214,7 @@ def far_flood(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='fl-', dir=os.environ.get('TMPDIR') or scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_CACHE_HOME=str(root / 'cache'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') @@ -2284,7 +2313,7 @@ def by_hash(binary): scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rh-', dir=scratch)) cache = root / 'cache' - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_CACHE_HOME=str(cache), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2370,7 +2399,7 @@ def games(binary, libs, secs=10): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rg-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2481,7 +2510,7 @@ def far_find(binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rq-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1', PARDES_REPLICA_FAR='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2541,14 +2570,16 @@ def far_find(binary): def restore_client(binary): - """A Restore while a client is attached: the client is let go (its link - ends), the replacement core is the session's (its tape adopts it, its - options keep none), and a client attached after agrees with it, its - keys reaching it.""" + """A Restore while a client is attached: the client is told and joins + the restored session again by itself (P44, as at an Upgrade), saying + nothing on its screen; its keys reach the replacement core (the + session's: its tape adopts it, its options keep none) and it agrees with + it, as does a client attached after. A 9P connection is the old core's: + cut, dialled again.""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rr-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), XDG_DATA_HOME=str(root / 'data'), TERM='xterm-256color', SHELL=shutil.which('bash') or '/bin/bash', PARDES_NOTIME='1') (root / 'config' / 'pardes').mkdir(parents=True) @@ -2573,23 +2604,36 @@ def restore_client(binary): wait_for(f'client {name}\'s first frame', lambda: b'line 3 of the notes' in t.text(), timeout=30) time.sleep(.3) return t, c - t, c = client('a') + ta, ca = client('a') nine.write(f'/pane/{text}/exec', b'Dump\n') nine.write(f'/pane/{text}/exec', b'Restore\n') - wait_for('client a let go at the Restore', lambda: c.poll() is not None, timeout=30) - # The 9P link was the old core's. + + def cut(): + try: + nine.read('/index') + return False + except (OSError, EOFError): + return True + wait_for('the 9P connection cut at the Restore', cut, timeout=30) nine.socket.close() nine = reconnect(root / 'pardes-9p-back.sock') text = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') - t, c = client('r') - os.write(t.master, b'Oafter the restore\x1b') texts = lambda: b''.join(nine.read(f'/pane/{row.split()[0].decode()}/body') for row in nine.read('/index').splitlines() if row.split()[1] == b'text') - wait_for('the client\'s keys in the restored session', lambda: b'after the restore' in texts(), timeout=30) + # Client a, joined again by itself: its keys in the restored core. + os.write(ta.master, b'Oa after the restore\x1b') + wait_for('client a\'s keys in the restored session', lambda: b'a after the restore' in texts(), timeout=30) + assert ca.poll() is None, 'client a ended at the Restore' + seen = len(checks(root / 'a.check')) + wait_for('client a agrees once quiet', lambda: agreed(root / 'a.check', seen), timeout=60) + assert b'joined again' not in ta.text(), ('a notice left on client a\'s screen', ta.text()) + tr, cr = client('r') + os.write(tr.master, b'Or after the restore\x1b') + wait_for('client r\'s keys in the restored session', lambda: b'r after the restore' in texts(), timeout=30) seen = len(checks(root / 'r.check')) - wait_for('the client agrees once quiet', lambda: agreed(root / 'r.check', seen), timeout=60) - assert c.poll() is None, 'the client ended' - print(f'daemon: a Restore with a client attached: it was let go, and one attached after agreed ({len(checks(root / "r.check"))} checks), its keys in the restored session') + wait_for('client r agrees once quiet', lambda: agreed(root / 'r.check', seen), timeout=60) + assert ca.poll() is None and cr.poll() is None, 'a client ended' + print(f'daemon: a Restore with a client attached: it joined again by itself, saying nothing, its keys in the restored session and agreeing ({len(checks(root / "a.check"))} checks); the 9P connection cut; one attached after agreed ({len(checks(root / "r.check"))} checks)') exit_session(nine, text) sess.wait(timeout=60) nine.socket.close() @@ -2682,7 +2726,7 @@ def kitty_image(binary, secs=5): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ri-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -2743,7 +2787,7 @@ def main(binary, cycles): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rt-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -2804,7 +2848,7 @@ def main(binary, cycles): wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in term.text()) listed = wait_for('the client in --ps', lambda: (lambda out: f'client {c.pid} ' in out and out)( subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode())) - assert f'session work {session} (tty, detached)' in listed, listed + assert f'session work {session} {listed_as("detached")}' in listed, listed os.write(term.master, f'echo {typed}\r'.encode()) wait_for('its keys in the shell', lambda: typed.encode() in client.read(f'/pane/{shell}/body')) return c @@ -2934,7 +2978,9 @@ def main(binary, cycles): wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in term.text()) listed = wait_for('the client in --ps', lambda: (lambda out: f'client {stub.pid} ' in out and out)( subprocess.run([binary, '--ps'], env=env, capture_output=True, timeout=30).stdout.decode())) - assert f'session fresh {session} (tty, detached)' in listed, listed + # (Under the variable the killed stub was the pair's client: a loss, + # the session still a pair's, P36.) + assert f'session fresh {session} {"(tty)" if WITH_PAIR else listed_as("detached")}' in listed, listed print('daemon: a session whose stub was killed outright detached, and was attached again, as a client') # The end: the session quits, its shells hang up, its client and @@ -2977,7 +3023,7 @@ def gui(binary, cycles): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rtg-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() (root / 'caps').mkdir() env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'), SHELL='/bin/bash', PARDES_NOTIME='1', PARDES_TEST='1', PARDES_TEST_CAPTURE_DIR=str(root / 'caps'), @@ -2997,6 +3043,9 @@ def gui(binary, cycles): wait_for('the window session', sock.exists, timeout=20) client = Client(sock) shell = terminals(client)[0] + # The window's own process, or under the variable its child (a + # pair: the window a client of it). + session = int(dict(line.split(maxsplit=1) for line in client.read('/status').decode().splitlines())['pid']) assert not sized(client), 'a window owns the size' # With its window: another window is a client of the session (its # own process, its captures its own), listed by --ps; closed, it @@ -3005,22 +3054,23 @@ def gui(binary, cycles): wait_for('the second window drawn', lambda: (root / 'second' / 'latest.ppm').exists(), timeout=20) assert f'client {second.pid} ' in listed(), listed() second.close() - wait_for('the client gone from --ps', lambda: 'client ' not in listed()) + # (a pair's own window is a client too: the second's pid is what goes) + wait_for('the client gone from --ps', lambda: f'client {second.pid} ' not in listed()) assert not sized(client), 'the first window stays' - assert proc.poll() is None + assert alive(session) print('daemon: a second window on a window session a client of it (in --ps), closed alone') # Detached: the window closed, the process on; every attach after it # a window client, the session detached still. client.write(f'/pane/{shell}/exec', b'Detach\n') wait_for('the window closed', lambda: sized(client)) - assert proc.poll() is None, 'the process carries on with no window' - assert f'session win {proc.pid} (gui, detached)' in listed(), listed() + assert alive(session), 'the session carries on with no window' + assert f'session win {session} {listed_as("detached", "gui")}' in listed(), listed() baseline = None for cycle in range(cycles): w = Window(root, f'w{cycle}', [binary, 'attach'] if cycle % 2 else [binary, '--attach=win'], env) wait_for('the client window drawn', lambda: (root / f'w{cycle}' / 'latest.ppm').exists(), timeout=20) wait_for('the client in --ps', lambda: f'client {w.pid} ' in listed()) - assert f'session win {proc.pid} (gui, detached)' in listed(), listed() + assert f'session win {session} {listed_as("detached", "gui")}' in listed(), listed() now = (fds(proc.pid), len(processes(root))) baseline = baseline or now assert now == baseline, (cycle, now, baseline) @@ -3037,14 +3087,14 @@ def gui(binary, cycles): tty_attach.terminate() tty_attach.wait(timeout=10) term.close() - assert proc.poll() is None + assert alive(session) print('daemon: a terminal attached to a window session by name, as a client') nobody = subprocess.run([binary, '--attach=nobody'], env=env, cwd=root, timeout=10, stdout=subprocess.PIPE, stderr=subprocess.PIPE) assert nobody.returncode == 1 and b"no session called 'nobody'" in nobody.stderr, nobody.stderr # Detached and told to end: it ends. client.write(f'/pane/{shell}/exec', b'Exit\n') - proc.wait(timeout=10) + wait_for('the session ended', lambda: not alive(session)) client.socket.close() wait_for('the daemon gone once idle', lambda: not [p for p in processes(root) if alive(p)], timeout=5) print('daemon: window session ended, nothing left behind') @@ -3072,7 +3122,7 @@ def gui_pair(gui_binary): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rgp-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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') (root / 'config' / 'pardes').mkdir(parents=True) @@ -3100,7 +3150,7 @@ def gui_pair(gui_binary): try: w, nine, session, pane = started('gp', env) - wait_for('the window listed its client', lambda: f'session gp {session} (tty)' in listed() + wait_for('the window listed its client', lambda: f'session gp {session} (gui)' in listed() and f'client {w.pid} ' in listed()) w.keys(b'Ofrom-the-window\x1b') wait_for('its keys in the session\'s text', lambda: b'from-the-window' in nine.read(f'/pane/{pane}/body')) @@ -3118,7 +3168,7 @@ def gui_pair(gui_binary): os.kill(w.pid, signal.SIGKILL) w.p.wait(timeout=10) wait_for('the client unlisted', lambda: f'client {w.pid} ' not in listed()) - assert alive(session) and f'session gl {session} (tty)' in listed(), listed() + assert alive(session) and f'session gl {session} (gui)' in listed(), listed() nine.socket.close() assert subprocess.run([binary, 'kill', 'gl'], env=env, capture_output=True, timeout=30).returncode == 0 wait_for('the session ended', lambda: not alive(session), timeout=30) @@ -3243,7 +3293,7 @@ def upgrades(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='rtu-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -3344,6 +3394,10 @@ def upgrades(old, new): # (A client of a build that execs at an Upgrade comes back: its # connection is the session's again.) gone = 2 if b'detached from' in term2.text() else 0 if knows_exec(old) and stub2.poll() is None else 1 + # (Under the variable a pair's session of a build that keeps its + # client's terminal, P48, lets it go: close-on-exec, not carried; + # such a build's put-back turns the in-band resize off.) + gone += 1 if WITH_PAIR and b'\x1b[?2048l\x1b[0m' in Path(old).read_bytes() else 0 return fds_before[0] - 2 - gone + min(state_fds(session), 1) - state_before, fds_before[1] try: wait_for('the fds level', lambda: (fds(session), fds(daemon)) == level(), timeout=5) @@ -3553,7 +3607,7 @@ def upgrade_clients(old, new): scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' scratch.mkdir(parents=True, exist_ok=True) root = Path(tempfile.mkdtemp(prefix='ruc-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() 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) @@ -3655,7 +3709,7 @@ def gui_upgrades(old, new): another build.""" scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn' root = Path(tempfile.mkdtemp(prefix='rtgu-', dir=scratch)) - env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_') and 'PAGER' not in k} + env = base_env() display = Path(os.environ.get('WAYLAND_DISPLAY', 'wayland-0')) if not display.is_absolute(): display = Path(os.environ.get('XDG_RUNTIME_DIR', f'/run/user/{os.getuid()}')) / display @@ -3746,6 +3800,9 @@ def gui_upgrades(old, new): if __name__ == '__main__': + WITH_PAIR = sys.argv[1:2] == ['--with-pair'] + if WITH_PAIR: + del sys.argv[1] # A session's state file is its HOME's, never the user's: the dumps a # test makes there would push the user's out. os.environ.pop('XDG_DATA_HOME', None) diff --git a/test/panes.zig b/test/panes.zig index 32cfd530..7d0b6396 100644 --- a/test/panes.zig +++ b/test/panes.zig @@ -4316,6 +4316,61 @@ const PdfAddon = struct { try std.testing.expect(a.core.panes[c.id] == null and win.core().panes[c.id] == null); try std.testing.expect(win.diverged == null); } + + test "Addon load <path> typed in a session lands on its client too, which runs the kind from that path while its bytes are the session's and shows its line once they are not" { + const R = pardes.replica; + const gpa = std.testing.allocator; + const io = std.testing.io; + const a = try R.Authority.init(gpa, .{ .cols = 80, .rows = 24, .file = "mise.toml" }, .{ .vtable = &host_vtable }); + defer a.deinit(); + const r = try R.Replica.init(gpa, 1, try a.unit(0, 0)); + defer r.deinit(); + const Land = struct { + a: *R.Authority, + r: *R.Replica, + fn step(l: @This(), ev: pardes.Event) !void { + l.r.confirm(try l.a.local(ev)); + } + }; + const land: Land = .{ .a = a, .r = r }; + // The image addon at a path of its own, in no addons directory. + var tmp = std.testing.tmpDir(.{}); + defer tmp.cleanup(); + const lib = try std.Io.Dir.cwd().readFileAlloc(io, addons.image, gpa, .limited(256 << 20)); + defer gpa.free(lib); + try tmp.dir.writeFile(io, .{ .sub_path = "libpic.so", .data = lib }); + try tmp.dir.writeFile(io, .{ .sub_path = "dot.ppm", .data = "P6\n1 1\n255\n\x01\x02\x03" }); + var buf: [4096]u8 = undefined; + const dir = buf[0..try tmp.dir.realPath(io, &buf)]; + var line: [4200]u8 = undefined; + try land.step(.{ .command = try std.fmt.bufPrint(&line, "Addon load {s}/libpic.so", .{dir}) }); + try std.testing.expect(r.diverged == null); + try std.testing.expect(a.core.kinds.byName("image") != null and r.core().kinds.byName("image") != null); + // A picture: the client runs the kind from the session's path. + try land.step(.{ .command = try std.fmt.bufPrint(&line, "Look {s}/dot.ppm", .{dir}) }); + try jobs(a.core, land); + const id = for (a.core.panes, 0..) |slot, i| { + if (slot) |pane| if (pane.addon != null) break i; + } else return error.NoPicture; + try std.testing.expect(r.core().panes[id].?.addon.?.ops != null); + r.settle(); + try std.testing.expect(r.diverged == null); + // The file written over since (one byte more): a client joining + // now finds other bytes there and shows the kind's line. + const longer = try std.mem.concat(gpa, u8, &.{ lib, "\x00" }); + defer gpa.free(longer); + try tmp.dir.writeFile(io, .{ .sub_path = "libpic.so", .data = longer }); + const was = pardes.tape.on; + pardes.tape.on = &a.t; + const bytes = try pardes.dump.byteDump(a.core); + pardes.tape.resync(&a.t); + pardes.tape.on = was; + defer a.core.gpa.free(bytes); + const late = try R.Replica.initDump(gpa, 2, 0, bytes, .{ .cols = 80, .rows = 24 }); + defer late.deinit(); + try std.testing.expect(late.loaded(pardes.tape.digestOf(a.core))); + try std.testing.expect(late.core().panes[id].?.addon.?.ops == null); + } }; test { |
