#!/usr/bin/env python3 import json, ast from pathlib import Path ROOT=Path(__file__).resolve().parents[1] OUT=ROOT/'verifier_creation' errors=[] for p in [OUT/'VERIFIER_CREATION.md',OUT/'result.json',OUT/'plans',OUT/'scripts']: if not p.exists(): errors.append(f'missing: {p.relative_to(ROOT)}') res={} if (OUT/'result.json').exists(): try: res=json.loads((OUT/'result.json').read_text(encoding='utf-8')) except Exception as e: errors.append(f'invalid result.json: {e}') plans=list((OUT/'plans').glob('*.md')) if (OUT/'plans').exists() else [] scripts=list((OUT/'scripts').glob('*_verifier.py')) if (OUT/'scripts').exists() else [] if res: if res.get('mode')!='READ_ONLY_VERIFIER_CREATION': errors.append('wrong mode') if res.get('plans')!=len(plans): errors.append('plan count mismatch') if res.get('scripts')!=len(scripts): errors.append('script count mismatch') for s in scripts: txt=s.read_text(encoding='utf-8',errors='ignore') try: ast.parse(txt) except Exception as e: errors.append(f'{s.relative_to(ROOT)} syntax: {e}') low=txt.lower() for bad in ['git commit','git push','gh issue create','rm -rf','pip install','npm install']: if bad in low: errors.append(f'{s.relative_to(ROOT)} contains dangerous command {bad}') for must in ['json.dumps','git status --short','non-destructive']: if must not in low: errors.append(f'{s.relative_to(ROOT)} missing {must}') for jp in res.get('jobs',[]): p=Path(jp) if not p.exists(): errors.append(f'missing job {jp}'); continue data=json.loads(p.read_text(encoding='utf-8')) if data.get('mode')!='review_only': errors.append(f'{p.name} not review_only') f=' '.join(data.get('forbidden_actions',[])).lower() if 'modify source project files' not in f or 'commit' not in f or 'push' not in f: errors.append(f'{p.name} missing forbids') if errors: print('verify_verifier_creation: failed') for e in errors: print('-',e) raise SystemExit(1) print(f'verify_verifier_creation: passed ({len(plans)} plans, {len(scripts)} scripts)')