313 lines
12 KiB
Python
313 lines
12 KiB
Python
"""Synthetic saved-state transformations only; no upstream/media/history execution."""
|
|
|
|
import ast
|
|
import copy
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from scripts import audit_reference_conversion as audit
|
|
from scripts.verify_frontend_sources import verify
|
|
|
|
from calliope.comfyui.serialization_reference import (
|
|
SCAIL_LOAD_COMMIT,
|
|
serialize_scail_load_node,
|
|
)
|
|
from calliope.comfyui.structure_reference import SCAIL_LOAD_PROFILES
|
|
from calliope.comfyui.ui2api import convert, convert_reference
|
|
from tests.test_setget_reference import connect
|
|
from tests.test_videoinfo_reference import graph as info_graph
|
|
|
|
REPO = Path(__file__).resolve().parents[2]
|
|
ROOT = REPO / "docs/hel-892/scail-load-reference"
|
|
PROFILE = "comfy-frontend-1.37.11-scail-load-8e4d7947-info-537f3a02-kj-ab72eda7-reference"
|
|
ACTION = "example_ComfyUI_workflows/6-动作迁移/Wan2.1_Scail-2_动作迁移_WanAnimatePlus_v4.2.json"
|
|
ROLE = "example_ComfyUI_workflows/6-动作迁移/Wan2.1_Scail-2_角色迁移_WanAnimatePlus_v4.2.json"
|
|
|
|
|
|
def loader():
|
|
node = next(n for n in json.loads((REPO / ACTION).read_bytes())["nodes"] if n["id"] == 573)
|
|
# Explicit synthetic no-UE premise, NEVER a conversion of the real graph.
|
|
node["properties"].pop("widget_ue_connectable")
|
|
node["properties"].pop("ue_properties")
|
|
node["id"] = 17
|
|
for s in node["inputs"]:
|
|
s["link"] = None
|
|
for s in node["outputs"]:
|
|
s["links"] = []
|
|
return node
|
|
|
|
|
|
def graph():
|
|
g = info_graph(0)
|
|
old = g["nodes"][0]
|
|
new = loader()
|
|
for target, source in zip(new["outputs"], old["outputs"]):
|
|
target["links"] = source.get("links", [])
|
|
g["nodes"][0] = new
|
|
supply = loader()
|
|
supply["id"] = 900
|
|
supply["widgets_values"]["video"] = "synthetic-other.mp4"
|
|
g["nodes"].append(supply)
|
|
connect(g, 30, 900, 1, 17, 6, "INT")
|
|
connect(g, 31, 900, 1, 17, 7, "INT")
|
|
return g
|
|
|
|
|
|
@pytest.mark.parametrize("profile", SCAIL_LOAD_PROFILES)
|
|
@pytest.mark.parametrize("rate", [0, 8, 16, 16.25, 60])
|
|
def test_whole_graph_nonzero_info_slot_and_external_cap_skip(profile, rate):
|
|
g = graph()
|
|
g["extra"] = {"frontendVersion": SCAIL_LOAD_PROFILES[profile]}
|
|
g["nodes"][0]["widgets_values"].update(force_rate=rate, frame_load_cap=81, skip_first_frames=9)
|
|
original = copy.deepcopy(g)
|
|
result = convert_reference(g, profile)
|
|
assert result.prompt is not None, result.issues
|
|
assert result.prompt["17"]["inputs"]["force_rate"] == rate
|
|
assert result.prompt["17"]["inputs"]["frame_load_cap"] == ["900", 1]
|
|
assert result.prompt["17"]["inputs"]["skip_first_frames"] == ["900", 1]
|
|
assert result.prompt["546"]["inputs"]["video_info"] == ["17", 3]
|
|
assert result.prompt["12"]["inputs"]["frame_rate"] == ["546", 0]
|
|
assert result.reference_only and g == original and convert(g).prompt is None
|
|
assert "videopreview" not in result.prompt["17"]["inputs"]
|
|
g["nodes"][0]["widgets_values"]["videopreview"]["params"]["force_rate"] = 999
|
|
assert convert_reference(g, profile).prompt == result.prompt
|
|
g["nodes"][-1]["widgets_values"]["video"] = "changed.mp4"
|
|
assert convert_reference(g, profile).prompt["900"]["inputs"]["video"] == "changed.mp4"
|
|
# Change just cap's upstream instance. Skip must retain its original source.
|
|
other = loader()
|
|
other["id"] = 901
|
|
other["outputs"][1]["links"] = [30]
|
|
g["nodes"].append(other)
|
|
g["nodes"][-2]["outputs"][1]["links"].remove(30)
|
|
next(e for e in g["links"] if e[0] == 30)[1] = 901
|
|
prompt = convert_reference(g, profile).prompt
|
|
assert prompt["17"]["inputs"]["frame_load_cap"] == ["901", 1]
|
|
assert prompt["17"]["inputs"]["skip_first_frames"] == ["900", 1]
|
|
g["nodes"][0]["widgets_values"]["video"] = "changed-instance17.mp4"
|
|
assert convert_reference(g, profile).prompt["17"]["inputs"]["video"] == "changed-instance17.mp4"
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
"mutation",
|
|
[
|
|
"old_version",
|
|
"release",
|
|
"provider",
|
|
"aux",
|
|
"mode",
|
|
"bool_mode",
|
|
"array",
|
|
"missing",
|
|
"extra",
|
|
"mirror",
|
|
"width10",
|
|
"height513",
|
|
"dim_bool",
|
|
"format",
|
|
"vae",
|
|
"batch",
|
|
"force_link",
|
|
"nan",
|
|
"bool_rate",
|
|
"skip_bool",
|
|
"nth_zero",
|
|
"slot_type",
|
|
"slot_name",
|
|
"slot_bool",
|
|
"slot_extra",
|
|
"bad_reverse",
|
|
"bad_link_type",
|
|
"cap_bool_link",
|
|
"ue_top",
|
|
"ue_nested",
|
|
"ue_node",
|
|
"ue_bad",
|
|
"override",
|
|
"literal_aux",
|
|
"frontend",
|
|
"nested",
|
|
],
|
|
)
|
|
def test_mutations_fail_closed_and_precise_new_loader_pointer(mutation):
|
|
g = graph()
|
|
n, vals = g["nodes"][0], g["nodes"][0]["widgets_values"]
|
|
if mutation == "old_version":
|
|
n["properties"]["ver"] = "8550981384301e9bc5bfea83e5c2c75258102593"
|
|
elif mutation == "release":
|
|
n["properties"]["ver"] = "1.7.9"
|
|
elif mutation == "provider":
|
|
n["properties"]["cnr_id"] = "other"
|
|
elif mutation == "aux":
|
|
n["properties"]["aux_id"] = "VHS_LoadVideo"
|
|
elif mutation == "mode":
|
|
n["mode"] = 4
|
|
elif mutation == "bool_mode":
|
|
n["mode"] = False
|
|
elif mutation == "array":
|
|
n["widgets_values"] = list(vals.values())
|
|
elif mutation == "missing":
|
|
vals.pop("format")
|
|
elif mutation == "extra":
|
|
vals["unknown"] = 1
|
|
elif mutation == "mirror":
|
|
n["widgets_values_named"] = copy.deepcopy(vals)
|
|
elif mutation == "width10":
|
|
vals["custom_width"] = 10
|
|
elif mutation == "height513":
|
|
vals["custom_height"] = 513
|
|
elif mutation == "dim_bool":
|
|
vals["custom_width"] = False
|
|
elif mutation == "format":
|
|
vals["format"] = "Wan"
|
|
elif mutation == "vae":
|
|
n["inputs"][1]["link"] = 60
|
|
elif mutation == "batch":
|
|
n["inputs"][0]["link"] = 60
|
|
elif mutation == "force_link":
|
|
n["inputs"][3]["link"] = 60
|
|
elif mutation == "nan":
|
|
vals["force_rate"] = float("nan")
|
|
elif mutation == "bool_rate":
|
|
vals["force_rate"] = True
|
|
elif mutation == "skip_bool":
|
|
vals["skip_first_frames"] = False
|
|
elif mutation == "nth_zero":
|
|
vals["select_every_nth"] = 0
|
|
elif mutation == "slot_type":
|
|
n["outputs"][3]["type"] = "INT"
|
|
elif mutation == "slot_name":
|
|
n["outputs"][3]["name"] = "frame_count"
|
|
elif mutation == "slot_bool":
|
|
n["outputs"][3]["slot_index"] = True
|
|
elif mutation == "slot_extra":
|
|
n["outputs"].append(copy.deepcopy(n["outputs"][0]))
|
|
elif mutation == "bad_reverse":
|
|
g["nodes"][-1]["outputs"][1]["links"].remove(30)
|
|
elif mutation == "bad_link_type":
|
|
g["links"][-1][5] = "FLOAT"
|
|
elif mutation == "cap_bool_link":
|
|
n["inputs"][6]["link"] = True
|
|
elif mutation == "ue_top":
|
|
n["properties"]["widget_ue_connectable"] = {"custom_width": True}
|
|
elif mutation == "ue_nested":
|
|
n["properties"]["ue_properties"] = {"widget_ue_connectable": {"custom_height": True}}
|
|
elif mutation == "ue_node":
|
|
n["widget_ue_connectable"] = {"custom_width": True}
|
|
elif mutation == "ue_bad":
|
|
n["properties"]["ue_properties"] = [1]
|
|
elif mutation == "override":
|
|
n["properties"]["onConfigure"] = "custom"
|
|
elif mutation == "literal_aux":
|
|
g["nodes"][3]["properties"]["aux_id"] = "SetNode"
|
|
elif mutation == "frontend":
|
|
g["extra"] = {"frontendVersion": "1.48.7"}
|
|
elif mutation == "nested":
|
|
g["definitions"] = {"subgraphs": [{"id": "unknown"}]}
|
|
result = convert_reference(g, PROFILE)
|
|
assert result.prompt is None
|
|
if mutation not in ("bad_reverse", "bad_link_type", "literal_aux", "frontend", "nested"):
|
|
assert any(
|
|
x["code"] == "scail_load_reference_invalid" and x["pointer"] == "/nodes/0"
|
|
for x in result.issues
|
|
), result.issues
|
|
|
|
|
|
@pytest.mark.parametrize("path,nid", [(ACTION, 573), (ROLE, 112)])
|
|
def test_actual_graph_ue_and_literal_provenance_remain_closed(path, nid):
|
|
g = json.loads((REPO / path).read_bytes())
|
|
original = copy.deepcopy(g)
|
|
result = convert_reference(g, PROFILE)
|
|
assert result.prompt is None and g == original
|
|
assert any(
|
|
i["code"] == "scail_load_reference_invalid"
|
|
and i["node_id"] == str(nid)
|
|
and "UE" in i["message"]
|
|
for i in result.issues
|
|
)
|
|
assert any(i["code"] == "setget_reference_invalid" for i in result.issues)
|
|
assert audit.profile_attempt(g, PROFILE)["status"] == "rejected"
|
|
|
|
|
|
def test_exact_historical_emission_is_not_user_provenance():
|
|
assert verify(ROOT)["sources_verified"]
|
|
old = (ROOT / "kj-276955e45fa48c794b47bf49dbc22f2d955d76a8__setgetnodes.js").read_text()
|
|
new = (ROOT / "kj-e56b3061ed49251a7b8a5450a2e18295548ea7a1__setgetnodes.js").read_text()
|
|
assert 'this.properties["aux_id"] = "SetNode"' in old
|
|
assert 'this.properties["aux_id"] = "GetNode"' in old
|
|
assert new.count('this.properties["aux_id"] = "kijai/ComfyUI-KJNodes"') == 2
|
|
assert 'this.properties["aux_id"] = "SetNode"' not in new
|
|
tree = ast.parse((ROOT / "videohelpersuite__load_video_nodes.py").read_text())
|
|
cls = next(n for n in tree.body if isinstance(n, ast.ClassDef) and n.name == "LoadVideoUpload")
|
|
assert cls.lineno > 0
|
|
assert '"VHS_LoadVideo": LoadVideoUpload,' in (ROOT / "videohelpersuite__nodes.py").read_text()
|
|
assert serialize_scail_load_node(loader())["custom_width"] == 0
|
|
assert (
|
|
len(
|
|
[
|
|
p
|
|
for p in audit.REFERENCE_PROFILES[:26]
|
|
if p not in (audit.GRID_PROFILE, audit.H3_PROFILE)
|
|
]
|
|
)
|
|
== 24
|
|
)
|
|
|
|
|
|
def test_named_map_order_external_removal_and_old_contracts():
|
|
g = graph()
|
|
expected = convert_reference(g, PROFILE).prompt
|
|
n = g["nodes"][0]
|
|
n["widgets_values"] = dict(reversed(list(n["widgets_values"].items())))
|
|
assert convert_reference(g, PROFILE).prompt == expected
|
|
for lid, slot, value in [(30, 6, 42), (31, 7, 13)]:
|
|
g["links"] = [e for e in g["links"] if e[0] != lid]
|
|
g["nodes"][-1]["outputs"][1]["links"].remove(lid)
|
|
n["inputs"][slot]["link"] = None
|
|
n["widgets_values"][n["inputs"][slot]["name"]] = value
|
|
result = convert_reference(g, PROFILE)
|
|
assert result.prompt["17"]["inputs"]["frame_load_cap"] == 42
|
|
assert result.prompt["17"]["inputs"]["skip_first_frames"] == 13
|
|
for old in audit.REFERENCE_PROFILES[:22]:
|
|
assert convert_reference(g, old).prompt is None
|
|
|
|
|
|
def test_frontend_requires_explicit_1486_and_fixed_restore_order_evidence():
|
|
p1486 = "comfy-frontend-1.48.6-scail-load-8e4d7947-info-537f3a02-kj-ab72eda7-reference"
|
|
assert convert_reference(graph(), p1486).prompt is None
|
|
assert audit.profile_attempt(graph(), p1486)["status"] == "not_applicable"
|
|
js = (ROOT / "web__js__VHS.core.js").read_text()
|
|
assert "w.value = widgetDict[w.name];" in js
|
|
assert "w.callback?.(w.value)" in js
|
|
assert "if (v == 0)" in js
|
|
assert "const s = this.options.step" in js
|
|
assert "Math.round((v - sh) / s) * s + sh" in js
|
|
py = (ROOT / "videohelpersuite__load_video_nodes.py").read_text()
|
|
cls = py[py.index("class LoadVideoUpload:") : py.index("class LoadVideoPath:")]
|
|
assert cls.index('"custom_width"') < cls.index('"format"')
|
|
assert "step" not in next(line for line in cls.splitlines() if '"custom_width"' in line)
|
|
assert '"format": get_load_formats()' in cls
|
|
assert SCAIL_LOAD_COMMIT in json.dumps(json.loads((ROOT / "sources.json").read_text()))
|
|
|
|
|
|
@pytest.mark.parametrize("width,height", [(0, 0), (512, 0), (0, 768), (384, 640), (8192, 8)])
|
|
def test_proven_construction_before_restore_dimension_fixed_points(width, height):
|
|
g = graph()
|
|
g["nodes"][0]["widgets_values"].update(custom_width=width, custom_height=height)
|
|
result = convert_reference(g, PROFILE)
|
|
assert result.prompt is not None, result.issues
|
|
assert result.prompt["17"]["inputs"]["custom_width"] == width
|
|
assert result.prompt["17"]["inputs"]["custom_height"] == height
|
|
js = (ROOT / "web__js__VHS.core.js").read_text()
|
|
start = js.index("function addLoadCommon")
|
|
end = js.index("function path_stem", start)
|
|
construction = js[start:end]
|
|
assert construction.index("initializeLoadFormat(nodeType, nodeData)") < construction.index(
|
|
"for (let widget of this.widgets)"
|
|
)
|
|
assert "widget.callback?.(widget.value)" in construction
|
|
assert (
|
|
"'AnimateDiff': {'target_rate': 8, 'dim': (8,0,512,512)}"
|
|
in (ROOT / "videohelpersuite__load_video_nodes.py").read_text()
|
|
)
|