321 lines
12 KiB
Python
321 lines
12 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 "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"] == "c188a7383a6c7a0dbd5d4d0717527b096ec73c1232373ee50c731bceefcfe7fb"
|
|
assert len(inv["fields"]) == 81 and not inv["notes"] and len(inv["scopes"]) == 1
|
|
sc = inv["scopes"][0]
|
|
assert (sc["nodes"], sc["edges"], sc["named_nodes"]) == (52, 49, 46)
|
|
assert sc["modes"].count(0) == 51 and sc["modes"].count(4) == 1
|
|
assert {e["node"] for e in inv["empty"]} == {74, 80, 84, 107, 115, 116}
|
|
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"]
|
|
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=61, int=16, bool=3, NoneType=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.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"]} == {
|
|
135: [74, 0, 65, 0],
|
|
136: [66, 0, 67, 0],
|
|
137: [68, 0, 69, 0],
|
|
138: [70, 0, 71, 0],
|
|
139: [83, 0, 72, 0],
|
|
140: [72, 0, 73, 0],
|
|
141: [83, 0, 73, 1],
|
|
142: [93, 0, 73, 2],
|
|
143: [96, 0, 74, 0],
|
|
144: [78, 0, 74, 1],
|
|
145: [65, 0, 75, 0],
|
|
146: [80, 0, 75, 1],
|
|
147: [81, 0, 75, 2],
|
|
148: [96, 0, 80, 0],
|
|
149: [76, 0, 80, 1],
|
|
150: [82, 0, 83, 0],
|
|
151: [98, 0, 84, 0],
|
|
152: [73, 0, 90, 0],
|
|
153: [90, 0, 91, 0],
|
|
154: [92, 0, 96, 0],
|
|
155: [98, 0, 96, 1],
|
|
156: [84, 0, 96, 2],
|
|
157: [98, 1, 96, 3],
|
|
158: [97, 0, 96, 4],
|
|
159: [89, 0, 98, 0],
|
|
160: [88, 0, 98, 1],
|
|
161: [87, 0, 98, 2],
|
|
162: [86, 0, 98, 3],
|
|
163: [85, 0, 98, 4],
|
|
164: [95, 0, 98, 6],
|
|
165: [94, 0, 98, 8],
|
|
166: [77, 0, 98, 9],
|
|
167: [79, 0, 98, 10],
|
|
172: [100, 5, 101, 0],
|
|
173: [100, 3, 102, 0],
|
|
174: [100, 4, 103, 0],
|
|
175: [100, 1, 104, 0],
|
|
176: [107, 1, 105, 0],
|
|
177: [107, 0, 106, 0],
|
|
179: [107, 3, 108, 0],
|
|
180: [113, 0, 110, 0],
|
|
181: [100, 6, 111, 0],
|
|
182: [109, 0, 112, 0],
|
|
188: [63, 0, 107, 0],
|
|
189: [63, 0, 100, 0],
|
|
190: [63, 1, 100, 1],
|
|
191: [63, 2, 100, 2],
|
|
192: [63, 3, 100, 3],
|
|
193: [75, 0, 99, 0],
|
|
}
|
|
assert ns[100]["outputs"][0]["links"] == [] and ns[100]["outputs"][1]["links"] == [175]
|
|
assert ns[100]["outputs"][2]["links"] == [] and "links" not in ns[100]["outputs"][7]
|
|
assert ns[100]["outputs"][8]["links"] is None
|
|
assert next(i for i in ns[100]["inputs"] if i["name"] == "previous")["link"] is None
|
|
for name in ["videos", "mode"]:
|
|
assert next(i for i in ns[98]["inputs"] if i["name"] == name)["link"] is None
|
|
assert all("link" not in i for i in ns[63]["inputs"])
|
|
assert ns[96]["widgets_values"] == [304583185482826, "fixed", 8, 1, "euler", "beta", 1]
|
|
assert ns[113]["widgets_values"] == [0, "randomize", None] and ns[109]["widgets_values"] == [
|
|
False
|
|
]
|
|
assert ns[96]["outputs"][0]["links"] == [143, 148]
|
|
assert ns[65]["mode"] == 4 and ns[65]["widgets_values"] == [
|
|
1920,
|
|
1920,
|
|
"nvidia_rtx_vsr",
|
|
"resize",
|
|
"0, 0, 0",
|
|
"center",
|
|
32,
|
|
"cpu",
|
|
]
|
|
assert all("links" not in x for x in ns[99]["outputs"])
|
|
assert ns[63]["widgets_values"][:3] == ["832 x 480 (16:9)", "stretch", "MiniMax"]
|
|
raw = ns[63]["widgets_values"][3]
|
|
state = json.loads(raw)
|
|
assert raw == ns[63]["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(),
|
|
) == (
|
|
34752,
|
|
0,
|
|
0,
|
|
403,
|
|
False,
|
|
"80c7ff455784e048a03365a9bfe602bf86e06a14f5aff0eb6c5f16ed78220ded",
|
|
)
|
|
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
|
|
assert state["muted"] is False and type(state["volume_db"]) is int and state["volume_db"] == 0
|
|
assert (
|
|
state["total_length"] == 176
|
|
and state["frame_rate"] == 24
|
|
and state["task_markers"] == []
|
|
and state["task_overview"] is False
|
|
)
|
|
assert [t["type"] for t in state["tracks"]] == ["task", "video", "audio", "audio"]
|
|
assert [
|
|
[(s["start_frame"], s["end_frame"]) for s in t["segments"]] for t in state["tracks"]
|
|
] == [[(0, 120)], [], [(0, 120)], [(0, 176)]]
|
|
binds = block["node_bindings"]
|
|
assert (
|
|
len(binds) == 52
|
|
and sum(bool(x["candidates"]) for x in binds) == 21
|
|
and sum(x["source_id"] == "unknown" for x in binds) == 31
|
|
)
|
|
assert not any("MemoryEfficient" in x["class_type"] for x in binds)
|
|
assert all(
|
|
x["source_id"] == "unknown" and not x["candidates"]
|
|
for x in binds
|
|
if x["class_type"] in ["SetNode", "GetNode", "Label (rgthree)"]
|
|
)
|
|
|
|
def text(key, file):
|
|
return (
|
|
REF / next(e["local_file"] for e in rows if e["id"] == key and e["file"] == file)
|
|
).read_text()
|
|
|
|
ed = text("mediaeditor", "nodes/basic.py")
|
|
tree = ast.parse(ed)
|
|
classes = {n.name: n for n in tree.body if isinstance(n, ast.ClassDef)}
|
|
methods = {
|
|
k: next(
|
|
n for n in classes[k].body if isinstance(n, ast.FunctionDef) and n.name == "execute"
|
|
)
|
|
for k in ["MultiTrackEditor", "TimelineEditor"]
|
|
}
|
|
ast_evidence = {}
|
|
for k, m in methods.items():
|
|
names = [n for n in ast.walk(m) if isinstance(n, ast.Name) and n.id == "prompt_override"]
|
|
calls = [
|
|
n
|
|
for n in ast.walk(m)
|
|
if isinstance(n, ast.Call)
|
|
and isinstance(n.func, ast.Name)
|
|
and n.func.id in {"_parse_override_segments", "_build_tracks_info_and_media_outputs"}
|
|
]
|
|
ast_evidence[k] = dict(
|
|
lines=[m.lineno, m.end_lineno],
|
|
Store=sum(isinstance(n.ctx, ast.Store) for n in names),
|
|
Load=sum(isinstance(n.ctx, ast.Load) for n in names),
|
|
calls=[
|
|
dict(callee=c.func.id, line=c.lineno, text=ast.get_source_segment(ed, c))
|
|
for c in calls
|
|
],
|
|
)
|
|
assert (
|
|
ast_evidence["MultiTrackEditor"]["Store"] == 1
|
|
and ast_evidence["MultiTrackEditor"]["Load"] == 0
|
|
)
|
|
assert all(
|
|
"prompt_override" not in c["text"] for c in ast_evidence["MultiTrackEditor"]["calls"]
|
|
)
|
|
assert any(
|
|
c["callee"] == "_parse_override_segments" for c in ast_evidence["TimelineEditor"]["calls"]
|
|
)
|
|
assert 'tooltip="If provided, overrides all segment prompts in the timeline."' in ed
|
|
assert "return None, lambda: None, set()" in text("swap", "block_swap.py")
|
|
task = (
|
|
text("mediaout", "nodes/basic.py").split("class MultiTrackTaskOutput")[1].split("class ")[0]
|
|
)
|
|
assert "previous" not in task and "LOCKED_AUDIO" not in task
|
|
assert json.loads(text("frontend", "package.json"))["version"] == "1.47.11"
|
|
assert "serialize" in text("frontend", "src/lib/litegraph/src/LGraphNode.ts")
|
|
result = dict(
|
|
sources=checks,
|
|
positions=81,
|
|
paired_positions=81,
|
|
list_types=types,
|
|
notes=0,
|
|
edges=49,
|
|
accurate_nodes=21,
|
|
unknown_identity_nodes=[e for e in binds if e["source_id"] == "unknown"],
|
|
track_raw_sha256=hashlib.sha256(raw.encode()).hexdigest(),
|
|
parsed_track_data=state,
|
|
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 / "method-ast.json").write_text(
|
|
json.dumps(
|
|
dict(
|
|
commit="74c6f8b64a86bd280061c20ed42cb067322e1822",
|
|
classes=ast_evidence,
|
|
upstream_executed=False,
|
|
),
|
|
ensure_ascii=False,
|
|
indent=2,
|
|
)
|
|
+ "\n"
|
|
)
|
|
print("PASS81 positions/named,zero Note,49edges,21exact/31unknown,34752state; static only")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|