import json
from pathlib import Path
from starter import evaluate
P=Path(__file__).parent
cases=json.loads((P/'fixtures/cases.json').read_text(encoding='utf-8'))['cases']
required={'artifact_state','cohort_state','health_gate','budget_gate','stage_result','next_stage','audit_event','reason'}
for c in cases:
    try: r=evaluate(c)
    except NotImplementedError:
        print('STARTER_NOT_IMPLEMENTED: implement evaluate(case), then rerun checks.'); raise SystemExit(2)
    assert isinstance(r,dict) and required<=set(r)
    assert isinstance(r['audit_event'],str) and r['audit_event'].strip()
    assert isinstance(r['reason'],str) and r['reason'].strip()
    assert r['stage_result'] in {'PROMOTE','BLOCKED','HALT','ROLLBACK','CONVERGED','UNKNOWN'}
print(f'PASS learner shape/safety checks for {len(cases)} cases')
