Files
aigc-home/docs/hel-892/director-replace-document-evidence/verify_sources.py
T
2026-11-01 10:50:03 +08:00

334 lines
13 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))
import collections
from build_definition import PATHS, REPO
assert inv["sha256"] == "dce57cfc239c9f90cda2107fff5614b2cb0944e0441d9d8137b3f1c325f41a7a"
assert len(inv["fields"]) == 53 and len(inv["notes"]) == 2
assert len(inv["scopes"]) == 1
sc = inv["scopes"][0]
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (27, 42, 22)
assert sc["modes"].count(0) == 26 and sc["modes"].count(4) == 1
assert {e["node"] for e in inv["empty"]} == {182, 181, 232, 214, 230} and 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"]
and f["scope"] == "root"
)
assert canonical(f["value"]) == canonical(x["value"]) == canonical(f["named_value"])
types = collections.Counter(x["json_type"] for x in inv["fields"])
assert types == dict(str=30, int=17, bool=4, NoneType=1, float=1)
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.23.0"
)
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"]} == {
479: [186, 0, 181, 1],
481: [187, 0, 182, 1],
485: [199, 0, 191, 0],
486: [181, 0, 191, 1],
487: [214, 3, 191, 2],
510: [182, 0, 199, 0],
515: [185, 0, 203, 0],
516: [187, 0, 203, 1],
517: [186, 0, 203, 2],
518: [212, 4, 203, 3],
519: [212, 5, 203, 4],
523: [214, 0, 203, 8],
524: [214, 1, 203, 9],
525: [212, 3, 203, 10],
531: [205, 0, 208, 0],
533: [210, 0, 208, 2],
535: [213, 0, 212, 0],
536: [213, 1, 212, 1],
537: [213, 2, 212, 2],
538: [213, 3, 212, 3],
539: [213, 0, 214, 0],
542: [183, 0, 215, 0],
543: [215, 0, 205, 0],
544: [215, 0, 208, 1],
575: [229, 0, 230, 0],
576: [232, 0, 230, 1],
577: [231, 1, 230, 2],
578: [231, 2, 230, 3],
579: [231, 0, 232, 0],
580: [203, 1, 230, 4],
581: [230, 1, 182, 0],
582: [230, 1, 181, 0],
584: [203, 0, 232, 1],
585: [203, 1, 231, 1],
586: [228, 0, 231, 0],
587: [204, 0, 229, 0],
588: [233, 0, 231, 2],
589: [208, 0, 228, 0],
593: [191, 0, 234, 1],
595: [212, 6, 203, 5],
596: [212, 6, 234, 0],
600: [212, 0, 203, 6],
}
assert ns[212]["outputs"][0]["links"] == [600] and ns[212]["outputs"][1]["links"] == []
assert (
ns[211]["widgets_values"] == ns[210]["widgets_values"] == [False]
and ns[211]["outputs"][0]["links"] == []
)
assert "links" not in ns[230]["outputs"][0] and ns[230]["outputs"][1]["links"] == [581, 582]
assert ns[233]["widgets_values"] == [8, "fixed"] and ns[233]["widgets_values_named"] == dict(
value=8, fixed="fixed"
)
assert ns[204]["widgets_values"] == [596023196572720, "fixed", None] and ns[229][
"widgets_values"
] == [0, "fixed"]
assert ns[231]["widgets_values"] == [6, 12, 3, "dual_clock_euler", "native_flow"]
assert ns[199]["mode"] == 4 and ns[199]["widgets_values"] == [
1920,
1920,
"nvidia_rtx_vsr",
"resize",
"0, 0, 0",
"center",
32,
"cpu",
]
raw = ns[213]["widgets_values"][-1]
state = json.loads(raw)
assert raw == ns[213]["widgets_values_named"]["track_data"]
assert (
len(raw),
raw.count("\r"),
raw.count("\n"),
raw.count("\\n"),
raw.endswith("\n"),
hashlib.sha256(raw.encode()).hexdigest(),
) == (
36884,
0,
0,
415,
False,
"5f12646222dce32f28a62b9f9c2e7f739c49cbf5934bf4d051c3714f20f61480",
)
keys = []
def scan(v, p=""):
if isinstance(v, dict):
for k, x in v.items():
if (
any(
t in k.lower()
for t in [
"api_key",
"apikey",
"authorization",
"access_token",
"password",
"secret",
]
)
and x
):
keys.append(p + "/" + k)
scan(x, p + "/" + k)
elif isinstance(v, list):
for i, x in enumerate(v):
scan(x, p + "/" + str(i))
scan(state)
assert not keys
assert state["muted"] is False and state["volume_db"] == 0 and type(state["volume_db"]) is int
assert len(state["task_markers"]) == 1 and state["task_markers"][0]["frame"] == 192
assert (
state["task_overview"] is False
and state["total_length"] == 360
and state["frame_rate"] == 24
)
assert [t["type"] for t in state["tracks"]] == ["task", "video"] and all(
len(t["segments"]) == 1
and t["segments"][0]["start_frame"] == 0
and t["segments"][0]["end_frame"] == 360
for t in state["tracks"]
)
note_hashes = {
237: (48, "0eda2ba7aeb48a72f2fe0557b5ce77b038c2c24336e98566ebe8a185c47444ef"),
238: (6, "a57b98fb2989a851996b90c93212e161c1c3de55af052f95d14d370e57578ef0"),
}
for nid, (length, digest) in note_hashes.items():
text = ns[nid]["widgets_values"][0]
assert len(text) == length and hashlib.sha256(text.encode()).hexdigest() == digest
assert (
text == ns[nid]["widgets_values_named"]["text"]
and "\n" not in text
and not ns[nid]["inputs"]
and not ns[nid]["outputs"]
)
compare = ns[234]["widgets_values"][0]
assert (
type(compare) is str
and len(compare) == 57
and compare == ns[234]["widgets_values_named"]["compare_video"]
)
assert (
json.loads(compare) == dict(save_output=False, filename_prefix="MiniMax/ComfyUI")
and not ns[234]["outputs"]
)
binds = block["node_bindings"]
assert len(binds) == 25 and all(len(e["candidates"]) == 1 for e in binds)
def text(key, file):
return (
REF / next(e["local_file"] for e in rows if e["id"] == key and e["file"] == file)
).read_text()
t8 = text("t8", "nodes.py")
cl = t8.split("class MiniMaxH3DualClockSamplerT8")[1].split("class MiniMaxH3AudioT8Extension")[
0
]
assert "sampler_name" not in cl and "scheduler" not in cl and "setup_dual_clock_sampling" in cl
assert "MiniMaxH3DualClockSamplerT8," in t8.split("class MiniMaxH3AudioT8Extension")[1]
assert "return patched_model, sampler, sigmas" in text("t8", "sampling.py")
sw = text("swap", "block_swap.py")
assert (
"return None, lambda: None, set()" in sw
and "mgr, cleanup, _dit_swap_names, _dit_all_swls = install_block_swap"
in text("swap", "uniblockswap_node.py")
)
cmp = text("mediaeditor", "nodes/video.py")
assert (
'return io.NodeOutput(ui={"compare_videos": [payload]})' in cmp
and 'settings.get("save_output") is True' in cmp
)
front = text("mediaeditor", "frontend/src/index.ts")
comp = text("mediaeditor", "frontend/src/components/widgets/compareVideoWidget.tsx")
assert "save_output: true" in front and "save_output: false" in comp
assert "widget.serializeValue = () => currentValue" in text(
"mediaeditor", "frontend/src/lib/create-react-widget.ts"
)
prim = text("core0300", "comfy_extras/nodes_primitive.py")
assert "control_after_generate=io.ControlAfterGenerate.fixed" in prim
assert "controlAfterGenerateName: name" in text("frontend", "src/scripts/widgets.ts")
for key, repo in [
("swap", "https://github.com/smthemex/ComfyUI_UniBlockSwap"),
("t8", "https://github.com/T8mars/comfyui-minimax-h3-audio-T8"),
]:
assert (
json.loads((REF / (key + "-registry-response.txt")).read_bytes())["repository"] == repo
)
result = dict(
sources=checks,
positions=53,
paired_positions=53,
list_types=types,
notes=2,
edges=42,
accurate_nodes=25,
unknown_identity_nodes=[],
track_raw_sha256=hashlib.sha256(raw.encode()).hexdigest(),
parsed_track_data=state,
compare_raw=compare,
compare_sha256=hashlib.sha256(compare.encode()).hexdigest(),
credential_keys_found=keys,
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(binds, ensure_ascii=False, indent=2) + "\n"
)
print("PASS53 positions/named,2Note,42edges,25exact,36884state/57compare; static only")
if __name__ == "__main__":
main()