"""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"] == "87412366e6bedd2a2f4490d1a945d0fc005251bb49a20e4ba1157cd6c4ddfbcd" assert len(g["nodes"]) == 109 and len(g["links"]) == 100 and not g.get("definitions") assert collections.Counter(n["mode"] for n in g["nodes"]) == {0: 109} assert all("widgets_values" in n and "widgets_values_named" not in n for n in g["nodes"]) assert len(inv["fields"]) == 147 and len(inv["notes"]) == 6 assert {x["node"] for x in inv["empty"]} == {17, 172, 238, 25, 253, 260, 266, 267, 278} assert all(x["state"] == "empty_list" for x in inv["empty"]) assert collections.Counter(f["json_type"] for f in inv["fields"]) == dict( str=96, int=35, bool=8, float=2, NoneType=4, 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)) == (45, 2, 56) assert all(x["class_type"] in ["GetNode", "SetNode"] for x in unknown) for nid in ["263", "274"]: assert "audioUI" not in schemas[nid] and "upload" not in schemas[nid] assert nodes[int(nid)]["widgets_values"][1:] == [None, None] assert type(nodes[248]["widgets_values"][0]) is int assert nodes[174]["widgets_values"] == [5] 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), (632, 263, 262), (643, 262, 268), (644, 268, 190), (645, 200, 25), (650, 274, 275), (652, 275, 277), (651, 277, 276), (653, 280, 278), (437, 26, 25), (655, 26, 278), (654, 278, 279), (656, 281, 129), (661, 286, 232), (542, 32, 183), (646, 273, 269), (657, 32, 282), (658, 273, 283), (659, 284, 129), (660, 285, 129), (662, 287, 232), (663, 288, 232), (606, 191, 245), (609, 235, 246), (664, 209, 14), (568, 209, 210), ]: assert edges[eid][0] == src and edges[eid][2] == dst assert nodes[172]["outputs"][1]["links"] == [] assert nodes[238]["outputs"][1]["links"] == [] assert "links" not in nodes[253]["outputs"][1] assert not {239, 240} & nodes.keys() for nid, ids in [(129, [656, 659, 660]), (232, [661, 662, 663])]: assert nodes[nid]["widgets_values"][0] == "two_speakers" assert ( next(x for x in nodes[nid]["inputs"] if x["name"] == "clip_vision_output")["link"] is None ) for name, eid in zip( ["mode.audio_encoder_output_2", "mode.mask_1", "mode.mask_2"], ids, strict=True ): assert next(x for x in nodes[nid]["inputs"] if x["name"] == name)["link"] == eid assert nodes[209]["outputs"][0]["links"] == [568, 664] assert nodes[14]["inputs"][1]["link"] == 664 assert nodes[171]["widgets_values"] == [73361528061560, "randomize"] assert nodes[229]["widgets_values"] == [665118465597533, "randomize"] histories = [] for nid, rate, save in [(245, 16, False), (246, 25, True)]: 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 w["save_output"] is save v = w["videopreview"] raw_order_json = json.dumps(v, ensure_ascii=False, separators=(",", ":")) histories.append( dict( node=nid, original_key_order=list(v), params_key_order=list(v["params"]), original_order_json=raw_order_json, original_order_sha256=hashlib.sha256(raw_order_json.encode()).hexdigest(), sorted_canonical_sha256=hashlib.sha256(canonical(v)).hexdigest(), comparison="原对象键序JSON与排序canonical分别记,不是HTTP或源文件对象片段原字节", ) ) write("history-order-evidence.json", histories) 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.parent / "singleloop-reference/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), ("205", 4, 0, False), ("206", 24, 4, False), ("217", 6, 0, False), ("289", 84, 0, 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=109, edges=100, saved_fields=147, notes=notes, texts=texts, accurate_instances=45, 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 147 values/6 full Notes/100 physical edges; " "45 exact/2 bounded unresolved/56 no-version aliases" ) if __name__ == "__main__": main()