"""Independent original and declared-source audit; never import upstream.""" 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 main(): raw = (REPO / PATHS[0]).read_bytes() assert sha(raw) == "395dc48ad21d9da6a3a815654922193a9893696015154f53be0cc6f484882637" g = json.loads(raw) inv = inventory() b = build() nodes = {n["id"]: n for n in g["nodes"]} assert len(inv["fields"]) == len(b["fields"]) == 318 assert collections.Counter(f["json_type"] for f in inv["fields"]) == { "str": 158, "int": 96, "bool": 43, "float": 12, "dict": 9, } for s, f in zip(inv["fields"], b["fields"], strict=True): assert s["pointer"] == f["pointer"] and canonical(s["value"]) == canonical(f["value"]) assert s["json_type"] == f["json_type"] and f["named_state"] == "missing" assert "named_value" not in f and "named_pointer" not in f assert len(inv["empty"]) == len(b["zero_saved_nodes"]) == 13 assert collections.Counter(x["state"] for x in inv["empty"]) == { "missing": 5, "empty_list": 7, "empty_dict": 1, } assert nodes[101]["widgets_values"] == {} and nodes[550]["widgets_values"] == nodes[321][ "widgets_values" ] == [{}, {}] assert "frontendVersion" not in g["extra"] expected = {"root": g["links"]} endpoints = [] graphs = [("root", g)] + [ (str(h) + ":", s) for h, s in zip([494, 541], g["definitions"]["subgraphs"], strict=True) ] assert [len(s["nodes"]) for _, s in graphs] == [126, 4, 4] assert [len(s["links"]) for _, s in graphs] == [105, 8, 9] assert collections.Counter(n["mode"] for n in g["nodes"]) == {0: 96, 4: 30} assert all(n["mode"] == 0 for n in graphs[1][1]["nodes"]) and all( n["mode"] == 4 for n in graphs[2][1]["nodes"] ) for h, v in [(494, [512, 8]), (541, [512, 8, 1])]: assert nodes[h]["widgets_values"] == v and "proxyWidgets" not in nodes[h]["properties"] for scope, s in graphs: assert not any("widgets_values_named" in n for n in s["nodes"]) expected[scope] = s["links"] valid = {n["id"] for n in s["nodes"]} if scope != "root": valid |= {s["inputNode"]["id"], s["outputNode"]["id"]} for e in s["links"]: a, z = (e[1], e[3]) if isinstance(e, list) else (e["origin_id"], e["target_id"]) assert a in valid and z in valid endpoints.append({"scope": scope, "edge": e}) notes = [] assert [ (n["node"], n["characters"], n["lf_count"], n["ends_with_lf"]) for n in inv["notes"] ] == [ (38, 37, 0, False), (64, 96, 1, False), (95, 205, 8, False), (575, 78, 2, False), (573, 456, 12, False), (253, 451, 15, True), ] for s, n in zip(inv["notes"], b["comments"], strict=True): assert s["text"] == n["text"] and s["pointer"] == n["pointer"] t = n["text"] assert "\r" not in t notes.append( dict( node=n["node_id"], characters=len(t), LF=t.count("\n"), CR=t.count("\r"), tail_LF=t.endswith("\n"), sha256=sha(t.encode()), ) ) rows = json.loads((REF / "sources.json").read_bytes())["sources"] 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 = [x for x in b["node_bindings"] if x["implementation_verified"]] gaps = [x for x in b["node_bindings"] if x["source_id"].startswith("unresolved-")] unknown = [x for x in b["node_bindings"] if x["source_id"] == "unknown-no-version"] assert len(accurate) == 49 and len(gaps) == 10 and len(unknown) == 67 assert {x["node_id"] for x in gaps} == { "37", "62", "67", "71", "43", "41", "69", "66", "40", "58", } 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"] 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) edges = {e[0]: e for e in g["links"]} for eid, a, z in [ (61, 37, 69), (809, 66, 69), (900, 584, 66), (58, 69, 62), (59, 67, 62), (897, 347, 574), (898, 574, 40), (39, 40, 41), (42, 41, 43), (43, 43, 44), (656, 45, 40), ]: assert edges[eid][1] == a and edges[eid][3] == z assert nodes[41]["outputs"][1]["links"] is None and nodes[112]["outputs"][1]["links"] == [] assert ( nodes[58]["inputs"][3]["name"] == "positive_prompt" and nodes[58]["inputs"][3]["link"] is None ) assert ( nodes[574]["widgets_values"] == [0.7, 1, 1] and type(nodes[574]["widgets_values"][2]) is int ) phase = next( f for f in b["fields"] if f["node_id"] == "574" and f["field"] == "phase2_start_step" ) assert phase["schema_default"] == "0" and phase["role"] == "schema_input" assert nodes[200]["outputs"][0]["links"] is None assert all("links" not in nodes[i]["outputs"][0] for i in [119, 86, 542]) assert "links" not in nodes[101]["outputs"][2] histories = [] for nid in [119, 200, 86, 542, 112]: v = nodes[nid]["widgets_values"]["videopreview"] ordered = json.dumps(v, 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(v)), ) ) sensitive = [] def scan(v, p=""): if isinstance(v, dict): for k, x in v.items(): if ( re.fullmatch( r"api[_-]?key|authorization|password|secret|access[_-]?token", k, re.I ) and x ): 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 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("independent-inventory.json", inv) 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", hosts=[494, 541], 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=318, notes=notes, texts=texts, accurate_instances=49, unresolved_instances=10, unknown_instances=67, sensitive_positions=sensitive, ), ) write("history-order-evidence.json", histories) print( "PASS318 saved/6 Notes/134 nodes/122 scoped records;" "49 exact/10 gaps/67 unknown/2 boundaries" ) if __name__ == "__main__": main()