Files
aigc-home/docs/hel-892/r2v-skills-document-evidence/verify_sources.py
T
2026-11-01 14:49:41 +08:00

245 lines
11 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 ast
import collections
import hashlib
import json
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"] == "soundflow":
proof = "本轮规范身份与准确提交API请求原记录,未取得类,不作为接口实现"
elif "member_crc32" in e:
import zlib
members = json.loads((REF / "vhspkg-members.json").read_bytes())
member = next(m for m in members if m["name"] == e["file"])
assert e["member_crc32"] == member["crc"] == zlib.crc32(raw)
assert member["size"] == len(raw) and e["tag"] == "1.7.9"
reg = json.loads((REF / "vhs-version-registry-response.json").read_bytes())
assert reg["version"] == e["tag"] and reg["downloadUrl"] == e["url"]
assert e["package_sha256"] == "unknown-not-downloaded-whole-archive"
proof = "准确1.7.9发布身份/Range必要成员SHA与CRC;整包SHA和Git绑定未知"
elif e["id"] == "llama-unavailable":
proof = "准确20571提交不可得的有界调查原记录,仅缺口,不作为schema实现"
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))
from build_definition import PATHS, REPO
assert inv["sha256"] == "4c1305fdfe6d5643e64a7b6c99cc92e331ffc9475f30fef5e0119c887367aab0"
assert len(inv["fields"]) == 81 and len(inv["notes"]) == 3
sc = inv["scopes"][0]
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (28, 35, 24)
assert collections.Counter(sc["modes"]) == {0: 27, 4: 1}
assert collections.Counter(f["json_type"] for f in inv["fields"]) == dict(
str=41, int=29, float=6, bool=5
)
assert len(inv["empty"]) == 5 and sum(x["state"] == "missing" for x in inv["empty"]) == 4
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"])
g = json.loads((REPO / PATHS[0]).read_bytes())
ns = {n["id"]: n for n in g["nodes"]}
assert (
not g.get("definitions", {}).get("subgraphs") and g["extra"]["frontendVersion"] == "1.51.9"
)
assert g["links"] == json.loads((OUT / "expected-edges.json").read_bytes())
for eid, src, si, dst, di, typ in g["links"]:
assert eid in ns[src]["outputs"][si]["links"] and ns[dst]["inputs"][di]["link"] == eid
def inp(n, key):
return next(i for i in ns[n]["inputs"] if i["name"] == key)
assert ns[164]["mode"] == 4 and ns[150]["mode"] == 0
assert [inp(136, k)["link"] for k in ["ref_images.ref_image_0", "ref_images.ref_image_1"]] == [
297,
333,
]
assert inp(224, "latent_image")["link"] == 419 and inp(224, "model_hires")["link"] is None
assert inp(156, "duration")["link"] is None and inp(136, "prompt")["link"] == 342
assert [o["links"] for o in ns[131]["outputs"]] == [[], [275, 303], []]
assert inp(131, "values.b")["link"] is None
assert ns[224]["widgets_values"][:4] == [999, "fixed", 1, 4]
assert ns[156]["widgets_values"][7:9] == [112090405387938, "randomize"]
assert ns[194]["widgets_values"] == [24, 8, "sRGB", "none"]
assert ns[217]["widgets_values"] == ["video/MiniMaxH3", "auto", "auto", "auto"]
assert ns[217]["outputs"][0]["links"] is None
assert [inp(153, k)["link"] for k in ["vae", "audio_vae"]] == [None, None]
expected = {
117: (1964, 43, True, "afe756a7a7bcd5452d83bde21725c446377e9be9b1556516616c170ec20a7284"),
140: (325, 10, False, "6f8bb9786e44748d969c27aef1e37f53c47016f724bb33daa788a94c2a47143b"),
116: (2473, 26, False, "c5ae05e6eff86a704ca371deb45e1bf33cccb35fb37c75008b2416225fb87198"),
}
notes = []
for nid, (chars, lf, tail, digest) in expected.items():
raw = ns[nid]["widgets_values"][0]
assert (
len(raw),
raw.count("\r"),
raw.count("\n"),
raw.endswith("\n"),
raw.count("\\n"),
hashlib.sha256(raw.encode()).hexdigest(),
) == (chars, 0, lf, tail, 0, digest)
notes.append(
dict(node=str(nid), characters=chars, LF=lf, CR=0, tail_LF=tail, sha256=digest)
)
assert len(block["node_bindings"]) == 25 and all(
len(b["candidates"]) == 1 for b in block["node_bindings"]
)
def rawfile(id, file):
return (
REF / next(e["local_file"] for e in rows if e["id"] == id and e["file"] == file)
).read_text()
assert '"ModelPreviewOverrideKJ": {"class": ModelPreviewOverrideKJ' in rawfile(
"kj", "__init__.py"
)
assert "MiniMaxH3MemoryEfficientSageAttentionPatch" in rawfile("kj", "__init__.py")
tree = ast.parse(rawfile("kj", "nodes/preview_override_node.py"))
preview = next(
x for x in tree.body if isinstance(x, ast.ClassDef) and x.name == "ModelPreviewOverrideKJ"
)
assert "audio_vae" not in ast.unparse(preview)
assert "optional=True" in ast.unparse(preview)
assert "class QwenH3Prompt(" in rawfile(
"qwen", "node.py"
) and "QwenH3PromptExtension" in rawfile("qwen", "__init__.py")
assert '"H3SigmaRefiner": H3SigmaRefiner' in rawfile("sigma", "py/h3_sigma_refiner.py")
for id, file, token in [
("core0330", "comfy_extras/nodes_minimax_h3.py", "return ["),
("core0345", "comfy_extras/nodes_video.py", "SaveVideo"),
("core0350", "comfy_extras/nodes_sparse_attention.py", "return [BlockSparseAttention]"),
]:
assert token in rawfile(id, file)
for f in block["fields"]:
if f["node_id"] == "156" and f["field"] == "duration":
assert "int10" in f["limits"] and "外线110" not in f["limits"]
(OUT / "source-check.json").write_text(
json.dumps(
dict(
checks=checks,
notes=notes,
accurate=25,
unresolved=0,
unknown=0,
source_SHA=inv["sha256"],
edges=g["links"],
no_upstream_execution=True,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
(OUT / "identity-gaps.json").write_text(
json.dumps(
dict(
accurate_class_instances=25,
unknown_class_instances=0,
unresolved_classes=0,
interface_gaps=[
"153源audio_vae不在准确c986 schema/execute;vae为空,不能从后版补口",
"153额外preview保存空串没有准确后端字段",
"224末四切块保存项无准确后端schema",
"194第四codec=none没有准确0.34.0接口映射",
"217动态保存字符串与typed execute payload分列,未认证恢复",
],
licenses={
"sigma": "准确树无独立LICENSE;许可未知",
"selflift": "准确树许可状态沿首取记录,不认证模型许可",
},
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
"PASS 81 values, three complete notes, 35 physical edges, "
"25 exact classes; field gaps remain explicit"
)
if __name__ == "__main__":
main()