Spaces:
Paused
Paused
File size: 3,523 Bytes
d65b6b1 3ea399a 2420cdb d65b6b1 81f5ac0 fee06dd 2420cdb fee06dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | """Unit tests for workflow.py — pure functions over JSON dicts."""
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 "nodes" in wf
assert len(wf["nodes"]) > 0
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["nodes"].append({"id": -999})
b = workflow.load_template("t2v")
assert {-999} & {n.get("id") for n in b["nodes"]} == set()
def test_set_input_patches_widgets_values_in_place():
wf = workflow.load_template("t2v")
target_node = next(n for n in wf["nodes"] if n["type"] == "CLIPTextEncode")
workflow.set_input(wf, target_node["id"], 0, "new prompt text")
refetched = next(n for n in wf["nodes"] if n["id"] == target_node["id"])
assert refetched["widgets_values"][0] == "new prompt text"
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, 0, "x")
def test_validate_accepts_canonical_template():
wf = workflow.load_template("t2v")
workflow.validate(wf) # must not raise
def test_validate_rejects_workflow_with_no_nodes():
wf = {"nodes": [], "links": []}
with pytest.raises(ValueError, match="no nodes"):
workflow.validate(wf)
def test_validate_rejects_orphan_link():
wf = workflow.load_template("t2v")
wf["links"].append([99999, 1, 0, 999_999_999, 0, "INT"]) # destination doesn't exist
with pytest.raises(ValueError, match="orphan link"):
workflow.validate(wf)
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_set_input_handles_dict_widgets_values():
"""VHS_* nodes carry dict-style widgets_values; set_input must support str keys."""
wf = workflow.load_template("a2v")
# Find a node whose widgets_values is a dict (e.g., VHS_LoadAudioUpload).
target = next(
(n for n in wf["nodes"] if isinstance(n.get("widgets_values"), dict)),
None,
)
assert target is not None, "no dict-widgets node in a2v template"
# Pick an existing key to patch (don't invent one — tests should reflect real graph shape).
existing_key = next(iter(target["widgets_values"].keys()))
workflow.set_input(wf, target["id"], existing_key, "/tmp/new_value.wav")
refetched = next(n for n in wf["nodes"] if n["id"] == target["id"])
assert refetched["widgets_values"][existing_key] == "/tmp/new_value.wav"
|