"""Independent raw graph, exact Git identity and schema checks; never import upstream.""" import ast import hashlib import json import zlib 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"] == "llama-unavailable": report = json.loads(raw) assert ( report["registry_id"] == "llama-cpp_vllm" and report["requested_commit"] == "20571a3cf504b8308781d3cad2e432444ec3d75b" ) assert report["git_fetch"]["exit_code"] == 128 and report["raw"]["status"] == 404 assert "not our ref" in report["git_fetch"]["stderr"] assert ( hashlib.sha256((REF / "llama-prior-unavailable.json").read_bytes()).hexdigest() == report["prior_record_sha256"] ) checks.append( dict( id=e["id"], sha256=e["sha256"], proof=( "exact commit fetch rejected/raw4" + "04; no substitute schema/impleme" + "ntation/license" ), ) ) continue if "member_crc32" in e: meta = json.loads((REF / "showtext-registry.json").read_bytes()) assert meta["version"] == "1.2.5" members = json.loads((REF / "showtext-members.json").read_bytes()) member = next(m for m in members if m["name"] == e["file"]) assert member["crc"] == e["member_crc32"] == zlib.crc32(raw) assert e["package_sha256"] == "unknown-not-downloaded-whole-archive" proof = json.loads((REF / "showtext-range-proof.json").read_bytes()) assert proof and all(p["end"] >= p["start"] for p in proof) checks.append( dict( id=e["id"], file=e["file"], sha256=e["sha256"], proof="accurate 1.2.5 registry/Range member CRC+SHA; whole archive/Git unknown", ) ) 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"] == "afafb0e0ebdc445a7534041589b7f6a580e0b15b8293c2fd26907474892f5957" assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [ (21, 20, 18), (3, 13, 3), ] assert len(inv["fields"]) == 77 and [(n["node"], n["characters"]) for n in inv["notes"]] == [ (48, 1569), (50, 1965), ] assert [z["node"] for z in inv["empty"]] == [55, 59, 273] and all( z["state"] == "missing" for z in inv["empty"] ) assert inv["extra"]["frontendVersion"] == "1.45.20" from build_definition import PATHS, REPO g = json.loads((REPO / PATHS[0]).read_bytes()) sg = g["definitions"]["subgraphs"][0] nodes = {n["id"]: n for n in g["nodes"]} internal = {n["id"]: n for n in sg["nodes"]} def ptr(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"]) == canonical(b["named_value"]) == canonical(ptr(b["named_pointer"])) ) assert type(b["value"]) not in (list, dict) for n in block["comments"]: assert ptr(n["pointer"]) == ptr(n["named_pointer"]) == n["text"] assert all(n["mode"] == 0 for n in list(nodes.values()) + list(internal.values())) assert ( len(nodes[261]["widgets_values"]) == 9 and len(nodes[261]["inputs"]) == len(sg["inputs"]) == 10 ) assert nodes[261]["inputs"][0]["name"] == "images" and nodes[261]["inputs"][0]["link"] is None assert [len(nodes[n]["widgets_values"][0]) for n in [64, 274, 52, 271]] == [139, 5339, 479, 961] assert nodes[64]["widgets_values"][0].startswith(" ") assert ( len(nodes[261]["widgets_values"][6]) == 1505 and len(internal[194]["widgets_values"][2]) == 1535 ) assert nodes[261]["widgets_values"][6] != internal[194]["widgets_values"][2] assert internal[192]["widgets_values_named"]["load_mtp"] is False assert ( internal[193]["widgets_values_named"]["present_penalty"] == 1 and type(internal[193]["widgets_values_named"]["present_penalty"]) is int ) assert nodes[261]["widgets_values_named"]["mmproj"].endswith("BF16.gguf") and internal[192][ "widgets_values_named" ]["mmproj"].endswith("F32.gguf") assert ( all(i["link"] is None for i in nodes[268]["inputs"]) and nodes[268]["outputs"][0]["links"] == [] ) assert nodes[275]["widgets_values"] == [True] and nodes[275]["inputs"][2]["link"] == 407 assert nodes[273]["outputs"][0]["type"] == "*" and "ver" not in nodes[273]["properties"] edges = {e[0]: e for e in g["links"]} for eid, ends in { 77: (53, 0, 54, 3), 98: (49, 0, 53, 0), 99: (49, 1, 53, 1), 369: (261, 0, 260, 0), 389: (261, 0, 271, 0), 400: (274, 0, 261, 7), 405: (64, 0, 261, 6), 406: (64, 0, 275, 0), 402: (271, 0, 275, 1), 403: (275, 0, 52, 1), 407: (273, 0, 275, 2), 102: (60, 0, 54, 0), 97: (55, 0, 29, 0), }.items(): assert tuple(edges[eid][1:5]) == ends for eid, a, ao, z, zi, _ in g["links"]: assert eid in nodes[a]["outputs"][ao]["links"] and nodes[z]["inputs"][zi]["link"] == eid for e in sg["links"]: if e["origin_id"] == -10: assert e["id"] in sg["inputs"][e["origin_slot"]]["linkIds"] else: assert e["id"] in internal[e["origin_id"]]["outputs"][e["origin_slot"]]["links"] if e["target_id"] == -20: assert e["id"] in sg["outputs"][e["target_slot"]]["linkIds"] else: assert internal[e["target_id"]]["inputs"][e["target_slot"]]["link"] == e["id"] def source(key, file): return ( REF / next(e for e in rows if e["id"] == key and e["file"] == file)["local_file"] ).read_bytes() core = ast.parse(source("core0250", "nodes.py")) classes = {c.name: c for c in core.body if isinstance(c, ast.ClassDef)} ret = next( c.value for c in classes["SaveImage"].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) == () enums = [ ast.literal_eval(c) for c in ast.walk(classes["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) assert '"PainterVRAM": PainterVRAM' in source("painter", "PainterVRAM.py").decode() assert '"ShowText|pysssss": ShowText' in source("showtext", "py/show_text.py").decode() assert ( len(block["node_bindings"]) == 22 and len(block["zero_saved_nodes"]) == 3 and len(block["boundaries"]) == 1 ) assert sum(f["scope"] == "root" for f in block["fields"]) == 46 (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, all_checks_pass=True, source_fields=77, source_notes=2, physical_edges=33, upstream_imported=False, llama_accurate_implementation_unavailable=True, group_bypasser_identity_unknown=True, save0250_empty_return=True, clip0250_krea2_enum_present=False, ), ensure_ascii=False, indent=2, ) + "\n" ) print( ( "PASS exact identities, 77 dual-p" + "osition scalars, 2 complete note" + "s, one 9-cache/10-input boundary" + ", 33 edge records, preserved unk" + "nown identities" ) ) if __name__ == "__main__": main()