LTX2.3-Studio / tests /test_workflow.py
naajimit's picture
Upload 9 files
3c74a90 verified
Raw History Blame Contribute Delete
3.24 kB
"""Unit tests for workflow.py — pure functions over API-format JSON dicts.
The templates are `{node_id: {"class_type": ..., "inputs": {...}}}` (ComfyUI
"Save (API Format)"), not editor format. These tests were rewritten when the
templates moved to API format: the editor-format assertions (`wf["nodes"]`,
`widgets_values`, `workflow.validate`) no longer describe any code path.
"""
import json
import pytest
import workflow
def test_load_template_returns_dict_for_valid_mode():
wf = workflow.load_template("t2v")
assert isinstance(wf, dict)
assert len(wf) > 0
for node in wf.values():
assert isinstance(node.get("class_type"), str)
assert isinstance(node.get("inputs"), dict)
def test_load_template_raises_for_unknown_mode():
with pytest.raises(ValueError, match="unknown mode"):
workflow.load_template("nonexistent")
def test_load_template_returns_independent_copy():
"""Mutations to one returned dict must not affect later loads."""
a = workflow.load_template("t2v")
a["-999"] = {"class_type": "NoOp", "inputs": {}}
b = workflow.load_template("t2v")
assert "-999" not in b
def test_set_input_patches_inputs_in_place():
wf = workflow.load_template("t2v")
node_id, node = next(iter(wf.items()))
field = next(iter(node["inputs"]))
workflow.set_input(wf, node_id, field, "patched-value")
assert wf[node_id]["inputs"][field] == "patched-value"
def test_set_input_accepts_link_form_values():
"""Cross-node links arrive as [src_id, src_slot] lists."""
wf = workflow.load_template("t2v")
node_id = next(iter(wf))
workflow.set_input(wf, node_id, "latent", ["101", 0])
assert wf[node_id]["inputs"]["latent"] == ["101", 0]
def test_set_input_raises_for_unknown_node():
wf = workflow.load_template("t2v")
with pytest.raises(KeyError, match="node id"):
workflow.set_input(wf, 999_999_999, "anything", "x")
def test_load_template_remaps_retired_upscaler_filename():
"""Lightricks deleted the x2 spatial upscaler v1.0; templates still name it."""
for mode in workflow.VALID_MODES:
wf = workflow.load_template(mode)
assert wf["101"]["inputs"]["model_name"] == "ltx-2.3-spatial-upscaler-x2-1.1.safetensors", (
f"{mode} still loads a retired upscaler"
)
def test_load_template_leaves_no_retired_filenames_in_any_mode():
"""No retired model filename may reach the workflow handed to PromptExecutor."""
for mode in workflow.VALID_MODES:
serialized = json.dumps(workflow.load_template(mode))
for retired in ("ltx-2.3-spatial-upscaler-x2-1.0.safetensors",):
assert retired not in serialized, f"{mode} references retired {retired}"
def test_every_mode_has_at_least_one_output_node():
"""backend._execute_workflow picks output nodes by class_type prefix; a
template without one would silently produce nothing."""
output_prefixes = ("SaveVideo", "VHS_VideoCombine", "PreviewAudio", "CreateVideo")
for mode in workflow.VALID_MODES:
wf = workflow.load_template(mode)
assert any(n["class_type"].startswith(output_prefixes) for n in wf.values()), (
f"{mode} template has no output node"
)