"""Test node listing functionality.
Note: These tests require COMFYUI_ROOT to be set and ComfyUI to be available.
They are skipped if ComfyUI cannot be imported.
"""
import os
import pytest
# Skip all tests in this module if COMFYUI_ROOT is not set
pytestmark = pytest.mark.skipif(
not os.environ.get("COMFYUI_ROOT"),
reason="COMFYUI_ROOT environment variable not set"
)
@pytest.fixture
def bridge():
"""Create a ComfyBridge instance."""
from comfyui_mcp_server.comfy_bridge import ComfyBridge, ComfyImportError
root = os.environ.get("COMFYUI_ROOT", "")
try:
return ComfyBridge(comfyui_root=root, enable_execute=False)
except ComfyImportError as e:
pytest.skip(f"Could not import ComfyUI: {e}")
def test_list_nodes_returns_list(bridge):
"""list_nodes should return a list of strings."""
nodes = bridge.list_nodes()
assert isinstance(nodes, list)
assert len(nodes) > 0
assert all(isinstance(n, str) for n in nodes)
def test_list_nodes_contains_ksampler(bridge):
"""list_nodes should include core nodes like KSampler."""
nodes = bridge.list_nodes()
assert "KSampler" in nodes
def test_node_schema_ksampler(bridge):
"""node_schema should return schema for KSampler."""
schema = bridge.node_schema("KSampler")
assert schema.node_type == "KSampler"
assert isinstance(schema.input, dict)
assert schema.output is not None
def test_node_schema_unknown_raises(bridge):
"""node_schema should raise KeyError for unknown node."""
with pytest.raises(KeyError):
bridge.node_schema("NonExistentNodeType12345")