283 lines
12 KiB
Python
283 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"] == "698430e2b234a107b15f1bebf7704833afeea819bd21a3af56f7121daa1383e0"
|
|
assert len(inv["fields"]) == 65 and len(inv["notes"]) == 1
|
|
sc = inv["scopes"][0]
|
|
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (22, 24, 20)
|
|
assert sc["modes"].count(0) == 17 and sc["modes"].count(4) == 5
|
|
assert {x["node"] for x in inv["empty"]} == {30, 39} and all(
|
|
x["state"] == "missing" for x in inv["empty"]
|
|
)
|
|
assert collections.Counter(x["json_type"] for x in inv["fields"]) == dict(
|
|
str=38, int=18, float=5, bool=4
|
|
)
|
|
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.51.9"
|
|
)
|
|
assert {n["id"] for n in g["nodes"] if n["mode"] == 4} == {41, 42, 39, 34, 33}
|
|
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 expected == g["links"]
|
|
assert all(
|
|
"widgets_values" not in ns[i] and "widgets_values_named" not in ns[i] for i in [30, 39]
|
|
)
|
|
assert [o["links"] for o in ns[14]["outputs"]] == [[38], [], [], []]
|
|
assert [o["links"] for o in ns[17]["outputs"]] == [[], []]
|
|
assert [o["links"] for o in ns[25]["outputs"]] == [None, None]
|
|
assert all(i["link"] is None for i in ns[25]["inputs"])
|
|
assert not any(e[3] == 25 for e in g["links"])
|
|
assert ns[15]["outputs"][1]["links"] is None
|
|
assert ns[15]["widgets_values_named"]["fixed"] == "randomize"
|
|
assert (
|
|
ns[15]["widgets_values_named"]["enabled_tiling"] == "true"
|
|
and type(ns[15]["widgets_values_named"]["enabled_tiling"]) is str
|
|
)
|
|
texts = {}
|
|
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())
|
|
)
|
|
|
|
for nid, key, length, literal, hashval in [
|
|
(
|
|
14,
|
|
"track_data",
|
|
28701,
|
|
378,
|
|
"e8d2c44837d759b5f0ec54c11da0a892017d1ea5121a8e017d79b243a7fae06c",
|
|
),
|
|
(
|
|
17,
|
|
"project_data",
|
|
114,
|
|
0,
|
|
"d35d303b7a6df706e6fa8a8790c6e0e6b2340281cd8e54d4940fef40c9d79546",
|
|
),
|
|
]:
|
|
raw = ns[nid]["widgets_values_named"][key]
|
|
state = json.loads(raw)
|
|
nested = []
|
|
walk(state, key)
|
|
assert (
|
|
len(raw),
|
|
raw.count("\r"),
|
|
raw.count("\n"),
|
|
raw.count("\\n"),
|
|
raw.endswith("\n"),
|
|
) == (length, 0, 0, literal, False)
|
|
assert hashlib.sha256(raw.encode()).hexdigest() == hashval
|
|
texts[key] = dict(characters=len(raw), sha256=hashval, state=state, nested_strings=nested)
|
|
assert not credentials
|
|
assert texts["project_data"]["state"] == dict(
|
|
project_name="default",
|
|
width=1280,
|
|
height=736,
|
|
frame_rate=24,
|
|
clips=[],
|
|
auto_combine=True,
|
|
updated_at=0,
|
|
)
|
|
note = ns[43]["widgets_values"][0]
|
|
assert len(note) == 13 and note == "配置不够,尺寸不要设置太大" and not note.endswith("\n")
|
|
assert (
|
|
hashlib.sha256(note.encode()).hexdigest()
|
|
== "c8953a85be599be58c1f1c584b91f65c1cded2bf8dab96f0c2a5fb01dd351866"
|
|
)
|
|
assert len(block["node_bindings"]) == 21
|
|
assert sum(len(b["candidates"]) == 1 for b in block["node_bindings"]) == 19
|
|
assert {
|
|
b["node_id"] for b in block["node_bindings"] if b["source_id"] == "unresolved-project"
|
|
} == {"15", "17"}
|
|
assert not any(b["source_id"] == "unknown" for b in block["node_bindings"])
|
|
|
|
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
|
|
)
|
|
|
|
c = cl("mediaeditor", "nodes/basic.py", "MultiTrackEditor")
|
|
m = next(m for m in c.body if isinstance(m, ast.FunctionDef) and m.name == "execute")
|
|
assert any(
|
|
isinstance(n, ast.Call)
|
|
and isinstance(n.func, ast.Name)
|
|
and n.func.id == "build_multitrack_data_from_prompt_override"
|
|
for n in ast.walk(m)
|
|
)
|
|
selected_project = [
|
|
e["file"] for e in rows if e["id"] == "project" and e["file"].endswith(".py")
|
|
]
|
|
for f in selected_project:
|
|
assert not any(
|
|
isinstance(c, ast.ClassDef)
|
|
and c.name in ["EasyMultiTrackProject", "EasyMultiTrackProjectVideoCombine"]
|
|
for c in ast.parse(source("project", f)).body
|
|
)
|
|
assert "EasyMultiTrackProject" not in source("project", "__init__.py")
|
|
assert "EasyMultiTrackProject" in source("pack", "__init__.py")
|
|
for key, file, name in [
|
|
("hybrid", "minimaxh3.py", "MiniMaxH3HybridLoader"),
|
|
("pack", "nodes/common.py", "EasyModelLoaderPack"),
|
|
("pack", "nodes/video.py", "EasySaveVideo"),
|
|
("core0330", "comfy_extras/nodes_model_advanced.py", "ModelAttentionBackend"),
|
|
("kj", "nodes/preview_override_node.py", "ModelPreviewOverrideKJ"),
|
|
("kj", "nodes/minimax_nodes.py", "MiniMaxLowVRAMAttention"),
|
|
("kj", "nodes/minimax_nodes.py", "MiniMaxChunkFeedForward"),
|
|
]:
|
|
assert cl(key, file, name)
|
|
assert "source_video.save_to" in source("pack", "nodes/video.py")
|
|
assert "custom_base_globs" in source(
|
|
"hybrid", "minimaxh3.py"
|
|
) and "cached_patcher_init" in source("hybrid", "minimaxh3.py")
|
|
clip = ast.unparse(cl("core0290", "nodes.py", "CLIPLoader"))
|
|
assert "minimax" not in clip and "getattr" in clip
|
|
assert json.loads(source("frontend", "package.json"))["version"] == "1.51.9"
|
|
assert "@comfyorg/litegraph" not in source("frontend", "pnpm-lock.yaml")
|
|
assert "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=texts,
|
|
credentials=credentials,
|
|
note=dict(text=note, sha256=hashlib.sha256(note.encode()).hexdigest()),
|
|
all_physical_edges=expected,
|
|
editor_prompt_override_used=True,
|
|
project_classes_unresolved_in_selected_exact_entry_and_paths=selected_project,
|
|
frontend_litegraph=(
|
|
"embedded in same Git tree; independent MIT license; no npm package-lock inferred"
|
|
),
|
|
upstream_executed=False,
|
|
)
|
|
(OUT / "source-check.json").write_text(json.dumps(result, ensure_ascii=False, indent=2) + "\n")
|
|
print(
|
|
"PASS source rows",
|
|
len(rows),
|
|
"65 fields/1 Note,22 nodes/24 edges,19 accurate/2 unresolved; no upstream execution",
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|