Files
ARCADIA-Studio/harness/experiments/packaged-gui-close-865483b-20260911/verify-copy.py
T

21 lines
1.4 KiB
Python

"""Fresh-process second readback of closed originals and copies; no GUI/tests."""
from pathlib import Path
import hashlib,json
ROOT=Path(__file__).resolve().parent
def fingerprint(path):
with path.open('rb') as stream: digest=hashlib.file_digest(stream,'sha256').hexdigest().upper()
return path.stat().st_size,digest
manifest=json.loads((ROOT/'manifest.json').read_bytes())
rows=[]
for item in manifest['files']:
original=fingerprint(Path(item['original']));copied=fingerprint(ROOT/item['archive'])
assert original==copied==(item['bytes'],item['original_sha256'])
assert copied[1]==item['copy_sha256']
rows.append({'path':item['archive'],'bytes':copied[0],'sha256':copied[1]})
allowed={r['path'] for r in rows}|{'archive.py','verify-copy.py','README.md','manifest.json','package-readback.json'}
actual={p.relative_to(ROOT).as_posix() for p in ROOT.rglob('*') if p.is_file()}
assert actual==allowed,(actual-allowed,allowed-actual)
result={'result':'passed','method':'Independent second original/copy reopen using SHA256 file_digest, byte-size comparison and exact archive inventory','payload_files':len(rows),'payload_bytes':sum(r['bytes'] for r in rows),'manifest_sha256':fingerprint(ROOT/'manifest.json')[1],'package_readback_sha256':fingerprint(ROOT/'package-readback.json')[1],'files':rows}
(ROOT/'readback.json').write_text(json.dumps(result,indent=2)+'\n',encoding='utf-8')
print(json.dumps({k:v for k,v in result.items() if k!='files'},indent=2))