comfyui: add model discovery and actionable error messages

- Client queries ComfyUI /object_info to discover installed models
  (checkpoints, diffusion models, VAE, CLIP, LoRAs)
- Each tool declares its required models and checks them on execute()
- get_status() returns DEGRADED when server is up but models are missing
- Clear error messages tell the user exactly which models to download
- When COMFYUI_SERVER_URL is not set, error message tells the user to
  configure it in .env instead of silently failing on localhost:8188
- 8 new tests covering URL config, error messages, and model requirements

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
martimramos
2026-04-17 00:08:45 +01:00
committed by Alastair Beal
parent 6ec2bbb090
commit e3947e1f11
5 changed files with 225 additions and 12 deletions
+55
View File
@@ -171,3 +171,58 @@ class TestClientHelpers:
for _ in range(100):
s = ComfyUIClient.random_seed()
assert 0 <= s < 2**32
def test_is_default_url_when_env_not_set(self, monkeypatch):
from tools._comfyui.client import ComfyUIClient
monkeypatch.delenv("COMFYUI_SERVER_URL", raising=False)
client = ComfyUIClient()
assert client.is_default_url is True
def test_is_not_default_url_when_env_set(self, monkeypatch):
from tools._comfyui.client import ComfyUIClient
monkeypatch.setenv("COMFYUI_SERVER_URL", "http://myhost:9999")
client = ComfyUIClient()
assert client.is_default_url is False
def test_unavailable_reason_default_url(self, monkeypatch):
from tools._comfyui.client import ComfyUIClient
monkeypatch.delenv("COMFYUI_SERVER_URL", raising=False)
client = ComfyUIClient()
msg = client.unavailable_reason()
assert "COMFYUI_SERVER_URL" in msg
assert ".env" in msg
def test_unavailable_reason_custom_url(self, monkeypatch):
from tools._comfyui.client import ComfyUIClient
monkeypatch.setenv("COMFYUI_SERVER_URL", "http://myhost:9999")
client = ComfyUIClient()
msg = client.unavailable_reason()
assert "myhost:9999" in msg
assert "COMFYUI_SERVER_URL" not in msg
# ------------------------------------------------------------------
# Model discovery (offline, no server needed)
# ------------------------------------------------------------------
class TestModelRequirements:
def test_image_tool_has_required_models(self):
from tools.graphics.comfyui_image import _REQUIRED_MODELS
assert len(_REQUIRED_MODELS) > 0
assert any("flux" in m.lower() for m in _REQUIRED_MODELS)
def test_video_tool_has_required_models_i2v(self):
from tools.video.comfyui_video import _REQUIRED_MODELS_I2V
assert len(_REQUIRED_MODELS_I2V) > 0
assert any("i2v" in m.lower() for m in _REQUIRED_MODELS_I2V)
def test_video_tool_has_required_models_t2v(self):
from tools.video.comfyui_video import _REQUIRED_MODELS_T2V
assert len(_REQUIRED_MODELS_T2V) > 0
assert any("t2v" in m.lower() for m in _REQUIRED_MODELS_T2V)
def test_music_tool_has_required_models(self):
from tools.audio.comfyui_music import _REQUIRED_MODELS
assert len(_REQUIRED_MODELS) > 0
assert any("ace" in m.lower() for m in _REQUIRED_MODELS)