Files
aigc-home/docs/hel-892/director-multi-document-evidence/verify_sources.py
T
2026-11-01 12:04:37 +08:00

382 lines
14 KiB
Python

"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"] == "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"] == "34fde3a91f9ef932adc2837cc9d4254bf75a3251ad5c6474d90e4085690cbafc"
assert len(inv["fields"]) == 65 and len(inv["notes"]) == 2 and len(inv["scopes"]) == 1
sc = inv["scopes"][0]
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (18, 14, 15)
assert sc["modes"].count(0) == 15 and sc["modes"].count(4) == 3
assert {x["node"]: x["state"] for x in inv["empty"]} == {
8: "empty_list",
22: "missing",
23: "missing",
16: "missing",
}
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=34, int=22, bool=8, 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"]} == {
25: [19, 0, 18, 2],
26: [16, 0, 20, 0],
30: [20, 0, 24, 0],
31: [3, 0, 24, 1],
32: [4, 0, 24, 2],
33: [2, 0, 24, 3],
35: [24, 0, 6, 0],
36: [24, 1, 6, 1],
37: [24, 2, 6, 2],
38: [24, 5, 8, 0],
39: [17, 0, 16, 0],
40: [1, 0, 17, 0],
9: [6, 0, 7, 0],
34: [18, 0, 24, 8],
}
assert ns[8]["widgets_values"] == [] and ns[8]["widgets_values_named"] == {}
assert all(
"widgets_values" not in ns[i] and "widgets_values_named" not in ns[i] for i in [16, 22, 23]
)
assert {n["id"] for n in g["nodes"] if n["mode"] == 4} == {18, 19, 21}
assert (
next(i for i in ns[21]["inputs"] if i["name"] == "model")["link"] is None
and ns[21]["outputs"][0]["links"] == []
)
assert all(o["links"] is None for o in ns[7]["outputs"])
assert [o["links"] for o in ns[18]["outputs"]] == [[34], None, None]
assert all(
next(i for i in ns[24]["inputs"] if i["name"] == name)["link"] is None
for name in [
"i2v_groups",
"r2v_groups",
"semantic_bridge",
"selflift",
"face_refine",
"sigmas",
]
)
assert all(
next(o for o in ns[24]["outputs"] if o["name"] == name)["links"] is None
for name in ["frame_count", "source_images", "images_pre_refine", "images_pre_face_refine"]
)
assert all(k not in ns[24]["properties"] for k in ["cnr_id", "aux_id", "ver"])
assert ns[18]["properties"]["aux_id"] == "AIMixer/ComfyUI_MiniMaxH3_Director"
assert ns[18]["widgets_values"] == [
"upscale",
"lanczos",
0.25,
"euler",
1,
"inherit",
0,
"fixed",
"跟随导演台",
1,
1184,
720,
False,
False,
2,
128,
2,
128,
]
named = ns[18]["widgets_values_named"]
assert (
type(named["latent_upscale_model"]) is float
and type(named["enable_latent_chunking"]) is int
and type(named["enable_tiling"]) is int
)
raw = ns[24]["widgets_values_named"]["timeline_data"]
state = json.loads(raw)
prompt = ns[24]["widgets_values_named"]["global_prompt"]
assert (
len(raw),
raw.count("\r"),
raw.count("\n"),
raw.count("\\n"),
raw.endswith("\n"),
hashlib.sha256(raw.encode()).hexdigest(),
) == (10086, 0, 0, 6, False, "1350e59eb583b624e7655ef88e924c7422ec4ed364e7cee67c31b11afef4ffe8")
assert (
len(prompt),
prompt.count("\n"),
prompt.endswith("\n"),
hashlib.sha256(prompt.encode()).hexdigest(),
) == (281, 3, False, "d12788791411536b69f9d7c75859e25d704a34bf46b2565f3d05fcd8c59afab1")
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", "auth", "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
expected_state = dict(
version=5,
editMode="segment",
totalFrames=372,
frameRate=24,
timelineMode="fl2v",
width=576,
height=736,
refMaxSize=736,
durationSec=15,
liveTaePreview=True,
batchDetailMode="solo",
)
assert all(type(state[k]) is type(v) and state[k] == v for k, v in expected_state.items())
notes = []
for nid, length, lf, digest in [
(14, 185, 7, "420e950b040c70f4dad19fc97b6098b5ce957beb549de8acca9725167f7cbd83"),
(13, 452, 16, "e72ca08679fd91e2b0185be81dfd558a2b59613540df74d4fa3e5ea6cdb8e938"),
]:
text = ns[nid]["widgets_values"][0]
assert text == ns[nid]["widgets_values_named"]["text"]
assert (
len(text) == length
and text.count("\n") == lf
and text.endswith("\n")
and hashlib.sha256(text.encode()).hexdigest() == digest
)
notes.append(dict(node_id=nid, characters=length, LF=lf, tail_LF=True, sha256=digest))
binds = block["node_bindings"]
assert (
len(binds) == 16
and sum(bool(x["candidates"]) for x in binds) == 13
and sum(x["source_id"] == "unknown" for x in binds) == 3
)
assert {x["node_id"] for x in binds if x["source_id"] == "unknown"} == {"24", "22", "23"}
assert next(x for x in binds if x["node_id"] == "18")["source_id"] == "director"
def text(key, file):
return (
REF / next(e["local_file"] for e in rows if e["id"] == key and e["file"] == file)
).read_text()
refine = next(
n
for n in ast.parse(text("director", "nodes/director_refine.py")).body
if isinstance(n, ast.ClassDef) and n.name == "MiniMaxH3DirectorRefine"
)
schema = {
k.value: ast.unparse(v)
for d in ast.walk(refine)
if isinstance(d, ast.Dict)
for k, v in zip(d.keys, d.values, strict=True)
if isinstance(k, ast.Constant) and isinstance(k.value, str) and isinstance(v, ast.Tuple)
}
assert all(
k not in schema
for k in [
"seed",
"control_after_generate",
"confirm_first_pass",
"enable_latent_chunking",
"enable_tiling",
"tile_count",
"tile_overlap",
]
)
assert "list_h3_latent_upscale_models()" in schema["latent_upscale_model"]
pack = next(n for n in refine.body if isinstance(n, ast.FunctionDef) and n.name == "pack")
assert any(
isinstance(n, ast.Delete)
and any(isinstance(t, ast.Name) and t.id == "kwargs" for t in n.targets)
for n in ast.walk(pack)
)
assert '"MiniMaxH3DirectorRefine": MiniMaxH3DirectorRefine' in text("director", "__init__.py")
assert "MAX_REFINE_PASSES = 9999" in text("director", "director/refine_pack.py")
assert "DEFAULT_UPSCALE_MEGAPIXELS = 1.0" in text("director", "director/refine_pack.py")
assert (
'"minimax"'
in text("core0332", "nodes.py")
.split("class CLIPLoader:")[1]
.split("class DualCLIPLoader:")[0]
)
kj = text("kj", "nodes/ltxv_nodes.py")
cl = next(
n
for n in ast.parse(kj).body
if isinstance(n, ast.ClassDef) and n.name == "MiniMaxH3MemoryEfficientSageAttentionPatch"
)
assert (
"_cuda_archs is None" in ast.unparse(cl)
and "_ck is None" in ast.unparse(cl)
and "diffusion_model.blocks." in ast.unparse(cl)
)
assert (
"v_pad_len = 128" in kj
and "sm120" in kj
and "_quant_query_per_thread_int8_i64_kernel" in kj
)
assert "class PathchSageAttentionKJ" in text("kj", "nodes/model_optimization_nodes.py")
result = dict(
sources=checks,
positions=65,
paired_positions=65,
list_types=types,
notes=notes,
edges=14,
accurate_nodes=13,
unknown_identity_nodes=[x for x in binds if x["source_id"] == "unknown"],
timeline_raw_sha256=hashlib.sha256(raw.encode()).hexdigest(),
parsed_timeline_data=state,
prompt_sha256=hashlib.sha256(prompt.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"
)
(OUT / "refine-schema-differences.json").write_text(
json.dumps(
dict(
exact_commit="6ff79b4aa15d56055cfa61d915889867027c9ab1",
class_lines=[refine.lineno, refine.end_lineno],
pack_lines=[pack.lineno, pack.end_lineno],
extra_kwargs_deleted=True,
schema=schema,
saved=[
dict(
field=f["field"],
value=f["value"],
json_type=f["json_type"],
schema_present=f["field"] in schema,
source_type=f["type"],
limits=f["limits"],
)
for f in block["fields"]
if f["node_id"] == "18"
],
main24_still_unbound=True,
upstream_executed=False,
),
ensure_ascii=False,
indent=2,
)
+ "\n"
)
print(
"PASS65 positions/named,2MarkdownNotes,14edges,13exact/3unknown,"
"timeline10086/prompt281; static only"
)
if __name__ == "__main__":
main()