"""Verify exact static originals and bounded-search provenance without running upstream.""" from __future__ import annotations import hashlib import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] / "birefnet-reference" def main(): entries = json.loads((ROOT / "sources.json").read_bytes())["sources"] trees = { key: json.loads((ROOT / (key + "-tree.json")).read_bytes()) for key in ["core", "frontend"] } for tree in trees.values(): assert not tree["truncated"] for entry in entries: raw = (ROOT / entry["local_file"]).read_bytes() assert hashlib.sha256(raw).hexdigest() == entry["sha256"] assert len(entry["commit"]) == 40 and entry["commit"] in entry["url"] blob = next(x for x in trees[entry["id"]]["tree"] if x["path"] == entry["file"]) assert ( hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() == blob["sha"] ) search = json.loads((ROOT / "core-bounded-search.json").read_bytes()) assert not search["errors"] and not search["tree_truncated"] expected = { e["path"]: e["sha"] for e in trees["core"]["tree"] if e["path"] == "nodes.py" or e["path"].startswith("comfy_extras/") and e["path"].endswith(".py") } assert len(expected) == 101 assert {e["path"]: e["git_blob_sha1"] for e in search["files"]} == expected assert search["matches"]["RemoveBackground"] == [] assert search["matches"]["LoadBackgroundRemovalModel"] == [] print( f"PASS {len(entries)} exact originals; bounded 101-file Git blob ledger; " "no upstream execution" ) if __name__ == "__main__": main()