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

115 lines
4.2 KiB
Python

"Independent byte/Git identity, raw position/named copy and graph checks."
import datetime
import hashlib
import json
from build_definition import OUT, REF, REPO, build, canonical
from inventory import inventory
def main():
block = build()
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
for e in rows:
raw = (REF / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
if e["id"] in ["kj", "rgthree"]:
members = json.loads((REF / (e["id"] + "-members.json")).read_bytes())
info = next(x for x in members if x["name"] == e["file"])
import zlib
assert zlib.crc32(raw) == info["crc"] == e["member_crc32"]
assert e["git_commit_binding"] == "unknown"
assert (
json.loads((REF / (e["id"] + "-registry.json")).read_bytes())["version"] == e["tag"]
)
continue
assert (
hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
== e["git_blob_sha1"]
)
t = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
assert t["sha"] == e["tree"] and not t["truncated"]
assert next(x["sha"] for x in t["tree"] if x["path"] == e["file"]) == e["git_blob_sha1"]
c = (REF / (e["id"] + "-commit.txt")).read_bytes()
assert (
hashlib.sha1(b"commit " + str(len(c)).encode() + b"\0" + c).hexdigest() == e["commit"]
)
assert c.decode().splitlines()[0] == "tree " + e["tree"]
tag = json.loads((REF / (e["id"] + "-tag.json")).read_bytes())
assert tag["commit"] == e["commit"]
tr = (REF / (e["id"] + "-tag.txt")).read_bytes()
if tag["object"] != tag["commit"]:
assert (
hashlib.sha1(b"tag " + str(len(tr)).encode() + b"\0" + tr).hexdigest()
== tag["object"]
)
assert tr.decode().startswith("object " + e["commit"] + "\n")
else:
assert tr == c
inv = inventory()
assert len(inv["fields"]) == 36 and inv["nodes"] == 25 and inv["edges"] == 31
assert inv["notes"] == 1 and inv["named_nodes"] == 0
assert {x["node"]: x["state"] for x in inv["empty"]} == {
103: "empty_list",
141: "empty_list",
140: "empty_list",
139: "empty_list",
104: "empty_list",
143: "missing",
136: "missing",
135: "missing",
}
for a, f in zip(inv["fields"], block["fields"], strict=True):
assert (a["pointer"], a["json_type"], canonical(a["value"])) == (
f["pointer"],
f["json_type"],
canonical(f["value"]),
)
assert "named_value" not in f
g = json.loads((REPO / block["source_path"]).read_bytes())
ns = {n["id"]: n for n in g["nodes"]}
for edge, src, slot, dst, port, kind in g["links"]:
assert edge in ns[src]["outputs"][slot]["links"]
assert ns[dst]["inputs"][port]["link"] == edge
assert ns[src]["outputs"][slot]["type"] == kind
assert {n["id"]: n["mode"] for n in g["nodes"] if n["mode"] != 0} == {142: 4}
assert not g.get("definitions")
assert ns[103]["outputs"][1]["links"] == []
assert g["extra"]["frontendVersion"] == "1.36.13"
for e in block["sources"]:
data = (OUT / e["local_file"]).read_bytes()
assert hashlib.sha256(data).hexdigest() == e["sha256"]
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(data.decode().splitlines())
(OUT / "source-check.json").write_text(
json.dumps(
dict(
all_pass=True,
reverified_at=datetime.datetime.now(datetime.timezone.utc).isoformat(),
source_files=len(rows),
citations=len(block["sources"]),
counts=block["counts"],
named_nodes=0,
inventory=inv,
upstream_executed=False,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
(
"PASS 36 positions, 1 com"
"plete Note, 31 physic"
"al edges; exact Git and "
"registry text identit"
"y"
)
)
if __name__ == "__main__":
main()