#!/usr/bin/env python3 """Opt-in real Wayland smoke test. Run with no glassMxrph instance active.""" import json import os from pathlib import Path import subprocess import tempfile import time ROOT = Path(__file__).resolve().parents[1] SHELL = ROOT / 'quickshell' def ipc(method, *args): return subprocess.run(['quickshell', 'ipc', '--path', str(SHELL), 'call', 'shell', method, *args], text=True, capture_output=True) def eventually(check, timeout=8): end = time.monotonic() + timeout while time.monotonic() < end: try: if check(): return except (ValueError, KeyError, FileNotFoundError): pass time.sleep(.1) raise AssertionError('Runtime condition timed out') def status(): result = ipc('status') return json.loads(result.stdout) if result.returncode == 0 else {} if ipc('status').returncode == 0: raise SystemExit('Stop the existing glassMxrph instance before this isolated test.') with tempfile.TemporaryDirectory(prefix='glassmxrph-runtime-') as tmp: env = dict(os.environ, XDG_CONFIG_HOME=tmp + '/config', XDG_STATE_HOME=tmp + '/state') config = Path(tmp) / 'config/glassMxrph/config.json' palette = Path(tmp) / 'state/glassMxrph/palette.json' log = Path(tmp) / 'runtime.log' with log.open('w') as output: proc = subprocess.Popen([str(ROOT / 'scripts/glassmxrph'), 'run'], env=env, stdout=output, stderr=subprocess.STDOUT) try: eventually(lambda: status().get('ready')) duplicate = subprocess.run([str(ROOT / 'scripts/glassmxrph'), 'run'], env=env, capture_output=True, timeout=5) assert duplicate.returncode == 0, duplicate.stderr assert ipc('setPreference', 'appearance.customAccent', '"#167d9a"').stdout.strip() == 'true' assert ipc('setPreference', 'appearance.accentSource', '"custom"').stdout.strip() == 'true' eventually(lambda: config.exists() and json.loads(config.read_text())['appearance']['customAccent'] == '#167d9a') eventually(lambda: status().get('accent') == '#167d9a') palette.write_text(json.dumps({'accent':'#d29442'})) assert ipc('setPreference', 'appearance.accentSource', '"matugen"').stdout.strip() == 'true' eventually(lambda: status().get('accent') == '#d29442') palette.write_text(json.dumps({'accent':'#32966b'})) eventually(lambda: status().get('accent') == '#32966b') ipc('openSettings', 'appearance') eventually(lambda: status().get('settingsOpen')) ipc('close') eventually(lambda: status().get('settingsOpen') is False) # Corrupt external edits must not destroy valid in-memory settings or overwrite the file. eventually(lambda: json.loads(config.read_text())['appearance']['accentSource'] == 'matugen') config.write_text('{broken') eventually(lambda: bool(status().get('error'))) assert ipc('setPreference', 'appearance.customAccent', '"#ffffff"').stdout.strip() == 'false' assert config.read_text() == '{broken' proc.terminate() proc.wait(timeout=5) finally: if proc.poll() is None: proc.terminate() proc.wait(timeout=5) text = log.read_text() assert 'WARN' not in text and 'ERROR' not in text, text print('PASS: live Wayland, duplicate prevention, preference persistence, live palette updates, settings IPC, corrupt-file protection, clean runtime logs.')