From 669eb5a5f621389c930e3b89e49714d61f2791ca Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 12:16:28 -0700 Subject: [PATCH 1/5] fix(node): classify malformed installed versions consistently --- CHANGELOG.md | 3 +++ comfy_cli/command/node_deps.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b616d8128..f55927838 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,9 @@ history. ### Fixed +- `comfy node deps` reports malformed installed package versions as `unknown` + consistently across supported `packaging` versions. + - `comfy validate` no longer lets a dotted key left over from another dynamic-combo selection close a false dependency cycle or pull a pruned node back into the run. Checks stay on when the selection can't be resolved. diff --git a/comfy_cli/command/node_deps.py b/comfy_cli/command/node_deps.py index e08733aab..74dcb5957 100644 --- a/comfy_cli/command/node_deps.py +++ b/comfy_cli/command/node_deps.py @@ -273,10 +273,10 @@ def _classify(raw: str, installed_versions: dict[str, str] | None) -> dict[str, # A bare name is satisfied by any installed version. row["status"] = "satisfied" else: - from packaging.version import InvalidVersion + from packaging.version import InvalidVersion, Version try: - contains = req.specifier.contains(installed, prereleases=True) + contains = req.specifier.contains(Version(installed), prereleases=True) except InvalidVersion: # A dist whose recorded version isn't PEP 440 (rare, but a broken # `.dist-info` will do it) can't be compared. Say so rather than From 2e314a161bc4e04da5bba7aad1f47bff9956dc28 Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 13:32:38 -0700 Subject: [PATCH 2/5] fix(node): retain literal version strings during comparison --- comfy_cli/command/node_deps.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/comfy_cli/command/node_deps.py b/comfy_cli/command/node_deps.py index 74dcb5957..77cd4a2ee 100644 --- a/comfy_cli/command/node_deps.py +++ b/comfy_cli/command/node_deps.py @@ -276,7 +276,8 @@ def _classify(raw: str, installed_versions: dict[str, str] | None) -> dict[str, from packaging.version import InvalidVersion, Version try: - contains = req.specifier.contains(Version(installed), prereleases=True) + Version(installed) + contains = req.specifier.contains(installed, prereleases=True) except InvalidVersion: # A dist whose recorded version isn't PEP 440 (rare, but a broken # `.dist-info` will do it) can't be compared. Say so rather than From 4fc42b4701e26eb7ba89e192f7dd6f4697b9f565 Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 14:06:09 -0700 Subject: [PATCH 3/5] fix(node): compare arbitrary equality pins as raw strings --- CHANGELOG.md | 4 ++- comfy_cli/command/node_deps.py | 11 ++++++-- comfy_cli/schemas/node_deps.json | 2 +- tests/comfy_cli/command/test_node_deps.py | 34 +++++++++++++++++++++++ 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc315c6e9..cb448bf36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,9 @@ history. ### Fixed - `comfy node deps` reports malformed installed package versions as `unknown` - consistently across supported `packaging` versions. + consistently across supported `packaging` versions. Pure `===` constraints + compare raw version strings case-insensitively, including legacy versions, + without version normalization. - A typed `comfy model download` with no `--relative-path` now saves into the folder the running local ComfyUI scans for that model type, and says where. diff --git a/comfy_cli/command/node_deps.py b/comfy_cli/command/node_deps.py index 77cd4a2ee..d36319735 100644 --- a/comfy_cli/command/node_deps.py +++ b/comfy_cli/command/node_deps.py @@ -33,7 +33,8 @@ - ``unknown`` — the comparison could not be made: either the installed- packages probe failed (``pip list`` and its ``importlib.metadata`` fallback; accompanied by an ``installed_versions_unavailable`` warning on the report) - or the installed dist records a version that isn't PEP 440. + or the installed dist records a version that isn't PEP 440 and the requirement + includes an operator other than literal ``===`` equality. Known caveat: pyproject dependencies are read through the shared registry parser (:func:`comfy_cli.command.pack_scan.read_pyproject`), which drops the @@ -276,8 +277,12 @@ def _classify(raw: str, installed_versions: dict[str, str] | None) -> dict[str, from packaging.version import InvalidVersion, Version try: - Version(installed) - contains = req.specifier.contains(installed, prereleases=True) + if all(spec.operator == "===" for spec in req.specifier): + # Arbitrary equality compares raw strings, including legacy versions. + contains = all(installed.lower() == spec.version.lower() for spec in req.specifier) + else: + Version(installed) + contains = req.specifier.contains(installed, prereleases=True) except InvalidVersion: # A dist whose recorded version isn't PEP 440 (rare, but a broken # `.dist-info` will do it) can't be compared. Say so rather than diff --git a/comfy_cli/schemas/node_deps.json b/comfy_cli/schemas/node_deps.json index 48d20a1e0..c4ae0392f 100644 --- a/comfy_cli/schemas/node_deps.json +++ b/comfy_cli/schemas/node_deps.json @@ -85,7 +85,7 @@ "status": { "type": "string", "enum": ["satisfied", "mismatch", "missing", "unparseable", "unknown"], - "description": "`unparseable` covers pip options (-r, --extra-index-url) and bare VCS/URL lines; `unknown` means the comparison could not be made (the pip probe failed, or the installed dist records a non-PEP-440 version)." + "description": "`unparseable` covers pip options (-r, --extra-index-url) and bare VCS/URL lines; `unknown` means the comparison could not be made (the pip probe failed, or the installed dist records a non-PEP-440 version and the requirement includes an operator other than ===). Pure === constraints compare raw strings case-insensitively." } }, "required": ["raw", "name", "specifier", "source", "installed", "status"] diff --git a/tests/comfy_cli/command/test_node_deps.py b/tests/comfy_cli/command/test_node_deps.py index bfb256d57..4391b2504 100644 --- a/tests/comfy_cli/command/test_node_deps.py +++ b/tests/comfy_cli/command/test_node_deps.py @@ -255,6 +255,40 @@ def test_non_pep440_installed_version_is_unknown_not_a_crash(tmp_path, monkeypat assert reqs["weirdpkg"]["status"] == "satisfied" +@pytest.mark.parametrize( + "specifier, installed, expected", + [ + ("===foobar", "foobar", "satisfied"), + ("===FOOBAR", "foobar", "satisfied"), + ("===foobar", "FOOBAR", "satisfied"), + ("===foobar", "other", "mismatch"), + ("===foo", "foobar", "mismatch"), + ("===foobar,===FOOBAR", "foobar", "satisfied"), + ("===foobar,===other", "foobar", "mismatch"), + ("===v1.0", "v1.0", "satisfied"), + ("===1.0", "v1.0", "mismatch"), + ("===1.0", "1.0.0", "mismatch"), + ("===1.0", "1.0+local", "mismatch"), + ("===1.0.*", "1.0.1", "mismatch"), + ], +) +def test_arbitrary_equality_compares_raw_installed_values(specifier, installed, expected): + """Literal pins compare strings, including legacy values, without normalization.""" + row = node_deps_cmd._classify("weirdpkg" + specifier, {"weirdpkg": installed}) + + assert row["status"] == expected + assert row["installed"] == installed + + +@pytest.mark.parametrize("specifier", [">=1", "===foobar,>=1", ">=1,===foobar"]) +def test_non_pep440_installed_version_stays_unknown_with_nonliteral_constraints(specifier): + """A literal clause must not bypass validation required by another operator.""" + row = node_deps_cmd._classify("weirdpkg" + specifier, {"weirdpkg": "foobar"}) + + assert row["status"] == "unknown" + assert row["installed"] == "foobar" + + def test_pip_list_runs_once_for_the_whole_report(workspace, fake_pip): node_deps_cmd.build_report(str(workspace), python="/fake/python") From 26a7a6ea723ace830f6136a18a04367ae120c416 Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 15:36:22 -0700 Subject: [PATCH 4/5] test: isolate preflight fixtures and compare platform trust roots --- tests/comfy_cli/command/test_run.py | 34 +++++-- tests/comfy_cli/command/test_run_json.py | 92 ++++++++++++------- tests/comfy_cli/command/test_run_prompt.py | 16 +++- .../output/test_error_envelope_where.py | 8 +- tests/comfy_cli/test_http.py | 5 +- 5 files changed, 104 insertions(+), 51 deletions(-) diff --git a/tests/comfy_cli/command/test_run.py b/tests/comfy_cli/command/test_run.py index 9731c0233..3af335823 100644 --- a/tests/comfy_cli/command/test_run.py +++ b/tests/comfy_cli/command/test_run.py @@ -2363,14 +2363,29 @@ def test_markup_in_node_name_does_not_crash_confirm(self, monkeypatch): class TestExecuteUiWorkflow: + @pytest.fixture(autouse=True) + def local_preflight_catalog(self, monkeypatch): + """Validate against the complete conversion fixture without a live server.""" + from copy import deepcopy + + monkeypatch.setattr("comfy_cli.command.run._fetch_object_info", lambda *a, **k: deepcopy(self.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) + 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, }, { @@ -2384,19 +2399,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"]}}, @@ -2435,7 +2451,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() diff --git a/tests/comfy_cli/command/test_run_json.py b/tests/comfy_cli/command/test_run_json.py index a6ba3f478..eca122763 100644 --- a/tests/comfy_cli/command/test_run_json.py +++ b/tests/comfy_cli/command/test_run_json.py @@ -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", @@ -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" @@ -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"], @@ -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) @@ -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": [], @@ -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({}) @@ -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, }, { @@ -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"]}}, @@ -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 ( @@ -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" @@ -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) @@ -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" @@ -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", @@ -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, } ], @@ -1414,7 +1440,7 @@ 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")), ): lines, exit_code = _run_execute_capture(path, capsys) assert _envelope(lines)["error"]["code"] == "connection_error" @@ -1427,10 +1453,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, } ], @@ -1876,7 +1902,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" diff --git a/tests/comfy_cli/command/test_run_prompt.py b/tests/comfy_cli/command/test_run_prompt.py index c67139558..da6f3c557 100644 --- a/tests/comfy_cli/command/test_run_prompt.py +++ b/tests/comfy_cli/command/test_run_prompt.py @@ -9,6 +9,8 @@ from __future__ import annotations +import json +from pathlib import Path from unittest.mock import MagicMock, patch import pytest @@ -32,11 +34,15 @@ class TestExecuteSubmitsPreloadedGraph: """`preloaded` short-circuits file loading; the in-memory graph is what reaches the submit path (WorkflowExecution).""" + @pytest.fixture(autouse=True) + def preloaded_catalog(self): + """Validate the injected graph against a frozen catalog, without a server.""" + catalog = json.loads((Path(__file__).resolve().parents[1] / "fixtures/sd15_object_info.json").read_text()) + with patch("comfy_cli.command.run._fetch_object_info", return_value=catalog): + yield + def test_preloaded_graph_is_submitted(self): - injected = { - "6": {"class_type": "CLIPTextEncode", "inputs": {"text": "a red fox in snow"}}, - "9": {"class_type": "SaveImage", "inputs": {"images": ["8", 0]}}, - } + injected = build_default_workflow(prompt="a red fox in snow") with ( patch("comfy_cli.command.run.check_comfy_server_running", return_value=True), patch("comfy_cli.command.run.ExecutionProgress"), @@ -63,7 +69,7 @@ def test_preloaded_graph_is_submitted(self): def test_preloaded_skips_file_loading(self): """A non-existent path never triggers workflow_not_found when preloaded.""" - injected = {"9": {"class_type": "SaveImage", "inputs": {}}} + injected = build_default_workflow(prompt="fox") with ( patch("comfy_cli.command.run.check_comfy_server_running", return_value=True), patch("comfy_cli.command.run.ExecutionProgress"), diff --git a/tests/comfy_cli/output/test_error_envelope_where.py b/tests/comfy_cli/output/test_error_envelope_where.py index e84ae3a06..ed0ae837f 100644 --- a/tests/comfy_cli/output/test_error_envelope_where.py +++ b/tests/comfy_cli/output/test_error_envelope_where.py @@ -324,15 +324,19 @@ def _workflow(tmp_path): def test_cloud(self, tmp_path): err = LoadError("no object_info", details={"hint": "sign in"}) - with patch("comfy_cli.cql.engine.Graph.load", side_effect=err): + with patch("comfy_cli.cql.loader.resilient_load_object_info", side_effect=err) as load: env = _run(["--json", "validate", "--workflow", self._workflow(tmp_path), "--where", "cloud"]) + load.assert_called_once() + assert load.call_args.kwargs["mode"] == "cloud" assert env["error"]["code"] == "cql_no_graph" assert env["where"] == "cloud" def test_local(self, tmp_path): err = LoadError("no object_info", details={"hint": "comfy launch"}) - with patch("comfy_cli.cql.engine.Graph.load", side_effect=err): + with patch("comfy_cli.cql.loader.resilient_load_object_info", side_effect=err) as load: env = _run(["--json", "validate", "--workflow", self._workflow(tmp_path), "--where", "local"]) + load.assert_called_once() + assert load.call_args.kwargs["mode"] == "local" assert env["error"]["code"] == "cql_no_graph" assert env["where"] == "local" diff --git a/tests/comfy_cli/test_http.py b/tests/comfy_cli/test_http.py index 703199d85..20adb7027 100644 --- a/tests/comfy_cli/test_http.py +++ b/tests/comfy_cli/test_http.py @@ -819,7 +819,6 @@ def test_an_unloadable_supplement_falls_through_to_the_platform_roots(tmp_path, monkeypatch.setitem(sys.modules, "certifi", types.SimpleNamespace(where=lambda: str(broken))) real = ssl.create_default_context - populated = len(pathlib.Path(certifi.where()).read_text().split("-----BEGIN CERTIFICATE-----")) - 1 def platform_with_roots(*args, **kwargs): context = real(*args, **kwargs) @@ -827,13 +826,15 @@ def platform_with_roots(*args, **kwargs): context.load_verify_locations(cafile=certifi.where()) return context + expected_roots = set(platform_with_roots().get_ca_certs(binary_form=True)) + assert expected_roots, "the platform fixture must contain trust roots" monkeypatch.setattr(ssl, "create_default_context", platform_with_roots) # When context = http_mod.ssl_context() # Then - assert context.cert_store_stats()["x509_ca"] == populated, ( + assert set(context.get_ca_certs(binary_form=True)) == expected_roots, ( "the platform roots must survive a supplement that would not load" ) From e3bfa401d6b3970c2211ec11eacb069135b1e7dc Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 16:32:18 -0700 Subject: [PATCH 5/5] fix(node): preserve raw metadata in dependency comparisons --- CHANGELOG.md | 7 +- comfy_cli/command/node_deps.py | 62 +++++----- comfy_cli/error_codes.py | 6 +- comfy_cli/schemas/node_deps.json | 8 +- tests/comfy_cli/command/test_logs.py | 2 + tests/comfy_cli/command/test_node_deps.py | 140 ++++++++++++++++++++-- 6 files changed, 170 insertions(+), 55 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb448bf36..f1342635f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,9 +30,10 @@ history. ### Fixed - `comfy node deps` reports malformed installed package versions as `unknown` - consistently across supported `packaging` versions. Pure `===` constraints - compare raw version strings case-insensitively, including legacy versions, - without version normalization. + consistently across supported `packaging` versions. One metadata probe + preserves raw installed versions with or without pip. Every `===` clause + compares raw strings case-insensitively, including in mixed constraints; + ordinary clauses still require valid versions and use semantic comparison. - A typed `comfy model download` with no `--relative-path` now saves into the folder the running local ComfyUI scans for that model type, and says where. diff --git a/comfy_cli/command/node_deps.py b/comfy_cli/command/node_deps.py index d36319735..b16355512 100644 --- a/comfy_cli/command/node_deps.py +++ b/comfy_cli/command/node_deps.py @@ -8,14 +8,13 @@ ``--registry `` extends the same diff to a pack that is **not yet installed**: the registry's published dependency list for that pack's latest -version, diffed against the very same ``pip list`` map, so conflict risk can be +version, diffed against the same installed-version map, so conflict risk can be assessed *before* installing anything. Read-only by construction: it never installs anything and never shells out to -``cm-cli``. The only subprocess it runs is a single `` -m pip -list --format=json`` for the whole report (not once per pack), plus one -``importlib.metadata`` listing in the same interpreter when that interpreter has -no pip (a ``uv venv`` ships without it). The only network +``cm-cli``. The only subprocess it runs is one guarded ``importlib.metadata`` +listing in the workspace interpreter for the whole report (not once per pack). +It reads raw metadata versions whether or not pip is installed. The only network call is the registry's side-effect-free ``GET /nodes/{id}``, made solely for ``--registry`` ids — never ``install_node``, whose endpoint records an installation and fires an analytics event server-side on every call. @@ -31,8 +30,7 @@ bare VCS/URL line, or anything else :class:`packaging.requirements.Requirement` rejects. Kept in the report rather than dropped silently; - ``unknown`` — the comparison could not be made: either the installed- - packages probe failed (``pip list`` and its ``importlib.metadata`` fallback; - accompanied by an ``installed_versions_unavailable`` warning on the report) + packages metadata probe failed (accompanied by an ``installed_versions_unavailable`` warning on the report) or the installed dist records a version that isn't PEP 440 and the requirement includes an operator other than literal ``===`` equality. @@ -103,9 +101,9 @@ # --------------------------------------------------------------------------- -# Fallback probe for an interpreter without pip (a ``uv venv`` has none): the -# same ``[{"name", "version"}]`` shape as ``pip list --format=json``, read with -# the stdlib inside that interpreter. +# Read raw Name/Version metadata with the workspace interpreter's stdlib. +# `pip list` normalizes valid versions, losing spellings needed by `===`. +# The JSON shape stays [{"name", "version"}], with no pip dependency. # # - Before anything that could be shadowed is imported, every ``sys.path`` entry # naming the caller's directory is dropped (the ``-c`` ``''`` entry and e.g. @@ -176,23 +174,16 @@ def _list_installed(cmd: list[str], label: str) -> tuple[dict[str, str] | None, def pip_list(python: str) -> tuple[dict[str, str] | None, str | None]: - """Return ``(canonical_name -> version, error)`` for the workspace venv. - - Runs `` -m pip list --format=json`` once for the whole report. If - that exits non-zero — typically ``No module named pip`` in a uv-created - venv — the same interpreter is asked once more via ``importlib.metadata``. - A timeout or an interpreter that can't be started is not retried: the - fallback would hit the same wall and only double the wait. On failure the - map is ``None`` with a human-readable reason — a report that can't see the - venv is still a useful report. + """Return ``(canonical_name -> raw metadata version, error)`` for the venv. + + The legacy helper name is retained, but pip is never invoked: its display + output normalizes valid versions. One guarded ``importlib.metadata`` probe + preserves raw values and works in pip-less venvs too. A failed or timed-out + probe is not retried; the map is ``None`` with a human-readable reason so + the report can retain requirements with unknown installed versions. """ - versions, pip_error, exited_nonzero = _list_installed([python, "-m", "pip", "list", "--format=json"], "`pip list`") - if versions is not None or not exited_nonzero: - return versions, pip_error - versions, metadata_error, _ = _list_installed([python, "-c", _METADATA_LIST_SCRIPT], "`importlib.metadata`") - if versions is not None: - return versions, None - return None, f"{pip_error}; {metadata_error}" + versions, error, _ = _list_installed([python, "-c", _METADATA_LIST_SCRIPT], "`importlib.metadata`") + return versions, error # --------------------------------------------------------------------------- @@ -277,12 +268,15 @@ def _classify(raw: str, installed_versions: dict[str, str] | None) -> dict[str, from packaging.version import InvalidVersion, Version try: - if all(spec.operator == "===" for spec in req.specifier): - # Arbitrary equality compares raw strings, including legacy versions. - contains = all(installed.lower() == spec.version.lower() for spec in req.specifier) - else: + # Validate before any clause can short-circuit a mixed constraint. + if any(spec.operator != "===" for spec in req.specifier): Version(installed) - contains = req.specifier.contains(installed, prereleases=True) + contains = all( + installed.lower() == spec.version.lower() + if spec.operator == "===" + else spec.contains(installed, prereleases=True) + for spec in req.specifier + ) except InvalidVersion: # A dist whose recorded version isn't PEP 440 (rare, but a broken # `.dist-info` will do it) can't be compared. Say so rather than @@ -506,7 +500,7 @@ def _registry_report( row["warning"] = message warnings.append({"code": "registry_partial_dependency_metadata", "message": message}) - # Same per-requirement diff, against the same single ``pip list`` map. + # Same per-requirement diff, against the same single installed-version map. rows: dict[str, dict[str, Any]] = {} for line in declared: if line not in rows: @@ -563,14 +557,14 @@ def build_report( workspace = Path(comfy_path) python = python or resolve_workspace_python(comfy_path) - installed_versions, pip_error = pip_list(python) + installed_versions, probe_error = pip_list(python) if installed_versions is None: warnings.append( { "code": "installed_versions_unavailable", "message": ( f"could not read installed packages from {python}" - + (f" ({pip_error})" if pip_error else "") + + (f" ({probe_error})" if probe_error else "") + " — every parseable requirement is reported with status 'unknown'" ), } diff --git a/comfy_cli/error_codes.py b/comfy_cli/error_codes.py index e7a82ee0c..23799bb01 100644 --- a/comfy_cli/error_codes.py +++ b/comfy_cli/error_codes.py @@ -1271,9 +1271,9 @@ class ErrorCode: # --- custom node dependency report (`comfy node deps`) -------------------- ErrorCode( "installed_versions_unavailable", - "`comfy node deps` could not read the workspace venv's installed packages (`pip list --format=json` " - "timed out, returned unparseable output, or exited non-zero and its `importlib.metadata` fallback " - "failed too), so every parseable requirement is reported with " + "`comfy node deps` could not read the workspace venv's raw installed-package metadata " + "(the guarded `importlib.metadata` probe timed out, returned unparseable output, or failed), " + "so every parseable requirement is reported with " '`status: "unknown"`. Surfaced in `data.warnings[]` (not as an error envelope) so the declared ' "requirements are still reported.", "check the workspace interpreter runs (`comfy env`), then re-run", diff --git a/comfy_cli/schemas/node_deps.json b/comfy_cli/schemas/node_deps.json index c4ae0392f..b4cdebc95 100644 --- a/comfy_cli/schemas/node_deps.json +++ b/comfy_cli/schemas/node_deps.json @@ -7,7 +7,7 @@ "workspace": { "type": "string", "description": "Resolved ComfyUI workspace path." }, "python": { "type": "string", - "description": "Interpreter whose site-packages were probed (`pip list --format=json`, run once for the whole report; an `importlib.metadata` listing in the same interpreter when it has no pip)." + "description": "Interpreter whose raw Name/Version metadata was read with one guarded importlib.metadata probe for the whole report, whether or not pip is installed." }, "compiled_lock": { "type": "object", @@ -80,12 +80,12 @@ "source": { "type": "string", "enum": ["requirements.txt", "pyproject.toml", "registry"] }, "installed": { "type": ["string", "null"], - "description": "Version found in the workspace venv, or null when missing/unparseable/unknown." + "description": "Raw metadata version found in the workspace venv, or null when missing/unparseable/unavailable." }, "status": { "type": "string", "enum": ["satisfied", "mismatch", "missing", "unparseable", "unknown"], - "description": "`unparseable` covers pip options (-r, --extra-index-url) and bare VCS/URL lines; `unknown` means the comparison could not be made (the pip probe failed, or the installed dist records a non-PEP-440 version and the requirement includes an operator other than ===). Pure === constraints compare raw strings case-insensitively." + "description": "`unparseable` covers pip options (-r, --extra-index-url) and bare VCS/URL lines; `unknown` means the comparison could not be made (the metadata probe failed, or the installed dist records a non-PEP-440 version and the requirement includes an operator other than ===). Each === clause compares raw strings case-insensitively; any other operator requires a PEP-440-valid installed version." } }, "required": ["raw", "name", "specifier", "source", "installed", "status"] @@ -109,7 +109,7 @@ }, "warnings": { "type": "array", - "description": "Non-fatal problems. `installed_versions_unavailable` means the installed-packages probe (pip, then importlib.metadata) failed, so every requirement is `unknown`. `registry_unavailable` (transient — retry) / `registry_node_not_found` (permanent 404 — do NOT retry) / `registry_no_dependency_metadata` mean a `--registry` candidate could not be diffed; `registry_partial_dependency_metadata` means its `declared` list lost malformed entries and is incomplete; `registry_invalid_node_id` means a `--registry` value was blank or outside `[A-Za-z0-9._-]` and was rejected without a request. Every other row is unaffected.", + "description": "Non-fatal problems. `installed_versions_unavailable` means the installed-packages metadata probe failed, so every requirement is `unknown`. `registry_unavailable` (transient — retry) / `registry_node_not_found` (permanent 404 — do NOT retry) / `registry_no_dependency_metadata` mean a `--registry` candidate could not be diffed; `registry_partial_dependency_metadata` means its `declared` list lost malformed entries and is incomplete; `registry_invalid_node_id` means a `--registry` value was blank or outside `[A-Za-z0-9._-]` and was rejected without a request. Every other row is unaffected.", "items": { "type": "object", "properties": { diff --git a/tests/comfy_cli/command/test_logs.py b/tests/comfy_cli/command/test_logs.py index 0fe1a5e0b..e713f527f 100644 --- a/tests/comfy_cli/command/test_logs.py +++ b/tests/comfy_cli/command/test_logs.py @@ -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) diff --git a/tests/comfy_cli/command/test_node_deps.py b/tests/comfy_cli/command/test_node_deps.py index 4391b2504..b1ac0e634 100644 --- a/tests/comfy_cli/command/test_node_deps.py +++ b/tests/comfy_cli/command/test_node_deps.py @@ -1,8 +1,9 @@ """Tests for ``comfy node deps`` — per-pack declared-vs-installed dependencies. Builds a fixture workspace with fake ``custom_nodes//requirements.txt`` + -``pyproject.toml`` under tmp_path and mocks the single ``pip list --format=json`` -subprocess to a fixed payload, so nothing touches a real venv or the network. +``pyproject.toml`` under tmp_path. Most cases mock the single installed-metadata +probe; integration cases use an isolated interpreter and hand-written metadata. +No package installer or network setup is needed. """ from __future__ import annotations @@ -231,7 +232,7 @@ def test_environment_marker_is_surfaced_not_evaluated(tmp_path, fake_pip): # --------------------------------------------------------------------------- -# pip list behavior +# installed-metadata probe behavior # --------------------------------------------------------------------------- @@ -289,15 +290,130 @@ def test_non_pep440_installed_version_stays_unknown_with_nonliteral_constraints( assert row["installed"] == "foobar" +@pytest.mark.parametrize( + "specifier, installed, expected", + [ + ("===v1.0,>=1", "v1.0", "satisfied"), + (">=1,===v1.0", "v1.0", "satisfied"), + ("===1.0,>=1", "v1.0", "mismatch"), + (">=1,===1.0", "v1.0", "mismatch"), + ("===v1.0,!=2", "v1.0", "satisfied"), + ("===v1.0,==1.0", "v1.0", "satisfied"), + ("===v1.0,<1", "v1.0", "mismatch"), + ("===1.0rc1,>=0", "1.0rc1", "satisfied"), + ("===1.0rc1,<1.0", "1.0rc1", "mismatch"), + ("===other,>=1", "foobar", "unknown"), + (">=1,===other", "foobar", "unknown"), + ], +) +def test_mixed_constraints_preserve_raw_literals_and_semantic_clauses(specifier, installed, expected): + """Adding an ordinary clause must neither normalize a literal nor skip validation.""" + row = node_deps_cmd._classify("weirdpkg" + specifier, {"weirdpkg": installed}) + + assert row["status"] == expected + assert row["installed"] == installed + + +@pytest.fixture +def isolated_probe_python(tmp_path): + """A real interpreter with no package installers or network setup.""" + import venv + + root = tmp_path / "probe-venv" + venv.EnvBuilder(with_pip=False, symlinks=os.name != "nt").create(root) + python = str(root / ("Scripts/python.exe" if sys.platform == "win32" else "bin/python")) + site = subprocess.run( + [python, "-c", "import sysconfig; print(sysconfig.get_path('purelib'))"], + capture_output=True, + text=True, + check=True, + ).stdout.strip() + return python, Path(site) + + +def _write_dist_info(site: Path, directory: str, name: str, version: str) -> None: + dist = site / directory + dist.mkdir(parents=True) + (dist / "METADATA").write_text(f"Metadata-Version: 2.1\nName: {name}\nVersion: {version}\n") + + +@pytest.mark.parametrize("pip_present", [False, True]) +def test_report_uses_one_raw_metadata_probe_with_or_without_pip( + tmp_path, monkeypatch, isolated_probe_python, pip_present +): + python, site = isolated_probe_python + _write_dist_info(site, "Foo-1.0.dist-info", "Foo", "v1.0") + if pip_present: + # Pip is importable, but must never be the source of raw version data. + # Its output is deliberately not faked: only the real metadata is read. + pip = site / "pip" + pip.mkdir() + (pip / "__init__.py").write_text("") + (pip / "__main__.py").write_text('raise AssertionError("pip must not be invoked")\n') + workspace = tmp_path / "ComfyUI" + _make_pack(workspace, "pack", requirements="foo===v1.0\nfoo===1.0\nfoo>=1\nfoo\nabsent\n") + monkeypatch.setenv("PYTHONPATH", "") + calls = [] + real_run = subprocess.run + + def record(cmd, **kwargs): + calls.append((cmd, kwargs)) + return real_run(cmd, **kwargs) + + monkeypatch.setattr(node_deps_cmd.subprocess, "run", record) + report, warnings = node_deps_cmd.build_report(str(workspace), python=python) + reqs = _reqs_by_raw(_packs_by_name(report)["pack"]) + + assert warnings == [] + assert reqs["foo===v1.0"]["installed"] == "v1.0" + assert reqs["foo===v1.0"]["status"] == "satisfied" + assert reqs["foo===1.0"]["status"] == "mismatch" + assert reqs["foo>=1"]["status"] == "satisfied" + assert reqs["foo"]["status"] == "satisfied" + assert reqs["absent"]["status"] == "missing" + assert len(calls) == 1 + assert calls[0][0] == [python, "-c", node_deps_cmd._METADATA_LIST_SCRIPT] + assert calls[0][1]["timeout"] == 60 + assert calls[0][1]["check"] is True + + +def test_metadata_probe_excludes_cwd_and_keeps_first_canonical_copy(tmp_path, monkeypatch, isolated_probe_python): + python, site = isolated_probe_python + first, second, leftovers, cwd = [tmp_path / name for name in ("first", "second", "leftovers", "caller")] + _write_dist_info(first, "foo_pack-1.0.dist-info", "Foo.Pack", "v1.0") + _write_dist_info(second, "foo_pack-2.0.dist-info", "foo-pack", "v2.0") + _write_dist_info(site, "foo_pack-3.0.dist-info", "foo_pack", "v3.0") + _write_dist_info(leftovers, "~oo_pack-0.1.dist-info", "foo-pack", "v0.1") + _write_dist_info(cwd, "foo_pack-9.0.dist-info", "foo-pack", "v9.0") + (cwd / "json.py").write_text('raise AssertionError("caller json.py imported")\n') + broken = first / "broken-1.0.dist-info" + broken.mkdir() + (broken / "METADATA").write_bytes(b"Name: broken\nVersion: 1.0\nSummary: \xff\xfe\n") + workspace = tmp_path / "ComfyUI" + _make_pack(workspace, "pack", requirements="foo-pack===v1.0\nfoo-pack>=1\nabsent\n") + monkeypatch.chdir(cwd) + monkeypatch.setenv("PYTHONPATH", os.pathsep.join([".", str(leftovers), str(first), str(second)])) + + report, warnings = node_deps_cmd.build_report(str(workspace), python=python) + reqs = _reqs_by_raw(_packs_by_name(report)["pack"]) + + assert warnings == [] + assert reqs["foo-pack===v1.0"]["installed"] == "v1.0" + assert reqs["foo-pack===v1.0"]["status"] == "satisfied" + assert reqs["foo-pack>=1"]["status"] == "satisfied" + assert reqs["absent"]["status"] == "missing" + + def test_pip_list_runs_once_for_the_whole_report(workspace, fake_pip): node_deps_cmd.build_report(str(workspace), python="/fake/python") - assert len(fake_pip.calls) == 1, f"pip list ran {len(fake_pip.calls)}x — must be once per report" - assert fake_pip.calls[0] == ["/fake/python", "-m", "pip", "list", "--format=json"] + assert len(fake_pip.calls) == 1, f"installed probe ran {len(fake_pip.calls)}x — must be once per report" + assert fake_pip.calls[0] == ["/fake/python", "-c", node_deps_cmd._METADATA_LIST_SCRIPT] def test_pip_list_failure_degrades_to_unknown_with_a_warning(workspace, monkeypatch): - monkeypatch.setattr(node_deps_cmd.subprocess, "run", _FakePipList(returncode=2)) + probe = _FakePipList(returncode=2) + monkeypatch.setattr(node_deps_cmd.subprocess, "run", probe) report, warnings = node_deps_cmd.build_report(str(workspace), python="/fake/python") @@ -306,14 +422,16 @@ def test_pip_list_failure_degrades_to_unknown_with_a_warning(workspace, monkeypa reqs = _reqs_by_raw(pack) assert reqs["opencv-python>=4.7"]["status"] == "unknown" assert reqs["opencv-python>=4.7"]["installed"] is None - # unparseable lines stay unparseable — the pip probe can't change that + # unparseable lines stay unparseable — the installed probe can't change that assert reqs["-r other-requirements.txt"]["status"] == "unparseable" assert pack["summary"]["unknown"] == 4 assert pack["summary"]["unparseable"] == 3 + assert len(probe.calls) == 1 -def test_pip_list_unparseable_output_degrades_to_unknown(workspace, monkeypatch): - monkeypatch.setattr(node_deps_cmd.subprocess, "run", _FakePipList(stdout="not json at all")) +@pytest.mark.parametrize("stdout", ["not json at all", "{}"]) +def test_pip_list_unparseable_output_degrades_to_unknown(workspace, monkeypatch, stdout): + monkeypatch.setattr(node_deps_cmd.subprocess, "run", _FakePipList(stdout=stdout)) report, warnings = node_deps_cmd.build_report(str(workspace), python="/fake/python") @@ -370,7 +488,7 @@ def test_interpreter_without_pip_still_reports_installed_versions(tmp_path, monk def test_pip_list_timeout_is_not_retried(workspace, monkeypatch): - """A hung interpreter would hang the fallback too; don't double the wait.""" + """A hung interpreter must not be retried; do not double the wait.""" calls = [] def _hang(cmd, **kwargs): @@ -507,7 +625,7 @@ def test_registry_candidate_is_diffed_against_the_same_pip_list(workspace, fake_ assert all(r["source"] == "registry" for r in row["requirements"]) assert row["summary"] == {"satisfied": 1, "mismatch": 1, "missing": 1, "unparseable": 1, "unknown": 0} - # A single `pip list`, shared with the installed packs — not one per entry. + # One installed-version probe, shared with installed packs — not one per entry. assert len(fake_pip.calls) == 1