"""Replay predeclared similarity screen without replacing quarantined cases."""
import json,shutil,tempfile
from pathlib import Path
import r115_leak_screen as screen
from r112_scaleup_synthetic_compare import sha
R=Path(__file__).resolve().parents[1];O=R/'results/r115';original=json.loads((O/'leak-screen.json').read_text());assert original['protocol_sha256']==sha(O/'protocol.json') and original['annotation_audit_sha256']==sha(O/'annotation-audit.json') and original['image_manifest_sha256']==sha(O/'image-manifest.json') and original['script_sha256']==sha(R/'research/r115_leak_screen.py')
with tempfile.TemporaryDirectory(prefix='r115-screen-',dir='/tmp') as tmp:
 root=Path(tmp)
 for name in ('protocol.json','annotation-audit.json','image-manifest.json'):shutil.copyfile(O/name,root/name)
 screen.O=root;screen.main();assert (root/'leak-screen.json').read_bytes()==(O/'leak-screen.json').read_bytes()
out={'format':'r115-gunduz-leak-screen-verify-v1','screen_sha256':sha(O/'leak-screen.json'),'files':len(original['records']),'quarantined':sum(x['quarantined'] for x in original['records']),'checks':'Full comparison was recomputed with identical results; hashes and predeclared quarantine rule checked. This is a coarse fingerprint screen, not proof of sample or model independence.'};(O/'leak-screen-verify.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out,indent=2))
