"""Exact semantic PASS and immutable source/contract identity before custody.""" import json from pathlib import Path from phase2_h1_worker_v2 import sha,checked from phase2_home_freeze_io import verify def read(p):return json.loads(Path(p).read_text()) def validate_review(root): root=Path(root);c=read(root/'contract.json');proof=verify(root,'implementation');binding=read(root/'expected-review-binding.json');review=read(root/'review.json') expected=dict(reviewed_commit=proof['commit'],contract_sha256=sha(root/'contract.json'),implementation_proof_sha256=sha(root/'implementation-git-freeze.json'),comparison_contract_sha256=c['comparison_contract_sha256'],code_sha256=c['code_sha256']) if binding!=expected:raise PermissionError('Review binding differs from implementation') if review.get('verdict')!='PASS':raise PermissionError('Actual exact PASS required') for name,value in expected.items(): if review.get(name)!=value:raise PermissionError('Review identity mismatch: '+name) checked(c['comparison_contract'],expected['comparison_contract_sha256']) for p,h in expected['code_sha256'].items():checked(p,h) frozen=verify(root,'implementation-review') for p in [root/'review.json',root/'expected-review-binding.json',root/'contract.json']: if frozen['files'].get(str(p.resolve()))!=sha(p):raise PermissionError('Review freeze does not include exact required file') return review