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

65 lines
2.3 KiB
Python

"""Verify exact Git blob/tag/tree, line ranges and original graph inventory offline."""
import hashlib
import json
from build_definition import OUT, REPO, build
def main():
b = build()
roots = {}
for e in b["sources"]:
root = (OUT / e["local_file"]).parent
raw = (OUT / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
tree = json.loads((root / (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 = json.loads((root / (e["id"] + "-tag.json")).read_bytes())
assert tag["object"]["type"] == "commit" and tag["object"]["sha"] == e["commit"]
roots[e["id"]] = e["commit"]
assert roots == dict(
core="bb131be9e83d2f773c90f1d6f1e4b248a498c8c5",
frontend="7bd9f8b0d0b854ccb5a947623468f36a392ea0ff",
video="87a003e0c975b8f13e2d4067dd0710e56edd7ba5",
)
g = json.loads((REPO / b["source_path"]).read_bytes())
sub = g["definitions"]["subgraphs"][0]
assert (
len(g["nodes"]) == 5
and len(g["links"]) == 2
and len(sub["nodes"]) == 13
and len(sub["links"]) == 34
)
assert len(b["fields"]) == 47 and len(b["comments"]) == 2
(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)),
inherited_seedvr_investigation=(
"seedvr2-document-evidence/source"
"-check.json; bounded 0.27.0, no "
"new global absence claim"
),
upstream_executed=False,
),
indent=2,
)
+ "\n"
)
print("PASS exact sources, line ranges, tag/tree/blob and 47+2 inventory")
if __name__ == "__main__":
main()