"""Semantic review gate: every identity is supplied by an immutable binding.""" import json from pathlib import Path from phase2_h1_worker_v2 import sha def validate_review(path,binding): review=json.loads(Path(path).read_text()) if not isinstance(review,dict) or review.get('verdict')!='PASS':raise PermissionError('Review verdict must be exactly PASS') for field in ['reviewed_commit','contract_sha256','launch_proof_sha256','fix_commit']: if not isinstance(review.get(field),str) or review[field]!=binding[field]:raise PermissionError('Review identity mismatch: '+field) expected=binding['fix_source_sha256'] if not expected or review.get('fix_source_sha256')!=expected:raise PermissionError('Review does not cover all fixed repair sources') for p,h in expected.items(): if sha(p)!=h:raise PermissionError('Reviewed repair source changed: '+p) old=Path(binding['original_root']) if sha(old/'contract.json')!=binding['contract_sha256'] or sha(old/'launch-git-freeze.json')!=binding['launch_proof_sha256']:raise PermissionError('Original frozen root identity changed') if json.loads((old/'launch-git-freeze.json').read_text())['commit']!=binding['reviewed_commit']:raise PermissionError('Original launch commit changed') return review