"Recheck selected bytes, real Git identities, citations and every graph endpoint." import hashlib import json import zlib from build_definition import OUT, PATHS, REF, REPO, build, canonical from inventory import inventory def main(): block = build() 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"] root = REF / e["identity_root"] key = e["identity_key"] if key == "kj": members = json.loads((root / "kj-members.json").read_bytes()) info = next(x for x in members if x["name"] == e["file"]) assert zlib.crc32(raw) == info["crc"] == e["member_crc32"] assert json.loads((root / "kj-registry.json").read_bytes())["version"] == "1.3.9" assert e["git_commit_binding"] == "unknown" and e["package_sha256"].startswith( "unknown" ) proof = "exact 1.3.9 registry + necessary ZIP CRC/SHA; full package SHA/Git unknown" else: blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest() assert blob == e["git_blob_sha1"] tree = json.loads((root / (key + "-tree.json")).read_bytes()) assert tree["sha"] == e["tree"] and not tree["truncated"] assert next(t["sha"] for t in tree["tree"] if t["path"] == e["file"]) == blob c = (root / (key + "-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((root / (key + "-tag.json")).read_bytes()) assert tag["commit"] == e["commit"] t = (root / (key + "-tag.txt")).read_bytes() if tag["object"] != e["commit"]: assert ( hashlib.sha1(b"tag " + str(len(t)).encode() + b"\0" + t).hexdigest() == tag["object"] ) assert t.decode().startswith("object " + e["commit"] + "\n") else: assert t == c proof = "raw commit/tag + real tree + selected blobs; no full tree rehash" if key == "tt": assert not any( t["path"].lower().split("/")[-1].startswith("license") for t in tree["tree"] ) assert e["license_file"].startswith("未知") else: lic = next(x for x in rows if x["id"] == e["id"] and x["file"] == "LICENSE") assert ( hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest() == lic["sha256"] ) checks.append( dict( id=e["id"], file=e["file"], sha256=e["sha256"], commit=e["commit"], tree=e["tree"], proof=proof, license_file=e["license_file"], ) ) inv = inventory() assert [s["nodes"] for s in inv["scopes"]] == [9, 18] assert [s["edges"] for s in inv["scopes"]] == [10, 32] assert all(s["named_nodes"] == 0 and set(s["modes"]) == {0} for s in inv["scopes"]) assert len(inv["fields"]) == 37 and sum(f["scope"] == "root" for f in inv["fields"]) == 17 assert all(f["json_type"] not in ["list", "dict"] for f in inv["fields"]) assert [(n["node"], n["characters"]) for n in inv["notes"]] == [(97, 1396)] assert {x["node"]: x["state"] for x in inv["empty"]} == { 143: "missing", 148: "empty_list", 149: "empty_list", 141: "empty_list", 140: "empty_list", 139: "empty_list", 103: "empty_list", 104: "empty_list", 135: "missing", 136: "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"]), ) 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()) g = json.loads((REPO / PATHS[0]).read_bytes()) sub = g["definitions"]["subgraphs"][0] endpoints = [] for scope, graph in [("root", g), ("definition", sub)]: ns = {n["id"]: n for n in graph["nodes"]} ids = [] for original in graph["links"]: if scope == "root": eid, a, ao, z, zi, kind = original else: eid, a, ao, z, zi, kind = [ original[k] for k in ["id", "origin_id", "origin_slot", "target_id", "target_slot", "type"] ] ids.append(eid) source = graph["inputs"][ao] if a == -10 else ns[a]["outputs"][ao] target = graph["outputs"][zi] if z == -20 else ns[z]["inputs"][zi] assert eid in source.get("linkIds", source.get("links", [])) assert eid in target["linkIds"] if z == -20 else target["link"] == eid assert (source["type"] == "*" or kind in source["type"].split(",")) and ( target["type"] == "*" or kind in target["type"].split(",") ) endpoints.append( dict( scope=scope, edge=original, source_backref=True, target_backref=True, source_type=source["type"], target_type=target["type"], ) ) assert len(ids) == len(set(ids)) # Reverse verification retains duplicate boundary output declarations. for n in graph["nodes"]: for slot in n.get("inputs", []): assert slot.get("link") is None or slot["link"] in ids for slot in n.get("outputs", []): assert all(link in ids for link in slot.get("links") or []) if scope == "definition": for boundary in graph["inputs"] + graph["outputs"]: assert all(link in ids for link in boundary["linkIds"]) ns = {n["id"]: n for n in g["nodes"]} inner = {n["id"]: n for n in sub["nodes"]} assert len(ns[149]["properties"]["proxyWidgets"]) == 10 assert len(ns[149]["inputs"]) == len(sub["inputs"]) == 9 for outer, boundary in zip(ns[149]["inputs"], sub["inputs"], strict=True): assert (outer["name"], outer["type"]) == (boundary["name"], boundary["type"]) assert ns[149]["widgets_values"] == sub["widgets"] == [] assert [i["link"] for i in ns[149]["inputs"]] == [ 286, None, None, None, None, None, None, 300, 299, ] assert sub["outputs"][0]["linkIds"] == [201, 201] assert inner[103]["outputs"][1]["links"] == [] assert ns[9]["outputs"] == ns[148]["outputs"] == [] assert ns[76]["outputs"][1]["links"] is None assert ns[146]["outputs"][3]["links"] == [] and ns[146]["inputs"][1]["link"] is None assert ns[147]["widgets_values"] == ["right", True] assert [284, 76, 0, 147, 0, "IMAGE"] in g["links"] assert [290, 149, 0, 147, 1, "IMAGE"] in g["links"] assert inner[110]["widgets_values"] == ["flux2-vae.safetensors"] assert inner[142]["widgets_values"][1] == 0.8 assert g["extra"]["frontendVersion"] == "1.36.13" result = dict( all_pass=True, source_files=len(rows), citations=len(block["sources"]), counts=block["counts"], sources=checks, endpoints=endpoints, inventory=inv, upstream_executed=False, ) (OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n") print( ( "PASS 37 scalar positions, full N" "ote, 42 bidirectional edges, exa" "ct references with explicit assu" "mptions" ) ) if __name__ == "__main__": main()