"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"]) == 63 and len(inv["notes"]) == 1 assert [(x["nodes"], x["edges"]) for x in inv["scopes"]] == [(6, 5), (23, 43)] assert inv["scopes"][0]["modes"] == [0, 0, 0, 4, 0, 0] assert inv["scopes"][1]["modes"] == [0] * 23 assert all(m == 0 for m in inv["scopes"][1]["modes"]) assert all((x["named_nodes"] == 0 for x in inv["scopes"])) assert inv["extra"]["frontendVersion"] == "1.45.21" for raw, field in zip(inv["fields"], block["fields"], strict=True): assert raw["pointer"] == field["pointer"] assert canonical(raw["value"]) == canonical(field["value"]) assert raw["json_type"] == field["json_type"] assert [(n["pointer"], n["text"]) for n in block["comments"]] == [ (n["pointer"], n["text"]) for n in inv["notes"] ] assert [n["characters"] for n in inv["notes"]] == [1668] from build_definition import PATHS, REPO g = json.loads((REPO / PATHS[0]).read_bytes()) sg = g["definitions"]["subgraphs"][0] root = {n["id"]: n for n in g["nodes"]} inside = {n["id"]: n for n in sg["nodes"]} for eid, a, ao, z, zi, kind in g["links"]: assert eid in root[a]["outputs"][ao]["links"] and root[z]["inputs"][zi]["link"] == eid for e in sg["links"]: (a, ao, z, zi) = (e["origin_id"], e["origin_slot"], e["target_id"], e["target_slot"]) if a == -10: assert e["id"] in sg["inputs"][ao]["linkIds"] else: assert e["id"] in inside[a]["outputs"][ao]["links"] if z == -20: assert e["id"] in sg["outputs"][zi]["linkIds"] else: assert inside[z]["inputs"][zi]["link"] == e["id"] assert len(sg["inputs"]) == len(root[30]["inputs"]) == 12 assert len(root[30]["widgets_values"]) == 11 assert sum(len(x["linkIds"]) for x in sg["inputs"]) == 16 assert sg["widgets"] == [] and "proxyWidgets" not in root[30]["properties"] assert [i for (i, n) in inside.items() if n.get("widgets_values") == []] == [13, 20, 58, 62] assert not {3, 6, 22, 23, 27, 28, 51} & inside.keys() assert root[75]["widgets_values"] == [] and root[75]["mode"] == 4 assert root[48]["type"] == "MarkdownNote" assert {e["id"] for e in rows} == {"core0250", "core0280", "core0292", "core051", "frontend"} core = next((e for e in rows if e["id"] == "core0250" and e["file"] == "nodes.py")) tree = ast.parse((REF / core["local_file"]).read_bytes()) save = next((c for c in tree.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) == () and root[29]["outputs"][0]["type"] == "IMAGE" assert root[29]["outputs"][0]["links"] == [] clip = next((c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == "CLIPLoader")) enums = [ ast.literal_eval(x) for x in ast.walk(clip) if isinstance(x, ast.List) and all((isinstance(y, ast.Constant) and isinstance(y.value, str) for y in x.elts)) ] assert not any(("krea2" in x for x in enums)) and inside[11]["widgets_values"][1] == "krea2" assert inside[16]["widgets_values"] == [ "", 512, "on", 0.7, 64, 0.95, 0.05, 1.05, 0, 0, False, True, ] assert sum((f["role"] == "boundary_saved_cache" for f in block["fields"])) == 15 assert sum((f["scope"] == "root" for f in block["fields"])) == 17 assert sum((f["scope"] == "30" for f in block["fields"])) == 46 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()) bindings = [] aliases = { "PrimitiveBoolean": "Boolean", "PrimitiveStringMultiline": "StringMultiline", "ComfySwitchNode": "SwitchNode", } for scope, graph in [("root", g), ("30", sg)]: for node in graph["nodes"]: cls = node["type"] if cls in ["Note", "MarkdownNote"]: continue if node["id"] == 30 and scope == "root": bindings.append( dict( scope=scope, node_id=30, registration="子图宿主,frontend边界参考;独立backend类/恢复未知", ) ) continue key = { "0.25.0": "core0250", "0.28.0": "core0280", "0.29.2": "core0292", "0.5.1": "core051", }[node["properties"]["ver"]] symbol = aliases.get(cls, cls) matched = [] for e in rows: if ( e["id"] != key or not e["file"].endswith(".py") or not (e["file"] == "nodes.py" or e["file"].startswith("comfy_extras/")) ): continue tree = ast.parse((REF / e["local_file"]).read_bytes()) klass = next( (c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == symbol), None ) if klass is None: continue registrations = [] for item in ast.walk(tree): if isinstance(item, ast.Dict): for k, v in zip(item.keys, item.values, strict=True): if ( isinstance(k, ast.Constant) and k.value == cls and isinstance(v, ast.Name) and v.id == symbol ): registrations.append([item.lineno, item.end_lineno]) if ( isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)) and item.name == "get_node_list" ): if any(isinstance(n, ast.Name) and n.id == symbol for n in ast.walk(item)): registrations.append([item.lineno, item.end_lineno]) assert registrations, (key, cls, "registration missing") matched.append( dict( file=e["file"], class_lines=[klass.lineno, klass.end_lineno], registration_lines=registrations, sha256=e["sha256"], ) ) assert matched, (key, cls) bindings.append( dict( scope=scope, node_id=node["id"], class_type=cls, version=node["properties"]["ver"], source_id=key, bindings=matched, ) ) (OUT / "node-version-bindings.json").write_text( json.dumps(bindings, ensure_ascii=False, indent=2) + "\n" ) (OUT / "source-check.json").write_text( json.dumps( dict( sources=checks, counts=block["counts"], physical_edges_checked=48, boundary_inputs=16, declared_inputs=12, host_cache=11, inventory_matches_definition=True, source_save_outputs=root[29]["outputs"], accurate_save_return=[], clip_krea2_enum_missing=True, clip_enums=enums, no_upstream_execution=True, ), ensure_ascii=False, indent=2, ) + "\n" ) print( ( "PASS exact identities," "63 positions,one1668 n" "ote,48 edges,12 inputs" "/16 boundaries/11 cach" "es,independent version" "s and CLIP conflict" ) ) if __name__ == "__main__": main()