From d5affe4caffe1acf72a2f4fd1cd2cb2f01c174c8 Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Tue, 20 Oct 2026 17:53:40 -0700 Subject: [PATCH 1/4] fix(build): validate public pins during dry runs --- CHANGELOG.md | 10 ++ comfy_cli/command/build.py | 83 ++++++++---- comfy_cli/error_codes.py | 4 +- .../skills/comfy-build-failures/SKILL.md | 9 +- comfy_cli/skills/comfy-build/SKILL.md | 20 ++- tests/comfy_cli/command/build_auth_support.py | 21 ++- .../command/test_build_auth_matrix.py | 13 ++ tests/comfy_cli/command/test_build_push.py | 120 ++++++++++++++++++ 8 files changed, 245 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bbf3db5e..0c3055ff9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -170,6 +170,16 @@ history. already finished. Neither old key is published any more. The second exit was also skipping the trimming and redaction that key drives, so it emitted the full traceback and a `current_inputs` that can hold an api_key. +- `comfy build push --dry-run` now runs the push's registry-pin check, so a + pin the builder cannot place fails the dry run with the push's own + `build_registry_pin_missing` error instead of passing it. A version the + registry has Flagged was the common case: the dry run passed, and the push + was refused only after the plan had been disclosed. The check asks the + builder's snapshot importer to place each public pack, a read that writes + nothing, and the dry run still uploads and saves nothing. A spec that pins + a public pack now needs sign-in for its dry run (`build_not_signed_in` + otherwise); a spec whose packs are all local still sends no request. + - `comfy workflow validate` (and `comfy run`'s pre-submit check) accepts a literal the server converts before checking it: an integer string on an INT input (`"1536"`), a numeric string on a FLOAT input, a number on a STRING diff --git a/comfy_cli/command/build.py b/comfy_cli/command/build.py index 7ddc30d11..09bb43307 100644 --- a/comfy_cli/command/build.py +++ b/comfy_cli/command/build.py @@ -1878,6 +1878,37 @@ def _write_spec(renderer, path: Path, spec: dict) -> None: raise typer.Exit(code=1) from error +def _require_public_pins(renderer, client, public_nodes: list[dict], spec_file: Path) -> None: + """Ask the builder's importer to place every public pack, and refuse with + ``build_registry_pin_missing`` naming each identity it could not place: a + registry version it does not publish (a Flagged one among them), or a + repository it cannot normalize. + + The importer reads the snapshot and writes nothing, which is what lets + ``push --dry-run`` make the same call and refuse the same way. A lookup that + itself fails exits through ``_builder_call`` rather than passing the pins.""" + imported = _builder_call( + renderer, + lambda: client.resolve_snapshot(snapshot_from_definition({"customNodes": public_nodes})), + ) + checked = (imported.get("definition") or {}).get("customNodes") or [] + try: + missing = public_node_identities(public_nodes) - public_node_identities( + public_node_projection({"customNodes": checked}) + ) + except BuildSpecInvalidError as error: + renderer.error(code=error.code, message=str(error), details={"path": str(spec_file)}) + raise typer.Exit(code=1) from error + if missing: + labels = sorted(f"{identity.kind}:{identity.value}@{identity.version or '-'}" for identity in missing) + renderer.error( + code="build_registry_pin_missing", + message="the builder could not resolve these custom node identities: " + ", ".join(labels), + hint="edit the spec to name a published registry version or normalized repository, or remove the node", + ) + raise typer.Exit(code=1) + + @app.command("push", help="Push the local comfy-build spec to the builder.") @tracking.track_command("build") def push_cmd( @@ -1911,7 +1942,13 @@ def push_cmd( help="With --release, cut the release even though the save warned about a model link.", ), ] = False, - dry_run: Annotated[bool, typer.Option("--dry-run", help="Compute uploads locally; send no HTTP requests.")] = False, + dry_run: Annotated[ + bool, + typer.Option( + "--dry-run", + help="Compute uploads locally and check public custom node pins with the builder; upload and save nothing.", + ), + ] = False, models_dir: Annotated[ str | None, typer.Option("--models-dir", help="Models folder used to resolve model localPath values."), @@ -1926,7 +1963,7 @@ def push_cmd( if release and dry_run: renderer.error( code="build_missing_input", - message="--release cuts a release from a real push, and --dry-run sends nothing.", + message="--release cuts a release from a real push, and --dry-run saves nothing.", hint="drop --dry-run to cut the release, or drop --release to preview the push", details={"conflict": ["--release", "--dry-run"]}, ) @@ -2007,15 +2044,30 @@ def push_cmd( if reported: payload["skipped_symlinks"] = reported if dry_run: + # The pin check is the one question a dry run asks the builder: it is a + # read, it costs nothing, and it is the refusal a push otherwise meets + # only after the plan was disclosed. A spec without a public pin asks + # nothing, so it needs no sign-in. + public_nodes = public_node_projection(preparation.definition) + if public_nodes: + _require_public_pins(renderer, _builder_client(renderer, builder_url), public_nodes, paths.spec_file) # The envelope is the whole answer and prints nothing in pretty mode, so a # person gets the real push's opening line and word that nothing moved. # "Already held" is what the spec records; the builder, never asked, # may hold more. if renderer.is_pretty(): renderer.info(plan_line(len(uploads), payload["upload_bytes"], already_held_count(preparation))) - renderer.info( - "--dry-run: nothing was sent; the builder may already hold more of these than the spec records." - ) + if public_nodes: + count = len(public_nodes) + renderer.info(f"The builder resolved {count} public custom node pin{'' if count == 1 else 's'}.") + renderer.info( + "--dry-run: nothing was uploaded or saved; the builder may already hold more of these " + "than the spec records." + ) + else: + renderer.info( + "--dry-run: nothing was sent; the builder may already hold more of these than the spec records." + ) if _has_models(spec): renderer.info(f"--dry-run reads no folder list from the builder, so {_FOLDER_CASE_UNCHECKED}.") renderer.emit(payload, command="build push", changed=False) @@ -2032,26 +2084,7 @@ def push_cmd( public_nodes = public_node_projection(preparation.definition) if public_nodes: - imported = _builder_call( - renderer, - lambda: client.resolve_snapshot(snapshot_from_definition({"customNodes": public_nodes})), - ) - checked = (imported.get("definition") or {}).get("customNodes") or [] - try: - missing = public_node_identities(public_nodes) - public_node_identities( - public_node_projection({"customNodes": checked}) - ) - except BuildSpecInvalidError as error: - renderer.error(code=error.code, message=str(error), details={"path": str(paths.spec_file)}) - raise typer.Exit(code=1) from error - if missing: - labels = sorted(f"{identity.kind}:{identity.value}@{identity.version or '-'}" for identity in missing) - renderer.error( - code="build_registry_pin_missing", - message="the builder could not resolve these custom node identities: " + ", ".join(labels), - hint="edit the spec to name a published registry version or normalized repository, or remove the node", - ) - raise typer.Exit(code=1) + _require_public_pins(renderer, client, public_nodes, paths.spec_file) # Said before the first byte moves, and said even when nothing will: a # multi-GB upload is otherwise silent until it ends, and "0 files" is diff --git a/comfy_cli/error_codes.py b/comfy_cli/error_codes.py index 24b40a01a..f518ab604 100644 --- a/comfy_cli/error_codes.py +++ b/comfy_cli/error_codes.py @@ -1371,7 +1371,9 @@ class ErrorCode: "build_registry_pin_missing", "`comfy build push` sent its identity-keyed public-node subset to the builder's snapshot importer, " "which could not vouch for one or more pins. Pushing anyway would save a definition that cannot " - "reconstruct every requested public node.", + "reconstruct every requested public node. `push --dry-run` makes the same read-only check and " + "refuses the same way, uploading and saving nothing. A version the registry has Flagged " + "is refused here too, though the message does not say so.", "edit the spec to name a published registry version or normalized repository, or remove the node", ), ErrorCode( diff --git a/comfy_cli/skills/comfy-build-failures/SKILL.md b/comfy_cli/skills/comfy-build-failures/SKILL.md index 02bb12b51..f808a6b2f 100644 --- a/comfy_cli/skills/comfy-build-failures/SKILL.md +++ b/comfy_cli/skills/comfy-build-failures/SKILL.md @@ -102,8 +102,13 @@ can take (a model's `sourceUri`, a node's `registryVersion` or `repository`), fi - `resolves to a duplicate node directory` — two entries claim one folder, so one of them goes. - `build_registry_pin_missing` — the builder could not place a public pack. - The message names each identity; correct the `registryVersion` against a - registry search, or remove the pack. + `push --dry-run` refuses the same way, before anything is uploaded or saved. + The message names each identity but not why. A version the registry has + Flagged lands here: check its `status` at + `https://api.comfy.org/nodes//versions`, and pin a version that is not + `NodeVersionStatusFlagged`, or the pack's `repository` and a commit `gitRef`. + Otherwise correct the `registryVersion` against a registry search, or remove + the pack. - `build_spec_stale` — the remote moved under you, or `--id` names a Build the spec's `syncedRevision` does not belong to. See *Revising*. diff --git a/comfy_cli/skills/comfy-build/SKILL.md b/comfy_cli/skills/comfy-build/SKILL.md index 83a2e85ce..a57ddb0ee 100644 --- a/comfy_cli/skills/comfy-build/SKILL.md +++ b/comfy_cli/skills/comfy-build/SKILL.md @@ -114,10 +114,13 @@ comfy build validate comfy build push --dry-run ``` -Everything above is offline and spends nothing. `validate` reads the spec, and -`--dry-run` computes every upload without instantiating an HTTP client at all. -Read what it plans, decide the pins, run the conflict prediction in -`comfy-build-pins`, disclose, get a yes. Only then: +Everything above spends nothing. `validate` reads the spec offline. `--dry-run` +computes every upload locally and makes one read: it asks the builder to place +each public pack, and refuses with `build_registry_pin_missing` exactly as `push` +would, so a pin the push cannot save fails here, before you disclose the plan. +A spec that pins a public pack therefore needs sign-in for the dry run; one whose +packs are all local sends nothing. Read what it plans, decide the pins, run the +conflict prediction in `comfy-build-pins`, disclose, get a yes. Only then: ```shell comfy build push @@ -192,7 +195,8 @@ comfy --json build init --name --from-workflow .json never carries — `comfy-build-authoring` is that procedure. - **The pack pins are the registry's newest published version**, because a workflow names none. Importing the same file next week can then build something - else. Say that out loud. + else. Say that out loud. The newest can be a version the registry has Flagged, + which the builder will not place, so run `push --dry-run` before you disclose. - **A workflow names no ComfyUI version either**, so set one before cutting: `comfy build update --comfy-version `, or edit `baseComfyVersion`. - **`unresolvedClasses` is the list to take to the user.** Those node classes are @@ -227,7 +231,11 @@ show the user rather than as instructions to act on. - **Whether a registry pin exists.** `push` asks the builder to place every public pack before it saves, and refuses with `build_registry_pin_missing` naming each identity it could not resolve. If that lookup itself fails, the - command **exits** — it does not warn and proceed. + command **exits** — it does not warn and proceed. `push --dry-run` makes the + same check. A version the registry has **Flagged** is refused this way too, + and the message does not say so: read the version's `status` from + `https://api.comfy.org/nodes//versions`, then pin a version that is not + `NodeVersionStatusFlagged`, or pin the pack by `repository` and a commit `gitRef`. **A local pack is uploaded from the spec.** `push` packages each custom node directory and uploads it, so a pack that publishes nothing still travels. diff --git a/tests/comfy_cli/command/build_auth_support.py b/tests/comfy_cli/command/build_auth_support.py index fb4f02706..a726741ae 100644 --- a/tests/comfy_cli/command/build_auth_support.py +++ b/tests/comfy_cli/command/build_auth_support.py @@ -27,7 +27,6 @@ # Keyed on the URL *path* so a route carrying query parameters (`?cursor=`, # `?os=&gpu=`) still matches. _ROUTES: dict[tuple[str, str], tuple[int, JsonObject]] = { - ("POST", "/v1/snapshots/resolve"): (200, {"definition": _EMPTY_DEFINITION, "report": {}}), ("POST", "/v1/builds"): (201, {"id": BUILD_ID, "updatedAt": REVISION}), ("GET", "/v1/builds"): (200, {"builds": [{"id": BUILD_ID, "name": "Matrix"}]}), ("GET", f"/v1/builds/{BUILD_ID}"): ( @@ -99,6 +98,8 @@ def __call__( path = urlsplit(url).path if (method, path) == ("POST", "/v1/models/resolve"): return 200, {"results": _resolved_filenames(body)} + if (method, path) == ("POST", "/v1/snapshots/resolve"): + return 200, {"definition": {"models": [], "customNodes": _placed_nodes(body)}, "report": {}} route = _ROUTES.get((method, path)) if route is None: pytest.fail(f"unexpected Builder call: {method} {url}") @@ -113,6 +114,24 @@ def _resolved_filenames(body: JsonObject | None) -> list[JsonValue]: return [{"filename": filename, "candidates": []} for filename in filenames] +def _placed_nodes(body: JsonObject | None) -> list[JsonValue]: + """Every pack the snapshot names, placed as asked: the importer vouches for + each pin, so a push or dry run that sends one gets past its pin check.""" + assert body is not None + snapshot = body["snapshot"] + assert isinstance(snapshot, dict) + placed: list[JsonValue] = [] + for entry in snapshot.get("snapshots") or []: + assert isinstance(entry, dict) + for node in entry.get("customNodes") or []: + assert isinstance(node, dict) + if node["type"] == "cnr": + placed.append({"name": node["dirName"], "id": node["id"], "registryVersion": node["version"]}) + else: + placed.append({"name": node["dirName"], "repository": node["url"]}) + return placed + + def write_snapshot(root: Path) -> Path: path = root / "snapshot.json" path.write_text(json.dumps({"customNodes": [], "pipPackages": {}, "pythonVersion": "3.12"}), encoding="utf-8") diff --git a/tests/comfy_cli/command/test_build_auth_matrix.py b/tests/comfy_cli/command/test_build_auth_matrix.py index fca091c29..003a50015 100644 --- a/tests/comfy_cli/command/test_build_auth_matrix.py +++ b/tests/comfy_cli/command/test_build_auth_matrix.py @@ -53,6 +53,7 @@ class FixtureKind(Enum): VALIDATE_REMOTE_LOOKUP = "validate --remote (lookupable)" PUSH = "push" PUSH_DRY_RUN = "push --dry-run" + PUSH_DRY_RUN_PINNED = "push --dry-run (public pins)" PULL = "pull" STATUS = "status" LS = "ls" @@ -95,7 +96,10 @@ class BuildAuthCase: BuildAuthCase(FixtureKind.VALIDATE_REMOTE_ZERO, "validate", True, _ZERO_PLUS, 1), BuildAuthCase(FixtureKind.VALIDATE_REMOTE_LOOKUP, "validate", True, _ZERO_PLUS, 2), BuildAuthCase(FixtureKind.PUSH, "push", True, _ONE_PLUS), + # A dry run asks the builder only to place the spec's public pins, the read the + # push makes before it saves, so a spec without one stays signed out and silent. BuildAuthCase(FixtureKind.PUSH_DRY_RUN, "push", False, _ZERO), + BuildAuthCase(FixtureKind.PUSH_DRY_RUN_PINNED, "push", True, _ONE_PLUS, 1), BuildAuthCase(FixtureKind.PULL, "pull", True, _ONE_PLUS), BuildAuthCase(FixtureKind.STATUS, "status", True, _ONE_PLUS), BuildAuthCase(FixtureKind.LS, "ls", True, _ONE_PLUS), @@ -165,6 +169,15 @@ def _prepare(kind: FixtureKind, root: Path) -> list[str]: case FixtureKind.PUSH_DRY_RUN: write_spec(root, models=[], nodes=[]) return ["build", "push", "--dry-run", str(root)] + case FixtureKind.PUSH_DRY_RUN_PINNED: + write_spec( + root, + models=[], + nodes=[ + {"name": "registry-node", "id": "registry-node", "registryVersion": "1.0.0", "source": "registry"} + ], + ) + return ["build", "push", "--dry-run", str(root)] case FixtureKind.PULL: write_spec(root, models=[], nodes=[]) return ["build", "pull", "-y", "--id", BUILD_ID, str(root)] diff --git a/tests/comfy_cli/command/test_build_push.py b/tests/comfy_cli/command/test_build_push.py index 29d065995..fd52305d7 100644 --- a/tests/comfy_cli/command/test_build_push.py +++ b/tests/comfy_cli/command/test_build_push.py @@ -61,6 +61,7 @@ def _schema(name: str) -> JsonObject: def test_dry_run_is_signed_out_and_zero_http(workspace: Path, monkeypatch: pytest.MonkeyPatch) -> None: + """Only a public pin needs the builder, so a spec without one asks it nothing.""" # Given path = write_spec(workspace) before = path.read_bytes() @@ -294,6 +295,125 @@ def test_pin_gate_normalizes_equivalent_repository_identities(workspace: Path, m assert len(client.snapshots) == 1 +#: A pin to a version the registry has Flagged. The builder's importer cannot +#: place it, so the push refuses it. +_FLAGGED_PIN: JsonObject = { + "name": "ComfyUI-DepthAnythingV3", + "id": "ComfyUI-DepthAnythingV3", + "registryVersion": "0.1.19", + "source": "registry", +} + +_REGISTRY_PIN: JsonObject = { + "name": "registry-node", + "id": "registry-node", + "registryVersion": "1.0.0", + "source": "registry", +} + + +class _FlaggedImporter(RecordingBuilder): + """The importer's answer for a Flagged version, in the shape the live builder + sends: the pack is left out of the definition and named in the report.""" + + def resolve_snapshot(self, snapshot: JsonObject) -> JsonObject: + super().resolve_snapshot(snapshot) + return { + "definition": {}, + "report": {"notInRegistry": [_FLAGGED_PIN["id"]], "unresolvedNodes": [_FLAGGED_PIN["id"]]}, + } + + +def test_a_dry_run_refuses_a_flagged_pin_with_the_push_s_own_error( + tmp_path: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + """A dry run is the free check before disclosing and spending, so it must + refuse a pin the builder cannot place the way the push does, not pass it.""" + # Given + pushed_root = make_workspace(tmp_path / "push") + write_spec(pushed_root, models=[], nodes=[_FLAGGED_PIN]) + pushed = _FlaggedImporter() + _install_client(monkeypatch, pushed) + push = invoke_push(pushed_root) + + dry_root = make_workspace(tmp_path / "dry-run") + spec = write_spec(dry_root, models=[], nodes=[_FLAGGED_PIN]) + before = spec.read_bytes() + dry = _FlaggedImporter() + _install_client(monkeypatch, dry) + + # When + result = invoke_push(dry_root, "--dry-run") + + # Then + assert (push.exit_code, result.exit_code) == (1, 1) + error = envelope(result)["error"] + assert error == envelope(push)["error"] + assert error["code"] == "build_registry_pin_missing" + assert "registry:ComfyUI-DepthAnythingV3@0.1.19" in error["message"] + assert [call["method"] for call in dry.calls] == ["resolve_snapshot"] + assert spec.read_bytes() == before + + +def test_a_dry_run_asks_the_builder_only_to_place_its_public_pins( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + # Given + path = write_spec(workspace, nodes=[local_node(), _REGISTRY_PIN]) + before = path.read_bytes() + client = RecordingBuilder() + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 0, result.stderr + assert [call["method"] for call in client.calls] == ["resolve_snapshot"] + sent = client.snapshots[0]["snapshots"][0]["customNodes"] + assert [(node["id"], node["version"]) for node in sent] == [("registry-node", "1.0.0")] + data = envelope(result)["data"] + assert (data["dry_run"], data["upload_count"], data["uploaded"]) == (True, 2, 0) + assert path.read_bytes() == before + + +def test_a_dry_run_whose_pin_lookup_fails_exits_rather_than_passing( + workspace: Path, monkeypatch: pytest.MonkeyPatch +) -> None: + # Given + write_spec(workspace, models=[], nodes=[_REGISTRY_PIN]) + client = RecordingBuilder() + + def unreachable(snapshot: JsonObject) -> JsonObject: + raise urllib.error.URLError("connection refused") + + monkeypatch.setattr(client, "resolve_snapshot", unreachable) + _install_client(monkeypatch, client) + + # When + result = invoke_push(workspace, "--dry-run") + + # Then + assert result.exit_code == 1 + assert envelope(result)["error"]["code"] == "build_builder_error" + + +def test_a_dry_run_tells_a_person_it_checked_the_public_pins(workspace: Path, monkeypatch: pytest.MonkeyPatch) -> None: + # Given + write_spec(workspace, nodes=[local_node(), _REGISTRY_PIN]) + _install_client(monkeypatch, RecordingBuilder()) + + # When + result = invoke_push(workspace, "--dry-run", agentic=False) + + # Then + assert result.exit_code == 0, result.output + text = " ".join(result.stdout.split()) + assert "The builder resolved 1 public custom node pin." in text + assert "nothing was uploaded or saved" in text + assert "nothing was sent" not in text + + def test_a_skipped_symlink_is_named_on_stderr_and_carried_in_the_payload( workspace: Path, monkeypatch: pytest.MonkeyPatch ) -> None: From c904dc76532969b7a1ba0d81dd59ef45f89f337d Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 11:51:30 -0700 Subject: [PATCH 2/4] test: isolate valid workflow and certificate fixtures --- 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 ++-- tests/comfy_cli/test_http.py | 5 +- 4 files changed, 98 insertions(+), 49 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/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 be7a75eecc3f11e9a47052e8480b90076b0aa56c Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Sat, 31 Oct 2026 12:04:30 -0700 Subject: [PATCH 3/4] test: mock the validate catalog loader boundary --- tests/comfy_cli/output/test_error_envelope_where.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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" From 30a351f76a475460b2b740eae2196d768b423fb7 Mon Sep 17 00:00:00 2001 From: "eric.sun" Date: Mon, 2 Nov 2026 15:47:25 -0800 Subject: [PATCH 4/4] test(run): assert object-info target and timeout --- tests/comfy_cli/command/test_run.py | 6 +++++- tests/comfy_cli/command/test_run_json.py | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/comfy_cli/command/test_run.py b/tests/comfy_cli/command/test_run.py index 3af335823..aadc20bf4 100644 --- a/tests/comfy_cli/command/test_run.py +++ b/tests/comfy_cli/command/test_run.py @@ -2368,7 +2368,11 @@ 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 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") diff --git a/tests/comfy_cli/command/test_run_json.py b/tests/comfy_cli/command/test_run_json.py index eca122763..f32bdaf15 100644 --- a/tests/comfy_cli/command/test_run_json.py +++ b/tests/comfy_cli/command/test_run_json.py @@ -1440,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._PLAIN_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)