320 lines
14 KiB
Python
320 lines
14 KiB
Python
"Verify exact text, Git/package provenance and source graph without upstream imports."
|
||
|
||
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"\x00" + 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"
|
||
assert 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"]
|
||
for file, key in [
|
||
("llama-prior-unavailable.json", "prior_record_sha256"),
|
||
("llama-prior-registry.json", "prior_registry_sha256"),
|
||
]:
|
||
assert hashlib.sha256((REF / file).read_bytes()).hexdigest() == report[key]
|
||
checks.append(
|
||
dict(
|
||
id=e["id"],
|
||
sha256=e["sha256"],
|
||
proof=("既有证据与本图有界fetch拒绝/raw404分别核准;不是schema/实现/许可依据"),
|
||
)
|
||
)
|
||
continue
|
||
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 mem"
|
||
"ber SHA; whole artifac"
|
||
"t digest reused, Git u"
|
||
"nknown"
|
||
)
|
||
elif "member_crc32" in e:
|
||
root = REF / e["identity_root"]
|
||
m = json.loads((root / (e["identity_key"] + "-registry.json")).read_bytes())
|
||
members = json.loads((root / (e["identity_key"] + "-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/se"
|
||
"lected blob; complete "
|
||
"tree listing, not full"
|
||
" 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()
|
||
or x["file"] == "LICENSE"
|
||
)
|
||
)
|
||
)
|
||
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 len(inv["fields"]) == 105 and len(inv["notes"]) == 3
|
||
assert [(x["nodes"], x["edges"]) for x in inv["scopes"]] == [(8, 3), (21, 41), (4, 14)]
|
||
assert inv["scopes"][0]["modes"] == [0] * 8
|
||
assert inv["scopes"][1]["modes"] == [0] * 14 + [4, 4, 0, 0, 0, 0, 4]
|
||
assert inv["scopes"][2]["modes"] == [4] * 4
|
||
assert all(x["named_nodes"] == 0 for x in inv["scopes"])
|
||
assert inv["extra"]["frontendVersion"] == "1.45.19"
|
||
for raw, field in zip(inv["fields"], block["fields"], strict=True):
|
||
assert raw["pointer"] == field["pointer"] and canonical(raw["value"]) == canonical(
|
||
field["value"]
|
||
)
|
||
assert raw["json_type"] == field["json_type"]
|
||
assert [(n["pointer"], n["text"]) for n in block["comments"]] == [
|
||
(n["pointer"], n["text"]) for n in inv["notes"]
|
||
]
|
||
assert [n["characters"] for n in inv["notes"]] == [1657, 1965, 70]
|
||
from build_definition import PATHS, REPO
|
||
|
||
g = json.loads((REPO / PATHS[0]).read_bytes())
|
||
main, nested = g["definitions"]["subgraphs"]
|
||
roots = {n["id"]: n for n in g["nodes"]}
|
||
ns = {n["id"]: n for n in main["nodes"]}
|
||
llm = {n["id"]: n for n in nested["nodes"]}
|
||
for graph in [g, main, nested]:
|
||
nodes = {n["id"]: n for n in graph["nodes"]}
|
||
for raw in graph["links"]:
|
||
if isinstance(raw, list):
|
||
eid, a, ao, z, zi, _kind = raw
|
||
else:
|
||
eid, a, ao, z, zi = [
|
||
raw[k] for k in ["id", "origin_id", "origin_slot", "target_id", "target_slot"]
|
||
]
|
||
if a == -10:
|
||
assert eid in graph["inputs"][ao]["linkIds"]
|
||
else:
|
||
assert eid in nodes[a]["outputs"][ao]["links"]
|
||
if z == -20:
|
||
assert eid in graph["outputs"][zi]["linkIds"]
|
||
else:
|
||
assert nodes[z]["inputs"][zi]["link"] == eid
|
||
assert len(roots[30]["widgets_values"]) == len(roots[30]["inputs"]) == len(main["inputs"]) == 15
|
||
assert (
|
||
len(ns[200]["widgets_values"]) == 9
|
||
and len(ns[200]["inputs"]) == len(nested["inputs"]) == 10
|
||
)
|
||
assert main["widgets"] == nested["widgets"] == []
|
||
assert all("proxyWidgets" not in h["properties"] for h in [roots[30], ns[200]])
|
||
assert "widgets_values" not in roots[204] and roots[204]["mode"] == 0
|
||
assert [n["id"] for n in main["nodes"] if n.get("widgets_values") == []] == [8, 13, 20]
|
||
assert {e["id"] for e in rows} == {"core0250", "core0270", "frontend", "llama-unavailable"}
|
||
assert all(
|
||
len(llm[i]["widgets_values"]) == count
|
||
for i, count in [(191, 2), (192, 7), (193, 13), (194, 10)]
|
||
)
|
||
assert all(
|
||
llm[i]["properties"]["ver"] == ("20571a3cf504b8308781d3cad2e432444ec3d75b")
|
||
and llm[i]["properties"]["cnr_id"] == "llama-cpp_vllm"
|
||
for i in [192, 193, 194]
|
||
)
|
||
assert sum(f["scope"] == "root" for f in block["fields"]) == 20
|
||
assert sum(f["scope"] == "30" for f in block["fields"]) == 53
|
||
assert sum(f["scope"] == "30:200" for f in block["fields"]) == 32
|
||
assert all(
|
||
f["schema_default"].startswith("未知") and f["input_name"] is None
|
||
for f in block["fields"]
|
||
if f["scope"] == "30:200"
|
||
)
|
||
core = next(e for e in rows if e["id"] == "core0250" and e["file"] == "nodes.py")
|
||
tree = ast.parse((REF / core["local_file"]).read_bytes())
|
||
save = next(c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == "SaveImage")
|
||
ret = next(
|
||
c.value
|
||
for c in save.body
|
||
if isinstance(c, ast.Assign)
|
||
and any(isinstance(n, ast.Name) and n.id == "RETURN_TYPES" for n in c.targets)
|
||
)
|
||
assert (
|
||
ast.literal_eval(ret) == ()
|
||
and roots[29]["outputs"][0]["type"] == "IMAGE"
|
||
and roots[29]["outputs"][0]["links"] is None
|
||
)
|
||
clip = next(c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == "CLIPLoader")
|
||
enums = [
|
||
ast.literal_eval(x)
|
||
for x in ast.walk(clip)
|
||
if isinstance(x, ast.List)
|
||
and all(isinstance(y, ast.Constant) and isinstance(y.value, str) for y in x.elts)
|
||
]
|
||
assert not any("krea2" in x for x in enums) and ns[11]["widgets_values"][1] == "krea2"
|
||
bindings = []
|
||
aliases = {
|
||
"PrimitiveBoolean": "Boolean",
|
||
"PrimitiveStringMultiline": "StringMultiline",
|
||
"ComfySwitchNode": "SwitchNode",
|
||
}
|
||
for scope, graph in [("root", g), ("30", main), ("30:200", nested)]:
|
||
for node in graph["nodes"]:
|
||
cls = node["type"]
|
||
if cls in ["Note", "MarkdownNote"]:
|
||
continue
|
||
version = node.get("properties", {}).get("ver")
|
||
key = {"0.25.0": "core0250", "0.27.0": "core0270"}.get(version)
|
||
if node["id"] in [30, 200] or key is None:
|
||
bindings.append(
|
||
dict(
|
||
scope=scope,
|
||
node_id=node["id"],
|
||
class_type=cls,
|
||
declared_version=version,
|
||
registration="未知:子图宿主/准确插件不可得/身份缺失;不认证实现或恢复",
|
||
)
|
||
)
|
||
continue
|
||
symbol = aliases.get(cls, cls)
|
||
matched = []
|
||
for e in rows:
|
||
if e["id"] != key or not (
|
||
e["file"] == "nodes.py" or e["file"].startswith("comfy_extras/")
|
||
):
|
||
continue
|
||
tree = ast.parse((REF / e["local_file"]).read_bytes())
|
||
klass = next(
|
||
(c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == symbol), None
|
||
)
|
||
if klass is None:
|
||
continue
|
||
registrations = []
|
||
for item in ast.walk(tree):
|
||
if isinstance(item, ast.Dict):
|
||
for k, v in zip(item.keys, item.values, strict=True):
|
||
if (
|
||
isinstance(k, ast.Constant)
|
||
and k.value == cls
|
||
and isinstance(v, ast.Name)
|
||
and v.id == symbol
|
||
):
|
||
registrations.append([item.lineno, item.end_lineno])
|
||
if (
|
||
isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef))
|
||
and item.name == "get_node_list"
|
||
and any(isinstance(n, ast.Name) and n.id == symbol for n in ast.walk(item))
|
||
):
|
||
registrations.append([item.lineno, item.end_lineno])
|
||
assert registrations, (key, cls)
|
||
matched.append(
|
||
dict(
|
||
file=e["file"],
|
||
class_lines=[klass.lineno, klass.end_lineno],
|
||
registration_lines=registrations,
|
||
sha256=e["sha256"],
|
||
)
|
||
)
|
||
assert matched, (key, cls)
|
||
bindings.append(
|
||
dict(
|
||
scope=scope,
|
||
node_id=node["id"],
|
||
source_id=key,
|
||
version=version,
|
||
bindings=matched,
|
||
)
|
||
)
|
||
for e in block["sources"]:
|
||
raw = (OUT / e["local_file"]).read_bytes()
|
||
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
|
||
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines())
|
||
(OUT / "node-version-bindings.json").write_text(
|
||
json.dumps(bindings, ensure_ascii=False, indent=2) + "\n"
|
||
)
|
||
(OUT / "source-check.json").write_text(
|
||
json.dumps(
|
||
dict(
|
||
sources=checks,
|
||
counts=block["counts"],
|
||
physical_edges_checked=58,
|
||
boundaries=[dict(cache=15, inputs=15), dict(cache=9, inputs=10)],
|
||
inventory_matches_definition=True,
|
||
source_save_outputs=roots[29]["outputs"],
|
||
accurate_save_return=[],
|
||
clip_krea2_enum_missing=True,
|
||
clip_enums=enums,
|
||
llama_exact_implementation_unknown=True,
|
||
unknown_plugin_positions=32,
|
||
no_upstream_execution=True,
|
||
),
|
||
ensure_ascii=False,
|
||
indent=2,
|
||
)
|
||
+ "\n"
|
||
)
|
||
print(
|
||
(
|
||
"PASS 105 positions/3 n"
|
||
"otes/58 edges/two boun"
|
||
"daries/seven mode4/exa"
|
||
"ct sources and unknown"
|
||
" LLM/control identitie"
|
||
"s"
|
||
)
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|