"""Verify exact Git blob bytes without importing upstream modules or reading media.""" import hashlib import json from build_definition import OUT, REF, REPO, build def main(): entries = json.loads((REF / "sources.json").read_bytes())["sources"] for e in entries: raw = (REF / e["local_file"]).read_bytes() tree = json.loads((REF / (e["id"] + "-tree.json")).read_bytes()) assert tree["sha"] == e["commit"] and not tree["truncated"] blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() assert ( blob == e["git_blob_sha1"] == next(x["sha"] for x in tree["tree"] if x["path"] == e["file"]) ) assert hashlib.sha256(raw).hexdigest() == e["sha256"] b = build() g = json.loads((REPO / b["source_path"]).read_bytes()) for e in b["sources"]: raw = (OUT / e["local_file"]).read_bytes() assert hashlib.sha256(raw).hexdigest() == e["sha256"] assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines()) graphs = dict( source_path=b["source_path"], raw_sha256=b["source_sha256"], canonical_sha256=b["canonical_sha256"], nodes=g["nodes"], links=g["links"], extra=g["extra"], counts=b["counts"], missing_widgets=[18], ) (OUT / "source-graphs.json").write_text(json.dumps(graphs, ensure_ascii=False, indent=2) + "\n") (OUT / "source-check.json").write_text( json.dumps( dict( local_file_base="docs/hel-892/multivideo-reference", git_texts=len(entries), registry_texts=0, tree_metadata_json=4, unique_commits=4, files=entries, citations=len(b["sources"]), no_upstream_execution=True, no_assets_fetched=True, ), ensure_ascii=False, indent=2, ) + "\n" ) print( f"PASS {len(entries)} Git text originals, 4 tree metadata JSON, " f"{len(b['sources'])} citations" ) if __name__ == "__main__": main()