"""Independent raw graph, exact Git identity and schema checks; never import upstream.""" import ast import hashlib import json 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": 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"]["version"] == "0.15.15" assert ( lock["packages"]["node_modules/@comfyorg/litegraph"]["integrity"] == "sha512-" + e["artifact_sha512_base64"] ) checks.append( dict( id=e["id"], file=e["file"], sha256=e["sha256"], proof=( "exact lock and member SHA; reuse" + "d original artifact digest, no G" + "it claim" ), reverified_at=e["reverified_at"], ) ) continue 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") license_row = next( x for x in rows if x["id"] == e["id"] and (REF / x["local_file"]).resolve() == (REF / e["license_file"]).resolve() ) 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=( "rehashed commit/tag/se" "lected blob; complete " "tree listing, not tree" "-object rehash" ), reverified_at=e["reverified_at"], ) ) assert inv["sha256"] == "0d482e6c6fac70af6dd5549e8a464ee080a0ec135350d72d32a4ce4a8fd05bbe" assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [(17, 23, 14)] assert len(inv["fields"]) == 33 and inv["notes"] == [] assert [z["node"] for z in inv["empty"]] == [8, 41, 40] assert all(z["state"] == "missing" for z in inv["empty"]) assert inv["extra"]["frontendVersion"] == "1.23.0" and inv["definition_boundary"] == [] from build_definition import PATHS, REPO g = json.loads((REPO / PATHS[0]).read_bytes()) nodes = {n["id"]: n for n in g["nodes"]} assert all(n["mode"] == 0 for n in nodes.values()) and "definitions" not in g def pointer(p): o = g for k in p.strip("/").split("/"): o = o[int(k)] if isinstance(o, list) else o[k] return o for a, b in zip(inv["fields"], block["fields"], strict=True): assert a["pointer"] == b["pointer"] and a["json_type"] == b["json_type"] assert canonical(a["value"]) == canonical(b["value"]) assert canonical(pointer(b["named_pointer"])) == canonical(b["named_value"]) if b["node_id"] != "43": assert canonical(b["value"]) == canonical(b["named_value"]) history = next(f for f in block["fields"] if f["node_id"] == "43") assert len(history["value"]) == len(history["named_value"]) == 2 assert all( dict(a, img={}) == b for a, b in zip(history["value"], history["named_value"], strict=True) ) assert all("temp_rjutl" in h["url"] and h["selected"] is True for h in history["value"]) for eid, a, ao, z, zi, _kind in g["links"]: assert eid in nodes[a]["outputs"][ao]["links"] and nodes[z]["inputs"][zi]["link"] == eid edges = {e[0]: e for e in g["links"]} expected = { 69: (2, 0, 33, 0), 70: (33, 0, 32, 0), 60: (32, 0, 7, 0), 79: (40, 0, 7, 3), 83: (39, 0, 41, 0), 84: (41, 0, 40, 0), 80: (39, 0, 34, 2), 81: (39, 0, 35, 2), 86: (25, 0, 43, 1), 87: (8, 0, 43, 0), 74: (8, 0, 38, 0), } for eid, ends in expected.items(): assert tuple(edges[eid][1:5]) == ends assert all("links" not in o for o in nodes[39]["outputs"][1:]) assert "links" not in nodes[38]["outputs"][0] and nodes[38]["outputs"][1]["links"] == [] assert nodes[43]["outputs"][0]["links"] is None assert nodes[7]["widgets_values"] == [ 1051545309509482, "randomize", 10, 1, "euler", "beta57", 1, ] assert nodes[34]["widgets_values"] == ["transform the image to realistic photograph"] assert nodes[35]["widgets_values"] == [""] and nodes[33]["widgets_values"] == [True] assert all( i.get("link") is None for nid in [34, 35] for i in nodes[nid]["inputs"] if i["name"] in ["image2", "image3"] ) assert "cnr_id" not in nodes[39]["properties"] and "ver" not in nodes[39]["properties"] reg = json.loads((REF / "krea-registry.json").read_bytes()) assert ( reg["id"] == "comfyui-krea2-ostris-edit" and reg["repository"] == "https://github.com/ostris/ComfyUI-Krea2-Ostris-Edit" ) def source(key, file): return ( REF / next(e for e in rows if e["id"] == key and e["file"] == file)["local_file"] ).read_bytes() def classes(key, file): return {c.name: c for c in ast.parse(source(key, file)).body if isinstance(c, ast.ClassDef)} core = classes("core0250", "nodes.py") enums = [ ast.literal_eval(c) for c in ast.walk(core["CLIPLoader"]) if isinstance(c, ast.List) and all(isinstance(x, ast.Constant) and isinstance(x.value, str) for x in c.elts) ] assert all("krea2" not in v for v in enums) sampler = ast.parse(source("core0250", "comfy/samplers.py")) handlers = next( c.value for c in sampler.body if isinstance(c, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "SCHEDULER_HANDLERS" for t in c.targets) ) assert "beta57" not in [ast.literal_eval(k) for k in handlers.keys] save = classes("core0283", "nodes.py")["SaveImage"] ret = next( c.value for c in save.body if isinstance(c, ast.Assign) and any(isinstance(t, ast.Name) and t.id == "RETURN_TYPES" for t in c.targets) ) assert ast.literal_eval(ret) == ("IMAGE",) assert any(isinstance(c, ast.Constant) and c.value == "result" for c in ast.walk(save)) plugin = classes("kreaostris", "nodes.py") patch = plugin["Krea2OstrisEditModelPatch"] method = next(c for c in patch.body if isinstance(c, ast.FunctionDef) and c.name == "patch") assert ast.literal_eval(method.args.defaults[0]) is False assert all( f'"{cls}": {cls}' in source("kreaostris", "nodes.py").decode() for cls in plugin if cls in ["Krea2OstrisEditModelPatch", "TextEncodeKrea2OstrisEdit"] ) comparer = classes("rgthree", "py/image_comparer.py")["RgthreeImageComparer"] assert ast.unparse(comparer.bases[0]) == "PreviewImage" assert not any(isinstance(c, ast.Constant) and c.value == "result" for c in ast.walk(comparer)) assert len(block["node_bindings"]) == 17 and len(block["zero_saved_nodes"]) == 3 assert next(f for f in block["fields"] if f["field"] == "kv_cache")["schema_default"] == "False" (OUT / "node-version-bindings.json").write_text( json.dumps(block["node_bindings"], ensure_ascii=False, indent=2) + "\n" ) (OUT / "source-check.json").write_text( json.dumps( dict( files=checks, source_fields=33, source_notes=0, physical_edges=23, all_checks_pass=True, upstream_imported=False, save0283_has_image_result=True, clip0250_krea2_enum_present=False, scheduler0250_beta57_present=False, layerutility_identity_unknown=True, ), ensure_ascii=False, indent=2, ) + "\n" ) print( ( "PASS exact source identities, 17" + " bindings including one unknown," + " 33 dual positions, zero notes, " + "23 edges and preserved interface" + " gaps" ) ) if __name__ == "__main__": main()