#!/usr/bin/env python3 import json from pathlib import Path ROOT=Path(__file__).resolve().parents[1] OUT=ROOT/'test_generation' errors=[] required=[OUT/'TEST_GENERATION.md', OUT/'result.json', OUT/'plans', OUT/'patches'] for p in required: 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 [] patches=list((OUT/'patches').glob('*.patch.md')) if (OUT/'patches').exists() else [] if res: if res.get('mode')!='READ_ONLY_TEST_GENERATION': errors.append('mode is not READ_ONLY_TEST_GENERATION') if len(plans)!=res.get('plans'): errors.append(f'plan count mismatch {len(plans)} != {res.get("plans")}') if len(patches)!=res.get('patch_artifacts'): errors.append(f'patch count mismatch {len(patches)} != {res.get("patch_artifacts")}') for p in patches[:100]: txt=p.read_text(encoding='utf-8',errors='ignore').lower() for must in ['do not modify source repo directly','do not commit/push','verifier']: if must not in txt: errors.append(f'{p.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') allowed=' '.join(data.get('allowed_actions',[])).lower() forbidden=' '.join(data.get('forbidden_actions',[])).lower() if 'modify source project files' not in forbidden: errors.append(f'{p.name} missing source modify forbid') if 'commit' not in forbidden or 'push' not in forbidden: errors.append(f'{p.name} missing git forbid') if 'write projectintaketower' not in allowed: errors.append(f'{p.name} missing ProjectIntakeTower write scope') if errors: print('verify_test_generation: failed') for e in errors: print('-',e) raise SystemExit(1) print(f'verify_test_generation: passed ({len(plans)} plans, {len(patches)} patch artifacts)')