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

161 lines
7.1 KiB
Python

"Verify exact text, Git/package provenance and source graph without upstream imports."
import hashlib
import json
import zlib
from build_definition import OUT, REF, build, canonical
from inventory import inventory
def object_hash(kind, raw):
return hashlib.sha1(kind.encode() + b" " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
def main():
block, inv = build(), inventory()
rows = json.loads((REF / "sources.json").read_bytes())["sources"]
checks = []
for e in rows:
raw = (REF / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
if e["id"] == "litegraph":
root = REF / e["identity_root"]
assert (
json.loads((root / "litegraph__package__package.json").read_bytes())["version"]
== "0.15.15"
)
front = next(
x for x in rows if x["id"] == "frontend" and x["file"] == "package-lock.json"
)
lock = json.loads((REF / front["local_file"]).read_bytes())
assert (
lock["packages"]["node_modules/@comfyorg/litegraph"]["integrity"]
== "sha512-" + e["artifact_sha512_base64"]
)
proof = (
"Pinned frontend1.23.0 lock, exact0.15."
"15 member SHA; whole artifact digest r"
"eused, Git unknown"
)
elif e["id"] == "seedpkg":
root = REF / e["identity_root"]
acquisition = json.loads((root / "seedpkg-acquisition.json").read_bytes())
assert acquisition["archive_sha256"] == e["package_sha256"]
assert not acquisition["complete_archive_retained"]
member = next(
x
for x in json.loads((root / "seedpkg-members.json").read_bytes())
if x["name"] == e["file"]
)
assert member["crc"] == e["member_crc32"] == zlib.crc32(raw)
assert e["file"] in acquisition["selected_members_verified_before_removal"]
assert json.loads((root / "seedpkg-registry.json").read_bytes())["version"] == "2.5.22"
proof = (
"Exact2.5.22 acquisition SHA recorded; retained text SHA/CRC rechecked; "
"full archive removed, Git unknown"
)
else:
root = REF / e["identity_root"]
key = e["identity_key"]
commit = (root / (key + "-commit.txt")).read_bytes()
tree = json.loads((root / (key + "-tree.json")).read_bytes())
assert object_hash("commit", commit) == e["commit"]
assert commit.decode().splitlines()[0] == "tree " + e["tree"] == "tree " + tree["sha"]
assert not tree["truncated"]
assert (
next(t["sha"] for t in tree["tree"] if t["path"] == e["file"])
== e["git_blob_sha1"]
== object_hash("blob", raw)
)
tag = json.loads((root / (key + "-tag.json")).read_bytes())
tag_raw = (root / (key + "-tag.txt")).read_bytes()
assert tag["commit"] == e["commit"]
if tag["object"] == e["commit"]:
assert tag_raw == commit
else:
assert object_hash("tag", tag_raw) == tag["object"]
assert tag_raw.decode().startswith("object " + e["commit"] + "\n")
proof = (
"Rehashed commit/tag/selected blo"
"b; complete tree listing, not fu"
"ll tree-object rehash"
)
if not e["license_file"].startswith("未知"):
license_row = next(
x for x in rows if x["id"] == e["id"] and x["local_file"] == e["license_file"]
)
assert (
hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest()
== license_row["sha256"]
)
checks.append(dict(id=e["id"], file=e["file"], sha256=e["sha256"], proof=proof))
assert len(inv["fields"]) == 121 and len(inv["notes"]) == 1
assert inv["scopes"][0]["nodes"] == 53 and inv["scopes"][0]["edges"] == 55
assert sum(n["mode"] == 0 for n in inv["nodes"]) == 47
assert sum(n["mode"] == 4 for n in inv["nodes"]) == 6
assert sum(f["json_type"] == "list" for f in inv["fields"]) == 2
assert {n["node"]: n["state"] for n in inv["empty"]} == {
663: "empty_list",
553: "empty_list",
579: "empty_list",
694: "empty_list",
568: "missing",
648: "missing",
655: "missing",
571: "missing",
}
assert [(n["node"], len(n["text"])) for n in inv["notes"]] == [(690, 6)]
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 [(n["node"], n["pointer"], n["text"]) for n in inv["notes"]] == [
(int(n["node_id"]), n["pointer"], n["text"]) for n in block["comments"]
]
ns = {n["id"]: n for n in inv["nodes"]}
mismatches = []
for eid, a, ao, z, zi, kind in inv["links"]:
src, dst = ns[a]["outputs"][ao], ns[z]["inputs"][zi]
assert eid in src["links"] and dst["link"] == eid
if not (src["type"] == "*" or kind == src["type"]) or not (
dst["type"] == "*" or kind == dst["type"]
):
mismatches.append(
dict(
edge=eid, source_type=src["type"], destination_type=dst["type"], edge_type=kind
)
)
assert ns[562]["outputs"][1]["links"] == []
assert [x.get("link") for x in ns[661]["inputs"]] == [3368, 3370, 3369, None, 3375, 3376, None]
assert ns[661]["widgets_values"] == [1.0000000000000002]
assert ns[715]["inputs"][3]["link"] == 3488
assert not any(n["type"] == "SetLatentNoiseMask" for n in inv["nodes"])
assert ns[591]["outputs"][0]["type"] == ns[707]["outputs"][0]["type"] == "IMAGE"
assert len(ns[592]["widgets_values"]) == len(ns[706]["widgets_values"]) == 1
assert inv["extra"]["frontendVersion"] == "1.23.0"
assert inv["extra"]["workflowRendererVersion"] == "LG"
assert ns[593]["properties"]["ver"] == "6109df6591a4cf2bc9d3b113d03f7297fa9248e9"
for nid in [679, 680, 681, 683, 682, 677, 678, 684, 685, 686, 687, 688, 695, 696, 697, 698]:
assert "ver" not in ns[nid]["properties"] and "cnr_id" not in ns[nid]["properties"]
for e in block["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())
result = dict(
sources=checks,
counts=block["counts"],
physical_edges_checked=55,
original_type_mismatches=mismatches,
inventory_matches_definition=True,
no_upstream_execution=True,
)
(OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
print("PASS exact Git/package text, 121 positions, 1 note, 55 physical edges")
if __name__ == "__main__":
main()