File size: 2,260 Bytes
a7841c5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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()