summaryrefslogtreecommitdiff
path: root/test/gpu_snake_interaction.py
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 10:56:42 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commitf2b02c455f2bcdfb905a015eefbb630a28b4b12e (patch)
treec344c7ad42ec288dd5e1ebd0eb6d25f5aa2fbccc /test/gpu_snake_interaction.py
parentfc38c73c59f7855a4caad8aa4d3bb8e023309c13 (diff)
downloadpardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.tar.gz
pardes-f2b02c455f2bcdfb905a015eefbb630a28b4b12e.zip
addons: an addon can hand the frontend a GPU scene (ABI 3.1), and a snake drawn by shaders does; a commit's patch keeps its own +Diff pane; a real ZLS checked through the window build
ABI 3.1 appends an optional `gpu` callback and its context to pa_paint: one self-contained sketchbook SGPU v1 scene for the pane, at most 4 MiB, copied during the call, the last successful call winning. The SDL frontend runs it on its own GPU through sketchbook's executor and composites its target texture into the pane; replicas carry the scene beside the authoritative pane frame; cells and rasters stay the fallback for terminals, older hosts and frontends without an executor. addons/snake_shader is such an addon (`zig build snake-shader`, the SnakeShader word: a board that follows its pane, buffered turns, a CRT look), with test/gpu_snake.py, test/gpu_snake_interaction.py and test/gpu_upgrade.py. Commit patches open as `+Diff-<short-hash>` and reuse only their own commit's pane, so another paged patch no longer replaces one already open. The language-server client looks in the standard per-user bin directory, which desktop launchers often leave out of PATH, and takes an empty answer that beats the startup progress notification onto the wire; test/real_zls.py checks imports, hover, references, rename previews, diagnostics and completion against a real ZLS from a private home. The dump's schema reader skips two fields older builds persisted, and a replica's shadow of a kind ticks when the authority's does. The reference, the guide, the building and setup notes and the changelog say so. The working copy as it stood on 2026-11-12; message written by Claude from the diff, at the author's request.
Diffstat (limited to 'test/gpu_snake_interaction.py')
-rw-r--r--test/gpu_snake_interaction.py119
1 files changed, 119 insertions, 0 deletions
diff --git a/test/gpu_snake_interaction.py b/test/gpu_snake_interaction.py
new file mode 100644
index 00000000..a3e5b2b4
--- /dev/null
+++ b/test/gpu_snake_interaction.py
@@ -0,0 +1,119 @@
+#!/usr/bin/env python3
+"""Check snake v1 migration, resize, hover and idle animation in a private GUI."""
+import argparse
+import io
+import json
+import os
+from pathlib import Path
+import subprocess
+import time
+from PIL import Image, ImageChops, ImageStat
+from ninep import Client
+from gpu_snake import wait
+from daemon import install, processes
+
+parser = argparse.ArgumentParser(description=__doc__)
+for name in ['binary', 'old_addon', 'new_addon', 'output']:
+ parser.add_argument(name, type=Path)
+args = parser.parse_args()
+root = args.output.resolve()
+root.mkdir(parents=True, mode=0o700)
+(root / 'config/pardes').mkdir(parents=True)
+(root / 'config/pardes/init').write_text('Shell /bin/bash\nMessageLinger 0\n')
+addon = root / 'snake.so'
+install(args.old_addon.resolve(), addon)
+env = {k: v for k, v in os.environ.items() if not k.startswith('PARDES_')}
+env.pop('XDG_DATA_HOME', None)
+env.update(HOME=str(root), XDG_RUNTIME_DIR=str(root), XDG_CONFIG_HOME=str(root / 'config'),
+ PARDES_TEST='1', PARDES_TEST_CAPTURE_DIR=str(root), PARDES_TEST_COLS='100',
+ PARDES_TEST_ROWS='30', SDL_VIDEO_DRIVER='offscreen', PARDES_DAEMON='on')
+log = (root / 'stderr.log').open('w')
+p = subprocess.Popen([str(args.binary.resolve()), '--9p=snake'], cwd=root, env=env,
+ stdin=subprocess.PIPE, stdout=subprocess.DEVNULL, stderr=log, start_new_session=True)
+client = None
+try:
+ sock = root / '9p/pardes/snake'
+ wait(sock.exists)
+ client = Client(sock)
+ text = int(client.read('/pane/new'))
+ client.write(f'/pane/{text}/body', b'unsaved text preserved\n')
+ shells = wait(lambda: [line for line in client.read('/sessions').splitlines() if line.startswith(b'shell ')])
+
+ def execute(word):
+ client.write(f'/pane/{text}/exec', (word + '\n').encode())
+
+ execute(f'Addon load {addon}')
+ execute('SnakeShader')
+ client.write('/focus', str(text).encode())
+ snake = int(next(line.split()[0] for line in client.read('/index').splitlines()
+ if line.split()[1] == b'snake_shader'))
+
+ def body():
+ return client.read(f'/pane/{snake}/body').splitlines()
+
+ state = body()[:4]
+ install(args.new_addon.resolve(), addon)
+ execute('Addon reload snake_shader')
+ wait(lambda: len(body()) == 6)
+ assert body()[:4] == state, body()
+ time.sleep(.2)
+ board = body()[4]
+ execute('Addon reload snake_shader')
+ time.sleep(.2)
+ assert body()[:4] == state and body()[4] == board, body()
+
+ screen = json.loads(client.read('/screen'))
+ rows = [''.join(cell[0] for cell in screen['cells'][i:i + screen['cols']])
+ for i in range(0, len(screen['cells']), screen['cols'])]
+ tag = next(i for i, row in enumerate(rows) if 'SnakeShader' in row)
+ bottom = next((i for i in range(tag + 1, len(rows)) if ' Collapse ' in rows[i]), len(rows))
+
+ def capture(name):
+ stamp = (root / 'latest.ppm').stat().st_mtime_ns
+ wait(lambda: (root / 'latest.ppm').stat().st_mtime_ns > stamp)
+ im = Image.open(io.BytesIO((root / 'latest.ppm').read_bytes())).convert('RGB')
+ im.save(root / (name + '.png'))
+ return im.crop((0, (tag + 1) * im.height // screen['rows'], im.width, bottom * im.height // screen['rows']))
+
+ a = capture('idle-a')
+ time.sleep(.25)
+ b = capture('idle-b')
+ idle_change = sum(ImageStat.Stat(ImageChops.difference(a, b)).mean)
+ assert 0 < idle_change < 2, idle_change
+ assert body()[:4] == state, body()
+ client.write('/mousein', f'm 10 {tag + 4} 0\n'.encode())
+ wait(lambda: body()[5] != b'hover -1 -1')
+ hovered = capture('hover')
+ hover_change = sum(ImageStat.Stat(ImageChops.difference(b, hovered)).mean)
+ assert hover_change > idle_change, (hover_change, idle_change)
+ client.write('/mousein', b'm 0 0 0\n')
+ wait(lambda: body()[5] == b'hover -1 -1')
+ execute('Newcol')
+ wait(lambda: body()[4] != board)
+ assert body()[:4] == state, body()
+ assert client.read(f'/pane/{text}/body') == b'unsaved text preserved\n'
+ assert [line for line in client.read('/sessions').splitlines() if line.startswith(b'shell ')] == shells
+ result = {'state': [line.decode() for line in state], 'before': board.decode(),
+ 'after': body()[4].decode(), 'idle_pixel_change': idle_change, 'hover_pixel_change': hover_change}
+ (root / 'result.json').write_text(json.dumps(result, indent=2) + '\n')
+ print('PASS: migration, reload, resize, hover, idle animation, text and shells', result, flush=True)
+except Exception:
+ if client:
+ for path in ['/addons', '/log', '/index']:
+ print(path, client.read(path).decode(), flush=True)
+ if 'snake' in globals():
+ print('game', body(), flush=True)
+ raise
+finally:
+ if client:
+ client.socket.close()
+ if p.poll() is None:
+ p.kill()
+ p.wait(timeout=10)
+ for pid in processes(root):
+ try:
+ os.kill(pid, 9)
+ except ProcessLookupError:
+ pass
+ p.stdin.close()
+ log.close()