189 lines
7.0 KiB
Python
189 lines
7.0 KiB
Python
"""Audit original declarations and exact references; no plugin or media execution."""
|
|
|
|
import hashlib
|
|
import json
|
|
from collections import Counter
|
|
|
|
from build_definition import EXPECTED, OUT, PATHS, REPO, build
|
|
|
|
|
|
def string_record(nid, field, value):
|
|
return dict(
|
|
node_id=nid,
|
|
field=field,
|
|
characters=len(value),
|
|
LF=value.count("\n"),
|
|
CR=value.count("\r"),
|
|
tail_LF=value.endswith("\n"),
|
|
tail_space=value.endswith(" "),
|
|
sha256=hashlib.sha256(value.encode()).hexdigest(),
|
|
)
|
|
|
|
|
|
def main():
|
|
raw = (REPO / PATHS[0]).read_bytes()
|
|
assert hashlib.sha256(raw).hexdigest() == EXPECTED
|
|
graph, block = json.loads(raw), build()
|
|
assert len(graph) == len(block["node_bindings"]) == 32
|
|
assert all(nid.isdecimal() for nid in graph)
|
|
assert all(set(n) == {"inputs", "class_type", "_meta"} for n in graph.values())
|
|
assert Counter(f["json_type"] for f in block["fields"]) == dict(
|
|
str=40, int=27, bool=6, float=1, NoneType=1
|
|
)
|
|
assert block["sources"] == block["comments"] == []
|
|
assert all(
|
|
n["scope"] == "root" and not n["implementation_verified"] for n in block["node_bindings"]
|
|
)
|
|
expected = {
|
|
"115": {"megapixels": ["6146", 0]},
|
|
"122": {"samples": ["125", 0], "vae": ["119", 0]},
|
|
"124": {"model": ["5960", 0]},
|
|
"125": {
|
|
"noise": ["129", 0],
|
|
"guider": ["126", 0],
|
|
"sampler": ["123", 0],
|
|
"sigmas": ["124", 0],
|
|
"latent_image": ["6187", 1],
|
|
},
|
|
"126": {"model": ["5960", 0], "conditioning": ["6187", 0]},
|
|
"131": {"values.a": ["132", 0]},
|
|
"142": {"model": ["6126", 0]},
|
|
"5959": {"model": ["127", 0]},
|
|
"5960": {"model": ["142", 0]},
|
|
"6090": {"image": ["6147", 0]},
|
|
"6091": {"image": ["6148", 0]},
|
|
"6110": {"frame_rate": ["5650", 0], "images": ["122", 0], "audio": ["6193", 0]},
|
|
"6126": {"model": ["5959", 0]},
|
|
"6127": {"string_b": ["138", 0]},
|
|
"6187": {
|
|
"prompt": ["6127", 0],
|
|
"length": ["131", 1],
|
|
"clip": ["128", 0],
|
|
"vae": ["119", 0],
|
|
"context_latent": ["6190", 0],
|
|
"audio_vae": ["120", 0],
|
|
"ref_images": ["6188", 0],
|
|
},
|
|
"6188": {"image_1": ["6090", 0], "image_2": ["6091", 0]},
|
|
"6190": {
|
|
"vae": ["119", 0],
|
|
"images": ["6192", 0],
|
|
"audio_vae": ["120", 0],
|
|
"audio": ["6191", 2],
|
|
},
|
|
"6192": {"width": ["115", 0], "height": ["115", 1], "image": ["6191", 0]},
|
|
"6193": {"samples": ["125", 0], "vae": ["120", 0]},
|
|
}
|
|
references = {
|
|
nid: {k: v for k, v in n["inputs"].items() if isinstance(v, list)}
|
|
for nid, n in graph.items()
|
|
}
|
|
references = {nid: ports for nid, ports in references.items() if ports}
|
|
assert references == expected and sum(len(p) for p in expected.values()) == 40
|
|
assert set(graph["6187"]["inputs"]) == {
|
|
"prompt",
|
|
"length",
|
|
"context_frames",
|
|
"pin_last_frame",
|
|
"ref_image_size",
|
|
"clip",
|
|
"vae",
|
|
"context_latent",
|
|
"audio_vae",
|
|
"ref_images",
|
|
}
|
|
assert graph["6188"]["inputs"]["Update inputs"] is None
|
|
assert graph["6188"]["inputs"]["inputcount"] == 2
|
|
for nid in ("6090", "6091"):
|
|
assert type(graph[nid]["inputs"]["width"]) is int
|
|
assert graph[nid]["inputs"]["width"] == graph[nid]["inputs"]["height"] == 1024
|
|
assert type(graph["132"]["inputs"]["value"]) is int and graph["132"]["inputs"]["value"] == 12
|
|
assert type(graph["5650"]["inputs"]["value"]) is int and graph["5650"]["inputs"]["value"] == 24
|
|
assert (
|
|
type(graph["6146"]["inputs"]["value"]) is float and graph["6146"]["inputs"]["value"] == 0.7
|
|
)
|
|
assert graph["6110"]["inputs"]["save_output"] is True
|
|
fixed_strings = [
|
|
(
|
|
"6127",
|
|
"string_a",
|
|
33,
|
|
"5038c7802127f45218e32393cb071cdab38677bb92bdf5e305fad2bd9fa4cac3",
|
|
),
|
|
("6147", "image", 20, "68f9e7ec817e6133cd258daa6609091f4fac12852825891e60e15d259e280d3d"),
|
|
("6148", "image", 20, "68f9e7ec817e6133cd258daa6609091f4fac12852825891e60e15d259e280d3d"),
|
|
("6191", "video", 30, "0cef473d68a8b5a70183dcd8d369fc7e0f78866dca4d696ec4514db5fe57a179"),
|
|
(
|
|
"131",
|
|
"expression",
|
|
63,
|
|
"3624220e274fac45b4d3e93c698d632d0aa4e9abd949450f18e6aec63904acd9",
|
|
),
|
|
]
|
|
for nid in ("6090", "6091", "6192"):
|
|
fixed_strings.append(
|
|
(
|
|
nid,
|
|
"pad_color",
|
|
7,
|
|
"3ac9e93b30803d39c0852f53da1a76a3f0675dc4a38b257c6794cd00a239e964",
|
|
)
|
|
)
|
|
strings = []
|
|
for nid, key, length, digest in fixed_strings:
|
|
value = graph[nid]["inputs"][key]
|
|
assert len(value) == length and hashlib.sha256(value.encode()).hexdigest() == digest
|
|
strings.append(string_record(nid, key, value))
|
|
assert graph["6127"]["inputs"]["string_a"] == "r34i1sm , ultra realistic video. "
|
|
assert graph["6127"]["inputs"]["delimiter"] == " " and graph["138"]["inputs"]["value"] == ""
|
|
strings += [string_record("6127", "delimiter", " "), string_record("138", "value", "")]
|
|
models = [
|
|
string_record(f["node_id"], f["field"], f["value"])
|
|
for f in block["fields"]
|
|
if f["field"] in {"unet_name", "lora_name", "clip_name", "vae_name", "filename_prefix"}
|
|
]
|
|
samplers = [nid for nid, n in graph.items() if n["class_type"] == "SamplerCustomAdvanced"]
|
|
assert samplers == ["125"]
|
|
audit = dict(
|
|
path=PATHS[0],
|
|
sha256=EXPECTED,
|
|
original_bytes=len(raw),
|
|
source_nodes=32,
|
|
saved_inputs=75,
|
|
non_null_scalars=74,
|
|
saved_nulls=1,
|
|
complete_objects=0,
|
|
json_types=dict(Counter(f["json_type"] for f in block["fields"])),
|
|
references=block["api_references"],
|
|
node_identity_gaps=block["node_bindings"],
|
|
exact_implementation_sources=0,
|
|
original_fetch_time="unknown:未保留可证精确取得时刻",
|
|
strings=strings,
|
|
model_strings=models,
|
|
media_histories=0,
|
|
sampler_nodes=samplers,
|
|
null_inputs=[
|
|
dict(
|
|
node_id="6188",
|
|
field="Update inputs",
|
|
value=None,
|
|
pointer="/6188/inputs/Update inputs",
|
|
)
|
|
],
|
|
missing_inputs=[dict(node_id="6187", state="原未保存宽高/首尾帧/额外参考口,不补值")],
|
|
expressions=[
|
|
dict(
|
|
node_id="131",
|
|
field="expression",
|
|
value=graph["131"]["inputs"]["expression"],
|
|
sha256=fixed_strings[4][3],
|
|
)
|
|
],
|
|
)
|
|
(OUT / "original-audit.json").write_text(json.dumps(audit, ensure_ascii=False, indent=2) + "\n")
|
|
print("PASS original32 / saved75 incl null / references40 independently checked / source0")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|