278 lines
11 KiB
Python
278 lines
11 KiB
Python
"""Verify original positions and exact source declarations without execution."""
|
||
|
||
import ast
|
||
import hashlib
|
||
import json
|
||
import zlib
|
||
|
||
from build_definition import OUT, PATHS, REF, REPO, 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"] == "story-gap":
|
||
proof = "本批独立cnr/aux身份调查,准确网格类/映射未知"
|
||
elif 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 "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()
|
||
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 inv["sha256"] == "776b2f92f8906232c2ffe1b25c8b9cfe3398bfe45a9f80715f6ce5acc03e96b4"
|
||
assert len(inv["fields"]) == 62 and len(inv["notes"]) == 2
|
||
assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [(22, 20, 0)]
|
||
assert [(n["node"], n["characters"]) for n in inv["notes"]] == [(256, 979), (146, 611)]
|
||
assert [(n["node"], n["state"]) for n in inv["empty"]] == [
|
||
(253, "missing"),
|
||
(65, "empty_list"),
|
||
(77, "empty_list"),
|
||
(255, "empty_list"),
|
||
(204, "empty_list"),
|
||
]
|
||
assert [n["id"] for n in inv["nodes"] if n["mode"] == 4] == [85]
|
||
assert sum(n["mode"] == 0 for n in inv["nodes"]) == 21
|
||
assert inv["extra"]["frontendVersion"] == "1.45.21"
|
||
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 "named_value" not in f and "无此具名保存键" in f["named_pointer"]
|
||
graph = json.loads((REPO / PATHS[0]).read_bytes())
|
||
nodes = {n["id"]: n for n in graph["nodes"]}
|
||
assert not graph.get("definitions")
|
||
assert (
|
||
len(nodes[244]["widgets_values"][0]) == 6918 and len(nodes[76]["widgets_values"][0]) == 1003
|
||
)
|
||
assert nodes[243]["widgets_values"] == [
|
||
"Normal - Describe",
|
||
"",
|
||
"",
|
||
"images",
|
||
24,
|
||
256,
|
||
581751730589392,
|
||
"randomize",
|
||
True,
|
||
False,
|
||
]
|
||
assert nodes[201]["widgets_values"] == [2560, 1440, 4, 4, 20, False, False, "auto", 2, 2]
|
||
assert nodes[70]["widgets_values"] == [
|
||
268794848172667,
|
||
"randomize",
|
||
8,
|
||
1,
|
||
"euler",
|
||
"simple",
|
||
0.8,
|
||
]
|
||
assert all(n["type"] != "Crop" and "widgets_values_named" not in n for n in graph["nodes"])
|
||
for eid, a, ao, b, bi, _ in graph["links"]:
|
||
assert eid in nodes[a]["outputs"][ao]["links"]
|
||
assert nodes[b]["inputs"][bi]["link"] == eid
|
||
edges = {e[0]: tuple(e[1:5]) for e in graph["links"]}
|
||
for eid, expected in {
|
||
450: (244, 0, 243, 6),
|
||
451: (76, 0, 243, 5),
|
||
452: (243, 0, 77, 0),
|
||
435: (77, 0, 194, 1),
|
||
368: (201, 0, 204, 0),
|
||
369: (204, 0, 70, 3),
|
||
456: (201, 0, 255, 0),
|
||
455: (65, 0, 9, 0),
|
||
113: (66, 0, 83, 0),
|
||
116: (83, 0, 85, 0),
|
||
117: (85, 0, 70, 0),
|
||
73: (70, 0, 65, 0),
|
||
74: (63, 0, 65, 1),
|
||
367: (63, 0, 204, 1),
|
||
}.items():
|
||
assert edges[eid] == expected
|
||
assert all(
|
||
p["link"] is None for p in nodes[243]["inputs"] if p["name"] in ["images", "queue_handler"]
|
||
)
|
||
|
||
def source(key, file):
|
||
return (
|
||
REF / next(e["local_file"] for e in rows if e["id"] == key and e["file"] == file)
|
||
).read_bytes()
|
||
|
||
def classes(key, file):
|
||
return {c.name: c for c in ast.parse(source(key, file)).body if isinstance(c, ast.ClassDef)}
|
||
|
||
def assigned(cls, name):
|
||
return next(
|
||
n.value
|
||
for n in cls.body
|
||
if isinstance(n, ast.Assign)
|
||
and any(isinstance(t, ast.Name) and t.id == name for t in n.targets)
|
||
)
|
||
|
||
save = classes("core0364", "nodes.py")["SaveImage"]
|
||
assert ast.literal_eval(assigned(save, "RETURN_TYPES")) == ()
|
||
assert '"result"' not in ast.unparse(save) and "'result'" not in ast.unparse(save)
|
||
later = classes("core0283", "nodes.py")
|
||
assert ast.literal_eval(assigned(later["SaveImage"], "RETURN_TYPES")) == ("IMAGE",)
|
||
assert ast.unparse(later["PreviewImage"].bases[0]) == "SaveImage"
|
||
assert "random.choice" in ast.unparse(later["PreviewImage"])
|
||
preview = source("core0260", "comfy_extras/nodes_preview_any.py").decode()
|
||
assert (
|
||
"torch.set_printoptions(edgeitems=6)" in preview
|
||
and '"ui"' in preview
|
||
and '"result"' in preview
|
||
)
|
||
clip = classes("core0373", "nodes.py")["CLIPLoader"]
|
||
enums = [
|
||
ast.literal_eval(n)
|
||
for n in ast.walk(clip)
|
||
if isinstance(n, ast.List)
|
||
and all(isinstance(e, ast.Constant) and isinstance(e.value, str) for e in n.elts)
|
||
]
|
||
assert all("krea2" not in v for v in enums)
|
||
samplers = ast.parse(source("core0364", "comfy/samplers.py"))
|
||
names = next(
|
||
n.value
|
||
for n in samplers.body
|
||
if isinstance(n, ast.Assign)
|
||
and any(isinstance(t, ast.Name) and t.id == "KSAMPLER_NAMES" for t in n.targets)
|
||
)
|
||
assert "euler" in ast.literal_eval(names)
|
||
assert any(isinstance(n, ast.Constant) and n.value == "simple" for n in ast.walk(samplers))
|
||
llama = source("llama", "nodes.py").decode()
|
||
for cls in ["llama_cpp_model_loader", "llama_cpp_parameters", "llama_cpp_instruct_adv"]:
|
||
assert f'"{cls}": {cls}' in llama
|
||
assert '"presence_penalty"' in llama and '"present_penalty"' not in llama
|
||
assert any(p["name"] == "present_penalty" for p in nodes[242]["inputs"])
|
||
assert (
|
||
"if custom_prompt.strip() and" in llama
|
||
and "if force_offload:" in llama
|
||
and "LLAMA_CPP_STORAGE.clean()" in llama
|
||
)
|
||
tree = json.loads((REF / "llama-tree.json").read_bytes())
|
||
assert not any(t["path"] == "LICENSE" for t in tree["tree"])
|
||
assert b'license = {file = "LICENSE"}' in source("llama", "pyproject.toml")
|
||
assert (
|
||
json.loads((REF / "llama-registry-current.json").read_bytes())["repository"]
|
||
== "https://github.com/lihaoyun6/ComfyUI-llama-cpp_vlm"
|
||
)
|
||
kj = source("kjpkg", "nodes/model_optimization_nodes.py").decode()
|
||
assert (
|
||
"class PathchSageAttentionKJ" in kj
|
||
and '"sage_attention": (sageattn_modes, {"default": False' in kj
|
||
)
|
||
assert "from sageattention import sageattn" in kj and "torch.compiler.disable()" in kj
|
||
assert "PathchSageAttentionKJ" in source("kjpkg", "__init__.py").decode()
|
||
encrypt = source("encryptpkg", "__init__.py").decode()
|
||
assert (
|
||
"class StoryboardGridGenerator" not in encrypt and "import NODE_CLASS_MAPPINGS" in encrypt
|
||
)
|
||
gap = json.loads((REF / "identity-gaps.json").read_bytes())
|
||
assert gap["aux_tags"] == [] and [c["status"] for c in gap["aux_checks"]] == [200, 404, 404]
|
||
assert all(f["input_name"] is None for f in block["fields"] if f["node_id"] == "201")
|
||
assert len(block["node_bindings"]) == 20 and not block["boundaries"]
|
||
(OUT / "source-check.json").write_text(
|
||
json.dumps(
|
||
dict(
|
||
files=checks,
|
||
all_checks_pass=True,
|
||
source_fields=62,
|
||
source_notes=2,
|
||
physical_edges=20,
|
||
upstream_executed=False,
|
||
llama_exact_commit_available=True,
|
||
llama_exact_license_file_missing=True,
|
||
grid_exact_provider_and_mapping_unknown=True,
|
||
source_present_vs_implementation_presence_penalty_preserved=True,
|
||
preview0260_ui_and_string_result=True,
|
||
save0364_empty_data_return=True,
|
||
preview0283_image_data_return=True,
|
||
mode4_preserved=85,
|
||
),
|
||
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 raw62, notes979/611, exact sources, side effects and identity gaps; no execution")
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|