from pathlib import Path
import runpy,io,contextlib,re,sys
R=Path(__file__).resolve().parents[1];q1=R/'src/static_preflight_q1.py'
buf=io.StringIO();rc=0
try:
    with contextlib.redirect_stdout(buf): runpy.run_path(str(q1),run_name='__main__')
except SystemExit as e:
    rc=int(e.code or 0)
out=buf.getvalue();print(out,end='')
m=re.findall(r'SUMMARY\s+(\d+)/(\d+)\s+PASS',out);bp,bt=(map(int,m[-1]) if m else (0,1));checks=[]
def ck(n,v):checks.append((n,bool(v)))
PACK=R.parents[2]
try:
    sys.path.insert(0,str(PACK/'internal_verification/lab_oracles'))
    from semantic_bundle_validator import load_bundle,validate_bundle
    sem=validate_bundle(load_bundle(PACK))
    for n in ['toolchain_local_exact','requirements_local_exact','html_text_policy_exact','rich_html_policy_exact','dangerous_context_policy_exact','query_policy_exact','probe_expectations_exact','learner_evidence_blank','transfer_unprefilled','decision_unprefilled','table_schema_exact','assessment_exact']: ck(n,sem[n])
except ModuleNotFoundError:
    print('INFO standalone release mode: package-internal semantic oracle is intentionally unavailable')
for n,v in checks:print(('PASS' if v else 'FAIL'),n)
p=bp+sum(v for _,v in checks);t=bt+len(checks);print(f'SUMMARY {p}/{t} PASS');sys.exit(0 if rc==0 and p==t else 1)
