89 lines
4.7 KiB
Python
89 lines
4.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Wayland integration test. Uses private state and D-Bus, never stops legacy daemons."""
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import subprocess
|
|
import tempfile
|
|
import time
|
|
import sys
|
|
|
|
if os.environ.get("ADAPTIVE_SMOKE_TEST_BUS") != "1":
|
|
os.execvpe("dbus-run-session", ["dbus-run-session", "--", sys.executable, __file__], dict(os.environ, ADAPTIVE_SMOKE_TEST_BUS="1"))
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
with tempfile.TemporaryDirectory(prefix="adaptive-test-") as tmp:
|
|
env = dict(os.environ, QT_QPA_PLATFORM="wayland", QT_QUICK_CONTROLS_STYLE="Material",
|
|
XDG_STATE_HOME=tmp, XDG_CACHE_HOME=tmp, ADAPTIVE_NOTIFICATIONS="1")
|
|
log_path = Path(tmp, "shell.log")
|
|
with log_path.open("w") as log:
|
|
process = subprocess.Popen(["quickshell", "-p", str(ROOT), "--no-color"], env=env,
|
|
stdout=log, stderr=subprocess.STDOUT)
|
|
def ipc(*args):
|
|
return subprocess.run(["quickshell", "ipc", "--pid", str(process.pid),
|
|
"call", "shell", *args], env=env, capture_output=True, text=True, timeout=30)
|
|
try:
|
|
for _ in range(50):
|
|
if process.poll() is not None: raise RuntimeError(log_path.read_text())
|
|
if ipc("close").returncode == 0: break
|
|
time.sleep(.1)
|
|
else: raise RuntimeError("IPC did not become ready")
|
|
def status():
|
|
result = ipc("status")
|
|
assert result.returncode == 0, result.stderr
|
|
return json.loads(result.stdout)
|
|
for page in ["launcher", "settings", "audio", "network", "bluetooth", "wallpapers", "quickSettings", "recent", "power"]:
|
|
result = ipc(page)
|
|
assert result.returncode == 0, result.stderr
|
|
time.sleep(1)
|
|
print("PASS", page)
|
|
clients = subprocess.run(["hyprctl", "-j", "clients"], env=env, capture_output=True, text=True, check=True)
|
|
windows = json.loads(clients.stdout)
|
|
assert any(w.get("pid") == process.pid and w.get("title") == "Settings" for w in windows), "Settings must be a managed desktop window"
|
|
assert status()["settingsVisible"] is True
|
|
capture = os.environ.get("ADAPTIVE_CAPTURE_DIR")
|
|
if capture:
|
|
assert ipc("audio").returncode == 0
|
|
time.sleep(.5)
|
|
window = next(w for w in windows if w.get("pid") == process.pid and w.get("title") == "Settings")
|
|
x, y = window["at"]
|
|
width, height = window["size"]
|
|
subprocess.run(["grim", "-g", f"{x},{y} {width}x{height}", str(Path(capture, "adaptive-audio.png"))], env=env, check=True)
|
|
print("PASS managed Settings window", status())
|
|
for mode in ["phone", "tablet", "desktop"]:
|
|
assert ipc("mode", mode).returncode == 0
|
|
time.sleep(.3)
|
|
assert ipc("theme", "light").returncode == 0
|
|
time.sleep(.3)
|
|
configs = list(Path(tmp).rglob("preferences.json"))
|
|
assert len(configs) == 1, configs
|
|
data = json.loads(configs[0].read_text())
|
|
assert data["mode"] == "desktop" and data["theme"] == "light", data
|
|
data["favorites"] = ["test.desktop"]
|
|
configs[0].write_text(json.dumps(data))
|
|
time.sleep(.4)
|
|
assert status()["favorites"] == ["test.desktop"], status()
|
|
configs[0].write_text("{broken json")
|
|
time.sleep(.4)
|
|
assert status()["preferencesWritable"] is False, status()
|
|
ipc("theme", "dark")
|
|
time.sleep(.2)
|
|
assert configs[0].read_text() == "{broken json", "Corrupt preferences must not be overwritten"
|
|
configs[0].write_text(json.dumps(data))
|
|
time.sleep(.4)
|
|
assert status()["preferencesWritable"] is True and not status()["preferencesError"], status()
|
|
print("PASS external preferences, corruption protection and recovery")
|
|
subprocess.run(["notify-send", "--app-name=Adaptive Test", "Shell smoke test", "Plain text <b>body</b>"], env=env, check=True)
|
|
assert ipc("notifications").returncode == 0
|
|
time.sleep(1)
|
|
assert ipc("close").returncode == 0
|
|
print("PASS modes, persistence, notification delivery")
|
|
finally:
|
|
process.terminate()
|
|
try: process.wait(timeout=3)
|
|
except subprocess.TimeoutExpired: process.kill(); process.wait()
|
|
logs = log_path.read_text()
|
|
print(logs)
|
|
for marker in ["Failed to load configuration", "ReferenceError", "TypeError", "Binding loop", "Cannot assign", "is not a type", "Cannot create delegate"]:
|
|
assert marker not in logs, marker
|