sidrefresh's picture
Add files using upload-large-folder tool
a7841c5 verified
Raw History Blame Contribute Delete
2.26 kB
#!/usr/bin/env python3
"""Reject cluttered/modal startup before any learner actions."""
import json
import os
import re
from pathlib import Path
import subprocess
import time
def run(*args):
return subprocess.check_output(args, text=True).strip()
def check():
rows = run('wmctrl', '-lx').splitlines()
friction = [r for r in rows if 'friction.friction' in r.lower()]
if len(friction) != 1:
raise RuntimeError(f'Expected one Friction window, found {len(friction)}')
unwanted = [r for r in rows if any(n in r.lower() for n in ('chromium', 'x11vnc', 'shotcut', 'kdenlive'))]
if unwanted:
raise RuntimeError('Unexpected startup windows: ' + repr(unwanted))
modal = []
for row in rows:
win = row.split()[0]
props = run('xprop', '-id', win, '_NET_WM_STATE', '_NET_WM_WINDOW_TYPE', 'WM_TRANSIENT_FOR')
if '_NET_WM_STATE_MODAL' in props or '_NET_WM_WINDOW_TYPE_DIALOG' in props:
modal.append(row)
if modal:
raise RuntimeError('Modal setup dialog present: ' + repr(modal))
win = friction[0].split()[0]
subprocess.run(['wmctrl', '-ia', win], check=True)
time.sleep(.2)
active = re.search(r'0x[0-9a-fA-F]+', run('xprop', '-root', '_NET_ACTIVE_WINDOW')).group()
if int(active, 16) != int(win, 16):
raise RuntimeError('Friction did not receive focus')
props = run('xprop', '-id', win, '_NET_WM_STATE')
if not all(s in props for s in ('MAXIMIZED_VERT', 'MAXIMIZED_HORZ')):
raise RuntimeError('Friction is not maximized')
data = {'status':'ready','window':friction[0],'windows':rows,'display':os.environ.get('DISPLAY')}
Path('/logs/artifacts').mkdir(parents=True, exist_ok=True)
# Harness collection can recreate /logs/artifacts: initialize at runtime.
recorder = Path('/logs/artifacts/reference-viewing.jsonl')
if not recorder.exists():
recorder.write_text('{"event":"recorder_ready"}\n')
audit = Path('/logs/artifacts/action-audit.jsonl')
if not audit.exists():
audit.write_text('{"event":"audit_start","schema_version":1}\n')
Path('/logs/artifacts/startup-check.json').write_text(json.dumps(data,indent=2)+'\n')
print(json.dumps(data))
if __name__ == '__main__':
check()