"""Independent exact-original and bounded registration/schema audit, no imports of upstream.""" import ast import collections import hashlib import json import re from build_definition import BINDINGS, OUT, PATHS, REF, REPO, build, canonical, node_schema from inventory import inventory def write(name, value): (OUT / name).write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n") def registered(tree, symbol): for n in ast.walk(tree): if isinstance(n, ast.Assign) and any( isinstance(t, ast.Name) and t.id in ["NODE_CLASS_MAPPINGS", "NODE_CONFIG"] for t in n.targets ): if any(isinstance(x, ast.Name) and x.id == symbol for x in ast.walk(n.value)): return True if isinstance(n, (ast.FunctionDef, ast.AsyncFunctionDef)) and n.name == "get_node_list": if any(isinstance(x, ast.Name) and x.id == symbol for x in ast.walk(n)): return True return False def main(): inv = inventory() g = json.loads((REPO / PATHS[0]).read_bytes()) b = build() nodes = {n["id"]: n for n in g["nodes"]} assert inv["sha256"] == "ebd0c2823b70e5121f9642f781f2d0fa32cda6abe7d4a68fb0eecacc30e92d06" assert len(g["nodes"]) == 95 and len(g["links"]) == 90 and not g.get("definitions") assert collections.Counter(n["mode"] for n in g["nodes"]) == {0: 95} assert all("widgets_values" in n and "widgets_values_named" not in n for n in g["nodes"]) assert len(inv["fields"]) == 129 and len(inv["notes"]) == 5 assert {x["node"] for x in inv["empty"]} == {17, 172, 238, 25, 253, 260, 266, 267} assert all(x["state"] == "empty_list" for x in inv["empty"]) assert collections.Counter(f["json_type"] for f in inv["fields"]) == dict( str=82, int=34, bool=8, float=1, NoneType=2, dict=2 ) assert g["links"] == json.loads((OUT / "expected-edges.json").read_bytes()) for eid, src, si, dst, di, typ in g["links"]: assert eid in nodes[src]["outputs"][si]["links"] assert nodes[dst]["inputs"][di]["link"] == eid for f, x in zip(b["fields"], inv["fields"], strict=True): assert f["pointer"] == x["pointer"] and f["json_type"] == x["json_type"] assert type(f["value"]).__name__ == f["json_type"] assert canonical(f["value"]) == canonical(x["value"]) assert f["named_state"] == "missing" and "named_pointer" not in f and "named_value" not in f for note, x in zip(b["comments"], inv["notes"], strict=True): assert note["pointer"] == x["pointer"] and note["text"] == x["text"] manifest = json.loads((REF / "sources.json").read_bytes())["sources"] checks, trees = [], {} assert len({(e["id"], e["file"]) for e in manifest}) == len(manifest) for e in manifest: data = (REF / e["local_file"]).read_bytes() assert hashlib.sha256(data).hexdigest() == e["sha256"] blob = hashlib.sha1(b"blob " + str(len(data)).encode() + b"\x00" + data).hexdigest() if re.fullmatch("[0-9a-f]{40}", e.get("git_blob_sha1", "")): assert blob == e["git_blob_sha1"] if not e["license_file"].startswith("未知"): assert (REF / e["license_file"]).is_file() if e["file"].endswith(".py"): trees[e["local_file"]] = ast.parse(data) checks.append( dict( id=e["id"], file=e["file"], sha256=e["sha256"], git_blob_sha1=e.get("git_blob_sha1", "unknown"), first_acquisition=e.get("acquisition_time", "unknown"), reverified_at=e.get("reverified_at", "unknown"), license_file=e["license_file"], ) ) exact, unresolved, unknown, schemas = [], [], [], {} for bind in b["node_bindings"]: nid = bind["node_id"] key, file, symbol = BINDINGS[nid] if key == "unknown": assert not nodes[int(nid)]["properties"].get("ver") assert bind["source_id"] == "unknown-no-version" and not bind["candidates"] unknown.append( dict( node=nid, class_type=bind["class_type"], reason="aux名称无版本,准确身份/schema/默认/副作用/恢复未知", ) ) continue e = next(x for x in manifest if x["id"] == key and x["file"] == file) tree = trees[e["local_file"]] c = next((x for x in tree.body if isinstance(x, ast.ClassDef) and x.name == symbol), None) if c is None: assert nid in ["129", "232"] and key == "core051" assert not bind["implementation_verified"] and not bind["candidates"] unresolved.append( dict( node=nid, class_type=symbol, commit=e["commit"], scope="准确nodes_wan.py入口及所选nodes_model_patch.py未匹配;不证明全仓无类,不借main/后版", ) ) continue assert bind["implementation_verified"] assert any( registered(trees[x["local_file"]], symbol) for x in manifest if x["id"] == key and x["file"].endswith(".py") ), (nid, symbol) schemas[nid] = node_schema(c) exact.append( dict( node=nid, class_type=bind["class_type"], symbol=symbol, source=e["local_file"], commit=e["commit"], lines=[c.lineno, c.end_lineno], registered=True, schema=schemas[nid], ) ) assert (len(exact), len(unresolved), len(unknown)) == (42, 2, 46) assert all(x["class_type"] in ["GetNode", "SetNode"] for x in unknown) assert not any("audioUI" in schemas["263"] or "upload" in schemas["263"] for _ in [0]) assert nodes[263]["widgets_values"][1:] == [None, None] assert type(nodes[248]["widgets_values"][0]) is int assert nodes[212]["widgets_values"] == ["ceil((a*b+1-c)/c)"] assert nodes[254]["widgets_values"] == ["a+1"] edges = {e[0]: e[1:] for e in g["links"]} for eid, src, dst in [ (532, 129, 172), (599, 232, 238), (636, 172, 266), (641, 238, 267), (642, 267, 259), (625, 232, 259), (616, 252, 232), (628, 252, 260), (622, 259, 260), (626, 260, 253), (634, 265, 246), (621, 212, 252), (617, 252, 254), (618, 254, 255), (635, 254, 253), (619, 256, 257), (629, 200, 261), (630, 261, 25), (606, 191, 245), (609, 235, 246), (602, 32, 240), (601, 239, 240), ]: assert edges[eid][0] == src and edges[eid][2] == dst assert nodes[172]["outputs"][1]["links"] == [] assert nodes[238]["outputs"][1]["links"] == [] assert nodes[32]["outputs"][1]["links"] == [] assert "links" not in nodes[253]["outputs"][1] for nid, rate in [(245, 16), (246, 25)]: assert "links" not in nodes[nid]["outputs"][0] w = nodes[nid]["widgets_values"] assert type(w["frame_rate"]) is int and w["frame_rate"] == 25 assert w["videopreview"]["params"]["score"] == "0" assert w["videopreview"]["params"]["frame_rate"] == rate assert g["extra"]["frontendVersion"] == "1.37.11" front = next(e for e in manifest if e["id"] == "frontend" and e["file"] == "pnpm-lock.yaml") lock = (REF / front["local_file"]).read_text() assert front["commit"] == "4bf6a1960028cc5cda57d48f9fb01a74dfaade43" assert "link:packages/design-system" in lock and "@comfyorg/litegraph" not in lock assert any( e["id"] == "litegraph" and e["file"] == "src/lib/litegraph/LICENSE" for e in manifest ) ranges = json.loads((REF / "rgthree-range-requests.json").read_bytes()) assert not ranges["full_archive_acquired"] and all( r["status"] == 206 for r in ranges["requests"] ) sensitive = [] def scan(v, p=""): if isinstance(v, dict): for k, x in v.items(): if k.lower() in [ "api_key", "apikey", "secret", "password", "token", "access_token", "authorization", ] and x not in [None, "", [], {}]: sensitive.append(p + "/" + k) scan(x, p + "/" + k) elif isinstance(v, list): for i, x in enumerate(v): scan(x, p + "/" + str(i)) scan(g) assert not sensitive notes = [ dict( node=str(x["node"]), characters=len(x["text"]), LF=x["text"].count("\n"), CR=x["text"].count("\r"), literal_backslash_n=x["text"].count("\\n"), tail_LF=x["text"].endswith("\n"), sha256=hashlib.sha256(x["text"].encode()).hexdigest(), ) for x in inv["notes"] ] assert [(n["node"], n["characters"], n["LF"], n["tail_LF"]) for n in notes] == [ ("165", 2467, 55, True), ("211", 14, 0, False), ("217", 6, 0, False), ("205", 4, 0, False), ("206", 24, 4, False), ] texts = [ dict( node=f["node_id"], field=f["field"], characters=len(f["value"]), LF=f["value"].count("\n"), CR=f["value"].count("\r"), tail_LF=f["value"].endswith("\n"), sha256=hashlib.sha256(f["value"].encode()).hexdigest(), ) for f in b["fields"] if isinstance(f["value"], str) and len(f["value"]) > 100 ] write( "source-check.json", dict( original_sha256=inv["sha256"], nodes=95, edges=90, saved_fields=129, notes=notes, texts=texts, accurate_instances=42, unresolved_instances=unresolved, unknown_instances=unknown, sensitive_positions=sensitive, all_physical_edges_preserved=True, ), ) write( "exact-source-check.json", dict( sources=checks, exact_instances=exact, unresolved_instances=unresolved, unknown_instances=unknown, upstream_executed=False, ), ) write( "identity-gaps.json", dict( unresolved=unresolved, unknown=unknown, audio_license="准确31a树无LICENSE,pyproject引用未兑现;未知", published_members="rgthree与VHS只成员核准,Git/整包重取未知", scope="只准确入口及必要路径有界核准,不称全仓无类或目标支持", ), ) print( "PASS independent 129 values/5 full Notes/90 physical edges; " "42 exact/2 bounded unresolved/46 no-version aliases" ) if __name__ == "__main__": main()