257 lines
11 KiB
Python
257 lines
11 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"] == "a071e6070ee933396f225b4447c363bbf6b0df059b3cd43da567e81bc7937e84"
|
||
assert len(inv["fields"]) == 54 and len(inv["notes"]) == 3
|
||
assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [
|
||
(9, 5, 8),
|
||
(21, 42, 17),
|
||
]
|
||
assert all(set(s["modes"]) == {0} for s in inv["scopes"])
|
||
assert [(n["node"], n["state"]) for n in inv["empty"]] == [
|
||
(120, "missing"),
|
||
(23, "missing"),
|
||
(10, "missing"),
|
||
(14, "missing"),
|
||
(16, "missing"),
|
||
]
|
||
from build_definition import PATHS, REPO
|
||
|
||
g = json.loads((REPO / PATHS[0]).read_bytes())
|
||
d = g["definitions"]["subgraphs"][0]
|
||
|
||
def pointer(obj, p):
|
||
for bit in p.strip("/").split("/"):
|
||
bit = bit.replace("~1", "/").replace("~0", "~")
|
||
obj = obj[int(bit)] if isinstance(obj, list) else obj[bit]
|
||
return obj
|
||
|
||
for a, f in zip(inv["fields"], block["fields"], strict=True):
|
||
assert (a["pointer"], a["json_type"], canonical(a["value"])) == (
|
||
f["pointer"],
|
||
f["json_type"],
|
||
canonical(f["value"]),
|
||
)
|
||
assert (
|
||
canonical(pointer(g, f["pointer"]))
|
||
== canonical(pointer(g, f["named_pointer"]))
|
||
== canonical(f["value"])
|
||
== canonical(f["named_value"])
|
||
)
|
||
for graph in [g, d]:
|
||
ns = {n["id"]: n for n in graph["nodes"]}
|
||
for edge in graph["links"]:
|
||
if isinstance(edge, list):
|
||
eid, a, ao, z, zi, _ = edge
|
||
else:
|
||
eid, a, ao, z, zi = [
|
||
edge[k] for k in ["id", "origin_id", "origin_slot", "target_id", "target_slot"]
|
||
]
|
||
assert eid in (
|
||
ns[a]["outputs"][ao]["links"] if a >= 0 else graph["inputs"][ao]["linkIds"]
|
||
)
|
||
if z >= 0:
|
||
assert ns[z]["inputs"][zi]["link"] == eid
|
||
else:
|
||
assert eid in graph["outputs"][zi]["linkIds"]
|
||
ns = {n["id"]: n for n in g["nodes"]}
|
||
ins = {n["id"]: n for n in d["nodes"]}
|
||
assert len(ns[105]["widgets_values"]) == 13 and len(ns[105]["inputs"]) == len(d["inputs"]) == 15
|
||
assert d["widgets"] == [] and "proxyWidgets" not in ns[105] and "proxyWidgets" not in d
|
||
assert ns[105]["inputs"][0]["link"] == 218 and ns[105]["inputs"][1]["link"] is None
|
||
assert ns[119]["inputs"][0]["link"] is None
|
||
assert all(o["links"] is None for o in ns[120]["outputs"])
|
||
assert "widgets_values" not in ns[120] and "widgets_values_named" not in ns[120]
|
||
assert ns[115]["widgets_values"] == ["1:1 (Square)", 0.4, 32]
|
||
assert ns[92]["widgets_values"] == ["video/MiniMax_H3", "auto", "auto"]
|
||
assert g["links"] == [
|
||
[194, 105, 0, 92, 0, "VIDEO"],
|
||
[218, 114, 0, 105, 0, "IMAGE"],
|
||
[219, 115, 0, 105, 3, "INT"],
|
||
[220, 115, 1, 105, 4, "INT"],
|
||
[228, 119, 0, 120, 0, "IMAGE"],
|
||
]
|
||
assert [
|
||
(e["id"], e["origin_id"], e["target_id"], e["target_slot"])
|
||
for e in d["links"]
|
||
if e["id"] in [188, 199, 225, 226, 238, 239]
|
||
] == [
|
||
(188, 104, 14, 4),
|
||
(199, 107, 104, 7),
|
||
(225, 14, 10, 0),
|
||
(226, 14, 23, 0),
|
||
(238, 126, 122, 2),
|
||
(239, 126, 123, 2),
|
||
]
|
||
expression = "max(5, round(a * 24)) + (5 - (max(5, round(a * 24)) % 17)) % 17"
|
||
assert ins[107]["widgets_values"] == [expression]
|
||
assert ins[107]["inputs"][1]["link"] is None
|
||
assert ins[107]["outputs"][0]["links"] is None and ins[107]["outputs"][2]["links"] is None
|
||
assert type(ins[111]["widgets_values"][0]) is int and ins[111]["widgets_values"] == [2]
|
||
assert ns[105]["widgets_values"][3] == 5 and type(ns[105]["widgets_values"][3]) is int
|
||
assert ins[124]["widgets_values"] == [20, "fixed"] and ins[125]["widgets_values"] == [
|
||
6,
|
||
"fixed",
|
||
]
|
||
assert (
|
||
ins[122]["widgets_values"]
|
||
== ins[123]["widgets_values"]
|
||
== ins[126]["widgets_values"]
|
||
== [False]
|
||
)
|
||
assert ns[105]["widgets_values"][9] is True and ns[105]["widgets_values"][-1] == 8
|
||
for nid in [23, 10, 14, 16]:
|
||
assert "widgets_values" not in ins[nid] and "widgets_values_named" not in ins[nid]
|
||
assert [
|
||
(n["characters"], n["lf_count"], n["literal_backslash_n"], n["ends_with_lf"])
|
||
for n in inv["notes"]
|
||
] == [(1206, 16, 0, False), (2406, 48, 0, True), (280, 9, 0, False)]
|
||
assert [hashlib.sha256(n["text"].encode()).hexdigest() for n in inv["notes"]] == [
|
||
"35639593614305a3608bfff3da74bc2c6d98755f00568283efb828a246f92efe",
|
||
"da7ff34a6265ea2de2482cd475edc2eb5c37cf01596907a8c7fce5857f6bc832",
|
||
"fe3b286a1fbb11f8dac656a6302142931d60f1351361ebde7fb956447c267caa",
|
||
]
|
||
texts = [ns[105]["widgets_values"][0], ins[104]["widgets_values"][0]]
|
||
assert [(len(s), s.count("\n"), s.count("\\n"), s.endswith("\n")) for s in texts] == [
|
||
(1501, 4, 0, False),
|
||
(980, 12, 0, False),
|
||
]
|
||
assert [hashlib.sha256(s.encode()).hexdigest() for s in texts] == [
|
||
"36569548f832ab5efd3d944467f37f708de95f1f0bee2aeef6922b19acb16e0d",
|
||
"21953b89529474d17901875cb7f5d5120c406dfbd680c88065f9b672c2f326d9",
|
||
]
|
||
assert all(
|
||
b["source_id"] == "core0330" and len(b["candidates"]) == 1
|
||
for b in block["node_bindings"]
|
||
if b["node_id"] != "105"
|
||
)
|
||
assert all(b["source_version"] == "0.33.0" for b in block["node_bindings"])
|
||
assert (
|
||
block["counts"]["root_saved_fields"] == 24
|
||
and block["counts"]["internal_saved_fields"] == 30
|
||
)
|
||
(OUT / "source-check.json").write_text(
|
||
json.dumps(
|
||
dict(
|
||
files=checks,
|
||
positions=54,
|
||
standard_notes=3,
|
||
scopes=inv["scopes"],
|
||
edges_including_boundary=47,
|
||
accurate_implementation_nodes=26,
|
||
upstream_executed=False,
|
||
expression_evaluated=False,
|
||
),
|
||
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 exact sources,54 positional/named fields,3 notes,47 edge/boundary records; "
|
||
"no expression evaluation"
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|