107 lines
3.1 KiB
Python
107 lines
3.1 KiB
Python
"""Tests for LTX cache key generation."""
|
|
import pytest
|
|
import sys
|
|
import os
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
from generation_orchestrator import get_model_cache_key, _ltx_sort_components
|
|
|
|
|
|
def _ltx_conf():
|
|
return {
|
|
"model_type": "ltx_video",
|
|
"model": "ltx_model.safetensors",
|
|
"clip_models": ["c1.safetensors", "c2.safetensors"],
|
|
"vae_video": "vv.safetensors",
|
|
"vae_audio": "va.safetensors",
|
|
"latent_upscaler": "lup.safetensors",
|
|
}
|
|
|
|
|
|
def test_ltx_key_includes_all_files():
|
|
conf = _ltx_conf()
|
|
key = get_model_cache_key(conf)
|
|
assert "ltx" in key
|
|
assert "ltx_model.safetensors" in key
|
|
assert "c1.safetensors" in key
|
|
assert "c2.safetensors" in key
|
|
assert "vv.safetensors" in key
|
|
assert "va.safetensors" in key
|
|
assert "lup.safetensors" in key
|
|
|
|
|
|
def test_ltx_two_identical_configs_have_same_key():
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
assert get_model_cache_key(a) == get_model_cache_key(b)
|
|
|
|
|
|
def test_ltx_different_upscaler_different_key():
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
b["latent_upscaler"] = "different_upscaler.safetensors"
|
|
assert get_model_cache_key(a) != get_model_cache_key(b)
|
|
|
|
|
|
def test_ltx_different_video_vae_different_key():
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
b["vae_video"] = "other_vae.safetensors"
|
|
assert get_model_cache_key(a) != get_model_cache_key(b)
|
|
|
|
|
|
def test_ltx_different_clip_different_key():
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
b["clip_models"] = ["c1.safetensors", "alt_c2.safetensors"]
|
|
assert get_model_cache_key(a) != get_model_cache_key(b)
|
|
|
|
|
|
def test_ltx_sigma_change_does_not_change_key():
|
|
"""Sweeping sigmas should NOT trigger a model reload."""
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
a["sigmas_stage2"] = "0.85, 0.4, 0.0"
|
|
b["sigmas_stage2"] = "0.9, 0.5, 0.0"
|
|
assert get_model_cache_key(a) == get_model_cache_key(b)
|
|
|
|
|
|
def test_ltx_seed_change_does_not_change_key():
|
|
a = _ltx_conf()
|
|
b = _ltx_conf()
|
|
a["seed"] = 42
|
|
b["seed"] = 100
|
|
assert get_model_cache_key(a) == get_model_cache_key(b)
|
|
|
|
|
|
def test_checkpoint_key_unchanged():
|
|
"""Existing checkpoint behavior must not regress."""
|
|
conf = {"model_type": "checkpoint", "model": "sdxl.safetensors"}
|
|
assert get_model_cache_key(conf) == "sdxl.safetensors"
|
|
|
|
|
|
def test_diffusion_model_key_unchanged():
|
|
"""Existing non-checkpoint (diffusion_model/gguf) behavior must not regress."""
|
|
conf = {
|
|
"model_type": "diffusion_model",
|
|
"model": "flux.safetensors",
|
|
"text_encoders": ["t5.safetensors", "clip_l.safetensors"],
|
|
}
|
|
key = get_model_cache_key(conf)
|
|
assert "flux.safetensors" in key
|
|
assert "diffusion_model" in key
|
|
assert "t5.safetensors" in key
|
|
assert "clip_l.safetensors" in key
|
|
|
|
|
|
def test_ltx_sort_components_imports():
|
|
assert _ltx_sort_components({"model_type": "checkpoint"}) == (None, None, None, None)
|
|
ltx = {
|
|
"model_type": "ltx_video",
|
|
"clip_models": ["c1", "c2"],
|
|
"vae_video": "vv",
|
|
"vae_audio": "va",
|
|
"latent_upscaler": "lup",
|
|
}
|
|
assert _ltx_sort_components(ltx) == (("c1", "c2"), "vv", "va", "lup")
|