summaryrefslogtreecommitdiff
path: root/test/daemon.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-21 17:47:24 -0300
committerGabriel Schneider <[email protected]>2026-11-21 18:02:13 -0300
commitaefdb402b577c270111e2736e175611def0833e7 (patch)
treeaafba458ecfa2e98b221c46b0e030ff67e0d9d57 /test/daemon.py
parent3dc3e796a9b69ec35a8a920aa12f3e04e61a0ab5 (diff)
downloadpardes-aefdb402b577c270111e2736e175611def0833e7.tar.gz
pardes-aefdb402b577c270111e2736e175611def0833e7.zip
tests: a plain client watching a kitty image in a terminal under screen state joins again for ever, caught twice: core/replica.zig "a terminal's program shows a kitty image under screen state: the client's emulator never has it, and its tag says what the session's does" (an Authority and a Replica, the image fed in the session's order, a step after: the digests part in pane 0.tag, pane 0.tag_lead and pane 1.cwd, the last an inherited cwd that walks to the terminal's pane; `partsApart` names them) and test/daemon.py `kitty_image` (plain mode's list, alone `--kitty-image`: a detached session, a plain attach, the corpus scene 10's 8x8 RGB image printed in its shell, the client's joins counted over 5 s, 0 expected: on this base's Debug build 16 joins, 16 of 16 checks differ; on the installed build (6d937cd125ca) the same 16, 3.2 a second, session 20-30 ms and client 50-70 ms of CPU, 80 KB to the client's terminal); shell-test 1100/1104 with this test the one failure, core-test 898/1059 (161 skipped: it needs a shell)
Co-Authored-By: Claude Opus <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'test/daemon.py')
-rw-r--r--test/daemon.py75
1 files changed, 75 insertions, 0 deletions
diff --git a/test/daemon.py b/test/daemon.py
index c6ff6256..e1be141a 100644
--- a/test/daemon.py
+++ b/test/daemon.py
@@ -38,6 +38,8 @@ private HOME and runtime directory:
python3 -B test/daemon.py --far <pardes>
the far clients and their blob cache alone, one under `yes` across
a slow link, and a file by its hash
+ python3 -B test/daemon.py --kitty-image <pardes>
+ a plain client watching a kitty image in its session's terminal
python3 -B test/daemon.py --games <pardes> <lib> [seconds]
the games in the clients that show them, from zig build
addon-test's <prefix>/lib (libsnake, liblife, libliar)
@@ -2608,6 +2610,76 @@ def terminals(client):
return [int(row.split()[0]) for row in client.read('/index').splitlines() if row.split()[1] == b'term']
+def cpu_ticks(pid):
+ stat = open(f'/proc/{pid}/stat').read().rsplit(')', 1)[1].split()
+ return int(stat[11]) + int(stat[12])
+
+
+def kitty_image(binary, secs=5):
+ """A plain attach (screen state) watching a terminal in which a program
+ shows a kitty image (the corpus's scene 10's: 8x8 RGB, 10x4 cells): it
+ agrees with its session and does not join again (it joined again ~3.3
+ times a second: the tag said ` petscii:on` on the session's side only)."""
+ 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.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')
+ rgb = bytes((x * 30) % 256 for x in range(8 * 8 * 3))
+ (root / 'kitty.sh').write_text("printf '\\033_Ga=T,f=24,s=8,v=8,c=10,r=4;%s\\033\\\\'\nprintf '\\nKITTY\\n'\n"
+ % __import__('base64').b64encode(rgb).decode())
+ started, terms = [], []
+ try:
+ term = Term()
+ terms.append(term)
+ stub = term.spawn([binary, '--tty', '--9p=img'], env)
+ started.append(stub.pid)
+ wait_for('the session\'s 9P socket', (root / 'pardes-9p-img.sock').exists)
+ nine = Client(root / 'pardes-9p-img.sock')
+ session = int(dict(line.split(maxsplit=1) for line in nine.read('/status').decode().splitlines())['pid'])
+ started.append(session)
+ shell = terminals(nine)[0]
+ nine.write(f'/pane/{shell}/exec', b'Detach\n')
+ assert stub.wait(timeout=10) == 0, stub.returncode
+ t = Term(30, 100)
+ terms.append(t)
+ c = t.spawn([binary, 'attach', 'img'], dict(env, PARDES_REPLICA_CHECK=str(root / 'c.check')))
+ started.append(c.pid)
+ wait_for('the client\'s first frame', lambda: b'\x1b[?1049h' in t.text(), timeout=30)
+ wait_for('the client agrees', lambda: agreed(root / 'c.check', 0), timeout=30)
+ nine.write(f'/pane/{shell}/pty/data', f'clear; sh {root}/kitty.sh\r'.encode())
+ wait_for('KITTY in the session\'s body', lambda: b'KITTY' in nine.read(f'/pane/{shell}/body'), timeout=30)
+ wait_for('KITTY in the client\'s terminal', lambda: b'KITTY' in t.text(), timeout=30)
+ mark, seen = len(t.text()), len(checks(root / 'c.check'))
+ cpu = (cpu_ticks(session), cpu_ticks(c.pid))
+ time.sleep(secs)
+ cpu = [(cpu_ticks(p) - was) * 1000 // os.sysconf('SC_CLK_TCK') for p, was in zip((session, c.pid), cpu)]
+ again = t.text()[mark:].count(b'joined again')
+ said = checks(root / 'c.check')[seen:]
+ tag = nine.read(f'/pane/{shell}/tag')
+ print(f'kitty image: over {secs} s the client joined again {again} times ({again / secs:.1f}/s), its checks '
+ f'{len(said)} ({sum(s.startswith("differ") for s in said)} differ), CPU ms session {cpu[0]} client {cpu[1]}, '
+ f'{len(t.text()) - mark} bytes to its terminal; the session\'s tag {tag[:60]!r}')
+ assert again == 0 and c.poll() is None, (again, said[-3:])
+ assert agreed(root / 'c.check', seen), said
+ exit_session(nine, shell)
+ nine.socket.close()
+ wait_for('the client ended with its session', lambda: c.poll() is not None, timeout=20)
+ print('kitty image: a plain client watching a kitty image agreed and never joined again')
+ finally:
+ for t in terms:
+ t.close()
+ for pid in started + processes(root):
+ try:
+ os.kill(pid, signal.SIGKILL)
+ except OSError:
+ pass
+ shutil.rmtree(root, ignore_errors=True)
+
+
def main(binary, cycles):
scratch = Path(__file__).resolve().parent.parent.parent / '.scratch' / 'daemon' / 'dmn'
scratch.mkdir(parents=True, exist_ok=True)
@@ -2648,6 +2720,7 @@ def main(binary, cycles):
manage(binary)
relink(binary)
answer_late(binary)
+ kitty_image(binary)
shell = terminals(client)[0]
shell_pid = int(run(client, shell, b'echo $$\n').split(b'\n')[1])
started.append(shell_pid)
@@ -3662,6 +3735,8 @@ if __name__ == '__main__':
far_find(sys.argv[2])
elif sys.argv[1:2] == ['--far-find']:
far_find(sys.argv[2])
+ elif sys.argv[1:2] == ['--kitty-image']:
+ kitty_image(sys.argv[2])
elif sys.argv[1:2] == ['--restore']:
restore_client(sys.argv[2])
elif sys.argv[1:2] == ['--window-clients']: