"""Independently check original scopes, exact registration and protocol discrepancies.""" import ast import collections import hashlib import json import re from build_definition import OUT, PATHS, REF, REPO, build, canonical from inventory import inventory def sha(raw): return hashlib.sha256(raw).hexdigest() def write(name, value): (OUT / name).write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n") def node(g, nid): return next(n for n in g["nodes"] if str(n["id"]) == str(nid)) def main(): raw = (REPO / PATHS[0]).read_bytes() assert sha(raw) == "f0da1e6c1eab5706d29d8d12897db0cea0d9d5f7a73b4882cf07ef2a626dda45" original = inventory() g = json.loads(raw) b = build() assert len(original["fields"]) == len(b["fields"]) == 339 for saved, f in zip(original["fields"], b["fields"], strict=True): assert saved["pointer"] == f["pointer"] assert canonical(saved["value"]) == canonical(f["value"]) assert saved["json_type"] == f["json_type"] assert f["named_state"] == "missing" and "named_pointer" not in f assert "named_value" not in f assert collections.Counter(f["json_type"] for f in b["fields"]) == { "str": 171, "int": 104, "bool": 45, "float": 10, "NoneType": 2, "dict": 7, } assert len(original["empty"]) == len(b["zero_saved_nodes"]) == 15 assert collections.Counter(n["state"] for n in original["empty"]) == { "missing": 7, "empty_list": 7, "empty_dict": 1, } assert node(g, 546)["widgets_values"] == {} assert node(g, 629)["widgets_values"] == [{}, {}] assert "frontendVersion" not in g["extra"] assert set(g["extra"]) == {"ue_links", "ds", "links_added_by_ue", "favoritedWidgets"} assert "proxyWidgets" not in node(g, 663)["properties"] assert node(g, 663)["widgets_values"] == [1, 512, 8] s = g["definitions"]["subgraphs"][0] assert s["widgets"] == [] and len(s["inputs"]) == 4 and len(s["outputs"]) == 1 assert collections.Counter(n["mode"] for n in g["nodes"]) == {0: 98, 4: 38} assert [n["mode"] for n in s["nodes"]] == [4] * 5 assert not any("widgets_values_named" in n for n in g["nodes"] + s["nodes"]) expected = {"root": g["links"], "663:": s["links"]} endpoints = [] for scope, graph in [("root", g), ("663:", s)]: ids = {n["id"]: n for n in graph["nodes"]} if scope != "root": ids.update( { graph["inputNode"]["id"]: graph["inputNode"], graph["outputNode"]["id"]: graph["outputNode"], } ) for e in graph["links"]: origin, target = ( (e[1], e[3]) if isinstance(e, list) else (e["origin_id"], e["target_id"]) ) assert origin in ids and target in ids endpoints.append(dict(scope=scope, record=e, both_endpoints_exist=True)) assert len(endpoints) == 122 and len(g["links"]) == 113 and len(s["links"]) == 9 notes = [] for n, c in zip(original["notes"], b["comments"], strict=True): assert n["text"] == c["text"] and n["pointer"] == c["pointer"] text = n["text"] notes.append( dict( node=c["node_id"], characters=len(text), LF=text.count("\n"), CR=text.count("\r"), tail_LF=text.endswith("\n"), sha256=sha(text.encode()), ) ) assert [(n["characters"], n["LF"], n["tail_LF"]) for n in notes] == [ (96, 1, False), (37, 0, False), (205, 8, False), (78, 2, False), (456, 12, False), (451, 15, True), ] rows = json.loads((REF / "sources.json").read_bytes())["sources"] assert len({(e["id"], e["file"]) for e in rows}) == len(rows) trees = {} for e in rows: data = (REF / e["local_file"]).read_bytes() assert sha(data) == e["sha256"] if e.get("git_blob_sha1"): assert ( hashlib.sha1(b"blob " + str(len(data)).encode() + b"\0" + data).hexdigest() == e["git_blob_sha1"] ) tree = json.loads((REF / (e["id"] + "-tree.json")).read_bytes()) assert ( next(t["sha"] for t in tree["tree"] if t["path"] == e["file"]) == e["git_blob_sha1"] ) commit = (REF / (e["id"] + "-commit.txt")).read_bytes() assert ( hashlib.sha1(b"commit " + str(len(commit)).encode() + b"\0" + commit).hexdigest() == e["commit"] ) if not e["license_file"].startswith("未知"): assert (REF / e["license_file"]).is_file() if e["file"].endswith(".py"): trees[(e["id"], e["file"])] = ast.parse(data) accurate = [n for n in b["node_bindings"] if n["implementation_verified"]] gaps = [n for n in b["node_bindings"] if n["source_id"].startswith("unresolved-")] unknown = [n for n in b["node_bindings"] if n["source_id"] == "unknown-no-version"] assert len(accurate) == 53 and len(gaps) == 10 and len(unknown) == 71 assert {n["node_id"] for n in gaps} == { "37", "62", "67", "71", "597", "607", "69", "66", "614", "615", } for n in accurate: c = n["candidates"][0] e = rows[c["source"]] cls = next( x for x in trees[(e["id"], e["file"])].body if isinstance(x, ast.ClassDef) and x.name == c["symbol"] ) assert [cls.lineno, cls.end_lineno] == c["lines"] # Independently verify registered literal, V3 node_id or rgthree's exact NAME expansion. texts = [ (REF / x["local_file"]).read_text() for x in rows if x["id"] == e["id"] and x["file"].endswith(".py") ] assert ( any(re.search(r"[\"']" + re.escape(n["class_type"]) + r"[\"']\s*:", t) for t in texts) or any( re.search(r"node_id\s*=\s*[\"']" + re.escape(n["class_type"]) + r"[\"']", t) for t in texts ) or ( n["class_type"] == "Seed (rgthree)" and "RgthreeSeed.NAME: RgthreeSeed" in "\n".join(texts) ) ) c3 = "\n".join( (REF / e["local_file"]).read_text() for e in rows if e["id"] == "wanvideowrapper-c3bb8e98" and e["file"].endswith(".py") ) assert "WanAnimatePlus" not in c3 response = json.loads((REF / "761b-exact-commit-responses.json").read_bytes()) assert len(response) == 3 and all(r["status"] == 422 for r in response) edge = {e[0]: e for e in g["links"]} for eid, origin, target in [ (61, 37, 69), (957, 66, 69), (1040, 687, 66), (58, 69, 62), (59, 67, 62), (1030, 619, 667), (1031, 667, 614), (931, 614, 607), (930, 607, 597), (1044, 694, 615), ]: assert edge[eid][1] == origin and edge[eid][3] == target assert node(g, 607)["outputs"][1]["links"] is None assert node(g, 573)["outputs"][1]["links"] == [] assert node(g, 550)["outputs"][0]["links"] is None assert all("links" not in node(g, i)["outputs"][0] for i in [119, 567, 621]) assert "links" not in node(g, 546)["outputs"][2] histories = [] for nid in [119, 567, 621, 550, 573]: value = node(g, nid)["widgets_values"]["videopreview"] ordered = json.dumps(value, ensure_ascii=False, separators=(",", ":")) histories.append( dict( node=str(nid), original_order_json=ordered, original_order_sha256=sha(ordered.encode()), sorted_canonical_sha256=sha(canonical(value)), ) ) sensitive = [] def scan(value, pointer=""): if isinstance(value, dict): for key, item in value.items(): path = pointer + "/" + key if ( re.fullmatch( r"api[_-]?key|authorization|password|secret|access[_-]?token", key, re.I ) and item ): sensitive.append(path) scan(item, path) elif isinstance(value, list): for i, item in enumerate(value): scan(item, pointer + "/" + str(i)) scan(g) assert not sensitive 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=sha(f["value"].encode()), ) for f in b["fields"] if isinstance(f["value"], str) and len(f["value"]) > 100 ] write("expected-edges.json", expected) write("scoped-edge-check.json", dict(records=122, endpoints=endpoints)) write("proxy-check.json", dict(proxy_widgets=0, state="missing", frontend_version="unknown")) write("identity-gaps.json", dict(unresolved=gaps, unknown=unknown, frontend="unknown")) write( "exact-source-check.json", dict( accurate=accurate, unresolved=gaps, unknown=unknown, sources=len(rows), upstream_executed=False, ), ) write( "source-check.json", dict( original_sha256=sha(raw), saved_fields=339, notes=notes, texts=texts, accurate_instances=53, unresolved_instances=10, unknown_instances=71, sensitive_positions=sensitive, ), ) write("history-order-evidence.json", histories) print( "PASS339 saved/6 Notes/141 nodes/122 scoped records;53 exact/10 gaps/71 unknown/1 boundary" ) if __name__ == "__main__": main()