287 lines
12 KiB
Python
287 lines
12 KiB
Python
"Verify exact text, Git/package provenance and source graph without upstream imports."
|
|
|
|
import ast
|
|
import collections
|
|
import hashlib
|
|
import json
|
|
|
|
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实现"
|
|
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))
|
|
from build_definition import PATHS, REPO
|
|
|
|
assert inv["sha256"] == "172eb8af3aca70082941427520fdcca06568957bab3d39101c5e9d6641b45e4a"
|
|
assert len(inv["fields"]) == 53 and len(inv["notes"]) == 1
|
|
sc = inv["scopes"][0]
|
|
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (17, 18, 17)
|
|
assert sc["modes"] == [0] * 17 and inv["empty"] == []
|
|
assert collections.Counter(x["json_type"] for x in inv["fields"]) == dict(
|
|
str=28, int=19, float=3, bool=3
|
|
)
|
|
for f, x in zip(block["fields"], inv["fields"], strict=True):
|
|
assert f["pointer"] == x["pointer"] and f["json_type"] == x["json_type"]
|
|
assert canonical(f["value"]) == canonical(x["value"]) == canonical(f["named_value"])
|
|
g = json.loads((REPO / PATHS[0]).read_bytes())
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
assert (
|
|
not g.get("definitions", {}).get("subgraphs") and g["extra"]["frontendVersion"] == "1.52.7"
|
|
)
|
|
for eid, src, si, dst, di, typ in g["links"]:
|
|
assert eid in ns[src]["outputs"][si]["links"] and ns[dst]["inputs"][di]["link"] == eid
|
|
expected = json.loads((OUT / "expected-edges.json").read_bytes())
|
|
assert g["links"] == expected
|
|
assert [o["links"] for o in ns[7]["outputs"]] == [[], [], [17]]
|
|
assert [o["links"] for o in ns[8]["outputs"]] == [None, [20], [21], None]
|
|
assert [o["links"] for o in ns[10]["outputs"]] == [None]
|
|
assert next(i for i in ns[9]["inputs"] if i["name"] == "fps")["link"] is None
|
|
assert [i["link"] for i in ns[7]["inputs"][:4]] == [None, None, 44, 45]
|
|
assert (
|
|
next(i for i in ns[24]["inputs"] if i["name"] == "preview")["link"] is None
|
|
and len(ns[24]["widgets_values"]) == 3
|
|
)
|
|
assert ns[8]["widgets_values"] == [42, "fixed", True, "match"]
|
|
assert ns[10]["widgets_values"] == ["H3_plugin_matrix/CASE_ID", "mp4", "auto", "h264", "auto"]
|
|
assert ns[18]["widgets_values"] == [10, 3] and all(
|
|
type(v) is int for v in ns[18]["widgets_values"]
|
|
)
|
|
assert all(
|
|
next(i for i in ns[22]["inputs"] if i["name"] == name)["link"] is None
|
|
for name in ["vae", "audio_vae"]
|
|
)
|
|
raw = ns[7]["widgets_values_named"]["timeline_data"]
|
|
state = json.loads(raw)
|
|
nested = []
|
|
credentials = []
|
|
|
|
def walk(o, p=""):
|
|
if isinstance(o, dict):
|
|
for k, v in o.items():
|
|
if (
|
|
any(
|
|
x in k.lower()
|
|
for x in ["api_key", "apikey", "auth", "access_token", "password", "secret"]
|
|
)
|
|
and v
|
|
):
|
|
credentials.append(p + "/" + k)
|
|
walk(v, p + "/" + k)
|
|
elif isinstance(o, list):
|
|
for i, v in enumerate(o):
|
|
walk(v, p + "/" + str(i))
|
|
elif isinstance(o, str):
|
|
nested.append(
|
|
dict(pointer=p, characters=len(o), sha256=hashlib.sha256(o.encode()).hexdigest())
|
|
)
|
|
|
|
walk(state)
|
|
assert not credentials
|
|
assert (len(raw), raw.count("\r"), raw.count("\n"), raw.count("\\n"), raw.endswith("\n")) == (
|
|
12314,
|
|
0,
|
|
0,
|
|
64,
|
|
False,
|
|
)
|
|
assert (
|
|
hashlib.sha256(raw.encode()).hexdigest()
|
|
== "4374e17eef94e0780bc53f6197dd00dbc5444bfae27787245d36600a07fedfdd"
|
|
)
|
|
assert (
|
|
state["version"] == 9
|
|
and state["fps"] == 24
|
|
and state["globalPrompt"] == ""
|
|
and state["secondPass"] is True
|
|
)
|
|
assert state["secondPassHighSteps"] == 2 and state["selection"] == dict(
|
|
start=8.5, duration=11.541666666666666
|
|
)
|
|
assert state["videoAudioEnabled"] is True and state["videoClips"] == []
|
|
note = ns[25]["widgets_values"][0]
|
|
assert (len(note), note.count("\n"), note.count("\\n"), note.endswith("\n")) == (
|
|
325,
|
|
10,
|
|
0,
|
|
False,
|
|
)
|
|
assert (
|
|
hashlib.sha256(note.encode()).hexdigest()
|
|
== "6f8bb9786e44748d969c27aef1e37f53c47016f724bb33daa788a94c2a47143b"
|
|
)
|
|
assert "16:9" in note and ns[24]["widgets_values"][0] == "9:16 (Portrait Widescreen)"
|
|
assert len(block["node_bindings"]) == 16
|
|
assert sum(len(b["candidates"]) == 1 for b in block["node_bindings"]) == 14
|
|
assert {
|
|
b["node_id"] for b in block["node_bindings"] if b["source_id"] == "unresolved-timeline"
|
|
} == {"7", "8"}
|
|
|
|
def source(key, file):
|
|
return (
|
|
REF / next(e["local_file"] for e in rows if e["id"] == key and e["file"] == file)
|
|
).read_text()
|
|
|
|
def cl(key, file, name):
|
|
return next(
|
|
c
|
|
for c in ast.parse(source(key, file)).body
|
|
if isinstance(c, ast.ClassDef) and c.name == name
|
|
)
|
|
|
|
targets = {"MiniMaxH3TimelinePlanner", "MiniMaxH3FiniteSegmentSampler"}
|
|
for file in ["__init__.py", "minimax_h3_timeline_director.py"]:
|
|
assert not any(
|
|
isinstance(c, ast.ClassDef) and c.name in targets
|
|
for c in ast.parse(source("timeline", file)).body
|
|
)
|
|
assert not any(x in source("timeline", "__init__.py") for x in targets)
|
|
assert cl("timeline", "minimax_h3_timeline_director.py", "MiniMaxH3TimelineDirector")
|
|
for key, file, name in [
|
|
("core0340", "comfy_extras/nodes_video.py", "CreateVideo"),
|
|
("core0340", "comfy_extras/nodes_video.py", "SaveVideo"),
|
|
("core0360", "comfy_extras/nodes_minimax_h3.py", "MiniMaxH3SigmaShift"),
|
|
("core0360", "comfy_extras/nodes_model_advanced.py", "ModelAttentionBackend"),
|
|
("core0360", "comfy_extras/nodes_resolution.py", "ResolutionSelector"),
|
|
("core0360", "comfy_extras/nodes_sparse_attention.py", "BlockSparseAttention"),
|
|
("kj", "nodes/preview_override_node.py", "ModelPreviewOverrideKJ"),
|
|
]:
|
|
assert cl(key, file, name)
|
|
clip = ast.unparse(cl("core0340", "nodes.py", "CLIPLoader"))
|
|
assert "minimax" in clip and "getattr" in clip
|
|
create = ast.unparse(cl("core0340", "comfy_extras/nodes_video.py", "CreateVideo"))
|
|
assert "io.Combo.Input('bit_depth'" in create and "io.Combo.Input('color_space'" in create
|
|
assert "codec" not in [
|
|
a.arg
|
|
for m in cl("core0340", "comfy_extras/nodes_video.py", "CreateVideo").body
|
|
if isinstance(m, ast.FunctionDef) and m.name == "execute"
|
|
for a in m.args.args
|
|
]
|
|
save = source("core0340", "comfy_extras/nodes_video.py")
|
|
assert "if isinstance(format, dict)" in save and 'codec_name = codec["codec"]' in save
|
|
assert "io.Vae.Input" in ast.unparse(
|
|
cl("kj", "nodes/preview_override_node.py", "ModelPreviewOverrideKJ")
|
|
) and "audio_vae" in source("kj", "nodes/preview_override_node.py")
|
|
sparse = source("core0360", "comfy_extras/nodes_sparse_attention.py")
|
|
assert (
|
|
"ON_CLEANUP" in sparse
|
|
and "sol_attn_is_available" in sparse
|
|
and "q.shape != k.shape" in sparse
|
|
)
|
|
assert json.loads(source("frontend", "package.json"))["version"] == "1.52.7"
|
|
assert "@comfyorg/litegraph" not in source(
|
|
"frontend", "pnpm-lock.yaml"
|
|
) and "Permission is hereby granted" in source("frontend", "src/lib/litegraph/LICENSE")
|
|
result = dict(
|
|
source_rows=len(rows),
|
|
checks=checks,
|
|
counts=block["counts"],
|
|
bindings=block["node_bindings"],
|
|
texts=dict(
|
|
timeline_data=dict(
|
|
characters=len(raw),
|
|
sha256=hashlib.sha256(raw.encode()).hexdigest(),
|
|
state=state,
|
|
nested_strings=nested,
|
|
)
|
|
),
|
|
credentials=credentials,
|
|
note=dict(
|
|
text=note, characters=325, LF=10, sha256=hashlib.sha256(note.encode()).hexdigest()
|
|
),
|
|
all_physical_edges=expected,
|
|
unresolved_target_classes=sorted(targets),
|
|
accurate_candidate_only="MiniMaxH3TimelineDirector, not Planner/FiniteSampler",
|
|
create0340_bit_depth_combo_and_color_space_supported=True,
|
|
upstream_executed=False,
|
|
)
|
|
(OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
|
print(
|
|
"PASS source rows",
|
|
len(rows),
|
|
"53 fields/1 MarkdownNote,17 nodes/18 edges; "
|
|
"14 accurate/2 unresolved; no upstream execution",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|