Skip to content

Commit 61a3c47

Browse files
committed
Add tests.
1 parent ab42efc commit 61a3c47

File tree

2 files changed

+92
-6
lines changed

2 files changed

+92
-6
lines changed

comfy_cli/command/custom_nodes/command.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
extract_node_configuration,
2727
initialize_project_config,
2828
)
29-
from comfy_cli.validators import MutuallyExclusiveValidator
3029
from comfy_cli.workspace_manager import WorkspaceManager
3130

3231
console = Console()
@@ -36,9 +35,6 @@
3635
workspace_manager = WorkspaceManager()
3736
registry_api = RegistryAPI()
3837

39-
# Global validator for mutually exclusive dependency options
40-
g_deps_exclusivity = MutuallyExclusiveValidator()
41-
4238

4339
def validate_comfyui_manager(_env_checker):
4440
manager_path = _env_checker.get_comfyui_manager_path()
@@ -402,7 +398,6 @@ def install(
402398
"--fast-deps",
403399
show_default=False,
404400
help="Use new fast dependency installer",
405-
callback=g_deps_exclusivity.validate,
406401
),
407402
] = False,
408403
no_deps: Annotated[
@@ -411,7 +406,6 @@ def install(
411406
"--no-deps",
412407
show_default=False,
413408
help="Skip dependency installation",
414-
callback=g_deps_exclusivity.validate,
415409
),
416410
] = False,
417411
exit_on_fail: Annotated[
@@ -431,6 +425,10 @@ def install(
431425
typer.echo(f"Invalid command: {mode}. `install all` is not allowed", err=True)
432426
raise typer.Exit(code=1)
433427

428+
if fast_deps and no_deps:
429+
typer.echo("Cannot use --fast-deps and --no-deps together", err=True)
430+
raise typer.Exit(code=1)
431+
434432
validate_mode(mode)
435433

436434
if exit_on_fail:
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from unittest.mock import patch
2+
3+
from typer.testing import CliRunner
4+
5+
from comfy_cli.command.custom_nodes.command import app
6+
7+
runner = CliRunner()
8+
9+
10+
def test_install_no_deps_option_exists():
11+
"""Test that the --no-deps option appears in the help."""
12+
result = runner.invoke(app, ["install", "--help"])
13+
assert result.exit_code == 0
14+
assert "--no-deps" in result.stdout
15+
assert "Skip dependency installation" in result.stdout
16+
17+
18+
def test_install_fast_deps_and_no_deps_mutually_exclusive():
19+
"""Test that --fast-deps and --no-deps cannot be used together."""
20+
result = runner.invoke(app, ["install", "test-node", "--fast-deps", "--no-deps"])
21+
assert result.exit_code != 0
22+
assert "Cannot use --fast-deps and --no-deps together" in result.stdout
23+
24+
25+
def test_install_no_deps_alone_works():
26+
"""Test that --no-deps can be used by itself."""
27+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
28+
result = runner.invoke(app, ["install", "test-node", "--no-deps"])
29+
30+
# Should not exit with error due to mutual exclusivity
31+
if result.exit_code != 0:
32+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
33+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
34+
35+
# Verify execute_cm_cli was called with no_deps=True
36+
if mock_execute.called:
37+
_, kwargs = mock_execute.call_args
38+
assert kwargs.get("no_deps") is True
39+
assert kwargs.get("fast_deps") is False
40+
41+
42+
def test_install_fast_deps_alone_works():
43+
"""Test that --fast-deps can be used by itself."""
44+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
45+
result = runner.invoke(app, ["install", "test-node", "--fast-deps"])
46+
47+
# Should not exit with error due to mutual exclusivity
48+
if result.exit_code != 0:
49+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
50+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
51+
52+
# Verify execute_cm_cli was called with fast_deps=True
53+
if mock_execute.called:
54+
_, kwargs = mock_execute.call_args
55+
assert kwargs.get("fast_deps") is True
56+
assert kwargs.get("no_deps") is False
57+
58+
59+
def test_install_neither_deps_option():
60+
"""Test that install works without any deps options."""
61+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli") as mock_execute:
62+
result = runner.invoke(app, ["install", "test-node"])
63+
64+
# Should not exit with error due to mutual exclusivity
65+
if result.exit_code != 0:
66+
# Only acceptable if it fails due to missing ComfyUI setup, not mutual exclusivity
67+
assert "Cannot use --fast-deps and --no-deps together" not in result.stdout
68+
69+
# Verify execute_cm_cli was called with both flags False
70+
if mock_execute.called:
71+
_, kwargs = mock_execute.call_args
72+
assert kwargs.get("fast_deps") is False
73+
assert kwargs.get("no_deps") is False
74+
75+
76+
def test_multiple_commands_work_independently():
77+
"""Test that multiple commands work independently without state interference."""
78+
# First command with --no-deps should work
79+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"):
80+
result1 = runner.invoke(app, ["install", "test-node", "--no-deps"])
81+
if result1.exit_code != 0:
82+
assert "Cannot use --fast-deps and --no-deps together" not in result1.stdout
83+
84+
# Second command with --fast-deps should also work
85+
with patch("comfy_cli.command.custom_nodes.command.execute_cm_cli"):
86+
result2 = runner.invoke(app, ["install", "test-node2", "--fast-deps"])
87+
if result2.exit_code != 0:
88+
assert "Cannot use --fast-deps and --no-deps together" not in result2.stdout

0 commit comments

Comments
 (0)