diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-06 06:24:42 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-06 11:19:44 -0300 |
| commit | f48973ef58ca64383517a2a2190809f9c8735dbc (patch) | |
| tree | f994007ecb070f2522bb809319e1f986ee6a3b45 /test | |
| parent | 5a9ad72e45bcac6a0e96af70664b1685e4f10595 (diff) | |
| download | pardes-f48973ef58ca64383517a2a2190809f9c8735dbc.tar.gz pardes-f48973ef58ca64383517a2a2190809f9c8735dbc.zip | |
kinds #16, replication: daemon.py's window case a PDF in a detached session with a window client turning its wheel (wire 22), and the soak's tree holds design.pdf, which its Find opens
Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_016Y9MNAtZenFv4weoMD3cge
Diffstat (limited to 'test')
| -rw-r--r-- | test/daemon.py | 73 | ||||
| -rw-r--r-- | test/soak.py | 6 |
2 files changed, 76 insertions, 3 deletions
diff --git a/test/daemon.py b/test/daemon.py index e7fee37b..976b30e2 100644 --- a/test/daemon.py +++ b/test/daemon.py @@ -228,7 +228,7 @@ class Replica: """A replica's connection (src/wire.zig): length-prefixed messages, a tag byte and a little-endian u32 length. It is a near client: its first word after the hello says so.""" - WIRE = 21 + WIRE = 22 def __init__(self, path, timeout=10): self.path, self.timeout = path, timeout @@ -641,6 +641,76 @@ def sessions_listed(binary, env, root): return [[name, pid, rest] for name, pid, rest in rows] +def pdf_window(binary, gui_binary): + """A PDF in a terminal's detached session (the pdf addon its prefix + installs, `<prefix>/lib/pardes/addons/pdf.so`), a window client attached + and its wheel turned over the PDF: the session's page moves, the + window's digest is the session's, and the window, which runs no addon + code, draws the session's frames of it. Skipped when the build has no + pdf.so.""" + lib = Path(binary).resolve().parent.parent / 'lib' / 'pardes' / 'addons' / 'pdf.so' + if not lib.exists(): + print(f'daemon: no {lib}: the PDF window case skipped') + return + 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.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) + (root / 'config' / 'pardes').mkdir(parents=True) + (root / 'config' / 'pardes' / 'init').write_text('Shell bash\nMessageLinger 0\n') + doc = root / 'design.pdf' + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', doc) + notes = root / 'notes.txt' + notes.write_text('notes\n') + started = [] + try: + sess = subprocess.Popen([binary, '--detach=pdf', str(notes)], env=env, cwd=root, stdin=subprocess.DEVNULL, + stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, start_new_session=True) + started.append(sess.pid) + sock = root / 'pardes-replica.sock' + wait_for('the replica socket', sock.exists) + wait_for('the session\'s 9P socket', (root / 'pardes-9p-pdf.sock').exists) + nine = Client(root / 'pardes-9p-pdf.sock') + assert any(row.startswith(b'pdf ') for row in nine.read('/addons').splitlines()), nine.read('/addons') + nine.write('/look', f'{doc}\n'.encode()) + pdf = next(int(row.split()[0]) for row in nine.read('/index').splitlines() if row.split()[1] == b'pdf') + for row in nine.read('/index').splitlines(): + if row.split()[1] == b'text': + nine.write(f'/pane/{int(row.split()[0])}/ctl', b'Del\n') + def page(): + # A kind's prefix is its last frame's: one drawn first. + nine.read('/screen') + tag = nine.read(f'/pane/{pdf}/tag') + return int(tag[1:tag.index(b'/')]) if tag.startswith(b'[') else 0 + wait_for('the PDF at its first page', lambda: page() == 1) + check = root / 'w.check' + w = Window(root, 'w', [gui_binary, '--attach=' + str(sock) + ':pdf'], dict(env, PARDES_REPLICA_CHECK=str(check))) + started.append(w.pid) + wait_for('the window client agrees', lambda: agreed(check, 0), timeout=30) + for _ in range(60): + w.mouse('wheel', -3, 400, 400) + time.sleep(0.02) + wait_for('the session\'s PDF past its first page', lambda: page() > 1, timeout=30) + n = len(checks(check)) + wait_for('the window client agrees after the wheel', lambda: agreed(check, n), timeout=30) + assert w.close() == 0, w.said()[-800:] + print(f'daemon: a PDF in a detached session, a window client\'s wheel over it: the session at page {page()}, ' + f'the window\'s digest the session\'s {len(checks(check))} times') + exit_session(nine, pdf) + sess.wait(timeout=10) + nine.socket.close() + finally: + for pid in started: + try: + os.killpg(pid, signal.SIGKILL) + except (ProcessLookupError, PermissionError): + pass + shutil.rmtree(root, ignore_errors=True) + + def window_clients(binary, gui_binary): """Window replica clients (`pardes-gui --attach=<socket>:<name>`): of a terminal's detached session, directly and through the delay relay at @@ -1785,6 +1855,7 @@ if __name__ == '__main__': far(sys.argv[2]) elif sys.argv[1:2] == ['--window-clients']: window_clients(sys.argv[2], sys.argv[3]) + pdf_window(sys.argv[2], sys.argv[3]) elif sys.argv[1:2] == ['--ping']: ping(sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5]) if len(sys.argv) > 5 else 50) elif '--gui' in sys.argv: diff --git a/test/soak.py b/test/soak.py index d99f862c..dc40c17c 100644 --- a/test/soak.py +++ b/test/soak.py @@ -140,7 +140,9 @@ def fixture(at, rng): (at / 'code.zig').write_text(''.join(f'pub fn f{i}(x: u32) u32 {{\n return x * {i} + {rng.randrange(1000)}; // {rng.choice(WORDS)}\n}}\n\n' for i in range(120))) (at / 'big.txt').write_text(''.join(f'{i:06d} {" ".join(rng.choice(WORDS) for _ in range(9))}\n' for i in range(8000))) - (at / 'README').write_text('A directory to soak in.\nnotes.txt code.zig big.txt sub/\nsub/inner.txt:3\n') + (at / 'README').write_text('A directory to soak in.\nnotes.txt code.zig big.txt design.pdf sub/\nsub/inner.txt:3\n') + # A PDF to Look at: the pdf addon's pane, its jobs and its frames. + shutil.copy(Path(__file__).resolve().parent.parent / 'docs' / 'design.pdf', at / 'design.pdf') sub = at / 'sub' sub.mkdir(exist_ok=True) (sub / 'inner.txt').write_text(''.join(f'inner {i} {rng.choice(WORDS)}\n' for i in range(60))) @@ -646,7 +648,7 @@ def act_panes(c, rng, k): def act_find(c, rng, k): k(rng.choice([b' ff', b' fr', b' fg'])) time.sleep(rng.uniform(0.3, 1.0)) - k(rng.choice([b'notes\r', ESC, b'j\r', b'inner\r'])) + k(rng.choice([b'notes\r', ESC, b'j\r', b'inner\r', b'design\r'])) def act_shell(c, rng, k): |
