141 lines
5.0 KiB
Python
141 lines
5.0 KiB
Python
"Audit original API declarations and complete typed objects without implementation lookup."
|
||
|
||
import hashlib
|
||
import json
|
||
from collections import Counter
|
||
|
||
from build_definition import EXPECTED, OUT, PATHS, REPO, build, canonical
|
||
|
||
|
||
def typed(value):
|
||
if isinstance(value, dict):
|
||
return {key: typed(item) for key, item in value.items()}
|
||
if isinstance(value, list):
|
||
return [typed(item) for item in value]
|
||
return dict(json_type=type(value).__name__, value=value)
|
||
|
||
|
||
def main():
|
||
raw = (REPO / PATHS[0]).read_bytes()
|
||
assert hashlib.sha256(raw).hexdigest() == EXPECTED
|
||
graph, block = json.loads(raw), build()
|
||
types = Counter(f["json_type"] for f in block["fields"])
|
||
assert types == dict(str=38, int=22, bool=9, float=6, dict=2)
|
||
assert all(set(n) == {"inputs", "class_type", "_meta"} for n in graph.values())
|
||
assert len(graph) == len(block["node_bindings"]) == 57
|
||
assert block["sources"] == [] and all(
|
||
not n["implementation_verified"] and n["scope"] == "root" for n in block["node_bindings"]
|
||
)
|
||
assert set(graph["219"]["inputs"]) == {
|
||
"prompt",
|
||
"width",
|
||
"height",
|
||
"length",
|
||
"clip",
|
||
"vae",
|
||
"first_frame",
|
||
}
|
||
text = graph["6005"]["inputs"]["value"]
|
||
image_text = graph["6078"]["inputs"]["image"]
|
||
assert len(image_text) == 127 and image_text.startswith('"') and image_text.endswith('"')
|
||
assert image_text.count("\n") == 0 and not image_text.endswith("\n")
|
||
assert (
|
||
hashlib.sha256(image_text.encode()).hexdigest()
|
||
== "14fb088853337a9b11b04cd5df81b2249e6554a0cf76e7db1cd21f24c87f0f25"
|
||
)
|
||
assert graph["219"]["inputs"]["first_frame"] == ["6008", 0]
|
||
assert graph["6008"]["inputs"]["input"] == ["6078", 0]
|
||
assert graph["6008"]["inputs"]["resize_type.longer_size"] == ["115", 1]
|
||
assert len(text) == 2341 and text.count("\n") == 4 and not text.endswith("\n")
|
||
assert (
|
||
hashlib.sha256(text.encode()).hexdigest()
|
||
== "5014a4f10c36ce7e0fe2d43916148c9ed146275414e548669dea2e7a616167a2"
|
||
)
|
||
objects = []
|
||
for key in ("PowerLoraLoaderHeaderWidget", "lora_1"):
|
||
obj = graph["6010"]["inputs"][key]
|
||
objects.append(
|
||
dict(
|
||
node_id="6010",
|
||
field=key,
|
||
pointer="/6010/inputs/" + key,
|
||
value=obj,
|
||
nested_types=typed(obj),
|
||
canonical_sha256=hashlib.sha256(canonical(obj)).hexdigest(),
|
||
)
|
||
)
|
||
assert graph["6010"]["inputs"]["lora_1"]["on"] is True
|
||
assert type(graph["6010"]["inputs"]["lora_1"]["strength"]) is int
|
||
assert graph["6010"]["inputs"]["➕ Add Lora"] == ""
|
||
expressions = [
|
||
dict(
|
||
node_id=nid,
|
||
field=key,
|
||
value=graph[nid]["inputs"][key],
|
||
sha256=hashlib.sha256(graph[nid]["inputs"][key].encode()).hexdigest(),
|
||
)
|
||
for nid, key in [("220", "expression"), ("5974", "expression"), ("6061:4985", "sigmas")]
|
||
]
|
||
(OUT / "original-audit.json").write_text(
|
||
json.dumps(
|
||
dict(
|
||
path=PATHS[0],
|
||
sha256=EXPECTED,
|
||
original_bytes=len(raw),
|
||
source_nodes=57,
|
||
saved_inputs=77,
|
||
scalar_inputs=75,
|
||
complete_objects=2,
|
||
json_types=types,
|
||
references=block["api_references"],
|
||
node_identity_gaps=block["node_bindings"],
|
||
exact_implementation_sources=0,
|
||
original_fetch_time="unknown:未保留可证精确取得时刻",
|
||
strings=[
|
||
dict(
|
||
node_id="6078",
|
||
field="image",
|
||
characters=127,
|
||
LF=0,
|
||
CR=0,
|
||
tail_LF=False,
|
||
boundary_quotes_are_data=True,
|
||
sha256=hashlib.sha256(image_text.encode()).hexdigest(),
|
||
),
|
||
dict(
|
||
node_id="6005",
|
||
field="value",
|
||
characters=len(text),
|
||
LF=4,
|
||
CR=text.count("\r"),
|
||
tail_LF=False,
|
||
sha256=hashlib.sha256(text.encode()).hexdigest(),
|
||
),
|
||
],
|
||
objects=objects,
|
||
expressions=expressions,
|
||
missing_inputs=[
|
||
dict(
|
||
node_id="219",
|
||
missing_keys=["last_frame", "audio_vae"],
|
||
state="原键缺失,不补null/素材",
|
||
)
|
||
],
|
||
media_histories=0,
|
||
),
|
||
ensure_ascii=False,
|
||
indent=2,
|
||
)
|
||
+ "\n"
|
||
)
|
||
print(
|
||
(
|
||
"PASS original57 / typed77=scalar75+dict2 / references75 / implementation0; "
|
||
"quoted path, complete text/objects/expressions preserved"
|
||
)
|
||
)
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|