Files
aigc-home/docs/hel-892/rtx-video-document-evidence/verify_sources.py
T

70 lines
2.6 KiB
Python

"Verify exact static source bytes, tag/tree identities and evidence lines offline."
import hashlib
import json
import zipfile
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, "reused_git_texts": 0}
old_ref = REF.parent / "rtx-reference"
for e in es:
raw = (REF / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
if e["id"] == "rtx":
assert e["git_commit_binding"] == "unknown"
assert (
e["package_sha256"]
== json.loads((old_ref / "rtx-package.json").read_bytes())["sha256"]
)
package = (old_ref / "rtx-0.1.0-source.zip").read_bytes()
assert hashlib.sha256(package).hexdigest() == e["package_sha256"]
with zipfile.ZipFile(old_ref / "rtx-0.1.0-source.zip") as z:
assert z.read(e["file"]) == raw
counts["package_texts"] += 1
else:
tree = json.loads((old_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["reused_git_texts" if e.get("reused") else "git_texts"] += 1
tags = {}
for key in ["core", "frontend"]:
t = json.loads((old_ref / (key + "-tag.json")).read_bytes())
assert t["object"]["type"] == "commit" and t["object"]["sha"] == next(
e["commit"] for e in es if e["id"] == key
)
tags[key] = t["object"]["sha"]
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"]),
tags=tags,
package_git_binding="unknown",
all_pass=True,
local_file_base="docs/hel-892/rtx-video-document-evidence",
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print("PASS exact sources", counts)
if __name__ == "__main__":
main()