"Verify exact text, Git/package provenance and source graph without upstream imports." 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"] == "litegraph": root = REF / e["identity_root"] assert ( json.loads((root / "litegraph__package__package.json").read_bytes())["version"] == "0.15.15" ) front = next( x for x in rows if x["id"] == "frontend" and x["file"] == "package-lock.json" ) lock = json.loads((REF / front["local_file"]).read_bytes()) assert ( lock["packages"]["node_modules/@comfyorg/litegraph"]["integrity"] == "sha512-" + e["artifact_sha512_base64"] ) proof = ( "Pinned frontend1.23.0 lock, exact0.15." "15 member SHA; whole artifact digest r" "eused, Git unknown" ) elif "package_record" in e: package = json.loads((REF / e["package_record"]).read_bytes()) reg = json.loads((REF / e["registry_record"]).read_bytes()) member = next(x for x in package["members"] if x["path"] == e["file"]) assert member["saved"] and member["sha256"] == e["sha256"] assert reg["version"] == e["tag"] == "1.0.0" assert package["sha256"] == e["artifact_sha256"] proof = ( "复用已审准确发布成员SHA/registry/历史整包摘要记录;本轮未获取整包,不证明Git绑定" ) elif e["id"] == "llama-unavailable": proof = "准确20571提交不可得的有界调查原记录,仅缺口,不作为schema实现" elif "member_crc32" in e: root = REF / e["identity_root"] m = json.loads((root / (e["id"] + "-registry.json")).read_bytes()) members = json.loads((root / (e["id"] + "-members.json")).read_bytes()) member = next(x for x in members if x["name"] == e["file"]) assert m["version"] == e["tag"] assert member["crc"] == e["member_crc32"] == zlib.crc32(raw) assert e["package_sha256"].startswith("unknown") proof = "准确发布成员SHA/CRC;Range选定文本,完整包SHA与Git绑定未知" else: 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") proof = ( "Rehashed commit/tag/selected blo" "b; complete tree listing, not fu" "ll tree-object rehash" ) if not e["license_file"].startswith("未知"): 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=proof)) assert inv["sha256"] == "b6e232082089dd9c4046e0dc5bd1d046907525b8cb01758fb804b5f4aa11275e" assert len(inv["fields"]) == 122 and len(inv["notes"]) == 3 assert [(v["nodes"], v["edges"], v["named_nodes"]) for v in inv["scopes"]] == [ (17, 15, 14), (3, 8, 3), (4, 16, 4), (3, 8, 3), (15, 58, 13), ] assert inv["scopes"][0]["modes"] == [0] * 16 + [4] assert all(set(v["modes"]) == {0} for v in inv["scopes"][1:]) assert [ (n["characters"], n["lf_count"], n["literal_backslash_n"], n["ends_with_lf"]) for n in inv["notes"] ] == [(1248, 22, 0, False), (2569, 51, 0, True), (36, 0, 0, False)] from build_definition import PATHS, REPO g = json.loads((REPO / PATHS[0]).read_bytes()) def pointer(obj, path): for bit in path.strip("/").split("/"): bit = bit.replace("~1", "/").replace("~0", "~") obj = obj[int(bit)] if isinstance(obj, list) else obj[bit] return obj for a, f in zip(inv["fields"], block["fields"], strict=True): assert (a["pointer"], a["json_type"], canonical(a["value"])) == ( f["pointer"], f["json_type"], canonical(f["value"]), ) assert canonical(pointer(g, f["named_pointer"])) == canonical(f["named_value"]) if f["node_id"] != "505": assert canonical(f["named_value"]) == canonical(f["value"]) graphs = [g] + g["definitions"]["subgraphs"] for graph in graphs: ns = {n["id"]: n for n in graph["nodes"]} for edge in graph["links"]: if isinstance(edge, list): eid, a, ao, z, zi, _ = edge else: eid, a, ao, z, zi = [ edge[k] for k in ["id", "origin_id", "origin_slot", "target_id", "target_slot"] ] if a >= 0: assert eid in ns[a]["outputs"][ao]["links"] else: assert eid in graph["inputs"][ao]["linkIds"] if z >= 0: assert ns[z]["inputs"][zi]["link"] == eid else: assert eid in graph["outputs"][zi]["linkIds"] assert [ sum(f["scope"] == scope for f in block["fields"]) for scope in ["root", "504", "677", "683", "696"] ] == [53, 8, 13, 8, 40] ns = {n["id"]: n for n in g["nodes"]} for nid in [504, 677, 683, 689]: assert all(o.get("links") in [None, []] for o in ns[nid]["outputs"]) assert ns[698]["outputs"][0]["links"] == [1799] assert ns[696]["inputs"][18]["link"] == 1799 assert ns[704]["mode"] == 4 and all(o.get("links") in [None, []] for o in ns[704]["outputs"]) assert ns[470]["outputs"][1]["links"] in [None, []] assert ns[690]["outputs"][0]["links"] == [1782] and ns[690]["outputs"][1]["links"] == [1783] main = g["definitions"]["subgraphs"][3] assert ( len(main["inputs"]) == len(ns[696]["inputs"]) == 28 and len(ns[696]["widgets_values"]) == 18 ) assert "proxyWidgets" not in ns[696] and main["widgets"] == [] assert [e["origin_slot"] for e in main["links"] if e["id"] in [784, 785, 786, 787]] == [ 24, 25, 26, 27, ] fields = {(f["node_id"], f["field"]): f for f in block["fields"]} text = fields["696:479", "value"]["value"] assert (len(text), text.count("\n"), text.count("\\n"), text.endswith("\n")) == ( 10494, 77, 0, False, ) assert ( hashlib.sha256(text.encode()).hexdigest() == "eaff356cd2bdbcfd1aaf20502b5ccd8cbad16fa6e9afe41e3166eeee299c8e59" ) assert ( fields["696:500", "thinking"]["value"] is True and fields["696:500", "use_default_template"]["value"] is False ) assert type(fields["696:500", "sampling_mode.temperature"]["value"]) is int binds = {n["node_id"]: n for n in block["node_bindings"]} assert binds["677"]["source_version"] == "0.15.1" for nid in ["677:671", "677:674", "677:672"]: assert ( binds[nid]["source_version"] == "0.15.0" and binds[nid]["source_id"] == "unresolved-core0150" ) assert all( "未知" in f["schema_default"] and "未知" in f["unit"] for f in block["fields"] if f["node_id"] == nid ) assert binds["677:673"]["source_id"] == "core0150" assert all( binds[n]["source_id"] == "core0380" for n in [ "504:1", "504:2", "504:5", "683:680", "683:681", "683:682", "698", "696:474", "696:469", "696:485", "461", ] ) assert ( binds["505"]["source_id"] == "rgthree" and binds["701"]["source_id"] == binds["689"]["source_id"] == "aux" ) (OUT / "source-check.json").write_text( json.dumps( dict( files=checks, positions=122, standard_notes=3, scopes=inv["scopes"], source_edges_verified=105, upstream_executed=False, ), ensure_ascii=False, indent=2, ) + "\n" ) (OUT / "node-version-bindings.json").write_text( json.dumps(block["node_bindings"], ensure_ascii=False, indent=2) + "\n" ) print("PASS exact sources,122 positions/dual named,3 notes,105 edges/four boundaries") if __name__ == "__main__": main()