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

110 lines
4.3 KiB
Python

"""Verify exact text identities and both physical endpoint directions offline."""
import hashlib
import json
import zlib
from build_definition import OUT, PATHS, REF, REPO, build, canonical
from inventory import inventory
def main():
b = 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"] == "rgthree":
members = json.loads((REF / "rgthree-members.json").read_bytes())
member = next(x for x in members if x["name"] == e["file"])
assert zlib.crc32(raw) == member["crc"] == e["member_crc32"]
assert e["git_commit_binding"] == "unknown"
assert (
json.loads((REF / "rgthree-registry.json").read_bytes())["version"]
== e["tag"]
== "1.0.2512112053"
)
continue
identity = REF.parent / "flux2-img-reference" if e["id"] == "core" else REF
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
assert blob == e["git_blob_sha1"]
t = json.loads((identity / (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"]) == blob
c = (identity / (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((identity / (e["id"] + "-tag.json")).read_bytes())
assert tag["commit"] == e["commit"]
tr = (identity / (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"]) == 27 and inv["nodes"] == 23 and inv["edges"] == 28
assert inv["notes"] == 2 and inv["named_nodes"] == 0 and set(inv["modes"]) == {0}
assert {x["node"]: x["state"] for x in inv["empty"]} == {
k: "empty_list" for k in (125, 136, 138, 137, 139, 126)
}
for a, f in zip(inv["fields"], b["fields"], strict=True):
assert (a["pointer"], a["json_type"], canonical(a["value"])) == (
f["pointer"],
f["json_type"],
canonical(f["value"]),
)
assert f["evidence"]
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()), (
e["file"],
e["lines"],
)
g = json.loads((REPO / PATHS[0]).read_bytes())
ns = {n["id"]: n for n in g["nodes"]}
edges = []
for edge in g["links"]:
eid, a, ao, z, zi, kind = edge
source = ns[a]["outputs"][ao]
target = ns[z]["inputs"][zi]
assert eid in (source.get("links") or []) and target.get("link") == eid
assert source["type"] == target["type"] == kind
edges.append({"edge": edge, "source_backref": True, "target_backref": True})
assert (
ns[125]["outputs"][1]["links"] == [] and ns[76]["outputs"][1]["links"] is None
)
result = {
"all_pass": True,
"source_files": len(rows),
"citations": len(b["sources"]),
"counts": b["counts"],
"physical_endpoint_checks": edges,
"upstream_executed": False,
"source_protocol_conflicts_retained": [
"GetImageSize description promises passthrough but returns three INT",
"SaveImage/Comparer source IMAGE outputs absent from exact RETURN_TYPES",
],
}
(OUT / "source-check.json").write_text(
json.dumps(result, ensure_ascii=False, indent=2) + "\n"
)
print(
"PASS",
len(rows),
"text hashes;",
len(b["sources"]),
"citations; 27 positions and 28 bidirectional edges",
)
if __name__ == "__main__":
main()