"""Verify the selected source bytes against recorded GitHub Git blob IDs.""" from __future__ import annotations import hashlib import json from pathlib import Path ROOT = Path(__file__).resolve().parent.parent records = json.loads((ROOT/'manifests/local_verified_files.json').read_text()) failures = [] for record in records: p = ROOT/'verified_source'/record['repo'].split('/',1)[1]/record['path'] if not p.is_file(): failures.append(f"Missing: {p.relative_to(ROOT)}") continue data = p.read_bytes() actual = hashlib.sha1(b'blob '+str(len(data)).encode()+b'\0'+data).hexdigest() sha256 = hashlib.sha256(data).hexdigest() if actual != record['expected_git_blob_sha1'] or sha256 != record['sha256'] or len(data) != record['bytes']: failures.append(f"Mismatch: {p.relative_to(ROOT)}") if failures: raise SystemExit('\n'.join(failures)) print(f'{len(records)}/{len(records)} selected original files match their recorded Git blob IDs, lengths, and SHA-256 checksums.')