From 530f0fafdb43d7bac4114e884cf7fdf05ba8afde Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Fri, 4 Sep 2026 05:35:27 -0700 Subject: [PATCH 1/3] fix(cql): type-check autogrow slot keys against their template input MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An autogrow group's grown slot keys (`images.image0`, `model.images.image_1`, …) never entered `port_by_name` — `/object_info` declares the GROUP and never its slots — so the driver loop had no type to check them against: * a link-valued slot key got `dangling_edge` / `output_index_out_of_range` but skipped the `edge_type_mismatch` comparison, because `port_by_name.get(input_name)` was `None`; * a non-link slot key fell out at `if port is None: continue`, before `validate_shape` or `_validate_catalog_value` ever ran. So an `INT` output wired into `BatchImagesNode.images.image0` (template inner type `IMAGE`) validated clean here and was then hard-rejected by the server as `return_type_mismatch` — `execution.validate_inputs` → `validate_node_input` runs against the expanded `template_input`. Synthesize one `Port` per present, template-declared slot key from the group's own template input (`Port.autogrow_slot_port`), at both nesting depths, and consult it where `port_by_name` misses. The slot inherits everything the inner spec declares, so a COMBO template is membership-checked and a ranged INT template is range-checked, and it inherits the existing severities too — `edge_type_mismatch` stays advisory. Keys the template does not declare stay out: `images.bogus` is not an input of the node at all, so it draws no synthesized diagnostic (and nested, keeps reporting `unknown_input`). A template with no inner input declares no type to check against, so it synthesizes nothing — the real shape of `ByteDanceSeedreamNodeV2.model.images` in the captured catalog. The presence-based slot COUNT check is untouched. --- comfy_cli/cql/engine.py | 170 +++++++++-- tests/comfy_cli/cql/test_engine.py | 300 ++++++++++++++++++++ tests/comfy_cli/cql/test_nested_autogrow.py | 111 ++++++++ 3 files changed, 564 insertions(+), 17 deletions(-) diff --git a/comfy_cli/cql/engine.py b/comfy_cli/cql/engine.py index f0b915045..5304a8387 100644 --- a/comfy_cli/cql/engine.py +++ b/comfy_cli/cql/engine.py @@ -375,13 +375,14 @@ def autogrow_slot_example(self) -> str: return ", ".join(first) + ", …" @property - def autogrow_element_type(self) -> str | None: - """The socket type every grown slot of this autogrow input carries — - the single input the schema ``template`` declares (``IMAGE`` for - ``model.images``, ``VIDEO`` for ``model.reference_videos``). Every - group in the production catalog declares exactly one template input; - a template with none (or a non-autogrow port) reads as ``None``, which - callers treat as "accept the source type". + def autogrow_template_input_spec(self) -> Any | None: + """The single inner ``INPUT_TYPES`` spec this autogrow group's schema + ``template`` declares — the spec the server copies into every grown + slot (``["IMAGE", {}]`` for ``model.images``). + + ``None`` when there is nothing to read: a non-autogrow port, a template + with no ``input`` block (an older/partial catalog capture), or one whose + sections declare no input carrying a usable socket type. """ t = self.options.template if not self.is_autogrow or not isinstance(t, dict): @@ -399,9 +400,48 @@ def autogrow_element_type(self) -> str | None: for spec in section_def.values(): type_id = spec[0] if isinstance(spec, (list, tuple)) and spec else spec if isinstance(type_id, str) and type_id: - return type_id + return spec return None + @property + def autogrow_element_type(self) -> str | None: + """The socket type every grown slot of this autogrow input carries — + the single input the schema ``template`` declares (``IMAGE`` for + ``model.images``, ``VIDEO`` for ``model.reference_videos``). Every + group in the production catalog declares exactly one template input; + a template with none (or a non-autogrow port) reads as ``None``, which + callers treat as "accept the source type". + """ + spec = self.autogrow_template_input_spec + if spec is None: + return None + return spec[0] if isinstance(spec, (list, tuple)) and spec else spec + + def autogrow_slot_port(self, slot_key: str, *, required: bool) -> Port | None: + """A :class:`Port` for one grown slot of this group, parsed from the + template's inner input — the same input the server copies into the + node's expanded schema under this ``slot_key`` + (``Autogrow._expand_schema_for_dynamic``). + + Slot keys never appear in ``/object_info``'s own input list, so nothing + in ``Morphism.inputs`` types them; validation synthesizes one of these + per present, template-declared key so a slot gets the *same* edge, + shape and catalog checks as an ordinary input. Everything the inner + spec declares comes along — ``enum_values``/``enum_declared`` so a COMBO + template is membership-checked, ``options`` so a ranged ``INT`` template + is range-checked. + + ``None`` when :attr:`autogrow_template_input_spec` reads nothing (a + non-autogrow port, or a template with no inner input): with no declared + inner type there is nothing to check a slot against, and inventing one + would be the reject-what-you-cannot-read mistake the sibling autogrow + accessors all avoid. + """ + spec = self.autogrow_template_input_spec + if spec is None: + return None + return _port_from_spec(slot_key, spec, required) + @property def autogrow_limits(self) -> tuple[int, int | None]: """``(min, max)`` slots for this autogrow input, exactly as the frontend @@ -2448,7 +2488,7 @@ def validate_workflow(self, workflow: dict[str, Any]) -> dict[str, Any]: # _check_dynamic_combos already covers it. Sub-keys under an # unresolved selection keep the old generic checks. dyn_port_names = {p.name for p in m.inputs if p.is_dynamic_combo} - dyn_errors, dyn_warnings, dyn_valid_keys, dyn_unresolved = _check_dynamic_combos( + dyn_errors, dyn_warnings, dyn_valid_keys, dyn_unresolved, dyn_slot_ports = _check_dynamic_combos( node_id, class_type, m, node_inputs, range_is_error=node_id in reachable ) group_errors: list[dict] = [] @@ -2459,6 +2499,29 @@ def validate_workflow(self, workflow: dict[str, Any]) -> dict[str, Any]: ) group_errors.extend(e) group_warnings.extend(w) + # Autogrow slot keys (`images.image0`, `model.images.image_1`, …) + # are absent from `port_by_name` — object_info declares the GROUP, + # never its grown slots — so the per-input loop below had no type to + # check them against: a link-valued slot skipped the + # `edge_type_mismatch` comparison and a plain value fell out at + # `if port is None: continue`, before any shape or catalog check. + # An INT wired into an IMAGE slot validated clean here and was then + # hard-rejected by the server as `return_type_mismatch`. Synthesize + # one Port per present, template-declared slot key from the group's + # own template input so those keys route through exactly the same + # branches as any other input. + slot_ports: dict[str, Port] = {} + for base, agp in autogrow_ports.items(): + matched = {k for k in node_inputs if k.startswith(f"{base}.")} + # Only the keys the group actually grows: `images.bogus` is not + # an input of the node, so it gets no synthesized diagnostic. + # Where the catalog names no slots there is nothing to filter + # against and the historical prefix match stands. + declared = agp.autogrow_declared_slot_keys(matched) + slot_ports.update(_autogrow_slot_ports(base, agp, matched if declared is None else declared)) + # Nested groups are typed by the dynamic-combo walk, which is the + # only pass that knows which option expanded them. + slot_ports.update(dyn_slot_ports) for input_name, value in node_inputs.items(): if input_name in port_by_name and port_by_name[input_name].is_dynamic_group: continue @@ -2646,7 +2709,13 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar # known-type/empty-intersection mismatch is ever promoted — # a wildcard, a union overlap, or a blank/unknown type on # either end still yields no finding at all. - port = port_by_name.get(input_name) or _dotted_slot_port(port_by_name, input_name, node_inputs) + port = port_by_name.get(input_name) or slot_ports.get(input_name) + if port is None and not any(input_name.startswith(f"{base}.") for base in autogrow_ports): + # Autogrow suffixes are typed only via slot_ports, so a + # key the template never declared (`images.bogus`) gets + # no synthesized type. Other dotted keys (combo sub-inputs) + # still resolve through _dotted_slot_port. + port = _dotted_slot_port(port_by_name, input_name, node_inputs) if port is not None: src_type = src_m.outputs[out_idx].type dst_type = port.type @@ -2691,11 +2760,19 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar warnings.append(finding) continue - port = port_by_name.get(input_name) + port = port_by_name.get(input_name) or slot_ports.get(input_name) # A dotted key (`videos.video1`, `model.mask`) has no port of its # own; it is checked for a literal against the slot or sub-input # it resolves to, and every other check below is its group's. - link_port = port if port is not None else _dotted_slot_port(port_by_name, input_name, node_inputs) + # Do not promote _dotted_slot_port into `port`: combo sub-inputs + # are already shape/catalog-checked in the combo walk, and + # undeclared autogrow suffixes must not gain a synthesized type. + if port is not None: + link_port = port + elif any(input_name.startswith(f"{base}.") for base in autogrow_ports): + link_port = None + else: + link_port = _dotted_slot_port(port_by_name, input_name, node_inputs) # A literal on a socket that only carries a node's output. The # server does not type-check custom types (only INT/FLOAT/ # STRING/BOOLEAN/COMBO), so it hands the string to the node, @@ -3475,7 +3552,7 @@ def _dynamic_combo_options(spec: Any) -> list[dict]: def _check_dynamic_combos( node_id: str, class_type: str, m: Morphism, node_inputs: dict, *, range_is_error: bool = True -) -> tuple[list[dict], list[dict], set[str], set[str]]: +) -> tuple[list[dict], list[dict], set[str], set[str], dict[str, Port]]: """Validate every dynamic-combo input against the option its selector names. Mirrors the server: ``DynamicCombo._expand_schema_for_dynamic`` @@ -3494,21 +3571,26 @@ def _check_dynamic_combos( Also flags present dotted keys that match no sub-input of the resolved selection — a warning, not an error, because the server ignores extra - keys; that pass lives in ``_unknown_dotted_key_warnings``. Returns ``(errors, warnings, valid_keys, unresolved)`` — the caller + keys; that pass lives in ``_unknown_dotted_key_warnings``. Returns + ``(errors, warnings, valid_keys, unresolved, slot_ports)`` — the caller uses ``valid_keys``/``unresolved`` to exempt stale (server-ignored) dynamic sub-keys from the generic edge checks, which would otherwise - hard-error on e.g. a dangling link left over from a previous selection. + hard-error on e.g. a dangling link left over from a previous selection, + and ``slot_ports`` to type the autogrow slot keys a resolved option + expanded — this walk is the only pass that knows which option expanded + them, so the driver loop cannot derive them for itself. """ errors: list[dict] = [] warnings: list[dict] = [] present = node_inputs dynamic_ports = [p for p in m.inputs if p.is_dynamic_combo] if not dynamic_ports: - return errors, warnings, set(), set() + return errors, warnings, set(), set(), {} valid_keys: set[str] = set() unresolved: set[str] = set() resolved: dict[str, Any] = {} + slot_ports: dict[str, Port] = {} for port in dynamic_ports: e, w, v, u = _check_dynamic_combo_input( node_id, @@ -3519,6 +3601,7 @@ def _check_dynamic_combos( present, resolved, range_is_error=range_is_error, + slot_ports=slot_ports, ) errors.extend(e) warnings.extend(w) @@ -3526,7 +3609,7 @@ def _check_dynamic_combos( unresolved |= u warnings.extend(_unknown_dotted_key_warnings(node_id, present, dynamic_ports, valid_keys, unresolved, resolved)) - return errors, warnings, valid_keys, unresolved + return errors, warnings, valid_keys, unresolved, slot_ports def _unknown_dotted_key_warnings( @@ -3617,6 +3700,7 @@ def _check_dynamic_combo_input( depth: int = 0, *, range_is_error: bool = True, + slot_ports: dict[str, Port] | None = None, ) -> tuple[list[dict], list[dict], set[str], set[str]]: """One dynamic-combo input: resolve its selected option, check its sub-inputs. @@ -3627,6 +3711,13 @@ def _check_dynamic_combo_input( (mutated) records ``name -> selected key`` for every combo level that DID resolve, so the caller can attribute a stray key to the deepest resolved prefix. + + ``slot_ports`` is the second mutated accumulator, filled the same way and + for the same reason: an autogrow group nested in a resolved option grows + slot keys the top-level driver has no way to type on its own, so this walk + records a synthesized :class:`Port` per present slot key + (:func:`_autogrow_slot_ports`) for the driver's edge/shape/catalog checks. + Optional so the direct callers in the tests need not supply one. """ errors: list[dict] = [] warnings: list[dict] = [] @@ -3767,6 +3858,7 @@ def _check_dynamic_combo_input( resolved, depth, range_is_error=range_is_error, + slot_ports=slot_ports, ) errors.extend(e) warnings.extend(w) @@ -3786,12 +3878,17 @@ def _check_dynamic_combo_sub( depth: int, *, range_is_error: bool = True, + slot_ports: dict[str, Port] | None = None, ) -> tuple[list[dict], list[dict], set[str], set[str]]: """Presence + shape + catalog checks for one expanded sub-input. The sub-input spec is a plain ``INPUT_TYPES`` entry, so it goes through the same ``_parse_input_spec`` / :class:`Port` machinery as a top-level input and inherits identical shape and enum/range semantics. + + ``slot_ports`` is the mutated accumulator described on + :func:`_check_dynamic_combo_input`: an autogrow sub-input records one + synthesized :class:`Port` per slot key it grows into it. """ port = _port_from_spec(dotted, sub_spec, sub_required) @@ -3807,6 +3904,7 @@ def _check_dynamic_combo_sub( resolved, depth + 1, range_is_error=range_is_error, + slot_ports=slot_ports, ) if port.is_dynamic_group: @@ -3875,6 +3973,12 @@ def _check_dynamic_combo_sub( # against, so the historical prefix match stands. declared = port.autogrow_declared_slot_keys(matched) valid = matched if declared is None else declared + # Type each of those keys off the group's template input, so the driver + # loop edge/shape/catalog-checks a nested slot exactly as it does a + # top-level one. Only the valid keys: an undeclared `model.images.bogus` + # stays an `unknown_input` warning and gets no synthesized diagnostic. + if slot_ports is not None: + slot_ports.update(_autogrow_slot_ports(dotted, port, valid)) # The valid keys stay valid even when the count is short, so the slots # that ARE wired don't regress into `unknown_input` noise on top of the # count error. These errors flow into `dyn_errors`, which the driver @@ -4014,6 +4118,38 @@ def _autogrow_slot_errors(node_id: str, field: str, port: Port, slots: set[str], return [shortfall] if shortfall else [] +def _autogrow_slot_ports(field: str, port: Port, slots: Iterable[str]) -> dict[str, Port]: + """One synthesized :class:`Port` per present slot key of one autogrow group + — shared by the top-level driver loop and the dynamic-combo-nested path so a + slot is typed the same way at every nesting depth. + + ``slots`` must already be the keys the group actually grows + (:meth:`Port.autogrow_declared_slot_keys`, or the historical prefix match + where the catalog names none): a key the template never declares is not an + input of the node at all, so synthesizing a Port for it would invent a + diagnostic about something the server ignores. + + ``required`` per slot is the server's own answer — the specific names it + places in the expanded schema's ``required`` section + (:meth:`Port.autogrow_required_slot_names` over + :attr:`Port.autogrow_effective_min`), not merely the first ``min`` keys the + prompt happens to wire. It stays ``False`` where the catalog names no slots + for the same reason the count check falls back there: nothing declared them. + + Empty for a group whose template declares no inner input — there is no type + to check a slot against, so it keeps the pre-existing "no port, no + diagnostic" behaviour rather than guessing one. + """ + names = port.autogrow_required_slot_names(port.autogrow_effective_min) + required_keys = set() if names is None else {f"{field}.{name}" for name in names} + out: dict[str, Port] = {} + for key in slots: + slot_port = port.autogrow_slot_port(key, required=key in required_keys) + if slot_port is not None: + out[key] = slot_port + return out + + def _check_autogrow_required(node_id: str, autogrow_ports: dict[str, Port], node_data: dict) -> list[dict]: """Autogrow inputs wired with fewer slots than the server requires. diff --git a/tests/comfy_cli/cql/test_engine.py b/tests/comfy_cli/cql/test_engine.py index d873dc84f..f47826f6e 100644 --- a/tests/comfy_cli/cql/test_engine.py +++ b/tests/comfy_cli/cql/test_engine.py @@ -5460,3 +5460,303 @@ def test_count_instances_skips_a_sibling_def_with_non_list_nodes(self): "definitions": {"subgraphs": [{"id": "bad", "nodes": 5}, {"id": "u2", "nodes": [{"id": 9, "type": "u1"}]}]}, } assert _count_instances(wf, "u1") == 2 + +class TestAutogrowSlotPorts: + """Autogrow slot keys (``images.image0``, ``model.images.image_1``, …) are + type-, shape- and catalog-checked exactly as ordinary inputs are. + + ``/object_info`` declares the GROUP and never its grown slots, so a slot key + never entered ``port_by_name``: a link-valued one got ``dangling_edge`` / + ``output_index_out_of_range`` but skipped the ``edge_type_mismatch`` + comparison, and a plain-valued one fell out at ``if port is None: continue`` + before any shape or catalog check. An ``INT`` wired into an ``IMAGE`` slot + validated clean here and was then hard-rejected by the server as + ``return_type_mismatch`` (``execution.validate_inputs`` → + ``validate_node_input`` on the expanded ``template_input``). Validation now + synthesizes one :class:`Port` per present, template-declared slot key from + the group's own template input. + + ``Grow`` mirrors the live ``BatchImagesNode.images`` + (``prefix: image``, ``min: 1``, ``max: 50``, inner ``IMAGE``). + """ + + INFO = { + "IntSrc": { + "input": {"required": {}}, + "input_order": {"required": []}, + "output": ["INT"], + "output_name": ["value"], + "display_name": "IntSrc", + "python_module": "nodes", + }, + "ImgSrc": { + "input": {"required": {}}, + "input_order": {"required": []}, + "output": ["IMAGE"], + "output_name": ["image"], + "display_name": "ImgSrc", + "python_module": "nodes", + }, + "Grow": { + "input": { + "required": { + "images": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"image": ["IMAGE", {}]}}, + "prefix": "image", + "min": 1, + "max": 50, + } + }, + ] + } + }, + "input_order": {"required": ["images"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "Grow", + "python_module": "nodes", + }, + # Template inner type COMBO: the slot value is a catalog choice, so the + # synthesized port must inherit `enum_values`/`enum_declared`. + "GrowCombo": { + "input": { + "required": { + "opts": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"choice": ["COMBO", {"options": ["a", "b"]}]}}, + "prefix": "opt", + "min": 0, + } + }, + ] + } + }, + "input_order": {"required": ["opts"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "GrowCombo", + "python_module": "nodes", + }, + # Template inner type INT with a declared range: the synthesized port + # must inherit `options` so the range check applies to the slot. + "GrowInt": { + "input": { + "required": { + "counts": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"count": ["INT", {"min": 1, "max": 10}]}}, + "prefix": "n", + "min": 0, + } + }, + ] + } + }, + "input_order": {"required": ["counts"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "GrowInt", + "python_module": "nodes", + }, + # A template carrying no inner input at all: nothing declares the slot's + # type, so no port is synthesized and the historical "no port, no + # diagnostic" behaviour stands. + "GrowEmpty": { + "input": { + "required": { + "blanks": [ + "COMFY_AUTOGROW_V3", + {"template": {"input": {}, "prefix": "blank", "min": 0}}, + ] + } + }, + "input_order": {"required": ["blanks"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "GrowEmpty", + "python_module": "nodes", + }, + "Sink": { + "input": {"required": {"image": ["IMAGE", {}]}}, + "input_order": {"required": ["image"]}, + "output": [], + "output_name": [], + "output_node": True, + "display_name": "Sink", + "python_module": "nodes", + }, + } + + def _graph(self) -> Graph: + return Graph.from_object_info(self.INFO) + + def _wf(self, class_type: str, inputs: dict) -> dict: + """`class_type` fed by an INT producer (`"0"`) and an IMAGE producer + (`"1"`), consumed by an output node so the node is output-reachable (the + server prunes anything else, and the range checks are gated on that). + Producers `inputs` doesn't reference are dropped, so an unused one + doesn't add `node_not_reachable_from_output` noise to the assertions.""" + used = {str(v[0]) for v in inputs.values() if isinstance(v, list) and len(v) == 2} + producers = { + "0": {"class_type": "IntSrc", "inputs": {}}, + "1": {"class_type": "ImgSrc", "inputs": {}}, + } + return { + **{k: v for k, v in producers.items() if k in used}, + "2": {"class_type": class_type, "inputs": inputs}, + "3": {"class_type": "Sink", "inputs": {"image": ["2", 0]}}, + } + + # -- edges ------------------------------------------------------------ + + def test_int_source_into_an_image_slot_is_a_type_mismatch(self): + """The reported defect, top level: an INT output wired into + ``Grow.images.image0`` (template inner type ``IMAGE``) used to validate + clean and be hard-rejected by the server.""" + result = self._graph().validate_workflow(self._wf("Grow", {"images.image0": ["0", 0]})) + errs = [e for e in result["errors"] if e["code"] == "edge_type_mismatch"] + assert len(errs) == 1 + assert errs[0]["node_id"] == "2" + assert errs[0]["field"] == "images.image0" + assert "expects IMAGE but IntSrc[0] produces INT" in errs[0]["message"] + # Reachable type mismatches are hard errors (the server would reject + # the prompt); slot keys inherit that severity. + assert result["valid"] is False + + def test_correctly_wired_slot_stays_clean(self): + result = self._graph().validate_workflow(self._wf("Grow", {"images.image0": ["1", 0]})) + assert result["valid"] is True, result["errors"] + assert result["warnings"] == [] + + def test_undeclared_slot_key_gets_no_synthesized_diagnostic(self): + """``images.bogus`` is not a name the template grows, so the server + never places it in the node's schema — no port is synthesized for it and + it draws no edge diagnostic (nor a crash). The top level has no + unknown-input check, so it stays silent there; the nested path keeps + reporting ``unknown_input`` (see ``test_nested_autogrow.py``).""" + result = self._graph().validate_workflow( + self._wf("Grow", {"images.image0": ["1", 0], "images.bogus": ["0", 0]}) + ) + assert result["errors"] == [] + assert result["warnings"] == [] + + def test_dangling_slot_edge_keeps_its_existing_error(self): + """Regression pin: the checks a slot key ALREADY got must not change.""" + result = self._graph().validate_workflow(self._wf("Grow", {"images.image0": ["99", 0]})) + err = next(e for e in result["errors"] if e["code"] == "dangling_edge") + assert err["field"] == "images.image0" + + # -- shape / catalog -------------------------------------------------- + + def test_combo_template_slot_value_is_membership_checked(self): + """A COMBO template makes each slot a catalog choice; the synthesized + port inherits the option list, so an unknown value is the same + ``unknown_enum_value`` error any declared COMBO input gets.""" + result = self._graph().validate_workflow(self._wf("GrowCombo", {"opts.opt0": "zzz"})) + errs = [e for e in result["errors"] if e["code"] == "unknown_enum_value"] + assert len(errs) == 1 + assert errs[0]["node_id"] == "2" + assert errs[0]["field"] == "opts.opt0" + + def test_combo_template_slot_value_in_the_enum_is_clean(self): + result = self._graph().validate_workflow(self._wf("GrowCombo", {"opts.opt0": "a"})) + assert result["valid"] is True, result["errors"] + assert result["warnings"] == [] + + def test_ranged_int_template_slot_value_is_range_checked(self): + """A ranged INT template makes each slot range-checked: ``min: 1`` with + a slot value of ``0`` is the same ``below_min`` error a declared INT + input gets.""" + result = self._graph().validate_workflow(self._wf("GrowInt", {"counts.n0": 0})) + errs = [e for e in result["errors"] if e["code"] == "below_min"] + assert len(errs) == 1 + assert errs[0]["field"] == "counts.n0" + + def test_int_template_slot_shape_is_checked(self): + result = self._graph().validate_workflow(self._wf("GrowInt", {"counts.n0": "five"})) + errs = [e for e in result["errors"] if e["code"] == "shape_mismatch"] + assert len(errs) == 1 + assert errs[0]["field"] == "counts.n0" + + def test_template_with_no_inner_input_synthesizes_nothing(self): + """Nothing declares the slot's type, so there is nothing to check it + against — no port, no diagnostic, no crash.""" + result = self._graph().validate_workflow( + self._wf("GrowEmpty", {"blanks.blank0": ["0", 0], "blanks.blank1": "anything"}) + ) + assert result["errors"] == [] + assert result["warnings"] == [] + + # -- the synthesized ports themselves --------------------------------- + + def test_autogrow_slot_port_reads_the_template_input(self): + graph = self._graph() + grow = graph.node("Grow") + assert grow is not None + port = next(p for p in grow.inputs if p.name == "images") + slot = port.autogrow_slot_port("images.image0", required=True) + assert slot is not None + assert (slot.name, slot.type, slot.required) == ("images.image0", "IMAGE", True) + + def test_autogrow_slot_port_is_none_without_a_template_input(self): + graph = self._graph() + empty = graph.node("GrowEmpty") + sink = graph.node("Sink") + assert empty is not None and sink is not None + blanks = next(p for p in empty.inputs if p.name == "blanks") + assert blanks.autogrow_slot_port("blanks.blank0", required=False) is None + # A non-autogrow port has no template to read at all. + image = next(p for p in sink.inputs if p.name == "image") + assert image.autogrow_slot_port("image.x", required=False) is None + + def test_slot_ports_mark_the_servers_required_slot_names_required(self): + """``required`` per slot is the server's own answer — the names it + places in the expanded schema's ``required`` section (``names[:min]``), + not merely the first ``min`` keys the prompt happens to wire.""" + from comfy_cli.cql.engine import _autogrow_slot_ports + + graph = self._graph() + grow = graph.node("Grow") + assert grow is not None + port = next(p for p in grow.inputs if p.name == "images") + ports = _autogrow_slot_ports("images", port, ["images.image0", "images.image1"]) + # `min: 1` with the inner input in the template's own `required` + # section, so only slot 0 is required. + assert ports["images.image0"].required is True + assert ports["images.image1"].required is False + + def test_slot_ports_inherit_the_template_enum_and_options(self): + from comfy_cli.cql.engine import _autogrow_slot_ports + + graph = self._graph() + combo, ranged = graph.node("GrowCombo"), graph.node("GrowInt") + assert combo is not None and ranged is not None + opts = next(p for p in combo.inputs if p.name == "opts") + slot = _autogrow_slot_ports("opts", opts, ["opts.opt0"])["opts.opt0"] + assert slot.type == "COMBO" + assert slot.enum_values == ["a", "b"] + assert slot.enum_declared is True + counts = next(p for p in ranged.inputs if p.name == "counts") + int_slot = _autogrow_slot_ports("counts", counts, ["counts.n0"])["counts.n0"] + assert (int_slot.options.min, int_slot.options.max) == (1, 10) + + def test_slot_ports_skip_keys_the_template_never_declares(self): + """The filter is the caller's (``autogrow_declared_slot_keys``), but the + helper must not invent a port for a key it is handed either — it types + exactly the keys it is given, and the driver only ever hands it declared + ones.""" + from comfy_cli.cql.engine import _autogrow_slot_ports + + graph = self._graph() + grow = graph.node("Grow") + assert grow is not None + port = next(p for p in grow.inputs if p.name == "images") + assert port.autogrow_declared_slot_keys(["images.image0", "images.bogus"]) == {"images.image0"} + assert set(_autogrow_slot_ports("images", port, ["images.image0"])) == {"images.image0"} diff --git a/tests/comfy_cli/cql/test_nested_autogrow.py b/tests/comfy_cli/cql/test_nested_autogrow.py index d432c2ab7..e39857d03 100644 --- a/tests/comfy_cli/cql/test_nested_autogrow.py +++ b/tests/comfy_cli/cql/test_nested_autogrow.py @@ -251,3 +251,114 @@ def test_production_min_zero_group_stays_lenient(graph): assert port.autogrow_template_required is True assert port.autogrow_limits[0] == 0 assert port.autogrow_effective_min == 0 + + +# --------------------------------------------------------------------------- # +# (E) slot keys are type/shape/catalog-checked like any other input +# --------------------------------------------------------------------------- # + + +def _nano_banana_inputs(option_index: int = 0) -> dict: + """Every widget ``GeminiNanoBanana2V2`` requires for one model option, at + its schema defaults — everything except the ``images`` autogrow slots.""" + info = json.loads(FIXTURE.read_text()) + node = info["GeminiNanoBanana2V2"]["input"]["required"] + option = node["model"][1]["options"][option_index] + + def default_of(spec): + opts = spec[1] if isinstance(spec, list) and len(spec) > 1 and isinstance(spec[1], dict) else {} + if "default" in opts: + return opts["default"] + return (opts.get("options") or [""])[0] + + inputs = {"model": option["key"]} + inputs.update({k: default_of(v) for k, v in node.items() if k != "model"}) + inputs.update( + {f"model.{k}": default_of(v) for k, v in option["inputs"].get("required", {}).items() if k != "images"} + ) + return inputs + + +def _nano_banana_workflow(extra: dict) -> dict: + """``GeminiNanoBanana2V2`` fed by a ``LoadImage``, terminating in a + ``SaveImage``. ``LoadImage`` is the mis-wire source these tests need: + output ``[0]`` is ``IMAGE`` and output ``[1]`` is ``MASK``, so the same node + supplies both the correct and the wrongly-typed edge.""" + return { + "9": {"class_type": "LoadImage", "inputs": {"image": "example.png"}}, + "1": {"class_type": "GeminiNanoBanana2V2", "inputs": {**_nano_banana_inputs(), **extra}}, + "2": {"class_type": "SaveImage", "inputs": {"images": ["1", 0], "filename_prefix": "out"}}, + } + + +def _batch_images_workflow(extra: dict) -> dict: + """The ticket's top-level artifact: the production ``BatchImagesNode``, + whose ``images`` group declares ``prefix: image``, ``min: 1``, ``max: 50`` + and an inner ``IMAGE`` input.""" + return { + "9": {"class_type": "LoadImage", "inputs": {"image": "example.png"}}, + "1": {"class_type": "BatchImagesNode", "inputs": {**extra}}, + "2": {"class_type": "SaveImage", "inputs": {"images": ["1", 0], "filename_prefix": "out"}}, + } + + +def test_top_level_slot_key_edge_is_type_checked(graph): + """The defect: ``BatchImagesNode.images.image0`` never entered + ``port_by_name`` (object_info declares the GROUP, never its grown slots), so + a link into it skipped the ``edge_type_mismatch`` comparison entirely and a + wrongly-typed edge validated clean — while the server hard-rejects it as + ``return_type_mismatch``. ``LoadImage[1]`` is ``MASK``; the slot's template + input is ``IMAGE``.""" + result = graph.validate_workflow(_batch_images_workflow({"images.image0": ["9", 1]})) + errs = [e for e in result["errors"] if e["code"] == "edge_type_mismatch"] + assert len(errs) == 1 + assert errs[0]["node_id"] == "1" + assert errs[0]["field"] == "images.image0" + assert "expects IMAGE" in errs[0]["message"] + # Reachable type mismatches are hard errors (the server would reject). + assert result["valid"] is False + + +def test_top_level_correctly_wired_slot_stays_clean(graph): + result = graph.validate_workflow(_batch_images_workflow({"images.image0": ["9", 0]})) + assert result["valid"] is True, result["errors"] + assert result["warnings"] == [] + + +def test_top_level_undeclared_slot_key_gets_no_synthesized_diagnostic(graph): + """``images.bogus`` is not a name the template grows, so the server does not + place it in the node's schema at all — no Port is synthesized for it and it + draws no edge-type diagnostic (and, at the top level, no unknown-input one + either: that check does not exist there).""" + result = graph.validate_workflow(_batch_images_workflow({"images.image0": ["9", 0], "images.bogus": ["9", 1]})) + assert [w["code"] for w in result["warnings"]] == [] + assert result["errors"] == [] + + +def test_nested_slot_key_edge_is_type_checked(graph): + """The same defect one level down, on the fixture's ``GeminiNanoBanana2V2``: + ``model.images.image_1``'s template input is ``IMAGE``, and the nested walk + accepted every slot key wholesale without ever typing it.""" + result = graph.validate_workflow(_nano_banana_workflow({"model.images.image_1": ["9", 1]})) + errs = [e for e in result["errors"] if e["code"] == "edge_type_mismatch"] + assert len(errs) == 1 + assert errs[0]["node_id"] == "1" + assert errs[0]["field"] == "model.images.image_1" + assert "expects IMAGE but LoadImage[1] produces MASK" in errs[0]["message"] + assert result["valid"] is False + + +def test_nested_correctly_wired_slot_stays_clean(graph): + result = graph.validate_workflow(_nano_banana_workflow({"model.images.image_1": ["9", 0]})) + assert result["valid"] is True, result["errors"] + assert result["warnings"] == [] + + +def test_nested_undeclared_slot_key_is_still_unknown_input(graph): + """Post-#842 behaviour preserved: a key the template never declares stays + out of the synthesized ports AND out of the valid-key set, so it keeps + reporting ``unknown_input`` rather than gaining an edge diagnostic about a + slot the server ignores.""" + result = graph.validate_workflow(_nano_banana_workflow({"model.images.bogus": ["9", 1]})) + assert [(w["code"], w["field"]) for w in result["warnings"]] == [("unknown_input", "model.images.bogus")] + assert result["errors"] == [] From 8254b6bd757d384a632a6bd4227f09ca96a7b166 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Mon, 16 Nov 2026 15:47:15 -0800 Subject: [PATCH 2/3] fix(cql): clamp autogrow name expansion and don't type undeclared slots MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cap prefix expansion in autogrow_required_slot_names at Autogrow._MaxNames (100) and skip _autogrow_slot_ports when there are no slots, so a huge min with no max cannot allocate a billion-element list inside validation. When the catalog names no slots, do not synthesize ports from a prefix match — typo keys like images.bogus used to pick up a hard edge_type_mismatch, inverting "don't reject what you cannot read". Read the first value of the first non-empty template section the same way the server does: a classic list-form COMBO is a usable spec, nested autogrow / dynamic-combo types return nothing, and tuple wrappers are normalized so _parse_input_spec does not yield an UNKNOWN port. Slot ports share one parsed template Port. --- comfy_cli/cql/engine.py | 73 ++++++++++--- tests/comfy_cli/cql/test_engine.py | 164 +++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+), 16 deletions(-) diff --git a/comfy_cli/cql/engine.py b/comfy_cli/cql/engine.py index 5304a8387..f66928e23 100644 --- a/comfy_cli/cql/engine.py +++ b/comfy_cli/cql/engine.py @@ -242,6 +242,12 @@ def enum_listing_hint( # than by `int()`, which raises above 4300 digits. _MAX_AUTOGROW_INDEX_DIGITS = 6 +# The server's `Autogrow._MaxNames` cap: a group never grows more than this many +# slots. Required-name expansion (`[f"{prefix}{i}" for i in range(min)]`) must +# honour it, or a prompt-influenced / catalog `min` of 1e9 with no `max` would +# allocate a billion-element list inside validation. +_MAX_AUTOGROW_NAMES = 100 + def _finite_int(value: Any) -> int | None: """``int(value)`` for a real, finite JSON number, else ``None``. @@ -392,15 +398,31 @@ def autogrow_template_input_spec(self) -> Any | None: return None # Declaration order, not a hardcoded ("required", "optional"): the # server's `_expand_schema_for_dynamic` iterates `input.items()` and - # takes the first non-empty section, so a template that lists - # `optional` first is read from `optional`. + # takes the first value of the first non-empty section, so a template + # that lists `optional` first is read from `optional`. Scanning later + # inputs for a string `type_id` would skip a classic list-form COMBO + # (`[["a", "b"], {}]`) and could return a *later* input's spec. for section_def in inputs.values(): - if not isinstance(section_def, dict): + if not isinstance(section_def, dict) or not section_def: continue - for spec in section_def.values(): - type_id = spec[0] if isinstance(spec, (list, tuple)) and spec else spec - if isinstance(type_id, str) and type_id: - return spec + spec = next(iter(section_def.values())) + # `_parse_input_spec` only understands str / list; a tuple wrapper + # would otherwise yield a Port typed UNKNOWN and a false + # `edge_type_mismatch`. + if isinstance(spec, tuple): + spec = list(spec) + type_id = spec[0] if isinstance(spec, list) and spec else spec + # A classic list-form COMBO is a usable spec. A nested autogrow or + # dynamic-combo type is not: there is no socket type to check a + # slot against, and inventing one would be the reject-what-you- + # cannot-read mistake the sibling autogrow accessors all avoid. + if isinstance(type_id, list): + return spec + if not isinstance(type_id, str) or not type_id: + return None + if type_id.startswith("COMFY_AUTOGROW") or _is_dynamic_combo_type(type_id): + return None + return spec return None @property @@ -579,6 +601,10 @@ def autogrow_required_slot_names(self, count: int) -> list[str] | None: hi = self.autogrow_limits[1] if hi is not None: count = min(count, hi) + # `Autogrow._MaxNames` is 100: a prefix template with no `max` and a + # huge `min` (or a caller-supplied count) must not allocate a + # billion-element list inside validation. + count = min(count, _MAX_AUTOGROW_NAMES) # `autogrow_template` yields `names` or `prefix` and nothing else. return [f"{t['prefix']}{i}" for i in range(count)] @@ -2518,7 +2544,12 @@ def validate_workflow(self, workflow: dict[str, Any]) -> dict[str, Any]: # Where the catalog names no slots there is nothing to filter # against and the historical prefix match stands. declared = agp.autogrow_declared_slot_keys(matched) - slot_ports.update(_autogrow_slot_ports(base, agp, matched if declared is None else declared)) + # Only synthesize ports for keys the catalog actually names. + # When there is no naming template (`declared is None`), a + # prefix match would invent a type for typos (`images.bogus`) + # and invert "don't reject what you cannot read". + if declared is not None: + slot_ports.update(_autogrow_slot_ports(base, agp, declared)) # Nested groups are typed by the dynamic-combo walk, which is the # only pass that knows which option expanded them. slot_ports.update(dyn_slot_ports) @@ -3977,7 +4008,10 @@ def _check_dynamic_combo_sub( # loop edge/shape/catalog-checks a nested slot exactly as it does a # top-level one. Only the valid keys: an undeclared `model.images.bogus` # stays an `unknown_input` warning and gets no synthesized diagnostic. - if slot_ports is not None: + # And only when the catalog names slots — a `declared is None` + # prefix match would invent a type for typo keys the same way the + # top-level path used to. + if slot_ports is not None and declared is not None: slot_ports.update(_autogrow_slot_ports(dotted, port, valid)) # The valid keys stay valid even when the count is short, so the slots # that ARE wired don't regress into `unknown_input` noise on top of the @@ -4138,16 +4172,23 @@ def _autogrow_slot_ports(field: str, port: Port, slots: Iterable[str]) -> dict[s Empty for a group whose template declares no inner input — there is no type to check a slot against, so it keeps the pre-existing "no port, no - diagnostic" behaviour rather than guessing one. + diagnostic" behaviour rather than guessing one. Empty immediately when + there are no slots to type, so a huge ``min`` is never expanded just to + build a required-names set that nothing would use. + + Slot Ports share one parsed template Port (``enum_values`` / ``options`` + by reference) and differ only in ``name`` / ``required`` — one parse, not + one copy of the enum per slot. """ + slots = list(slots) + if not slots: + return {} names = port.autogrow_required_slot_names(port.autogrow_effective_min) required_keys = set() if names is None else {f"{field}.{name}" for name in names} - out: dict[str, Port] = {} - for key in slots: - slot_port = port.autogrow_slot_port(key, required=key in required_keys) - if slot_port is not None: - out[key] = slot_port - return out + prototype = port.autogrow_slot_port(slots[0], required=False) + if prototype is None: + return {} + return {key: replace(prototype, name=key, required=key in required_keys) for key in slots} def _check_autogrow_required(node_id: str, autogrow_ports: dict[str, Port], node_data: dict) -> list[dict]: diff --git a/tests/comfy_cli/cql/test_engine.py b/tests/comfy_cli/cql/test_engine.py index f47826f6e..a84372bd9 100644 --- a/tests/comfy_cli/cql/test_engine.py +++ b/tests/comfy_cli/cql/test_engine.py @@ -5461,6 +5461,7 @@ def test_count_instances_skips_a_sibling_def_with_non_list_nodes(self): } assert _count_instances(wf, "u1") == 2 + class TestAutogrowSlotPorts: """Autogrow slot keys (``images.image0``, ``model.images.image_1``, …) are type-, shape- and catalog-checked exactly as ordinary inputs are. @@ -5592,6 +5593,53 @@ class TestAutogrowSlotPorts: "display_name": "Sink", "python_module": "nodes", }, + # Inner IMAGE type but no names/prefix: declared_slot_keys is None, so + # slots must not be typed by a prefix match (a typo like images.bogus + # used to pick up an IMAGE port and hard-error). + "GrowNoNames": { + "input": { + "required": { + "images": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"image": ["IMAGE", {}]}}, + "min": 1, + } + }, + ] + } + }, + "input_order": {"required": ["images"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "GrowNoNames", + "python_module": "nodes", + }, + # Classic list-form COMBO as the template's first (and only) input — + # autogrow_template_input_spec must not skip it for lacking a string + # type_id. + "GrowListCombo": { + "input": { + "required": { + "opts": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"choice": [["a", "b"], {}]}}, + "prefix": "opt", + "min": 0, + } + }, + ] + } + }, + "input_order": {"required": ["opts"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "GrowListCombo", + "python_module": "nodes", + }, } def _graph(self) -> Graph: @@ -5760,3 +5808,119 @@ def test_slot_ports_skip_keys_the_template_never_declares(self): port = next(p for p in grow.inputs if p.name == "images") assert port.autogrow_declared_slot_keys(["images.image0", "images.bogus"]) == {"images.image0"} assert set(_autogrow_slot_ports("images", port, ["images.image0"])) == {"images.image0"} + + def test_no_naming_template_does_not_synthesize_ports_for_typo_keys(self): + """When the catalog names no slots, a prefix match must not invent a + type for `images.bogus` (or a deeper key). That's the reject-what-you- + cannot-read inversion: a typo used to hard-error as `edge_type_mismatch` + instead of staying silent at the top level.""" + result = self._graph().validate_workflow( + self._wf("GrowNoNames", {"images.image0": ["1", 0], "images.bogus": ["0", 0]}) + ) + assert result["errors"] == [] + assert result["warnings"] == [] + + def test_list_form_combo_template_is_membership_checked(self): + """A classic list-form COMBO (`[["a", "b"], {}]`) is a usable template + input; skipping it for lacking a string type_id used to leave the slot + untyped (and could pick up a later input's spec).""" + result = self._graph().validate_workflow(self._wf("GrowListCombo", {"opts.opt0": "zzz"})) + errs = [e for e in result["errors"] if e["code"] == "unknown_enum_value"] + assert len(errs) == 1 + assert errs[0]["field"] == "opts.opt0" + clean = self._graph().validate_workflow(self._wf("GrowListCombo", {"opts.opt0": "a"})) + assert clean["valid"] is True, clean["errors"] + + def test_slot_ports_are_empty_when_there_are_no_slots(self): + """A prefix template with a huge min and no max must not expand a + billion-element required-names list just to type zero slots.""" + from comfy_cli.cql.engine import _MAX_AUTOGROW_NAMES, _autogrow_slot_ports, _port_from_spec + + port = _port_from_spec( + "images", + [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"image": ["IMAGE", {}]}}, + "prefix": "image", + "min": 10**9, + } + }, + ], + True, + ) + assert _autogrow_slot_ports("images", port, []) == {} + names = port.autogrow_required_slot_names(port.autogrow_effective_min) + assert names is not None + assert len(names) == _MAX_AUTOGROW_NAMES + assert names[0] == "image0" + assert names[-1] == f"image{_MAX_AUTOGROW_NAMES - 1}" + + def test_template_input_spec_skips_nested_autogrow_and_dynamic_combo(self): + from comfy_cli.cql.engine import _port_from_spec + + nested = _port_from_spec( + "images", + [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"inner": ["COMFY_AUTOGROW_V3", {"template": {}}]}}, + "prefix": "image", + } + }, + ], + True, + ) + assert nested.autogrow_template_input_spec is None + assert nested.autogrow_slot_port("images.image0", required=False) is None + combo = _port_from_spec( + "images", + [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": { + "required": {"sel": ["COMFY_DYNAMICCOMBO_V3", {"options": [{"key": "a", "inputs": {}}]}]} + }, + "prefix": "image", + } + }, + ], + True, + ) + assert combo.autogrow_template_input_spec is None + + def test_template_input_spec_normalizes_a_tuple_wrapper(self): + """`_parse_input_spec` only understands str/list; a tuple wrapper must + not yield a Port typed UNKNOWN (and a false edge_type_mismatch).""" + from comfy_cli.cql.engine import _port_from_spec + + port = _port_from_spec( + "images", + [ + "COMFY_AUTOGROW_V3", + {"template": {"input": {"required": {"image": ("IMAGE", {})}}, "prefix": "image"}}, + ], + True, + ) + spec = port.autogrow_template_input_spec + assert isinstance(spec, list) + assert spec[0] == "IMAGE" + slot = port.autogrow_slot_port("images.image0", required=False) + assert slot is not None + assert slot.type == "IMAGE" + + def test_slot_ports_share_one_parsed_template_port(self): + from comfy_cli.cql.engine import _autogrow_slot_ports + + graph = self._graph() + combo = graph.node("GrowCombo") + assert combo is not None + opts = next(p for p in combo.inputs if p.name == "opts") + ports = _autogrow_slot_ports("opts", opts, ["opts.opt0", "opts.opt1"]) + assert ports["opts.opt0"].enum_values is ports["opts.opt1"].enum_values + assert ports["opts.opt0"].options is ports["opts.opt1"].options + assert ports["opts.opt0"].name == "opts.opt0" + assert ports["opts.opt1"].name == "opts.opt1" From 8af6a4d582c331aceb5004dbb4680042aba4aeb1 Mon Sep 17 00:00:00 2001 From: Matt Miller Date: Tue, 17 Nov 2026 01:24:09 +0000 Subject: [PATCH 3/3] fix(cql): keep nested no-naming autogrow slots untyped; COMBO element type autogrow_element_type now normalizes through _parse_input_spec, so a list-form COMBO template reads as "COMBO" instead of its choice list (which crashed the edge check with an unhashable type). The driver's dotted-key fallbacks skip autogrow slots at every depth, so an undeclared key under a nested group with no names/prefix no longer gains an inferred type. Co-Authored-By: Claude Opus 5.5 --- comfy_cli/cql/engine.py | 50 +++++++++----- tests/comfy_cli/cql/test_engine.py | 101 +++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+), 17 deletions(-) diff --git a/comfy_cli/cql/engine.py b/comfy_cli/cql/engine.py index f66928e23..a338e3e77 100644 --- a/comfy_cli/cql/engine.py +++ b/comfy_cli/cql/engine.py @@ -437,7 +437,10 @@ def autogrow_element_type(self) -> str | None: spec = self.autogrow_template_input_spec if spec is None: return None - return spec[0] if isinstance(spec, (list, tuple)) and spec else spec + # Through `_parse_input_spec`, not `spec[0]`: a classic list-form COMBO + # (`[["a", "b"], {}]`) has its choice LIST in position 0, and handing + # that to `Port.type` crashes every hashing type check downstream. + return _parse_input_spec(spec)[0] def autogrow_slot_port(self, slot_key: str, *, required: bool) -> Port | None: """A :class:`Port` for one grown slot of this group, parsed from the @@ -2741,12 +2744,13 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar # a wildcard, a union overlap, or a blank/unknown type on # either end still yields no finding at all. port = port_by_name.get(input_name) or slot_ports.get(input_name) - if port is None and not any(input_name.startswith(f"{base}.") for base in autogrow_ports): - # Autogrow suffixes are typed only via slot_ports, so a - # key the template never declared (`images.bogus`) gets - # no synthesized type. Other dotted keys (combo sub-inputs) - # still resolve through _dotted_slot_port. - port = _dotted_slot_port(port_by_name, input_name, node_inputs) + if port is None: + # Autogrow suffixes — top-level or nested under a + # dynamic combo — are typed only via slot_ports, so a + # key the template never declared (`images.bogus`, + # `model.images.bogus`) gets no synthesized type. Other + # dotted keys (combo sub-inputs) still resolve here. + port = _dotted_slot_port(port_by_name, input_name, node_inputs, autogrow_slots=False) if port is not None: src_type = src_m.outputs[out_idx].type dst_type = port.type @@ -2800,10 +2804,8 @@ def _structural(finding: dict, _node_id: str = node_id, _declared: bool = declar # undeclared autogrow suffixes must not gain a synthesized type. if port is not None: link_port = port - elif any(input_name.startswith(f"{base}.") for base in autogrow_ports): - link_port = None else: - link_port = _dotted_slot_port(port_by_name, input_name, node_inputs) + link_port = _dotted_slot_port(port_by_name, input_name, node_inputs, autogrow_slots=False) # A literal on a socket that only carries a node's output. The # server does not type-check custom types (only INT/FLOAT/ # STRING/BOOLEAN/COMBO), so it hands the string to the node, @@ -4906,7 +4908,9 @@ def _declared_link_targets(node_data: dict, graph: Graph) -> list[str]: return targets -def _resolve_dotted_slot(port_by_name: dict[str, Port], dotted: str, node_inputs: dict) -> tuple[Port | None, bool]: +def _resolve_dotted_slot( + port_by_name: dict[str, Port], dotted: str, node_inputs: dict, *, autogrow_slots: bool = True +) -> tuple[Port | None, bool]: """``(port, unresolved)`` for a dotted wire key. ``unresolved`` is True only when a dynamic combo on the path gave no basis @@ -4917,6 +4921,10 @@ def _resolve_dotted_slot(port_by_name: dict[str, Port], dotted: str, node_inputs selector that is absent. It is False for a key the current schema and selections genuinely do NOT declare, which is the case a caller may treat as stale. + + ``autogrow_slots=False`` returns ``(None, False)`` for a key that lands in + an autogrow group at any depth, for a caller that types those slots from + the template instead (:func:`_autogrow_slot_ports`). """ base, _, leaf = dotted.partition(".") if not leaf: @@ -4924,10 +4932,12 @@ def _resolve_dotted_slot(port_by_name: dict[str, Port], dotted: str, node_inputs port = port_by_name.get(base) if port is None: return None, False - return _resolve_dotted_under(port, dotted, node_inputs, 0) + return _resolve_dotted_under(port, dotted, node_inputs, 0, autogrow_slots=autogrow_slots) -def _dotted_slot_port(port_by_name: dict[str, Port], dotted: str, node_inputs: dict) -> Port | None: +def _dotted_slot_port( + port_by_name: dict[str, Port], dotted: str, node_inputs: dict, *, autogrow_slots: bool = True +) -> Port | None: """The port a dotted wire key targets: an autogrow slot or a combo sub-input. The server type-checks every entry in a node's ``inputs`` by name, dotted @@ -4945,12 +4955,16 @@ def _dotted_slot_port(port_by_name: dict[str, Port], dotted: str, node_inputs: d An autogrow slot whose group declares no element type is NOT one of those cases: it comes back as a ``"*"``-typed port, so the slot keeps its - structural link checks and accepts any source type. + structural link checks and accepts any source type — unless + ``autogrow_slots=False``, which yields ``None`` for every autogrow slot + (see :func:`_resolve_dotted_slot`). """ - return _resolve_dotted_slot(port_by_name, dotted, node_inputs)[0] + return _resolve_dotted_slot(port_by_name, dotted, node_inputs, autogrow_slots=autogrow_slots)[0] -def _resolve_dotted_under(port: Port, dotted: str, node_inputs: dict, depth: int) -> tuple[Port | None, bool]: +def _resolve_dotted_under( + port: Port, dotted: str, node_inputs: dict, depth: int, *, autogrow_slots: bool = True +) -> tuple[Port | None, bool]: """Walk ``dotted`` down from ``port``, whose name is a prefix of it. Returns ``(port, unresolved)`` as :func:`_resolve_dotted_slot` defines them. @@ -4972,6 +4986,8 @@ def _resolve_dotted_under(port: Port, dotted: str, node_inputs: dict, depth: int return next((p for p in fields if p.name == dotted), None), False return None, False if port.is_autogrow: + if not autogrow_slots: + return None, False element = port.autogrow_element_type if not element: # Older/partial catalogs can omit the element schema while still @@ -5015,7 +5031,7 @@ def _resolve_dotted_under(port: Port, dotted: str, node_inputs: dict, depth: int if sub.name == dotted: return sub, False if dotted.startswith(f"{sub.name}."): - return _resolve_dotted_under(sub, dotted, node_inputs, depth + 1) + return _resolve_dotted_under(sub, dotted, node_inputs, depth + 1, autogrow_slots=autogrow_slots) # The selection resolved and does not declare this key: genuinely stale. return None, False return None, False diff --git a/tests/comfy_cli/cql/test_engine.py b/tests/comfy_cli/cql/test_engine.py index a84372bd9..b539236e8 100644 --- a/tests/comfy_cli/cql/test_engine.py +++ b/tests/comfy_cli/cql/test_engine.py @@ -5640,6 +5640,78 @@ class TestAutogrowSlotPorts: "display_name": "GrowListCombo", "python_module": "nodes", }, + # A group nested under a dynamic combo's selected option, with an + # inner type but no names/prefix: the nested twin of GrowNoNames. + "NestedNoNames": { + "input": { + "required": { + "model": [ + "COMFY_DYNAMICCOMBO_V3", + { + "options": [ + { + "key": "m1", + "inputs": { + "required": { + "images": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"image": ["IMAGE", {}]}}, + "min": 0, + } + }, + ] + } + }, + } + ] + }, + ] + } + }, + "input_order": {"required": ["model"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "NestedNoNames", + "python_module": "nodes", + }, + # Same shape, list-form COMBO inner input: the slot type must read as + # the string "COMBO", never the choice list itself. + "NestedNoNamesListCombo": { + "input": { + "required": { + "model": [ + "COMFY_DYNAMICCOMBO_V3", + { + "options": [ + { + "key": "m1", + "inputs": { + "required": { + "images": [ + "COMFY_AUTOGROW_V3", + { + "template": { + "input": {"required": {"image": [["a", "b"], {}]}}, + "min": 0, + } + }, + ] + } + }, + } + ] + }, + ] + } + }, + "input_order": {"required": ["model"]}, + "output": ["IMAGE"], + "output_name": ["IMAGE"], + "display_name": "NestedNoNamesListCombo", + "python_module": "nodes", + }, } def _graph(self) -> Graph: @@ -5831,6 +5903,35 @@ def test_list_form_combo_template_is_membership_checked(self): clean = self._graph().validate_workflow(self._wf("GrowListCombo", {"opts.opt0": "a"})) assert clean["valid"] is True, clean["errors"] + def test_nested_no_naming_template_does_not_infer_a_slot_type(self): + """The nested twin of the no-naming case: `model.images.bogus` under a + group with no names/prefix gets no inferred IMAGE type, so an INT link + into it is not an `edge_type_mismatch`, and a literal on it is not a + `literal_on_link_input`.""" + wf = self._wf("NestedNoNames", {"model": "m1", "model.images.bogus": ["0", 0]}) + result = self._graph().validate_workflow(wf) + assert [e for e in result["errors"] if e["code"] == "edge_type_mismatch"] == [] + assert [w for w in result["warnings"] if w["code"] == "edge_type_mismatch"] == [] + assert result["valid"] is True, result["errors"] + literal = self._graph().validate_workflow(self._wf("NestedNoNames", {"model": "m1", "model.images.bogus": "x"})) + codes = {f["code"] for f in literal["errors"] + literal["warnings"]} + assert "literal_on_link_input" not in codes + + def test_nested_list_form_combo_slot_link_does_not_crash(self): + """A linked nested slot under a no-naming list-form COMBO template used + to reach `Port.type = ["a", "b"]` and raise `TypeError: unhashable + type: 'list'` in the edge check.""" + wf = self._wf("NestedNoNamesListCombo", {"model": "m1", "model.images.image0": ["1", 0]}) + result = self._graph().validate_workflow(wf) + assert [e for e in result["errors"] if e["code"] == "edge_type_mismatch"] == [] + + def test_list_form_combo_element_type_is_the_combo_type_string(self): + graph = self._graph() + grow = graph.node("GrowListCombo") + assert grow is not None + opts = next(p for p in grow.inputs if p.name == "opts") + assert opts.autogrow_element_type == "COMBO" + def test_slot_ports_are_empty_when_there_are_no_slots(self): """A prefix template with a huge min and no max must not expand a billion-element required-names list just to type zero slots."""