203 lines
8.6 KiB
Python
203 lines
8.6 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"] == "8b97388e142ddb67c84f2cbe0bb68c10f519e7615d75f1ea0005580fe4537ab2"
|
||
assert len(inv["fields"]) == 95 and len(inv["notes"]) == 4
|
||
assert (
|
||
len(inv["scopes"]) == 1
|
||
and inv["scopes"][0]["nodes"] == 69
|
||
and inv["scopes"][0]["edges"] == 58
|
||
)
|
||
assert set(inv["scopes"][0]["modes"]) == {0} and inv["scopes"][0]["named_nodes"] == 60
|
||
assert {n["node"] for n in inv["empty"]} == {218, 209, 212, 211, 219, 142, 126, 125, 272}
|
||
assert all(n["state"] == "missing" for n in inv["empty"])
|
||
for f, original in zip(block["fields"], inv["fields"], strict=True):
|
||
assert f["pointer"] == original["pointer"] and f["json_type"] == original["json_type"]
|
||
assert canonical(f["value"]) == canonical(original["value"])
|
||
assert canonical(f["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 = {
|
||
287: [127, 0, 142, 0],
|
||
295: [142, 0, 147, 0],
|
||
327: [147, 0, 149, 0],
|
||
436: [149, 0, 178, 0],
|
||
386: [178, 0, 224, 0],
|
||
413: [253, 0, 126, 0],
|
||
414: [253, 0, 124, 0],
|
||
415: [124, 0, 254, 0],
|
||
416: [254, 0, 208, 0],
|
||
354: [208, 0, 125, 3],
|
||
384: [125, 1, 211, 0],
|
||
420: [211, 0, 262, 0],
|
||
363: [211, 1, 212, 1],
|
||
421: [262, 0, 212, 0],
|
||
365: [212, 0, 209, 4],
|
||
375: [209, 0, 219, 0],
|
||
376: [209, 0, 218, 0],
|
||
418: [219, 0, 257, 0],
|
||
419: [257, 0, 220, 0],
|
||
}
|
||
for k, v in expected.items():
|
||
assert edges[k] == v, (k, edges[k], v)
|
||
assert ns[125]["outputs"][0]["links"] == [] and ns[209]["outputs"][1]["links"] == []
|
||
assert ns[282]["outputs"][0]["links"] is None
|
||
assert ns[262]["widgets_values"][5] == ns[262]["widgets_values_named"]["force_unload"] == "cuda"
|
||
assert next(i for i in ns[262]["inputs"] if i["name"] == "force_unload")["type"] == "BOOLEAN"
|
||
assert all(
|
||
b["source_id"] == "unknown"
|
||
for b in block["node_bindings"]
|
||
if b["class_type"]
|
||
in ["SetNode", "GetNode", "LayerUtility: PurgeVRAM V2", "Label (rgthree)"]
|
||
)
|
||
expected_text = {
|
||
117: (1670, 38, True, "3712abf649cd3bdd6b3aeaaa07a5fbeaff7e55d756abf0bd3fcc6b1311c09ad8"),
|
||
255: (526, 9, True, "426494ce4903a9dace25f62d1aa14b0802f788c5bc3c2a608c7b446b38558110"),
|
||
140: (452, 16, True, "e72ca08679fd91e2b0185be81dfd558a2b59613540df74d4fa3e5ea6cdb8e938"),
|
||
281: (129, 5, False, "e495da4a5e607e261ed393cd07ff34d6ad4fda82ede86166ae63bc60d2f7fb9c"),
|
||
138: (
|
||
10512,
|
||
126,
|
||
False,
|
||
"070167aecef0fb593c6cad6e3b6236351c10ad213c7a62d1b2d354e430ede6d3",
|
||
),
|
||
282: (2231, 4, False, "81c76e274a22fdd29ef94a8586fb6edb7ccf78b851204316e6e77323305a26a6"),
|
||
}
|
||
for nid, (length, lf, tail, sha) in expected_text.items():
|
||
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=95,
|
||
notes=4,
|
||
edges=58,
|
||
accurate_nodes=sum(bool(b["candidates"]) for b in block["node_bindings"]),
|
||
unknown_nodes=[b for b in block["node_bindings"] if b["source_id"] == "unknown"],
|
||
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 95 paired positions,4 notes,58 edges;",
|
||
result["accurate_nodes"],
|
||
"accurate nodes",
|
||
len(result["unknown_nodes"]),
|
||
"unknown",
|
||
len(result["unresolved_nodes"]),
|
||
"unresolved",
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|