Files
aigc-home/docs/hel-892/director-one-document-evidence/verify_sources.py
T
2026-11-01 09:20:09 +08:00

317 lines
12 KiB
Python

"Verify exact text, Git/package provenance and source graph without upstream imports."
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"] == "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))
assert inv["sha256"] == "526986a02875bbefebeb8a81cce9b58a8e764ab0c0092b2d8e858ecfac771638"
assert len(inv["fields"]) == 89 and not inv["notes"] and len(inv["scopes"]) == 1
scope = inv["scopes"][0]
assert (scope["nodes"], scope["edges"], scope["named_nodes"]) == (56, 54, 51)
assert scope["modes"] == [0] * 56
assert {e["node"] for e in inv["empty"]} == {62, 67, 70, 98, 105}
assert all(e["state"] == "missing" for e in inv["empty"])
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"])
assert f["scope"] == "root" and f["named_pointer"]
from build_definition import PATHS, REPO
g = json.loads((REPO / PATHS[0]).read_bytes())
ns = {n["id"]: n for n in g["nodes"]}
assert g["extra"]["frontendVersion"] == "1.47.11"
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
assert {e[0]: e[1:5] for e in g["links"]} == {
37: [21, 0, 25, 0],
38: [25, 1, 23, 1],
109: [62, 0, 53, 0],
110: [54, 0, 55, 0],
111: [56, 0, 57, 0],
112: [58, 0, 59, 0],
113: [84, 0, 60, 0],
114: [60, 0, 61, 0],
115: [84, 0, 61, 1],
116: [79, 0, 61, 2],
117: [82, 0, 62, 0],
118: [65, 0, 62, 1],
119: [82, 0, 67, 0],
120: [63, 0, 67, 1],
121: [85, 0, 70, 0],
122: [61, 0, 76, 0],
123: [76, 0, 77, 0],
124: [78, 0, 82, 0],
125: [85, 0, 82, 1],
126: [70, 0, 82, 2],
127: [85, 1, 82, 3],
128: [83, 0, 82, 4],
129: [69, 0, 84, 0],
130: [75, 0, 85, 0],
131: [74, 0, 85, 1],
132: [73, 0, 85, 2],
133: [72, 0, 85, 3],
134: [71, 0, 85, 4],
135: [81, 0, 85, 6],
136: [80, 0, 85, 8],
137: [64, 0, 85, 9],
138: [66, 0, 85, 10],
139: [100, 5, 86, 0],
140: [100, 3, 87, 0],
141: [100, 4, 88, 0],
142: [100, 1, 89, 0],
143: [98, 1, 90, 0],
144: [98, 0, 91, 0],
145: [98, 3, 92, 0],
146: [96, 0, 94, 0],
147: [100, 6, 95, 0],
148: [102, 0, 97, 0],
150: [93, 0, 99, 0],
155: [53, 0, 102, 0],
156: [67, 0, 102, 1],
157: [68, 0, 102, 2],
158: [41, 0, 98, 0],
159: [41, 0, 100, 0],
160: [41, 1, 100, 1],
161: [41, 2, 100, 2],
162: [41, 3, 100, 3],
163: [100, 2, 103, 0],
165: [23, 1, 85, 7],
170: [104, 0, 21, 1],
}
import collections
types = collections.Counter(f["json_type"] for f in inv["fields"])
assert types == dict(str=66, int=18, bool=4, NoneType=1)
raw = ns[41]["widgets_values"][3]
assert (
len(raw),
raw.count("\r"),
raw.count("\n"),
raw.count("\\n"),
raw.endswith("\n"),
hashlib.sha256(raw.encode()).hexdigest(),
) == (
33909,
0,
0,
393,
False,
"f0211b1d8337905469ad76c940d9018a4e58b584a5c5af66e435ce53e4c05f64",
)
state = json.loads(raw)
assert raw == ns[41]["widgets_values_named"]["track_data"]
assert state["muted"] is False and state["volume_db"] == 0 and type(state["volume_db"]) is int
assert (
state["task_markers"] == []
and state["task_overview"] is False
and state["total_length"] == 120
and state["frame_rate"] == 24
)
tracks = state["tracks"]
assert len(tracks) == 2 and tracks[0]["type"] == "task" and tracks[1]["type"] == "video"
assert len(tracks[0]["segments"]) == 1 and tracks[1]["segments"] == []
seg = tracks[0]["segments"][0]
assert seg["start_frame"] == 0 and seg["end_frame"] == 120
keys = []
def scan(v):
if isinstance(v, dict):
for k, x in v.items():
if k.lower() in {
"api_key",
"api_keys",
"authorization",
"access_token",
"password",
"secret",
}:
keys.append(k)
scan(x)
elif isinstance(v, list):
for x in v:
scan(x)
scan(state)
assert not keys
prompt = ns[23]["widgets_values"][0]
assert len(prompt) == 22 and prompt.count("\n") == 1 and prompt.count("\\n") == 0
assert (
hashlib.sha256(prompt.encode()).hexdigest()
== "a5654902d033099782a64ae90cfbc3a7961fe4cbff9b2cf5249920f875c60a9c"
)
assert ns[93]["widgets_values"] == [False] and ns[93]["widgets_values_named"] == {
"value": False
}
assert ns[96]["widgets_values"] == [387782047472665, "randomize", None]
assert ns[23]["widgets_values"][3:] == ["", ""] and ns[23]["inputs"][3]["type"] == "BOOLEAN"
assert ns[53]["widgets_values"] == [
1920,
1920,
"nvidia_rtx_vsr",
"resize",
"0, 0, 0",
"center",
32,
"cpu",
]
assert ns[53]["inputs"][1]["link"] is None and all(
"links" not in x for x in ns[53]["outputs"][1:]
)
assert ns[85]["inputs"][5]["name"] == "videos" and ns[85]["inputs"][5]["link"] is None
assert ns[82]["outputs"][0]["links"] == [117, 119]
assert len(ns[97]["outputs"]) == 2 and all("links" not in x for x in ns[97]["outputs"])
assert (
ns[98]["outputs"][2].get("links", "missing") == "missing"
and ns[100]["outputs"][0]["links"] == []
)
bind = {b["node_id"]: b for b in block["node_bindings"]}
assert len(bind) == 56 and sum(bool(b["candidates"]) for b in bind.values()) == 24
assert sum(b["source_id"] == "unknown" for b in bind.values()) == 32
assert all(
b["source_id"] == "unknown"
for b in bind.values()
if b["class_type"] in ["SetNode", "GetNode", "Label (rgthree)"]
)
assert (
bind["41"]["source_id"] == "mediaeditor"
and bind["85"]["source_id"] == "media85"
and all(bind[str(n)]["source_id"] == "mediaout" for n in [98, 100])
)
def text(key, file):
e = next(e for e in rows if e["id"] == key and e["file"] == file)
return (REF / e["local_file"]).read_text()
clip = text("core0290", "nodes.py").split("class CLIPLoader:")[1].split("class ")[0]
assert (
'"minimax"' not in clip
and "getattr(comfy.sd.CLIPType, type.upper(), comfy.sd.CLIPType.STABLE_DIFFUSION)" in clip
)
assert (
"MINIMAX"
not in text("core0290", "comfy/sd.py").split("class CLIPType(Enum):")[1].split("class ")[0]
)
audio = (
text("core0290", "comfy_extras/nodes_audio.py")
.split("def vae_decode_audio(")[1]
.split("class VAEDecodeAudio")[0]
)
assert "unbind" not in audio and 'vae.decode(samples["samples"])' in audio
assert 'codec_name = codec["codec"]' in text("core0302", "comfy_extras/nodes_video.py")
assert "class easySeed:" in text(
"easy", "py/nodes/seed.py"
) and '"easy seed": easySeed' in text("easy", "py/nodes/seed.py")
result = dict(
sources=checks,
positions=89,
paired_positions=89,
list_types=types,
notes=0,
edges=54,
accurate_nodes=24,
unknown_identity_nodes=[b for b in bind.values() if b["source_id"] == "unknown"],
track_raw_sha256=hashlib.sha256(raw.encode()).hexdigest(),
parsed_track_data=state,
credential_keys_found=keys,
preread_correction={"93": "false, not true"},
schema_conflicts=[
"core029 minimax CLIP enum absent",
"audio no nested extraction",
"SaveVideo one data port and dynamic codec vs source two/string",
"promptLine BOOLEAN vs saved string",
],
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("PASS89 positions/89 named/0Note/54edges;24 exact/32 unknown; 93 false corrected")
if __name__ == "__main__":
main()