215 lines
9.0 KiB
Python
215 lines
9.0 KiB
Python
"Verify exact text, Git/package provenance and source graph without upstream imports."
|
||
|
||
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"\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实现"
|
||
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())
|
||
)
|
||
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"] == "97f188c9295af0dbe6358a4b23117ca1612e812d2fa3df67dd7b10ee68e96fb5"
|
||
assert len(inv["fields"]) == 54 and len(inv["notes"]) == 1
|
||
assert (
|
||
len(inv["scopes"]) == 1
|
||
and inv["scopes"][0]["nodes"] == 20
|
||
and inv["scopes"][0]["edges"] == 27
|
||
)
|
||
assert inv["scopes"][0]["named_nodes"] == 16 and set(inv["scopes"][0]["modes"]) == {0}
|
||
assert {x["node"] for x in inv["empty"]} == {8, 11, 17, 10} and all(
|
||
x["state"] == "missing" for x in inv["empty"]
|
||
)
|
||
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"])
|
||
from build_definition import PATHS, REPO
|
||
|
||
g = json.loads((REPO / PATHS[0]).read_bytes())
|
||
ns = {n["id"]: n for n in g["nodes"]}
|
||
edges = {e[0]: e[1:5] for e in g["links"]}
|
||
expected = {
|
||
26: [1, 0, 17, 0],
|
||
27: [17, 0, 2, 0],
|
||
58: [2, 0, 39, 0],
|
||
59: [39, 0, 7, 0],
|
||
7: [7, 0, 8, 0],
|
||
8: [6, 0, 8, 1],
|
||
11: [7, 1, 10, 2],
|
||
12: [7, 2, 10, 3],
|
||
6: [6, 1, 7, 1],
|
||
13: [6, 1, 10, 4],
|
||
14: [10, 0, 11, 0],
|
||
17: [11, 0, 12, 0],
|
||
18: [11, 1, 12, 1],
|
||
53: [36, 0, 6, 11],
|
||
60: [15, 1, 39, 5],
|
||
57: [37, 0, 6, 5],
|
||
}
|
||
for k, v in expected.items():
|
||
assert edges[k] == v, (k, edges[k], v)
|
||
assert ns[10]["outputs"][1]["links"] == [] and "links" not in ns[12]["outputs"][0]
|
||
assert ns[6]["inputs"][5]["link"] == 57
|
||
missing_inputs = [
|
||
i
|
||
for i in ns[6]["inputs"]
|
||
if i["name"]
|
||
in [
|
||
"drive_audio",
|
||
"final_audio",
|
||
"last_frame",
|
||
"ref_images.ref_image_0",
|
||
"ref_videos.ref_video_0",
|
||
"ref_video_audios.ref_video_audio_0",
|
||
"ref_audios.ref_audio_0",
|
||
]
|
||
]
|
||
assert len(missing_inputs) == 7 and all("link" not in i for i in missing_inputs)
|
||
assert "links" not in ns[37]["outputs"][1]
|
||
assert not any(
|
||
i["name"] in ["semantic_bridge", "allow_above_reference_area"] for i in ns[6]["inputs"]
|
||
)
|
||
assert not any(i["name"] == "audio_vae" for i in ns[39]["inputs"])
|
||
assert ns[37]["widgets_values"] == ["1.png", "image"]
|
||
assert all(o["links"] == [] for o in ns[6]["outputs"][2:])
|
||
assert isinstance(ns[12]["widgets_values"], dict) and len(ns[12]["widgets_values"]) == 11
|
||
hs = next(f for f in block["fields"] if f["field"] == "videopreview")
|
||
assert hs["json_type"] == "dict" and hs["pointer"].endswith("/widgets_values/videopreview")
|
||
assert hs["value"] == ns[12]["widgets_values_named"]["videopreview"]
|
||
assert (
|
||
hashlib.sha256(json.dumps(hs["value"], ensure_ascii=False, indent=2).encode()).hexdigest()
|
||
== "11e381651620717ee408299c595c31cb24ad280998dae4fcd2742326544317a2"
|
||
)
|
||
assert {
|
||
b["node_id"] for b in block["node_bindings"] if b["source_id"].startswith("unresolved-")
|
||
} == {"7"}
|
||
assert sum(bool(b["candidates"]) for b in block["node_bindings"]) == 18
|
||
assert ns[6]["widgets_values_named"]["task_type"] == "I2VA — 图生音视频(首帧)"
|
||
assert any("resolve_task_type仅lower" in x for x in block["steps"])
|
||
for nid, length, lf, tail, sha in [
|
||
(35, 452, 16, True, "e72ca08679fd91e2b0185be81dfd558a2b59613540df74d4fa3e5ea6cdb8e938"),
|
||
(36, 174, 0, False, "8810e5e4871e482bfdbcf734112ef49e7ae18f7543f863dc048e52df4bbe5783"),
|
||
]:
|
||
text = ns[nid]["widgets_values"][0]
|
||
assert (
|
||
len(text) == length
|
||
and text.count("\n") == lf
|
||
and text.endswith("\n") == tail
|
||
and text.count("\\n") == 0
|
||
)
|
||
assert hashlib.sha256(text.encode()).hexdigest() == sha
|
||
result = dict(
|
||
sources=checks,
|
||
positions=54,
|
||
list_scalars=43,
|
||
dict_scalars=10,
|
||
complete_history_objects=1,
|
||
notes=1,
|
||
edges=27,
|
||
accurate_nodes=18,
|
||
unresolved_nodes=[
|
||
b for b in block["node_bindings"] if b["source_id"].startswith("unresolved-")
|
||
],
|
||
upstream_executed=False,
|
||
)
|
||
(OUT / "source-check.json").write_text(json.dumps(result, 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 54 dual-save entries (43 list scalars/10 dict scalars/1 history object),"
|
||
+ "1 Note,27 edges;18 exact/1 unresolved"
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|