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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
479 changes: 361 additions & 118 deletions comfy_cli/cql/engine.py

Large diffs are not rendered by default.

542 changes: 542 additions & 0 deletions tests/comfy_cli/cql/test_engine.py

Large diffs are not rendered by default.

90 changes: 90 additions & 0 deletions tests/comfy_cli/cql/test_nested_autogrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,93 @@ def test_show_payload_top_level_autogrow_uses_schema_names(graph):
assert images["autogrow"] is True
assert images["element_type"] == "IMAGE"
assert images["wire_as"].startswith("images.image0")


# --------------------------------------------------------------------------- #
# (D) the production catalog's own autogrow minimums are enforced
# --------------------------------------------------------------------------- #


def _grok_edit_v2_inputs(option_index: int = 0) -> tuple[dict, str]:
"""Every widget `GrokImageEditNodeV2` requires for one model option, at its
schema defaults — everything except the `images` autogrow slots."""
info = json.loads(FIXTURE.read_text())
node = info["GrokImageEditNodeV2"]["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, option["key"]


def _grok_edit_v2_workflow(extra: dict) -> dict:
inputs, _ = _grok_edit_v2_inputs()
return {
"9": {"class_type": "LoadImage", "inputs": {"image": "example.png"}},
"1": {"class_type": "GrokImageEditNodeV2", "inputs": {**inputs, **extra}},
"2": {"class_type": "SaveImage", "inputs": {"images": ["1", 0], "filename_prefix": "out"}},
}


def test_production_nested_autogrow_min_is_enforced(graph):
"""The false negative, on the real captured catalog rather than a synthetic
one: ``GrokImageEditNodeV2.model.images`` declares ``min: 1`` with its inner
input in the template's ``required`` section, so the server places slot 0 in
``required`` and rejects a prompt that wires none. This validated clean
before the ``autogrow_below_min`` check existed.

Same declaration shape as ``GrokVideoReferenceNode.model.reference_images``
(``TemplateNames(reference_1..7, min=1)``) on ComfyUI master.
"""
images = graph.node("GrokImageEditNodeV2")
assert images is not None
result = graph.validate_workflow(_grok_edit_v2_workflow({}))
assert result["valid"] is False
# Zero slots is `autogrow_no_slots` at every depth; a partial fill is
# `autogrow_below_min` (see test_production_nested_autogrow_counts_the_declared_names).
err = next(e for e in result["errors"] if e["code"] == "autogrow_no_slots")
assert err["node_id"] == "1"
assert err["field"] == "model.images"
assert "places 1 of them in `required`" in err["message"]
assert "model.images.image_1" in err["hint"]


def test_production_nested_autogrow_at_min_validates_clean(graph):
result = graph.validate_workflow(_grok_edit_v2_workflow({"model.images.image_1": ["9", 0]}))
assert result["valid"] is True, result["errors"]


def test_production_nested_autogrow_counts_the_declared_names(graph):
"""One wired slot against ``min: 1`` — but the wrong one. The server marks
``model.images.image_1`` required (``names[:min]``) and rejects a prompt
that only wires ``image_2``, so a bare count of the ``model.images.`` keys
is not the server's test."""
result = graph.validate_workflow(_grok_edit_v2_workflow({"model.images.image_2": ["9", 0]}))
assert result["valid"] is False
err = next(e for e in result["errors"] if e["code"] == "autogrow_below_min")
assert "'model.images.image_1'" in err["message"]
# The slot that IS wired stays a known key rather than unknown_input noise.
assert result["warnings"] == []


def test_production_min_zero_group_stays_lenient(graph):
"""``MinimaxHailuo03ReferenceNode``'s `reference_videos`/`reference_audios`
declare ``min: 0`` inside the option's ``required`` section — the deliberate
leniency that must survive the new minimum check."""
port = next(
p
for p in graph.autogrow_groups("MinimaxHailuo03ReferenceNode", MINIMAX_UI_WIDGETS)
if p.name == "model.reference_videos"
)
assert port.autogrow_template_required is True
assert port.autogrow_limits[0] == 0
assert port.autogrow_effective_min == 0
4 changes: 2 additions & 2 deletions tests/comfy_cli/cql/test_validate_runtime_failures.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def test_first_min_autogrow_slots_are_individually_required(self):
result = _graph().validate_workflow(wf)

assert not result["valid"]
assert ("required_input_missing", "videos.video0") in _codes(result)
assert ("autogrow_below_min", "videos") in _codes(result)

def test_required_autogrow_inside_dynamic_combo_needs_a_slot(self):
# A Grok image edit submitted with no image wired.
Expand All @@ -361,7 +361,7 @@ def test_required_autogrow_inside_dynamic_combo_needs_a_slot(self):
result = _graph().validate_workflow(wf)

assert not result["valid"]
assert ("required_input_missing", "model.images.image_1") in _codes(result)
assert ("autogrow_no_slots", "model.images") in _codes(result)

def test_nested_autogrow_with_first_slot_wired_is_valid(self):
wf = {
Expand Down
7 changes: 4 additions & 3 deletions tests/comfy_cli/cql/test_validate_server_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,8 @@ def test_string_source_id_still_validates(self, graph: Graph) -> None:
class TestAutogrowAnchor:
"""An autogrow group with `min: 1` requires the index-0 slot by name: the
server answers `required_input_missing: image0` for a group wired from
image1 upwards. The validator counted slots and never checked which."""
image1 upwards. `autogrow_below_min` reports the missing required slot
names (unified with the count shortfall), not a separate first-slot code."""

def test_missing_index_zero_slot_is_rejected(self, graph: Graph) -> None:
wf = {
Expand All @@ -375,7 +376,7 @@ def test_missing_index_zero_slot_is_rejected(self, graph: Graph) -> None:
}
result = graph.validate_workflow(wf)
assert not result["valid"]
assert "autogrow_missing_first_slot" in _codes(result)
assert "autogrow_below_min" in _codes(result)

def test_slots_from_index_zero_validate(self, graph: Graph) -> None:
wf = {
Expand Down Expand Up @@ -725,7 +726,7 @@ def test_a_named_group_skipping_its_first_name_is_rejected(self, graph: Graph) -
}
result = graph.validate_workflow(wf)
assert not result["valid"]
assert "autogrow_missing_first_slot" in _codes(result)
assert "autogrow_below_min" in _codes(result)

def test_a_group_with_min_zero_may_have_no_slots(self, graph: Graph) -> None:
"""GLSLShader.floats sits under `required` with min 0: a shader using no
Expand Down
109 changes: 109 additions & 0 deletions tests/comfy_cli/fixtures/dynamic_combo_object_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,114 @@
"output_node": true,
"api_node": true,
"python_module": "nodes"
},
"ImageSrc": {
"input": {"required": {}},
"input_order": {"required": []},
"output": ["IMAGE"],
"output_name": ["IMAGE"],
"category": "image",
"display_name": "Image Source",
"description": "Synthetic IMAGE producer for autogrow slot-count tests.",
"output_node": false,
"python_module": "nodes"
},
"Sink": {
"input": {"optional": {"image": ["IMAGE", {}]}},
"input_order": {"optional": ["image"]},
"output": [],
"output_name": [],
"category": "image",
"display_name": "Sink",
"description": "Synthetic output node; its only input is optional so it validates alone.",
"output_node": true,
"python_module": "nodes"
},
"AutogrowTopNode": {
"input": {
"required": {
"images": [
"COMFY_AUTOGROW_V3",
{"template": {"input": {"required": {"image": ["IMAGE", {}]}}, "prefix": "image", "min": 2, "max": 4}}
]
}
},
"input_order": {"required": ["images"]},
"output": ["IMAGE"],
"output_name": ["IMAGE"],
"category": "image",
"display_name": "Autogrow Top",
"description": "Synthetic top-level autogrow group with a min of 2 slots.",
"output_node": false,
"python_module": "nodes"
},
"AutogrowNestedNode": {
"input": {
"required": {
"model": [
"COMFY_DYNAMICCOMBO_V3",
{
"options": [
{
"key": "strict",
"inputs": {
"required": {
"refs": [
"COMFY_AUTOGROW_V3",
{"template": {"input": {"required": {"reference_image": ["IMAGE", {}]}}, "names": ["reference_1", "reference_2", "reference_3"], "min": 1}}
]
},
"optional": {}
}
},
{
"key": "strict_pair",
"inputs": {
"required": {
"refs": [
"COMFY_AUTOGROW_V3",
{"template": {"input": {"required": {"reference_image": ["IMAGE", {}]}}, "names": ["reference_1", "reference_2", "reference_3"], "min": 2}}
]
},
"optional": {}
}
},
{
"key": "lenient",
"inputs": {
"required": {
"refs": [
"COMFY_AUTOGROW_V3",
{"template": {"input": {"required": {"reference_image": ["IMAGE", {}]}}, "names": ["reference_1", "reference_2", "reference_3"], "min": 0}}
]
},
"optional": {}
}
},
{
"key": "optional_template",
"inputs": {
"required": {
"refs": [
"COMFY_AUTOGROW_V3",
{"template": {"input": {"optional": {"reference_image": ["IMAGE", {}]}}, "names": ["reference_1", "reference_2", "reference_3"], "min": 1}}
]
},
"optional": {}
}
}
]
}
]
}
},
"input_order": {"required": ["model"]},
"output": ["IMAGE"],
"output_name": ["IMAGE"],
"category": "image",
"display_name": "Autogrow Nested",
"description": "Synthetic dynamic-combo node whose options nest autogrow sub-inputs.",
"output_node": false,
"python_module": "nodes"
}
}
Loading