Files
aigc-home/docs/hel-892/gh-multi-document-evidence/verify_sources.py
T
2026-11-01 08:58:01 +08:00

336 lines
13 KiB
Python

"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"]
import re
prior_members = set(
re.findall(r"^SAVED (\S+) \d+$", (OUT / "art-gh-multi-second.txt").read_text(), re.M)
)
range_members = [
m for m in json.loads((REF / "art-members.json").read_bytes()) if m.get("saved")
]
range_logs = json.loads((REF / "art-range-requests.json").read_bytes())
assert len(prior_members) == 5 and len(range_members) == 8
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:
reg = json.loads((REF / "art-version.txt").read_bytes())
member = next(
m
for m in json.loads((REF / "art-members.json").read_bytes())
if m["name"] == e["file"]
)
assert reg["version"] == e["tag"] == "1.1.4"
assert member["saved"] and member["crc"] == e["member_crc32"] == zlib.crc32(raw)
assert member["sha256"] == e["sha256"]
assert e["package_sha256"].startswith("unknown")
index = next(i for i, m in enumerate(range_members) if m["name"] == e["file"])
assert e["reverified_at"] == range_logs[2 + 2 * index]["time"]
if e["file"] in prior_members:
assert e["acquisition_time"].startswith("未知:")
else:
assert e["acquisition_time"] == range_logs[2 + 2 * index]["time"]
proof = "准确1.1.4发布必要成员SHA/CRC与HTTP206中央目录;Git/整包SHA未知"
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"] == "827f43d5d9bdb6f2d6f4d8b69e86708e6d08642ed0df04bee15087d10b9a0e35"
assert len(inv["fields"]) == 106 and not inv["notes"] and len(inv["scopes"]) == 1
scope = inv["scopes"][0]
assert (scope["nodes"], scope["edges"], scope["named_nodes"]) == (35, 44, 28)
assert scope["modes"] == [0] * 35
assert {e["node"] for e in inv["empty"]} == {8, 111, 127, 10, 17, 124, 208}
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 sum("named_pointer" in f for f in block["fields"]) == 106
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.49.6"
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
expected = {
9: [9, 0, 10, 0],
10: [8, 0, 10, 1],
140: [120, 0, 12, 0],
141: [102, 0, 121, 0],
142: [122, 0, 12, 1],
144: [118, 0, 124, 0],
145: [124, 0, 8, 1],
147: [124, 1, 10, 4],
151: [124, 5, 102, 0],
152: [124, 6, 102, 2],
156: [124, 1, 126, 1],
157: [126, 0, 8, 0],
158: [126, 1, 10, 2],
161: [124, 2, 127, 1],
162: [124, 3, 127, 2],
163: [127, 0, 119, 0],
166: [17, 0, 126, 0],
180: [185, 0, 117, 0],
186: [126, 2, 187, 0],
230: [10, 1, 127, 0],
238: [127, 1, 102, 1],
263: [124, 2, 208, 1],
264: [124, 3, 208, 2],
266: [9, 0, 210, 0],
267: [8, 0, 210, 1],
268: [126, 1, 210, 2],
269: [187, 1, 210, 3],
277: [126, 2, 10, 3],
282: [210, 0, 208, 0],
291: [224, 0, 207, 1],
296: [223, 0, 232, 0],
300: [232, 0, 207, 0],
301: [232, 1, 207, 9],
302: [228, 0, 235, 0],
312: [244, 0, 210, 4],
331: [208, 0, 252, 0],
344: [252, 0, 222, 0],
362: [243, 0, 17, 0],
363: [78, 0, 264, 0],
364: [242, 0, 264, 1],
365: [264, 0, 243, 0],
366: [124, 4, 264, 2],
311: [10, 1, 244, 0],
367: [236, 0, 244, 3],
}
assert {e[0]: e[1:5] for e in g["links"]} == expected
assert (
ns[185]["inputs"][0]["name"] == "prompt_override" and ns[185]["inputs"][0]["link"] is None
)
assert len(ns[185]["widgets_values"]) == len(ns[185]["widgets_values_named"]) == 34
assert all(i.get("link") is None for i in ns[185]["inputs"])
prompt, state_raw = ns[185]["widgets_values"][7], ns[185]["widgets_values"][32]
expected_texts = [
(
prompt,
1895,
38,
38,
0,
0,
"10b6fcc0786d1724a1f075b08dc9488824d83334d7ef74b3934a64ee004f3422",
),
(
state_raw,
12759,
0,
0,
89,
76,
"f69102a83b465078275901642a991a6d696e151f87e15a8f23880fa319f62e90",
),
]
text_checks = []
for t, length, cr, lf, bn, br, sha in expected_texts:
assert (
len(t),
t.count("\r"),
t.count("\n"),
t.count("\\n"),
t.count("\\r"),
hashlib.sha256(t.encode()).hexdigest(),
) == (length, cr, lf, bn, br, sha)
assert not t.endswith("\n")
text_checks.append(
dict(
characters=length,
cr=cr,
lf=lf,
literal_backslash_n=bn,
literal_backslash_r=br,
sha256=sha,
)
)
state = json.loads(state_raw)
assert (
ns[185]["properties"]["gh_h3_state"]
== state_raw
== ns[185]["widgets_values_named"]["gh_state_json"]
)
assert ns[185]["widgets_values"][33] == ns[185]["widgets_values_named"]["gh_h3_panel"] == ""
assert state["mode"] == "text_keyframes" and state["media"] == state["vacantMediaSlots"] == []
assert (
state["prompt"] == state["prompts"]["text_keyframes"] == prompt
and state["prompts"]["all_reference"] == ""
)
op = state["optimizer"]
assert (
op["mode"] == "local"
and op["provider"] == "runninghub"
and op["read_media"] is True
and op["auto_optimize"] is False
)
assert (
op["has_api_key"] is False
and op["api_key"] == ""
and all(v == "" for v in op["api_keys"].values())
)
assert len(ns[111]["properties"]["text"]) == 25
assert not ns[111].get("widgets_values") and all(
k in ns[111]["properties"]
for k in ["fontSize", "fontColor", "stroke", "padding", "ue_properties"]
)
assert ns[10]["outputs"][0]["links"] == [] and ns[10]["outputs"][1]["links"] == [230, 311]
assert ns[210]["outputs"][0]["links"] == [282] and ns[210]["outputs"][1]["links"] == []
assert ns[187]["outputs"][0]["links"] == [] and ns[187]["outputs"][1]["links"] == [269]
assert ns[208]["outputs"][1]["links"] == []
assert ns[228]["widgets_values"] == [1.5, "float", None]
assert ns[244]["widgets_values"][2] == 2 and type(ns[244]["widgets_values"][2]) is int
import collections
types = collections.Counter(
f["json_type"] for f in inv["fields"] if isinstance(ns[f["node"]]["widgets_values"], list)
)
assert types == dict(str=55, int=21, bool=5, float=2, NoneType=1)
histories = []
for nid in [12, 207]:
v = ns[nid]["widgets_values"]
assert len(v) == 11 and v["save_metadata"] is False
assert ns[nid]["outputs"][0]["links"] is None
h = v["videopreview"]
assert h["params"]["score"] == 2 and type(h["params"]["score"]) is int
histories.append(
dict(
node=nid,
source_order_sha256=hashlib.sha256(
json.dumps(h, ensure_ascii=False, indent=2).encode()
).hexdigest(),
page_sorted_sha256=hashlib.sha256(
json.dumps(
json.loads(json.dumps(h, sort_keys=True)), ensure_ascii=False, indent=2
).encode()
).hexdigest(),
value=h,
)
)
assert (
ns[12]["widgets_values"]["save_output"] is True
and ns[207]["widgets_values"]["save_output"] is False
)
bind = {b["node_id"]: b for b in block["node_bindings"]}
assert sum(bool(b["candidates"]) for b in bind.values()) == 13
gh = [185, 124, 126, 127, 208, 210, 244]
assert all(
bind[str(n)]["source_id"] == "unknown" and bind[str(n)]["source_version"] == "未知"
for n in gh
)
assert all(bind[str(n)]["source_id"] == "unresolved-goohai" for n in [232, 228, 227])
assert bind["12"]["source_id"] == "vhs" and bind["207"]["source_id"] == "vhssecond"
assert bind["187"]["source_id"] == "core0311" and bind["252"]["source_id"] == "art"
assert all(bind[str(n)]["source_id"] == "easy" for n in [102, 264])
result = dict(
sources=checks,
positions=106,
paired_positions=106,
list_positions=84,
list_types=types,
dict_scalars=20,
complete_history_objects=2,
notes=0,
edges=44,
accurate_nodes=13,
unknown_identity_nodes=[b for b in bind.values() if b["source_id"] == "unknown"],
unresolved_nodes=[bind[str(n)] for n in [232, 228, 227]],
texts=text_checks,
histories=histories,
parsed_state=state,
custom_annotation=ns[111],
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("PASS106 positions/106 named/0Note/44edges;13 exact/19 unknown/3 unresolved")
if __name__ == "__main__":
main()