"Verify exact text, Git/package provenance and source graph without upstream imports." import ast 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"\x00" + 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 mem" "ber SHA; whole artifac" "t digest reused, Git u" "nknown" ) elif "member_crc32" in e: root = REF / e["identity_root"] m = json.loads((root / (e["identity_key"] + "-registry.json")).read_bytes()) members = json.loads((root / (e["identity_key"] + "-members.json")).read_bytes()) member = next((x for x in members if x["name"] == e["file"])) assert m["version"] == e["tag"] assert member["crc"] == e["member_crc32"] == zlib.crc32(raw) assert e["package_sha256"].startswith("unknown") proof = "准确发布成员SHA/CRC;Range选定文本,完整包SHA与Git绑定未知" 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/se" "lected blob; complete " "tree listing, not full" " tree-object rehash" ) if not e["license_file"].startswith("未知"): license_row = next( ( x for x in rows if x["id"] == e["id"] and ( (REF / x["local_file"]).resolve() == (REF / e["license_file"]).resolve() or x["file"] == "LICENSE" ) ) ) 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"]) == 175 and len(inv["notes"]) == 4 assert [(s["nodes"], s["edges"]) for s in inv["scopes"]] == [(266, 332)] assert inv["extra"]["frontendVersion"] == "1.35.9" and inv["scopes"][0]["named_nodes"] == 0 assert inv["scopes"][0]["modes"].count(0) == 228 and inv["scopes"][0]["modes"].count(2) == 38 assert sum((e["state"] == "missing" for e in inv["empty"])) == 161 assert sum((e["state"] == "empty_list" for e in inv["empty"])) == 27 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["pointer"], n["text"]) for n in block["comments"]] == [ (n["pointer"], n["text"]) for n in inv["notes"] ] from build_definition import PATHS, REPO g = json.loads((REPO / PATHS[0]).read_bytes()) ns = {n["id"]: n for n in g["nodes"]} type_counts = {} for n in g["nodes"]: type_counts[n["type"]] = type_counts.get(n["type"], 0) + 1 expected = { "Reroute": 131, "Reroute (rgthree)": 16, "Any Switch (rgthree)": 16, "Fast Muter (rgthree)": 4, "Mute / Bypass Repeater (rgthree)": 5, "Node Collector (rgthree)": 5, "PrimitiveStringMultiline": 18, "KSamplerAdvanced": 2, "SamplerCustom": 5, "KarrasScheduler": 5, "SplitSigmas": 3, "SetFirstSigma": 2, "ExtendIntermediateSigmas": 2, "VAEDecode": 6, "VAEEncode": 3, "PrimitiveInt": 6, "UpscaleModelLoader": 2, "ImageUpscaleWithModel": 2, "Image Resize (rgthree)": 5, } assert all(type_counts[k] == v for k, v in expected.items()) assert ns[524]["mode"] == 0 and ns[531]["mode"] == 2 checked = [] for eid, a, ao, z, zi, kind in g["links"]: assert eid in ns[a]["outputs"][ao]["links"] and ns[z]["inputs"][zi]["link"] == eid checked.append(eid) assert len(checked) == 332 and len(set(checked)) == 332 assert [ n["id"] for n in g["nodes"] if n["type"] == "PrimitiveStringMultiline" and n["mode"] == 0 ] == [125] assert ns[566]["inputs"][0]["label"] == "BAD" and ns[566]["inputs"][0]["type"] == "*" assert ns[392]["widgets_values"] == [{}, {"type": "PowerLoraLoaderHeaderWidget"}, {}, ""] assert sum((isinstance(f["value"], dict) for f in block["fields"])) == 3 assert not ns[57]["widgets_values"][0].endswith("\n") assert ns[9]["outputs"] == [] assert ns[341]["inputs"][1]["name"] == "seed" e = next((e for e in rows if e["id"] == "core0375" and e["file"] == "nodes.py")) parsed = ast.parse((REF / e["local_file"]).read_bytes()) save = next((c for c in parsed.body if isinstance(c, ast.ClassDef) and c.name == "SaveImage")) ret = next( ( c.value for c in save.body if isinstance(c, ast.Assign) and any((isinstance(n, ast.Name) and n.id == "RETURN_TYPES" for n in c.targets)) ) ) assert ast.literal_eval(ret) == () 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()) (OUT / "source-check.json").write_text( json.dumps( dict( sources=checks, counts=block["counts"], physical_edges_checked=len(checked), inventory_matches_definition=True, source_save_outputs=ns[9]["outputs"], type_counts=type_counts, accurate_save_return=[], bad_label_pointer=f"/nodes/{g['nodes'].index(ns[566])}/inputs/0/label", no_upstream_execution=True, ), ensure_ascii=False, indent=2, ) + "\n" ) print(("PASS exact sources,175 positions,4 notes,332 physical edges")) if __name__ == "__main__": main()