298 lines
13 KiB
Python
298 lines
13 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.get("http_metadata"):
|
|
proof = "本图规范身份与准确commit请求原文;未取得实现,不作为类/schema证据"
|
|
elif e["id"] == "soundflow":
|
|
proof = "本轮规范身份与准确提交API请求原记录,未取得类,不作为接口实现"
|
|
elif "member_crc32" in e:
|
|
import zlib
|
|
|
|
members = json.loads((REF / "vhspkg-members.json").read_bytes())
|
|
member = next(m for m in members if m["name"] == e["file"])
|
|
assert e["member_crc32"] == member["crc"] == zlib.crc32(raw)
|
|
assert member["size"] == len(raw) and e["tag"] == "1.7.9"
|
|
reg = json.loads((REF / "vhs-version-registry-response.json").read_bytes())
|
|
assert reg["version"] == e["tag"] and reg["downloadUrl"] == e["url"]
|
|
assert e["package_sha256"] == "unknown-not-downloaded-whole-archive"
|
|
proof = "准确1.7.9发布身份/Range必要成员SHA与CRC;整包SHA和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"] == "2be3981360fff849a53a928a6a2040c97bcf1944dce2df82d716a805c0ef2594"
|
|
assert len(inv["fields"]) == 112 and len(inv["notes"]) == 3
|
|
assert [(x["nodes"], x["edges"], x["named_nodes"]) for x in inv["scopes"]] == [
|
|
(36, 51, 31),
|
|
(3, 8, 3),
|
|
]
|
|
assert collections.Counter(inv["scopes"][0]["modes"]) == {0: 34, 4: 2}
|
|
assert inv["scopes"][1]["modes"] == [0] * 3
|
|
assert collections.Counter(f["json_type"] for f in inv["fields"]) == dict(
|
|
str=56, int=43, float=5, bool=7, dict=1
|
|
)
|
|
assert len(inv["empty"]) == 6 and sum(x["state"] == "missing" for x in inv["empty"]) == 5
|
|
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())
|
|
sg = g["definitions"]["subgraphs"][0]
|
|
ns = {n["id"]: n for n in g["nodes"]}
|
|
sn = {n["id"]: n for n in sg["nodes"]}
|
|
assert g["extra"]["frontendVersion"] == "1.53.6" and len(g["definitions"]["subgraphs"]) == 1
|
|
assert sg["id"] == "1d5d08b2-2321-43b2-8d8c-0964dc6c6e86"
|
|
assert dict(root=g["links"], internal=sg["links"]) == json.loads(
|
|
(OUT / "expected-edges.json").read_bytes()
|
|
)
|
|
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
|
|
for e in sg["links"]:
|
|
a, ai, b, bi = e["origin_id"], e["origin_slot"], e["target_id"], e["target_slot"]
|
|
if a == -10:
|
|
assert e["id"] in sg["inputs"][ai]["linkIds"] and sg["inputs"][ai]["type"] == e["type"]
|
|
else:
|
|
assert e["id"] in sn[a]["outputs"][ai]["links"]
|
|
if b == -20:
|
|
assert (
|
|
e["id"] in sg["outputs"][bi]["linkIds"] and sg["outputs"][bi]["type"] == e["type"]
|
|
)
|
|
else:
|
|
assert sn[b]["inputs"][bi]["link"] == e["id"]
|
|
|
|
def inp(n, k):
|
|
return next(i for i in ns[n]["inputs"] if i["name"] == k)
|
|
|
|
assert [n["id"] for n in g["nodes"] if n["mode"] == 4] == [121, 295]
|
|
assert ns[121]["outputs"][0]["links"] == [] and inp(194, "audio")["link"] == 667
|
|
assert inp(300, "latent_image")["link"] == 672 and inp(300, "model_hires")["link"] is None
|
|
assert inp(156, "duration")["link"] == 416 and inp(156, "prompt")["link"] == 446
|
|
assert inp(132, "value")["link"] == 666 and inp(131, "values.b")["link"] is None
|
|
assert [o["links"] for o in ns[131]["outputs"]] == [[416], [275, 303], []]
|
|
assert ns[217]["outputs"][0]["links"] == [] and all(
|
|
o["links"] == [] for o in ns[289]["outputs"]
|
|
)
|
|
assert ns[287]["widgets_values"] == [9, 4, "depth", "moge_3_vitg_fp16.safetensors"] and sn[5][
|
|
"widgets_values"
|
|
] == ["mask"]
|
|
assert len(block["boundaries"]) == 1 and len(block["boundaries"][0]["inputs"]) == 5
|
|
assert ns[300]["widgets_values"][:4] == [999, "fixed", 1, 4] and ns[156]["widgets_values"][
|
|
7:9
|
|
] == [419002063719418, "randomize"]
|
|
assert (
|
|
isinstance(ns[243]["widgets_values"], dict)
|
|
and len(ns[243]["widgets_values"]) == 10
|
|
and isinstance(ns[243]["widgets_values"]["videopreview"], dict)
|
|
)
|
|
notes = []
|
|
expected = {
|
|
117: (1964, 43, True, "afe756a7a7bcd5452d83bde21725c446377e9be9b1556516616c170ec20a7284"),
|
|
140: (325, 10, False, "6f8bb9786e44748d969c27aef1e37f53c47016f724bb33daa788a94c2a47143b"),
|
|
116: (2473, 26, False, "c5ae05e6eff86a704ca371deb45e1bf33cccb35fb37c75008b2416225fb87198"),
|
|
}
|
|
for nid, (chars, lf, tail, digest) in expected.items():
|
|
raw = ns[nid]["widgets_values"][0]
|
|
assert (
|
|
len(raw),
|
|
raw.count("\r"),
|
|
raw.count("\n"),
|
|
raw.endswith("\n"),
|
|
raw.count("\\n"),
|
|
hashlib.sha256(raw.encode()).hexdigest(),
|
|
) == (chars, 0, lf, tail, 0, digest)
|
|
notes.append(
|
|
dict(node=str(nid), characters=chars, LF=lf, CR=0, tail_LF=tail, sha256=digest)
|
|
)
|
|
bindings = block["node_bindings"]
|
|
assert len(bindings) == 36 and sum(len(b["candidates"]) == 1 for b in bindings) == 32
|
|
assert {b["node_id"] for b in bindings if b["source_id"] == "unknown"} == {"293", "298"}
|
|
assert {b["node_id"] for b in bindings if b["source_id"] == "unresolved-vhs"} == {"243"}
|
|
assert {b["node_id"] for b in bindings if b["source_id"] == "subgraph-definition"} == {"287"}
|
|
|
|
def rawfile(id, file):
|
|
return (
|
|
REF / next(e["local_file"] for e in rows if e["id"] == id and e["file"] == file)
|
|
).read_text()
|
|
|
|
tree = ast.parse(rawfile("kj", "nodes/preview_override_node.py"))
|
|
cl = next(
|
|
c for c in tree.body if isinstance(c, ast.ClassDef) and c.name == "ModelPreviewOverrideKJ"
|
|
)
|
|
assert "audio_vae" not in ast.unparse(cl) and "tiny_vae" in ast.unparse(cl)
|
|
assert '"easy cleanGpuUsed": cleanGPUUsed' in rawfile("easy", "py/nodes/logic.py")
|
|
assert "class EasySaveVideo(" in rawfile("mediaout", "nodes/video.py")
|
|
assert "StringMultiline," in rawfile("core0371", "comfy_extras/nodes_primitive.py")
|
|
assert "LoadMoGeModel, MoGeInference" in rawfile("core0380", "comfy_extras/nodes_moge.py")
|
|
assert json.loads(rawfile("frontend", "package.json"))["version"] == "1.53.6"
|
|
sensitive = []
|
|
|
|
def scan(x, p=""):
|
|
if isinstance(x, dict):
|
|
for k, v in x.items():
|
|
if k.lower() in [
|
|
"api_key",
|
|
"apikey",
|
|
"password",
|
|
"secret",
|
|
"token",
|
|
"access_token",
|
|
"authorization",
|
|
] and v not in [None, "", [], {}]:
|
|
sensitive.append(p + "/" + k)
|
|
scan(v, p + "/" + k)
|
|
elif isinstance(x, list):
|
|
for i, v in enumerate(x):
|
|
scan(v, p + "/" + str(i))
|
|
|
|
scan(g)
|
|
assert not sensitive
|
|
texts = [
|
|
dict(
|
|
node=str(n),
|
|
field=k,
|
|
characters=len(ns[n]["widgets_values_named"][k]),
|
|
sha256=hashlib.sha256(ns[n]["widgets_values_named"][k].encode()).hexdigest(),
|
|
)
|
|
for n, k in [(238, "value"), (156, "prompt"), (136, "prompt")]
|
|
]
|
|
(OUT / "source-check.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
checks=checks,
|
|
notes=notes,
|
|
texts=texts,
|
|
accurate=32,
|
|
unresolved=1,
|
|
unknown=2,
|
|
definition_hosts=1,
|
|
source_SHA=inv["sha256"],
|
|
no_upstream_execution=True,
|
|
nonempty_credential_keys=sensitive,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
(OUT / "identity-gaps.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
accurate_class_instances=32,
|
|
unknown_nodes=["293", "298"],
|
|
unresolved_nodes=[
|
|
"243: exact VHS Git not our ref, commit API422, registry version404; "
|
|
"canonical repo200, class/schema/unit/license unknown"
|
|
],
|
|
definition_hosts=["287: five boundaries only, not backend class"],
|
|
field_gaps=[
|
|
"153 audio_vae absent in exactc986, tiny_vae optional Combo separately",
|
|
"153 preview extra empty string",
|
|
"300 last four extra tiling values lack exact schema",
|
|
"194 codec none absent",
|
|
"217 dynamic strings/typed payload remain separate",
|
|
"416 frame-expression FLOAT enters Qwen seconds interface; do not repair units",
|
|
],
|
|
licenses={
|
|
"sigma": "accurate tree independent LICENSE unknown",
|
|
"selflift": "accurate tree independent LICENSE unknown",
|
|
"vhs": "accurate declared commit not acquired; license unknown",
|
|
},
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print(
|
|
"PASS112 saved entries/three notes/five boundaries/32 exact classes/one VHS gap/two unknown"
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|