#!/usr/bin/env python3 """Replay C313's fixed five cases with exact rational phase coordinates.""" from pathlib import Path import argparse,hashlib,json,runpy ROOT=Path(__file__).resolve().parent.parent def sha(p):return hashlib.sha256(p.read_bytes()).hexdigest() def load(name):return json.loads((ROOT/'sources'/name).read_text()) def main(out): manifest=json.loads((ROOT/'SOURCE_MANIFEST.json').read_text());source_checks=[] for name,item in manifest.items(): p=ROOT/'sources'/name assert p.stat().st_size==item['bytes'] and sha(p)==item['sha256'],name source_checks.append('frozen input '+name) previous=load('PREVIOUS_CERTIFICATE.json') for field,name in [('results_sha256','PREVIOUS_RESULTS.json'),('checkpoint_sha256','PREVIOUS_CHECKPOINT.md'),('next_step_decision_sha256','PREVIOUS_NEXT_STEP.json'),('data_sha256','PREVIOUS_DATA.json')]: assert previous[field]==manifest[name]['sha256'],field source_checks.append('predecessor binding '+name) checks=[] def check(name,condition): assert condition,name assert name not in checks,name checks.append(name) data=runpy.run_path(str(ROOT/'evidence/CALCULATION.py'))['run'](load,check) results={'step':'C313','status':'passed','assertions_passed':len(checks),'checks':checks,'source_checks_passed':len(source_checks),'source_checks':source_checks,'check_scope':'Five-case exact arithmetic, source labels and existing phase ancestry; no historical corroboration or wider census.','canonical_or_graph_edits':False,'new_independent_agent_review':True,'review_scope':'Separate mathematical script and source/method review.'} out.mkdir(parents=True,exist_ok=True) for name,obj in [('DATA.json',data),('RESULTS.json',results)]: (out/name).write_text(json.dumps(obj,ensure_ascii=False,indent=2)+'\n') print(json.dumps({'step':'C313','status':'passed','checks':len(checks),'source_checks':len(source_checks),'counts':data['counts']})) if __name__=='__main__': p=argparse.ArgumentParser();p.add_argument('--out',type=Path,required=True);main(p.parse_args().out)