"""Ad-hoc weblink engine probe — drives the real LinuxChromiumAdapter. Verifies the full launch → visible → teardown cycle outside the player, so weblink behaviour can be tested without a server-provided playlist. .venv/bin/python linux/_probe_weblink.py [url] """ import os import sys import time _HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, _HERE) sys.path.insert(0, os.path.join(os.path.dirname(_HERE), 'src')) from linux_display import ensure_session_environment # noqa: E402 ensure_session_environment() URL = sys.argv[1] if len(sys.argv) > 1 else 'https://example.com' REQUIRED = os.environ.get('KIWY_REQUIRE_SUBSTRING', '') from linux_browser import LinuxChromiumAdapter, find_linux_browser # noqa: E402 def chromium_count(): import subprocess out = subprocess.run(['pgrep', '-c', 'chromium'], capture_output=True, text=True) try: return int(out.stdout.strip()) except ValueError: return 0 def rss_mb(): import subprocess out = subprocess.run( ['ps', '-o', 'rss=', '-C', 'chromium'], capture_output=True, text=True ) total = sum(int(x) for x in out.stdout.split() if x.isdigit()) return total / 1024.0 def main(): print(f'URL: {URL}') print(f'baseline chromium procs: {chromium_count()}') adapter = LinuxChromiumAdapter( browser_path=find_linux_browser(), kiosk=True, profile_dir=os.path.join(os.getcwd(), '.kiosk-profile-probe'), ) print(f'flags: {adapter.extra_launch_args()}') launched = adapter.launch(URL, 1920, 1080) print(f'launch() -> {launched}') if not launched: print('FAIL: launch returned False') return 1 visible, reason = adapter.wait_visible(15.0) print(f'wait_visible() -> {visible} ({reason})') time.sleep(6) print(f'during: {chromium_count()} procs, {rss_mb():.0f} MB') if REQUIRED: # Fetch the same URL over HTTP and confirm it resolves, so a blank page # can be attributed to rendering rather than to the network. import urllib.request try: body = urllib.request.urlopen(URL, timeout=10).read(400_000).decode( 'utf-8', 'replace' ) print(f'server reachable; page contains {REQUIRED!r}: {REQUIRED in body}') except Exception as exc: print(f'server fetch failed (network/host issue, not the engine): {exc}') adapter.teardown() time.sleep(3) left = chromium_count() print(f'after teardown: {left} chromium procs (0 = no leak)') ok = visible and left == 0 print('RESULT:', 'PASS' if ok else 'FAIL') return 0 if ok else 1 if __name__ == '__main__': sys.exit(main())