Files
aigc-home/docs/hel-892/fasth3-i2v-document-evidence/verify_sources.py
T
2026-11-01 06:36:46 +08:00

297 lines
12 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"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"] == "c5eff277eeeeefacb39c4af2e5ac41251785cc18ca90c1678a653367f4dd5942"
assert len(inv["fields"]) == 56 and len(inv["notes"]) == 2
assert [(s["nodes"], s["edges"], s["named_nodes"]) for s in inv["scopes"]] == [
(8, 7, 7),
(18, 34, 14),
]
assert inv["scopes"][0]["modes"].count(0) == 7 and inv["scopes"][0]["modes"].count(4) == 1
assert set(inv["scopes"][1]["modes"]) == {0}
assert [(n["node"], n["state"]) for n in inv["empty"]] == [
(141, "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]
ns = {n["id"]: n for n in g["nodes"]}
ins = {n["id"]: n for n in d["nodes"]}
def pointer(obj, p):
for x in p.strip("/").split("/"):
x = x.replace("~1", "/").replace("~0", "~")
obj = obj[int(x)] if isinstance(obj, list) else obj[x]
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]:
nodes = {n["id"]: n for n in graph["nodes"]}
for edge in graph["links"]:
eid, a, ao, z, zi = (
edge[:5]
if isinstance(edge, list)
else [
edge[k] for k in ["id", "origin_id", "origin_slot", "target_id", "target_slot"]
]
)
assert eid in (
nodes[a]["outputs"][ao]["links"] if a >= 0 else graph["inputs"][ao]["linkIds"]
)
assert (
nodes[z]["inputs"][zi]["link"] == eid
if z >= 0
else eid in graph["outputs"][zi]["linkIds"]
)
assert len(ns[105]["widgets_values"]) == 10 and len(ns[105]["inputs"]) == len(d["inputs"]) == 12
assert d["widgets"] == [] and "proxyWidgets" not in ns[105] and "proxyWidgets" not in d
assert ns[105]["inputs"][0]["link"] == 262 and ns[105]["inputs"][1]["link"] == 275
assert g["links"] == [
[194, 105, 0, 92, 0, "VIDEO"],
[262, 136, 0, 105, 0, "IMAGE"],
[269, 142, 0, 141, 0, "IMAGE"],
[270, 136, 0, 142, 0, "IMAGE"],
[271, 141, 0, 105, 3, "INT"],
[272, 141, 1, 105, 4, "INT"],
[275, 144, 0, 105, 1, "IMAGE"],
]
assert ns[136]["mode"] == 0 and ns[144]["mode"] == 4
assert (
ns[136]["widgets_values"] == ns[144]["widgets_values"] == ["red_line_barrier.png", "image"]
)
assert ns[136]["outputs"][1]["links"] is None and ns[144]["outputs"][1]["links"] is None
assert (
ns[141]["outputs"][0]["links"] == [271]
and ns[141]["outputs"][1]["links"] == [272]
and ns[141]["outputs"][2]["links"] is None
)
assert (
ns[142]["widgets_values"] == ["nearest-exact", 0.4, 32]
and ns[142]["inputs"][0]["link"] == 270
)
assert ins[15]["widgets_values"] == [1, "fixed"]
edges = {
e["id"]: (e["origin_id"], e["origin_slot"], e["target_id"], e["target_slot"])
for e in d["links"]
}
expected = {
274: (6, 0, 143, 0),
273: (143, 0, 128, 0),
249: (128, 0, 127, 0),
266: (127, 0, 9, 0),
267: (127, 0, 16, 0),
258: (-10, 11, 128, 1),
188: (104, 1, 14, 4),
225: (14, 0, 10, 0),
226: (14, 0, 23, 0),
199: (107, 1, 104, 7),
}
assert all(edges[k] == v for k, v in expected.items())
assert ins[91]["widgets_values"] == [24, "auto", "sRGB", "none"] and ns[92][
"widgets_values"
] == ["video/MiniMax_H3", "auto", "auto", "auto"]
assert ins[143]["widgets_values"] == [10, 3] and ins[128]["widgets_values"] == [
"comfy kitchen attention"
]
assert ins[127]["widgets_values"] == [
"vsa",
10,
0.2,
1,
"",
12288,
256,
"exact_kv_and_rows",
False,
]
assert ins[107]["inputs"][1]["link"] is None and all(
ins[107]["outputs"][i]["links"] is None for i in [0, 2]
)
assert ins[111]["widgets_values"] == [2] and type(ins[111]["widgets_values"][0]) is int
unknown = {"136", "144", "105:127", "105:128", "105:143"}
assert {b["node_id"] for b in block["node_bindings"] if b["source_id"] == "unknown"} == unknown
assert (
sum(
b["source_id"] == "core0330" and len(b["candidates"]) == 1
for b in block["node_bindings"]
)
== 18
)
for n in [ns[136], ns[144], ins[127], ins[128], ins[143]]:
assert all(k not in n["properties"] for k in ["cnr_id", "aux_id", "ver"])
for f in block["fields"]:
if f["node_id"] in unknown:
assert "未知" in f["unit"] and "未知" in f["schema_default"] and "未知" in f["limits"]
assert next(n for n in inv["notes"] if n["node"] == 139)["text"].startswith("\n")
notes = {n["node"]: n for n in inv["notes"]}
for nid, count, lf, tail, sha in [
(139, 1319, 16, True, "309f6810d11feaadf4ee5a5cd5f5fb99b17f639383838cd631b283e8d2028585"),
(140, 1856, 43, True, "539cb7570ee93a331d1f85c2b17014c5dcc10ccf13f9f6d41a726cb154fee423"),
]:
n = notes[nid]
assert (n["characters"], n["lf_count"], n["ends_with_lf"], n["literal_backslash_n"]) == (
count,
lf,
tail,
0,
)
assert hashlib.sha256(n["text"].encode()).hexdigest() == sha
for text, count, lf, sha in [
(
ns[105]["widgets_values"][0],
6285,
5,
"f65182c0307e70a67c352d147505b76b7585a73181b2f150ef0d30e645549fb3",
),
(
ins[104]["widgets_values"][0],
980,
12,
"21953b89529474d17901875cb7f5d5120c406dfbd680c88065f9b672c2f326d9",
),
]:
assert (
len(text) == count
and text.count("\n") == lf
and text.count("\\n") == 0
and not text.endswith("\n")
)
assert hashlib.sha256(text.encode()).hexdigest() == sha
(OUT / "source-check.json").write_text(
json.dumps(
dict(
files=checks,
positions=56,
standard_notes=2,
edges_including_boundary=41,
accurate_implementation_nodes=18,
unknown_nodes=sorted(unknown),
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("PASS56 paired fields,2 notes,41 edges;18 exact core nodes/5 identity gaps")
if __name__ == "__main__":
main()