Download tasks/t23-dance-blob/environment/startup-check.py from refreshdotdev/Refresh-GUI-dataset: direct link, hf CLI and curl.
- Browser
- Download file 2.26 kB
-
https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/environment/startup-check.py
- Command line
-
hf download hf://datasets/refreshdotdev/Refresh-GUI-dataset/tasks/t23-dance-blob/environment/startup-check.py
-
curl -L -o startup-check.py https://huggingface.co/datasets/refreshdotdev/Refresh-GUI-dataset/resolve/main/tasks/t23-dance-blob/environment/startup-check.py
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() | |