Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion tests/comfy_cli/command/test_assets_library.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,22 @@ def reset_singleton():
reset_renderer_for_testing()


@pytest.fixture(scope="module")
def root_cli_ready():
"""Load the actual CLI before a test's target fake can bind into lazy modules."""
from click import Context
from typer.main import get_command

from comfy_cli.cmdline import app as root_app

root = get_command(root_app)
with Context(root) as context:
for name in root.list_commands(context):
root.get_command(context, name)


@pytest.fixture
def cloud_target(monkeypatch: pytest.MonkeyPatch):
def cloud_target(monkeypatch: pytest.MonkeyPatch, root_cli_ready):
from comfy_cli.target import Target

fake = Target(
Expand Down
9 changes: 8 additions & 1 deletion tests/comfy_cli/command/test_deploy_progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,14 @@ class _TerminalRenderer:
def __init__(self, width: int) -> None:
from rich.console import Console

self._console = Console(file=io.StringIO(), width=width, force_terminal=True, color_system=None)
# Emulate the promised terminal even when the caller exports TERM=dumb.
self._console = Console(
file=io.StringIO(),
width=width,
force_terminal=True,
color_system=None,
_environ={"TERM": "xterm-256color"},
)

def is_pretty(self) -> bool:
return True
Expand Down
2 changes: 2 additions & 0 deletions tests/comfy_cli/command/test_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,8 @@ def test_logs_pretty_no_mismatch_warning_for_explicit_port(monkeypatch, tmp_path

def test_logs_pretty_warns_when_explicit_port_falls_back_to_unsuffixed(monkeypatch, tmp_path, capsys):
"""The unsuffixed fallback encodes no port, so say so instead of staying silent."""
# Assert routing and prose on a stable wide console, not path-dependent wrapping.
monkeypatch.setenv("COLUMNS", "512")
_write_log(tmp_path, "comfyui.log", "no --port in argv\n")
_fake_env(monkeypatch, workspace=tmp_path)

Expand Down
3 changes: 2 additions & 1 deletion tests/comfy_cli/command/test_pretty_print_sanitize.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,8 @@ def test_status_glyph_keeps_its_own_tags_live(pretty):

from comfy_cli.output.glyphs import status_glyph

console = Console(file=pretty, force_terminal=True, width=80)
# This tests authored styling, independently of the caller's terminal type.
console = Console(file=pretty, force_terminal=True, width=80, _environ={"TERM": "xterm-256color"})
console.print(status_glyph("success"))
out = pretty.getvalue()

Expand Down
54 changes: 45 additions & 9 deletions tests/comfy_cli/command/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,22 @@ def test_collects_image_outputs(self, mock_execution):


class TestExecuteErrorHandling:
@pytest.fixture(autouse=True)
def local_preflight_catalog(self, monkeypatch):
"""Keep execute() off a live server: an empty catalog skips preflight."""

def target_catalog(host, port):
assert (host, port) == ("127.0.0.1", 8188)
return {}

monkeypatch.setattr("comfy_cli.command.run._fetch_object_info", target_catalog)

def unexpected_catalog_request(*args, **kwargs):
pytest.fail("unexpected real catalog request; mock the specific object_info transport")

monkeypatch.setattr("comfy_cli.http._PLAIN_OPENER.open", unexpected_catalog_request)
monkeypatch.setattr("comfy_cli.cql.engine._load_from_target", unexpected_catalog_request)

def _run_execute_expect_exit(self, workflow_file, **overrides):
kwargs = dict(host="127.0.0.1", port=8188, wait=True, verbose=False, timeout=30)
kwargs.update(overrides)
Expand Down Expand Up @@ -2363,14 +2379,33 @@ def test_markup_in_node_name_does_not_crash_confirm(self, monkeypatch):


class TestExecuteUiWorkflow:
@pytest.fixture(autouse=True)
def local_preflight_catalog(self, monkeypatch):
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
Comment thread
vqt123 marked this conversation as resolved.
Resolved
"""Validate against the complete conversion fixture without a live server."""
from copy import deepcopy

def target_catalog(host, port):
assert (host, port) == ("127.0.0.1", 8188)
return deepcopy(self.OBJECT_INFO)

monkeypatch.setattr("comfy_cli.command.run._fetch_object_info", target_catalog)

def unexpected_catalog_request(*args, **kwargs):
pytest.fail("unexpected real catalog request; mock the specific object_info transport")

monkeypatch.setattr("comfy_cli.http._PLAIN_OPENER.open", unexpected_catalog_request)
monkeypatch.setattr("comfy_cli.cql.engine._load_from_target", unexpected_catalog_request)

# The conversion success fixture must also be an executable graph:
# PreviewImage consumes IMAGE, not an EmptyLatentImage's LATENT output.
UI = {
"nodes": [
{
"id": 1,
"type": "EmptyLatentImage",
"type": "EmptyImage",
"inputs": [],
"outputs": [{"name": "LATENT", "type": "LATENT", "links": [10]}],
"widgets_values": [512, 512, 1],
"outputs": [{"name": "IMAGE", "type": "IMAGE", "links": [10]}],
"widgets_values": [512, 512, 1, 0],
"mode": 0,
},
{
Expand All @@ -2384,19 +2419,20 @@ class TestExecuteUiWorkflow:
"links": [[10, 1, 0, 2, 0, "IMAGE"]],
}
OBJECT_INFO = {
"EmptyLatentImage": {
"EmptyImage": {
"input": {
"required": {
"width": ["INT", {"default": 512}],
"height": ["INT", {"default": 512}],
"batch_size": ["INT", {"default": 1}],
"color": ["INT", {"default": 0}],
}
},
"input_order": {"required": ["width", "height", "batch_size"]},
"output": ["LATENT"],
"output_name": ["LATENT"],
"input_order": {"required": ["width", "height", "batch_size", "color"]},
"output": ["IMAGE"],
"output_name": ["IMAGE"],
"output_node": False,
"display_name": "Empty Latent Image",
"display_name": "Empty Image",
},
"PreviewImage": {
"input": {"required": {"images": ["IMAGE"]}},
Expand Down Expand Up @@ -2435,7 +2471,7 @@ def test_ui_workflow_is_converted_then_executed(self, ui_workflow_file):
assert mock_fetch.call_args.args == ("127.0.0.1", 8188, 30)
api_workflow = MockExec.call_args.args[0]
assert set(api_workflow) == {"1", "2"}
assert api_workflow["1"]["class_type"] == "EmptyLatentImage"
assert api_workflow["1"]["class_type"] == "EmptyImage"
assert api_workflow["2"]["inputs"]["images"] == ["1", 0]
mock_exec.queue.assert_called_once()

Expand Down
93 changes: 60 additions & 33 deletions tests/comfy_cli/command/test_run_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,30 @@ def ndjson_renderer():
reset_renderer_for_testing()


@pytest.fixture(autouse=True)
def local_preflight_catalog(monkeypatch):
"""Keep event/queue tests independent of any real server on localhost.

Validation still runs against complete schemas. Tests for conversion HTTP
and deliberately invalid catalogs override their specific boundary below.
"""
from copy import deepcopy

monkeypatch.setattr("comfy_cli.command.run._fetch_object_info", lambda *a, **k: deepcopy(OBJECT_INFO))

def unexpected_catalog_request(*args, **kwargs):
pytest.fail("unexpected real catalog request; mock the specific object_info transport")

monkeypatch.setattr("comfy_cli.http._PLAIN_OPENER.open", unexpected_catalog_request)


@pytest.fixture
def simple_workflow():
return {
"1": {
"class_type": "EmptyLatentImage",
"inputs": {"width": 64, "height": 64, "batch_size": 1},
"_meta": {"title": "Latent"},
"class_type": "EmptyImage",
"inputs": {"width": 64, "height": 64, "batch_size": 1, "color": 0},
"_meta": {"title": "Image"},
},
"2": {
"class_type": "SaveImage",
Expand Down Expand Up @@ -524,8 +541,8 @@ def test_queued_nodes_manifest_from_workflow(self, workflow_file, capsys, simple
nodes = queued["nodes"]
assert len(nodes) == 2
by_id = {n["node_id"]: n for n in nodes}
assert by_id["1"]["class_type"] == "EmptyLatentImage"
assert by_id["1"]["title"] == "Latent" # _meta.title wins
assert by_id["1"]["class_type"] == "EmptyImage"
assert by_id["1"]["title"] == "Image" # _meta.title wins
assert by_id["2"]["class_type"] == "SaveImage"
assert by_id["2"]["title"] == "Save"

Expand Down Expand Up @@ -621,7 +638,7 @@ def test_execution_error(self, workflow_file, capsys):
"data": {
"prompt_id": "p",
"node_id": "1",
"node_type": "EmptyLatentImage",
"node_type": "EmptyImage",
"exception_type": "RuntimeError",
"exception_message": "boom",
"traceback": [' File "x.py"\n', " raise RuntimeError\n"],
Expand All @@ -635,12 +652,12 @@ def test_execution_error(self, workflow_file, capsys):
assert any(e["type"] == "execution_error" for e in _events(lines))
env = _envelope(lines)
assert env["error"]["code"] == "execution_error"
assert env["error"]["message"] == "EmptyLatentImage (node 1): boom"
assert env["error"]["message"] == "EmptyImage (node 1): boom"
details = env["error"]["details"]
assert details["node_id"] == "1"
assert details["class_type"] == "EmptyLatentImage"
assert details["class_type"] == "EmptyImage"
assert details["exception_type"] == "RuntimeError"
assert details["title"] == "Latent" # from _meta.title
assert details["title"] == "Image" # from _meta.title
# The envelope carries only the traceback tail; the full traceback
# stays on the execution_error event.
assert isinstance(details["traceback_tail"], list)
Expand All @@ -658,7 +675,7 @@ def test_execution_error_node_id_coerced_to_str(self, workflow_file, capsys):
"data": {
"prompt_id": "p",
"node_id": 7,
"node_type": "EmptyLatentImage",
"node_type": "EmptyImage",
"exception_type": "RuntimeError",
"exception_message": "boom",
"traceback": [],
Expand Down Expand Up @@ -797,8 +814,8 @@ def test_node_ids_coerced_to_str(self, simple_workflow, capsys):
assert isinstance(ev["node"], str), f"{ev['type']} node is {type(ev['node']).__name__}"

def test_title_falls_back_to_class_type(self):
ex = _make_workflow_execution({"1": {"class_type": "EmptyLatentImage", "inputs": {}}})
assert ex.get_node_title("1") == "EmptyLatentImage"
ex = _make_workflow_execution({"1": {"class_type": "EmptyImage", "inputs": {}}})
assert ex.get_node_title("1") == "EmptyImage"

def test_title_falls_back_to_node_id_for_unknown(self):
ex = _make_workflow_execution({})
Expand All @@ -809,10 +826,10 @@ def test_title_falls_back_to_node_id_for_unknown(self):
"nodes": [
{
"id": 1,
"type": "EmptyLatentImage",
"type": "EmptyImage",
"inputs": [],
"outputs": [{"name": "LATENT", "type": "LATENT", "links": [10]}],
"widgets_values": [64, 64, 1],
"outputs": [{"name": "IMAGE", "type": "IMAGE", "links": [10]}],
"widgets_values": [64, 64, 1, 0],
"mode": 0,
},
{
Expand All @@ -827,17 +844,26 @@ def test_title_falls_back_to_node_id_for_unknown(self):
}

OBJECT_INFO = {
"EmptyLatentImage": {
"EmptyImage": {
"input": {
"required": {
"width": ["INT", {"default": 512}],
"height": ["INT", {"default": 512}],
"batch_size": ["INT", {"default": 1}],
"color": ["INT", {"default": 0}],
}
},
"input_order": {"required": ["width", "height", "batch_size"]},
"input_order": {"required": ["width", "height", "batch_size", "color"]},
"output": ["IMAGE"],
"output_name": ["IMAGE"],
"output_node": False,
"display_name": "Empty Latent Image",
"display_name": "Empty Image",
},
"SaveImage": {
"input": {"required": {"filename_prefix": ["STRING", {"default": "ComfyUI"}], "images": ["IMAGE"]}},
"input_order": {"required": ["filename_prefix", "images"]},
"output": [],
"output_node": True,
},
"PreviewImage": {
"input": {"required": {"images": ["IMAGE"]}},
Expand Down Expand Up @@ -970,7 +996,7 @@ def test_api_input_emits_prompt_preview_before_queued(self, workflow_file, capsy
assert types[0] == "prompt_preview"
assert "queued" in types
assert types.index("prompt_preview") < types.index("queued")
assert _events(lines)[0]["prompt"]["1"]["class_type"] == "EmptyLatentImage"
assert _events(lines)[0]["prompt"]["1"]["class_type"] == "EmptyImage"

def test_ui_input_emits_converted_then_prompt_preview_then_queued(self, ui_workflow_file, capsys):
with (
Expand Down Expand Up @@ -1035,7 +1061,7 @@ def test_api_input_emits_prompt_preview_and_envelope_only(self, workflow_file, c
assert [e["type"] for e in _events(lines)] == ["prompt_preview"]
preview = _events(lines)[0]
assert preview["schema"] == "event/1"
assert preview["prompt"]["1"]["class_type"] == "EmptyLatentImage"
assert preview["prompt"]["1"]["class_type"] == "EmptyImage"
env = _envelope(lines)
assert env["ok"] is True
assert env["data"]["status"] == "preview"
Expand Down Expand Up @@ -1092,7 +1118,7 @@ def test_print_prompt_text_mode_pretty_prints_json(self, workflow_file, capsys):
out, _err = capsys.readouterr()
parsed = json.loads(out)
assert "1" in parsed
assert parsed["1"]["class_type"] == "EmptyLatentImage"
assert parsed["1"]["class_type"] == "EmptyImage"

def test_print_prompt_does_not_post_when_workflow_invalid(self, capsys):
# Pre-flight failures (workflow_not_found, workflow_not_api_format)
Expand Down Expand Up @@ -1240,10 +1266,10 @@ def test_execution_cached_event_shape(self, workflow_file, capsys):

cached_events = [e for e in _events(lines) if e["type"] == "execution_cached"]
assert len(cached_events) == 2
# Node 1 has _meta.title="Latent"; class_type=EmptyLatentImage
# Node 1 has _meta.title="Image"; class_type=EmptyImage
n1 = next(e for e in cached_events if e["node"] == "1")
assert n1["class_type"] == "EmptyLatentImage"
assert n1["title"] == "Latent"
assert n1["class_type"] == "EmptyImage"
assert n1["title"] == "Image"
# Node 2 has _meta.title="Save"; class_type=SaveImage
n2 = next(e for e in cached_events if e["node"] == "2")
assert n2["class_type"] == "SaveImage"
Expand Down Expand Up @@ -1380,9 +1406,9 @@ class TestErrorPathCoverage:
def _make_workflow(self):
return {
"1": {
"class_type": "EmptyLatentImage",
"inputs": {"width": 64, "height": 64, "batch_size": 1},
"_meta": {"title": "Latent"},
"class_type": "EmptyImage",
"inputs": {"width": 64, "height": 64, "batch_size": 1, "color": 0},
"_meta": {"title": "Image"},
},
"2": {
"class_type": "SaveImage",
Expand All @@ -1399,10 +1425,10 @@ def test_object_info_timeout_routes_to_connection_error(self, capsys):
"nodes": [
{
"id": 1,
"type": "EmptyLatentImage",
"type": "EmptyImage",
"inputs": [],
"outputs": [],
"widgets_values": [64, 64, 1],
"widgets_values": [64, 64, 1, 0],
"mode": 0,
}
],
Expand All @@ -1414,9 +1440,10 @@ def test_object_info_timeout_routes_to_connection_error(self, capsys):
try:
with (
patch("comfy_cli.command.run.check_comfy_server_running", return_value=True),
patch("comfy_cli.http._AUTHED_OPENER.open", side_effect=TimeoutError("timed out")),
patch("comfy_cli.http._PLAIN_OPENER.open", side_effect=TimeoutError("timed out")) as mock_open,
):
lines, exit_code = _run_execute_capture(path, capsys)
mock_open.assert_called_once_with("http://127.0.0.1:8188/object_info", timeout=30)
assert _envelope(lines)["error"]["code"] == "connection_error"
finally:
os.unlink(path)
Expand All @@ -1427,10 +1454,10 @@ def test_object_info_non_json_body_routes_to_object_info_unavailable(self, capsy
"nodes": [
{
"id": 1,
"type": "EmptyLatentImage",
"type": "EmptyImage",
"inputs": [],
"outputs": [],
"widgets_values": [64, 64, 1],
"widgets_values": [64, 64, 1, 0],
"mode": 0,
}
],
Expand Down Expand Up @@ -1876,7 +1903,7 @@ def test_api_workflow_async_stream_matches_documented_archetype(
assert isinstance(queued["client_id"], str) and queued["client_id"]
assert queued["validation_warnings"] == []
assert queued["nodes"] == [
{"node_id": "1", "class_type": "EmptyLatentImage", "title": "Latent"},
{"node_id": "1", "class_type": "EmptyImage", "title": "Image"},
{"node_id": "2", "class_type": "SaveImage", "title": "Save"},
]
assert queued["base_url"] == "https://api.comfy.org"
Expand Down
Loading
Loading