Files
aigc-home/docs/hel-892/zimage-document-evidence/verify_sources.py
T
2026-10-31 08:35:25 +08:00

198 lines
7.5 KiB
Python

"Rehash exact sources and audit all saved values and physical endpoints; no repair."
import ast
import hashlib
import json
from build_definition import OUT, REF, build, canonical
from inventory import inventory
def main():
block = build()
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":
checks.append(
dict(
id=e["id"],
file=e["file"],
sha256=e["sha256"],
proof="复用既有准确锁包成员;仅重算成员SHA,完整包摘要沿用、Git绑定未知",
)
)
continue
blob = hashlib.sha1(b"blob " + str(len(raw)).encode() + b"\0" + raw).hexdigest()
assert blob == e["git_blob_sha1"]
tree = json.loads((REF / (e["id"] + "-tree.json")).read_bytes())
assert not tree["truncated"] and tree["sha"] == e["tree"]
assert next(t["sha"] for t in tree["tree"] if t["path"] == e["file"]) == blob
commit = (REF / (e["id"] + "-commit.txt")).read_bytes()
assert (
hashlib.sha1(b"commit " + str(len(commit)).encode() + b"\0" + commit).hexdigest()
== e["commit"]
)
assert commit.decode().splitlines()[0] == "tree " + e["tree"]
tag = json.loads((REF / (e["id"] + "-tag.json")).read_bytes())
tag_raw = (REF / (e["id"] + "-tag.txt")).read_bytes()
assert tag["commit"] == e["commit"]
if tag["object"] == e["commit"]:
assert tag_raw == commit
else:
assert (
hashlib.sha1(b"tag " + str(len(tag_raw)).encode() + b"\0" + tag_raw).hexdigest()
== tag["object"]
)
assert tag_raw.decode().startswith("object " + e["commit"] + "\n")
if e["id"] == "tt":
assert not any(
t["path"].lower().split("/")[-1].startswith(("license", "licence"))
for t in tree["tree"]
)
else:
lic = next(
x for x in rows if x["id"] == e["id"] and x["local_file"] == e["license_file"]
)
assert (
hashlib.sha256((REF / e["license_file"]).read_bytes()).hexdigest() == lic["sha256"]
)
checks.append(
dict(
id=e["id"],
file=e["file"],
sha256=e["sha256"],
commit=e["commit"],
tree=e["tree"],
license_file=e["license_file"],
proof=(
"raw commit/tag + selected blob reh"
"ashed; complete tree listing not t"
"ree-object rehash"
),
)
)
inv = inventory()
assert len(inv["fields"]) == 27 and len(inv["notes"]) == 0
assert inv["scopes"][0]["nodes"] == inv["scopes"][0]["edges"] == 16
assert [(n["id"], n["mode"]) for n in inv["nodes"] if n["mode"] != 0] == [(46, 4)]
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"]),
)
for e in block["sources"]:
raw = (OUT / e["local_file"]).read_bytes()
assert hashlib.sha256(raw).hexdigest() == e["sha256"]
assert 1 <= e["lines"][0] <= e["lines"][1] <= len(raw.decode().splitlines())
ns = {n["id"]: n for n in inv["nodes"]}
endpoints = []
for edge in inv["links"]:
eid, a, ao, z, zi, kind = edge
src, dst = ns[a]["outputs"][ao], ns[z]["inputs"][zi]
assert eid in (src.get("links") or []) and dst["link"] == eid
# Reroutes retain literal * edge type instead of rewriting it.
assert kind == "*" or src["type"] == "*" or kind == src["type"]
assert kind == "*" or dst["type"] == "*" or kind == dst["type"]
endpoints.append(dict(edge=edge, source_backref=True, target_backref=True))
ids = [e[0] for e in inv["links"]]
assert len(set(ids)) == 16
for n in ns.values():
for slot in n["inputs"]:
assert slot.get("link") is None or slot["link"] in ids
for slot in n["outputs"]:
assert all(x in ids for x in slot.get("links") or [])
assert [(x["node"], x["state"]) for x in inv["empty"]] == [
(38, "missing"),
(6, "empty_list"),
(8, "empty_list"),
(37, "missing"),
]
assert ns[47]["outputs"][0]["links"] is None
assert not any(e[1] == 47 and e[3] == 48 for e in inv["links"])
assert ns[36]["inputs"][2]["link"] is None
assert "link" not in ns[2]["inputs"][0]
tt = ast.parse((REF / "tt__nodes__resolution_selector.py").read_bytes())
table = next(
n
for n in ast.walk(tt)
if isinstance(n, ast.Assign)
and any(isinstance(t, ast.Name) and t.id == "RESOLUTIONS" for t in n.targets)
)
presets = ast.literal_eval(table.value)
assert len(presets) == 27 and presets[ns[55]["widgets_values"][1]] == (1080, 1920)
lock = json.loads((REF / "frontend__package-lock.json").read_bytes())
package = lock["packages"]["node_modules/@comfyorg/litegraph"]
assert package["version"] == "0.15.15"
lg = next(e for e in rows if e["id"] == "litegraph")
assert package["integrity"] == "sha512-" + lg["artifact_sha512_base64"]
assert (
json.loads(
(REF / lg["local_file"]).with_name("litegraph__package__package.json").read_bytes()
)["version"]
== "0.15.15"
)
selected = {
p: (REF / p).read_text()
for p in [
"core__nodes.py",
"core__comfy_extras__nodes_primitive.py",
"core__comfy_extras__nodes_sd3.py",
"lora__nodes.py",
]
}
classes = {
name: [n.name for n in ast.walk(ast.parse(text)) if isinstance(n, ast.ClassDef)]
for name, text in selected.items()
}
assert all("SetNode" not in names and "GetNode" not in names for names in classes.values())
(OUT / "identity-gaps.json").write_text(
json.dumps(
dict(
bounded_class_scan=classes,
scope="仅准确core选定定义/注册文本与完整树,非所有插件检索;Set/Get未获提供方版本",
set_get_identity="unknown",
ue_0246_restore="unknown",
model_support_compatibility="unknown; loader interface only",
tt_license="unknown; full tree no license text",
litegraph=(
"exact locked archived members; ful"
"l package hashes inherited, Git bi"
"nding unknown"
),
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
(OUT / "source-check.json").write_text(
json.dumps(
dict(
sources=checks,
endpoints=endpoints,
slot_states=inv["slots"],
presets=presets,
inventory_matched=True,
upstream_executed=False,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
(
"PASS exact source identities, 16 b"
"idirectional edges, 27 positions, "
"locked dependency, bounded gaps"
)
)
if __name__ == "__main__":
main()