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

59 lines
2.1 KiB
Python

"""Offline verification of exact Git text, inventories, citations and identities."""
import hashlib
import json
from build_definition import OUT, REF, REPO, build
from fetch_sources import PINS
def main():
b = build()
roots = {}
for e in b["sources"]:
raw = (OUT / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
tree = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
assert not tree["truncated"] and tree["sha"] == e["commit"]
assert (
hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
== e["git_blob_sha1"]
== next(x["sha"] for x in tree["tree"] if x["path"] == e["file"])
)
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines())
tag = REF / (e["id"] + "-tag.json")
if tag.exists():
obj = json.loads(tag.read_bytes())["object"]
assert obj["type"] == "commit" and obj["sha"] == e["commit"]
roots[e["id"]] = e["commit"]
assert roots == PINS
assert len(b["fields"]) == 46 and len(b["comments"]) == 1
g = json.loads((REPO / b["source_path"]).read_bytes())
assert len(g["nodes"]) == 13 and len(g["links"]) == 10 and "definitions" not in g
guhai = json.loads((REF / "guhai-tree.json").read_bytes())
missing_license = not any(
x["path"].lower() in ["license", "license.md", "copying", "license.txt"]
for x in guhai["tree"]
)
assert missing_license
(OUT / "source-check.json").write_text(
json.dumps(
dict(
all_pass=True,
commits=roots,
citations=len(b["sources"]),
git_texts=len({e["local_file"] for e in b["sources"]}),
local_file_base=str(OUT.relative_to(REPO)),
guhai_license="README generic statement only; exact license unknown",
upstream_executed=False,
),
indent=2,
)
+ "\n"
)
print("PASS exact sources, tag/tree/blob/line ranges and 46+1 inventory")
if __name__ == "__main__":
main()