diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-20 04:50:25 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-20 05:42:56 -0300 |
| commit | 32ac0d9d5f7de60f2045edbd1c15631306bd25d4 (patch) | |
| tree | be11dddf1bcafa3cdee710ff5553e42e4a7b4afa /test | |
| parent | 821509e5cbe47e73ce4f4fcdc5d092f3c5e1c986 (diff) | |
| download | pardes-32ac0d9d5f7de60f2045edbd1c15631306bd25d4.tar.gz pardes-32ac0d9d5f7de60f2045edbd1c15631306bd25d4.zip | |
pair: PARDES_PAIR (a working name, one variable) makes `pardes FILE` in a terminal a session and its first client over a socket pair (the last step's design 1.1, Z1): the daemon dialled first as for a stub, the terminal's size read, a fork; the parent is the client (the shell's job, the terminal its own, so WINCH/HUP/TERM reach what draws), its first join on its end of the pair (runtime/main.zig `pair`, tui.runClient unchanged); the child is the session (setsid, 0/1/2 on /dev/null, detached, registered on the dialled connection), its end taken as its first client before its first effects (the previous change); with no daemon too, where a pair's session ends with its last link (runtime/session.zig); without the variable nothing changes (tui core-test 856/1009, shell-test 1049/1052, term 17/17, pane 183/184, kitty 45/45, behaviour 275/275 and --replay, process-test 0 of 144 but pagercolor, which passed alone, both soaks diverged 0 unequal 0 corpus 22 of 22, the bytes soak's one unlisted stop now:1 the base's; daemon.py plain, far, games, upgrade both ways pass); test/daemon.py `pair` (and --pair): the job, the session its child in a session of its own, listed with its client, drawn, typed, digests agreed, Exit ends both, with no daemon a client killed outright ends its session, nothing left; process-test with the variable: 17 of 144 fail as pairs (the harness dials the launched pid's socket, its goldens are an own frontend's frames, a Restore lets the client go with no daemon to rejoin through, its signal and no-terminal cases are the own path's), and one daemon-on case leaves its pair session running (a killed client is a loss: Z4's harness), test/process.zig passes PARDES_PAIR through for that run
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 | 74 | ||||
| -rw-r--r-- | test/process.zig | 3 |
2 files changed, 76 insertions, 1 deletions
diff --git a/test/daemon.py b/test/daemon.py index 5214bb00..5a53f149 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -27,6 +27,8 @@ private HOME and runtime directory: the replica clients alone python3 -B test/daemon.py --launch <pardes> `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 --relink <pardes> the daemon killed: its sessions register again with the next python3 -B test/daemon.py --far <pardes> @@ -595,6 +597,75 @@ def launch(binary): shutil.rmtree(root, ignore_errors=True) +def pair(binary): + """PARDES_PAIR: `pardes FILE` in a terminal is a session forked off for + it with this terminal its first client (the last step's design, 1.1): + the job the client, the terminal its own; the session its child, in a + session of its own, registered (`ps`: detached, the client listed), + the file drawn, keys in, the digests agreed once quiet; the session's + Exit ends both. With no daemon the client killed outright ends the + session (its last link). Nothing left behind.""" + 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.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(30))) + terms = [] + + def session_of(name): + sock = root / f'pardes-9p-{name}.sock' + wait_for(f'session {name}\'s 9P socket', sock.exists) + nine = Client(sock) + return nine, int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid']) + + try: + t = Term(30, 100) + terms.append(t) + c = t.spawn([binary, '--9p=pair', str(notes)], dict(env, PARDES_REPLICA_CHECK=str(root / 'pair.check'))) + nine, session = session_of('pair') + assert session != c.pid and ppid(session) == c.pid and os.getsid(session) == session, (session, c.pid) + wait_for('the file drawn on the terminal', lambda: b'line 3 of the notes' in t.text(), timeout=30) + listed = lambda: subprocess.run([binary, 'ps'], env=env, capture_output=True).stdout.decode() + wait_for('the client listed', lambda: f'session pair {session} (tty, detached)' in listed() + and f'client {c.pid} ' in listed()) + pane = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'text') + os.write(t.master, b'Ofrom-the-pair\x1b') + wait_for('its keys in the session\'s text', lambda: b'from-the-pair' in nine.read(f'/pane/{pane}/body')) + wait_for('out of insert mode', lambda: normal_again(t)) + wait_for('the client agrees once quiet', lambda: agreed(root / 'pair.check', 0)) + exit_session(nine, pane) + code = c.wait(timeout=20) + wait_for('the session gone', lambda: not alive(session), timeout=20) + print(f'pair: client {c.pid} (the job) and session {session} (its child, setsid, listed detached with the client); ' + f'drawn, typed, agreed; Exit ended both (the client exit {code})') + nine.socket.close() + lone = Term(24, 80) + terms.append(lone) + c2 = lone.spawn([binary, '--9p=lone', str(notes)], dict(env, PARDES_DAEMON='off')) + nine2, session2 = session_of('lone') + wait_for('the lone pair drawn', lambda: b'line 3 of the notes' in lone.text(), timeout=30) + nine2.socket.close() + os.kill(c2.pid, signal.SIGKILL) + c2.wait(timeout=10) + wait_for('the lone session ended with its last link', lambda: not alive(session2), timeout=20) + wait_for('nothing left', lambda: not [p for p in processes(root) if alive(p)], timeout=20) + print(f'pair: with no daemon, client {c2.pid} killed outright, its session {session2} ended; nothing left behind') + 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 manage(binary): """`pardes --ps`, `--kill=NAME` and `--kill-all`: two detached sessions and their shells listed, one session killed outright and its shell @@ -1591,6 +1662,7 @@ def main(binary, cycles): far(binary) by_hash(binary) launch(binary) + pair(binary) manage(binary) relink(binary) shell = terminals(client)[0] @@ -2303,6 +2375,8 @@ if __name__ == '__main__': manage(sys.argv[2]) elif sys.argv[1:2] == ['--launch']: launch(sys.argv[2]) + elif sys.argv[1:2] == ['--pair']: + pair(sys.argv[2]) elif sys.argv[1:2] == ['--relink']: relink(sys.argv[2]) elif sys.argv[1:2] == ['--games']: diff --git a/test/process.zig b/test/process.zig index 8bcbddeb..e2a4f592 100644 --- a/test/process.zig +++ b/test/process.zig @@ -916,7 +916,8 @@ pub const Child = struct { while (environ[i]) |kv| { const entry = std.mem.span(kv); const eq = std.mem.indexOfScalar(u8, entry, '=') orelse entry.len; - if (std.mem.startsWith(u8, entry, "PARDES_") or std.mem.indexOf(u8, entry[0..eq], "PAGER") != null) { + // PARDES_PAIR kept: the suite run as pairs (main.zig `pair`). + if ((std.mem.startsWith(u8, entry, "PARDES_") and !std.mem.startsWith(u8, entry, "PARDES_PAIR=")) or std.mem.indexOf(u8, entry[0..eq], "PAGER") != null) { var name: [256]u8 = undefined; const n = std.fmt.bufPrintSentinel(&name, "{s}", .{entry[0..@min(eq, 255)]}, 0) catch _exit(126); _ = unsetenv(n); |
