fix(mcp-image-gen): fix Heretic/FLUX2 integration bugs
- Fix syntax error in server.py (dangling docstring lines) - Correct model filename: flux-2-klein-4b.safetensors (without -fp8) - Fix _WORKFLOW_REGISTRY key to match actual downloaded filename - Update get_models() to always include registry models as fallback - Fix test expectations to match corrected model names - All 37 tests passing
This commit is contained in:
@@ -31,7 +31,7 @@ COMFYUI_BASE = "http://test-comfyui:8188"
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_build_flux_workflow_structure():
|
||||
"""Verify build_flux_workflow returns a dict with correct node types."""
|
||||
"""Verify build_flux_workflow returns a dict with correct node types for default model."""
|
||||
wf = build_flux_workflow(
|
||||
prompt="a red cat",
|
||||
neg_prompt="ugly",
|
||||
@@ -52,6 +52,47 @@ def test_build_flux_workflow_structure():
|
||||
assert wf["33"]["class_type"] == "CLIPTextEncode"
|
||||
|
||||
|
||||
def test_build_flux_workflow_heretic_model():
|
||||
"""Verify FLUX.2 Klein 4B with Heretic Qwen3-4B encoder uses correct nodes."""
|
||||
wf = build_flux_workflow(
|
||||
prompt="a red cat",
|
||||
neg_prompt="ugly",
|
||||
width=1024,
|
||||
height=1024,
|
||||
steps=4,
|
||||
seed=42,
|
||||
model="flux-2-klein-4b.safetensors",
|
||||
)
|
||||
assert wf["6"]["class_type"] == "CLIPTextEncode"
|
||||
assert wf["30"]["class_type"] == "CLIPLoader" # Qwen3-4B uses single CLIPLoader
|
||||
assert wf["32"]["inputs"]["unet_name"] == "flux-2-klein-4b.safetensors"
|
||||
assert wf["31"]["inputs"]["vae_name"] == "flux2-vae.safetensors"
|
||||
assert wf["13"]["inputs"]["scheduler"] == "beta" # FLUX.2 Klein uses beta scheduler
|
||||
|
||||
|
||||
def test_workflow_registry_contains_both_models():
|
||||
"""Verify the registry contains both supported models."""
|
||||
assert "flux1-schnell.safetensors" in server._WORKFLOW_REGISTRY
|
||||
assert "flux-2-klein-4b.safetensors" in server._WORKFLOW_REGISTRY
|
||||
assert len(server._WORKFLOW_REGISTRY) == 2
|
||||
|
||||
|
||||
def test_workflow_registry_fallback():
|
||||
"""Unknown model falls back to default (FLUX.1-schnell)."""
|
||||
wf = build_flux_workflow(
|
||||
prompt="test",
|
||||
neg_prompt="",
|
||||
width=512,
|
||||
height=512,
|
||||
steps=4,
|
||||
seed=42,
|
||||
model="unknown-model.safetensors",
|
||||
)
|
||||
# Should have used default workflow (DualCLIPLoader)
|
||||
assert wf["30"]["class_type"] == "DualCLIPLoader"
|
||||
assert wf["32"]["inputs"]["unet_name"] == "unknown-model.safetensors"
|
||||
|
||||
|
||||
def test_build_flux_workflow_params_injected():
|
||||
"""Verify all parameters are injected into correct nodes."""
|
||||
wf = build_flux_workflow(
|
||||
@@ -202,14 +243,16 @@ async def test_list_available_models():
|
||||
@respx.mock
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_available_models_comfyui_offline():
|
||||
"""When ComfyUI is unreachable, list_available_models returns error message."""
|
||||
"""When ComfyUI is unreachable, list_available_models falls back to registry models."""
|
||||
respx.get(f"{COMFYUI_BASE}/object_info/CheckpointLoaderSimple").mock(
|
||||
side_effect=httpx.ConnectError("connection refused")
|
||||
)
|
||||
|
||||
result = await list_available_models()
|
||||
assert len(result) == 1
|
||||
assert "not reachable" in result[0].lower()
|
||||
# Should return registry models even when ComfyUI is offline
|
||||
assert isinstance(result, list)
|
||||
assert "flux1-schnell.safetensors" in result
|
||||
assert "flux-2-klein-4b.safetensors" in result
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user