193 lines
8.3 KiB
Python
193 lines
8.3 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"] == "5b45b49ebe4402c207e7d894e03a1bb53482b24a0c09ce50d549be4a01f9c6d0"
|
||
assert len(inv["fields"]) == 53 and len(inv["notes"]) == 1
|
||
assert (
|
||
len(inv["scopes"]) == 1
|
||
and inv["scopes"][0]["nodes"] == 19
|
||
and inv["scopes"][0]["edges"] == 26
|
||
)
|
||
assert inv["scopes"][0]["named_nodes"] == 15 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],
|
||
57: [2, 0, 38, 0],
|
||
58: [38, 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, 12],
|
||
59: [15, 1, 38, 6],
|
||
}
|
||
for k, v in expected.items():
|
||
assert edges[k] == v, (k, edges[k], v)
|
||
assert ns[10]["outputs"][1]["links"] == [] and ns[12]["outputs"][0]["links"] is None
|
||
assert all(n["link"] is None for n in ns[6]["inputs"][3:12])
|
||
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()
|
||
== "d6275d22d4faba84151b41b51638dcb8971ecf7513413c6d7a81b02e860883f7"
|
||
)
|
||
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"]) == 17
|
||
assert ns[6]["widgets_values_named"]["task_type"] == "T2VA — 文生音视频"
|
||
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, 179, 0, False, "6cebb68b17b046589805874680e78a112fdf199b99ec042c9a9facd3c346dcb5"),
|
||
]:
|
||
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=53,
|
||
list_scalars=42,
|
||
dict_scalars=10,
|
||
complete_history_objects=1,
|
||
notes=1,
|
||
edges=26,
|
||
accurate_nodes=17,
|
||
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 53 dual-save entries (42 list scalars/10 dict scalars/1 history object),"
|
||
+ "1 Note,26 edges;17 exact/1 unresolved"
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|