"Verify exact Git blobs, package-member hashes and editorial source lines offline." import hashlib import json from build_definition import OUT, REF, build def main(): es = json.loads((REF / "sources.json").read_bytes())["sources"] counts = {"git_texts": 0, "package_texts": 0} for e in es: raw = (REF / e["local_file"]).read_bytes() assert hashlib.sha256(raw).hexdigest() == e["sha256"] if e.get("git_commit_binding") == "unknown": assert e["commit"].startswith("发布包SHA256:") and len(e["commit"].split(":")[1]) == 64 counts["package_texts"] += 1 else: 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"]) ) counts["git_texts"] += 1 tag = json.loads((REF / "core-tag.json").read_bytes()) assert tag["object"]["type"] == "commit" and tag["object"]["sha"] == next( e["commit"] for e in es if e["id"] == "core" ) b = build() 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()) (OUT / "source-check.json").write_text( json.dumps( dict( **counts, citations=len(b["sources"]), tag=tag["ref"], commit=tag["object"]["sha"], package_git_binding="unknown", all_pass=True, local_file_base="docs/hel-892/storyboard-document-evidence", ), ensure_ascii=False, indent=2, ) + "\n" ) print("PASS exact identities, bytes and lines", counts) if __name__ == "__main__": main()