From 3d9b37099566fee53e78b7e4bec65413f617e04d Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Sun, 18 Oct 2026 00:54:28 +0000 Subject: [PATCH 01/11] test(workflow): agent-built nodes need widget-input sockets so human links reach the doc (PM-1897) --- .../test_add_node_widget_input_slots.py | 161 ++++++++++++++++++ 1 file changed, 161 insertions(+) create mode 100644 tests/comfy_cli/test_add_node_widget_input_slots.py diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py new file mode 100644 index 000000000..ee2ea8b84 --- /dev/null +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -0,0 +1,161 @@ +"""Agent-built nodes carry a socket entry for every scalar widget input. + +PM-1897: the agent said ``frame_load_cap`` on an agent-built Load Video (VHS) +and an agent-made custom node was a plain widget = 1000, while the user had +wired a PrimitiveInt into both on the canvas. ``_build_node`` wrote only LINK +inputs, so the shared document had no ``frame_load_cap`` slot. The frontend +gives every non-socketless widget input a socket, so a human link drawn into +it named an input the document did not hold and never reached it. + +A node the frontend creates serializes those entries +(``{"name", "type", "widget": {"name"}, "link": None}``), so an agent-built +node now does too. A link into such an input is then a CONCRETE connect: one +last-writer-wins register per input, instead of an autogrow-style ``grow`` +that mints a fresh slot per link and leaves two slots when two writers race. +""" + +from __future__ import annotations + +import copy + +import pytest + +from comfy_cli import workflow_ops +from comfy_cli.cql.engine import Graph +from comfy_cli.workflow_print import render_py +from comfy_cli.workflow_to_api import convert_ui_to_api + + +def _node(required: dict, outputs: list[str], optional: dict | None = None, names: list[str] | None = None) -> dict: + spec = {"required": required} + order = {"required": list(required)} + if optional: + spec["optional"] = optional + order["optional"] = list(optional) + return { + "input": spec, + "input_order": order, + "output": outputs, + "output_name": names or outputs, + "category": "test", + "display_name": "x", + "python_module": "custom_nodes.test", + } + + +OBJECT_INFO = { + "PrimitiveInt": _node({"value": ["INT", {"default": 0}]}, ["INT"]), + "VHS_LoadVideo": _node( + { + "video": [["clip.mp4"]], + "force_rate": ["FLOAT", {"default": 0}], + "frame_load_cap": ["INT", {"default": 0}], + "skip_first_frames": ["INT", {"default": 0}], + }, + ["IMAGE", "INT"], + optional={"meta_batch": ["VHS_BatchManager"], "vae": ["VAE"]}, + names=["IMAGE", "frame_count"], + ), + "CSVCVColumn": _node( + { + "csv_path": ["STRING", {"default": ""}], + "enabled": ["BOOLEAN", {"default": True}], + "frame_load_cap": ["INT", {"default": 0}], + }, + ["FLOAT"], + ), +} + +LOAD_VIDEO_LINK_INPUTS = [("meta_batch", "VHS_BatchManager"), ("vae", "VAE")] + + +@pytest.fixture +def graph() -> Graph: + return Graph.from_object_info(OBJECT_INFO) + + +def _add(workflow: dict, graph: Graph, class_type: str) -> dict: + workflow, op = workflow_ops.add_node(workflow, graph, class_type, pos=[0, 0]) + return next(n for n in workflow["nodes"] if n["id"] == op["node_id"]) + + +def _input(node: dict, name: str) -> list[dict]: + return [i for i in node["inputs"] if i.get("name") == name] + + +def _built(graph: Graph) -> tuple[dict, dict, dict]: + workflow: dict = {"nodes": [], "links": []} + primitive = _add(workflow, graph, "PrimitiveInt") + video = _add(workflow, graph, "VHS_LoadVideo") + return workflow, primitive, video + + +def test_add_node_writes_a_widget_socket_for_each_scalar_widget_input(graph): + workflow: dict = {"nodes": [], "links": []} + video = _add(workflow, graph, "VHS_LoadVideo") + csv = _add(workflow, graph, "CSVCVColumn") + + assert [(i["name"], i["type"]) for i in video["inputs"][:2]] == LOAD_VIDEO_LINK_INPUTS + for name, slot_type in [("force_rate", "FLOAT"), ("frame_load_cap", "INT"), ("skip_first_frames", "INT")]: + assert _input(video, name) == [{"name": name, "type": slot_type, "widget": {"name": name}, "link": None}] + assert _input(video, "video") == [] + for name, slot_type in [("csv_path", "STRING"), ("enabled", "BOOLEAN"), ("frame_load_cap", "INT")]: + assert _input(csv, name) == [{"name": name, "type": slot_type, "widget": {"name": name}, "link": None}] + + +def test_connect_into_a_widget_input_is_a_concrete_connect(graph): + workflow, primitive, video = _built(graph) + + workflow, op = workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "frame_load_cap") + + assert "grow" not in op + assert video["inputs"][op["to_slot"]]["name"] == "frame_load_cap" + assert _input(video, "frame_load_cap") == [ + {"name": "frame_load_cap", "type": "INT", "widget": {"name": "frame_load_cap"}, "link": op["link_id"]} + ] + + +def test_two_racing_links_into_one_widget_input_converge_on_one_slot(graph): + base, primitive, video = _built(graph) + second = _add(base, graph, "PrimitiveInt") + _, first_op = workflow_ops.connect(copy.deepcopy(base), graph, primitive["id"], 0, video["id"], "frame_load_cap") + _, second_op = workflow_ops.connect( + copy.deepcopy(base), graph, second["id"], 0, video["id"], "frame_load_cap", base_version=1 + ) + + converged = [] + for order in ([first_op, second_op], [second_op, first_op]): + replica = copy.deepcopy(base) + for op in order: + workflow_ops.apply_op(replica, op, graph) + node = next(n for n in replica["nodes"] if n["id"] == video["id"]) + converged.append(_input(node, "frame_load_cap")) + + assert converged[0] == converged[1] + assert [slot["link"] for slot in converged[0]] == [second_op["link_id"]] + + +def test_api_prompt_reads_the_widget_value_until_linked_then_the_link(graph): + workflow, primitive, video = _built(graph) + workflow_ops.set_widget(workflow, graph, video["id"], "frame_load_cap", 1000) + + unlinked = convert_ui_to_api(copy.deepcopy(workflow), OBJECT_INFO) + assert unlinked[str(video["id"])]["inputs"]["frame_load_cap"] == 1000 + + workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "frame_load_cap") + linked = convert_ui_to_api(workflow, OBJECT_INFO) + assert linked[str(video["id"])]["inputs"]["frame_load_cap"] == [str(primitive["id"]), 0] + + +def test_the_agent_print_shows_a_human_link_into_frame_load_cap(graph): + workflow, primitive, video = _built(graph) + slot = next(k for k, i in enumerate(video["inputs"]) if i["name"] == "frame_load_cap") + link_id = 501 + video["inputs"][slot]["link"] = link_id + primitive["outputs"][0]["links"] = [link_id] + workflow["links"].append([link_id, primitive["id"], 0, video["id"], slot, "INT"]) + + source = render_py(workflow, graph).source + + assert "frame_load_cap=primitive_int" in source + assert "frame_load_cap=0" not in source From f7b66bfe9f36ba8e8e8851a68f73227274c58f06 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Sun, 18 Oct 2026 01:03:10 +0000 Subject: [PATCH 02/11] fix(workflow): give agent-built nodes a socket entry for each scalar widget input (PM-1897) add_node wrote only link inputs, so the shared document had no slot for a widget input such as frame_load_cap. The frontend gives that input a socket, so a link a human drew into it named a slot the document lacked and never reached it; the agent kept reading the static widget value. Write {name, type, widget: {name}, link: null} for every non-socketless INT/FLOAT/STRING/BOOLEAN widget input, after the link inputs so link indices are unchanged. A link into such an input is now a concrete last-writer-wins connect on one named slot instead of a grow that mints a slot per link. COMBO stays on convert-on-connect: the concrete type check would refuse the STRING output that usually drives it. --- comfy_cli/workflow_ops.py | 20 +++++++++++++++++++ .../test_workflow_edit_nested_autogrow.py | 18 +++++++++++------ .../test_workflow_print_promoted_autogrow.py | 2 +- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/comfy_cli/workflow_ops.py b/comfy_cli/workflow_ops.py index 33be10737..c28b22cf3 100644 --- a/comfy_cli/workflow_ops.py +++ b/comfy_cli/workflow_ops.py @@ -3726,8 +3726,28 @@ def strip_internal(workflow: dict) -> dict: # --------------------------------------------------------------------------- +# Widget inputs a fresh node gets a socket entry for: the scalar types a +# primitive can drive. The frontend gives every non-socketless widget input a +# socket and serializes it as ``{"name", "type", "widget": {"name"}}``; without +# the entry the shared document has no slot for a link a human draws into that +# socket, so the link never reaches the document (PM-1897). COMBO is left on +# the convert-on-connect path: the concrete type check would refuse the STRING +# output that commonly drives it. +_SOCKETED_WIDGET_TYPES = frozenset({"INT", "FLOAT", "STRING", "BOOLEAN"}) + + +def _widget_input_entries(m) -> list[dict]: + return [ + {"name": p.name, "type": p.type, "widget": {"name": p.name}, "link": None} + for p in m.inputs + if not p.is_link and not p.is_socketless and p.type in _SOCKETED_WIDGET_TYPES + ] + + def _build_node(node_id: int, class_type: str, m, graph, pos: list, size: list, title: str | None = None) -> dict: + # Link inputs first, so their indices are unchanged; widget sockets after. inputs = [{"name": p.name, "type": p.type, "link": None} for p in m.inputs if p.is_link] + inputs += _widget_input_entries(m) outputs = [{"name": p.name, "type": p.type, "links": []} for p in m.outputs] # Widget values in positional order, including dynamic-combo selectors and # their sub-widgets — sourced from the engine so add-node matches the converter. diff --git a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py index 54b155687..cd8c60177 100644 --- a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py +++ b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py @@ -59,8 +59,12 @@ def _node(wf: dict, node_id: Any) -> dict: return next(n for n in wf["nodes"] if n["id"] == node_id) +def _is_widget_socket(entry: dict) -> bool: + return "widget" in entry and "grow_id" not in entry + + def _inputs(wf: dict, node_id: Any) -> list[str]: - return [i["name"] for i in _node(wf, node_id).get("inputs") or []] + return [i["name"] for i in _node(wf, node_id).get("inputs") or [] if not _is_widget_socket(i)] def _link_of(wf: dict, node_id: Any, name: str): @@ -152,7 +156,7 @@ def _add_loader(wf: dict, graph: Graph, class_type: str) -> tuple[dict, int]: def test_add_node_writes_frontend_width_widgets_and_no_group_inputs(graph): wf, _ = workflow_ops.add_node(_empty(), graph, "MinimaxHailuo03ReferenceNode") node = wf["nodes"][0] - assert node["inputs"] == [] + assert [i for i in node["inputs"] if not _is_widget_socket(i)] == [] order = graph.widget_order_default("MinimaxHailuo03ReferenceNode") assert len(node["widgets_values"]) == len(order) == 8 by_name = dict(zip(order, node["widgets_values"])) @@ -171,7 +175,7 @@ def test_connect_grows_first_nested_slot_by_its_schema_name(graph): wf, b = _add_loader(wf, graph, "GeminiNanoBanana2V2") widgets_before = list(_node(wf, b)["widgets_values"]) wf, op = workflow_ops.connect(wf, graph, a, "IMAGE", b, "model.images.image_1") - grown = _node(wf, b)["inputs"] + grown = [i for i in _node(wf, b)["inputs"] if not _is_widget_socket(i)] assert [i["name"] for i in grown] == ["model.images.image_1"] assert grown[0]["type"] == "IMAGE" assert grown[0]["link"] == op["link_id"] @@ -446,14 +450,16 @@ def test_full_group_reports_full_before_the_next_key_hint(graph): def test_a_real_widget_name_outranks_the_bare_element_guess(): """A node whose group's bare element vocabulary collides with a real - widget name keeps the widget→input conversion (the existing precedence).""" + widget name resolves to that widget's own input, never the group guess.""" oi = json.loads(FIXTURE.read_text()) oi["BatchImagesNode"]["input"]["required"]["image0"] = ["STRING", {"default": ""}] oi["BatchImagesNode"]["input_order"]["required"].append("image0") g = Graph.from_object_info(oi) wf, batch = _add_loader(_empty(), g, "BatchImagesNode") - _idx, grow = workflow_ops._resolve_input_target(_node(wf, batch), g, "image0", "STRING") - assert grow == {"name": "image0", "type": "STRING", "widget": "image0"} + node = _node(wf, batch) + idx, grow = workflow_ops._resolve_input_target(node, g, "image0", "STRING") + assert grow is None + assert node["inputs"][idx] == {"name": "image0", "type": "STRING", "widget": {"name": "image0"}, "link": None} def test_replay_collision_never_grows_past_the_schema_max(graph): diff --git a/tests/comfy_cli/test_workflow_print_promoted_autogrow.py b/tests/comfy_cli/test_workflow_print_promoted_autogrow.py index 6c9d55235..6c8129a2c 100644 --- a/tests/comfy_cli/test_workflow_print_promoted_autogrow.py +++ b/tests/comfy_cli/test_workflow_print_promoted_autogrow.py @@ -530,7 +530,7 @@ def test_cli_print_autogrow_addresses_match_connect(tmp_path, autogrow_graph): # that printed slot name is exactly what connect grows wf2, _ = workflow_ops.connect(wf, autogrow_graph, a, "IMAGE", b, "model.images.image_1") node = next(n for n in wf2["nodes"] if n["id"] == b) - assert [i["name"] for i in node["inputs"]] == ["model.images.image_1"] + assert [i["name"] for i in node["inputs"] if "widget" not in i] == ["model.images.image_1"] def test_no_catalog_still_prints_the_instance_values(promoted_graph): From 844681ce26407b690b636b8d27087cc112da92c3 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Sun, 18 Oct 2026 01:15:07 +0000 Subject: [PATCH 03/11] test(workflow): pin the widget-socket type check and the COMBO widget-name precedence --- .../command/test_workflow_edit_nested_autogrow.py | 12 ++++++++++++ tests/comfy_cli/test_add_node_widget_input_slots.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py index cd8c60177..88464d21c 100644 --- a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py +++ b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py @@ -462,6 +462,18 @@ def test_a_real_widget_name_outranks_the_bare_element_guess(): assert node["inputs"][idx] == {"name": "image0", "type": "STRING", "widget": {"name": "image0"}, "link": None} +def test_a_real_combo_widget_name_outranks_the_bare_element_guess(): + """A COMBO widget has no socket entry on an agent-built node, so it takes + the widget→input conversion, still ahead of the group's element guess.""" + oi = json.loads(FIXTURE.read_text()) + oi["BatchImagesNode"]["input"]["required"]["image0"] = [["a", "b"]] + oi["BatchImagesNode"]["input_order"]["required"].append("image0") + g = Graph.from_object_info(oi) + wf, batch = _add_loader(_empty(), g, "BatchImagesNode") + _idx, grow = workflow_ops._resolve_input_target(_node(wf, batch), g, "image0", "STRING") + assert grow == {"name": "image0", "type": "STRING", "widget": "image0"} + + def test_replay_collision_never_grows_past_the_schema_max(graph): """Two replicas each mint the LAST free slot of a 3-slot group. On replay the second arrival collides on ``video_3``; renaming it must not diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index ee2ea8b84..fc66bfd7b 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -159,3 +159,10 @@ def test_the_agent_print_shows_a_human_link_into_frame_load_cap(graph): assert "frame_load_cap=primitive_int" in source assert "frame_load_cap=0" not in source + + +def test_a_widget_socket_refuses_a_link_of_another_scalar_type(graph): + workflow, primitive, video = _built(graph) + + with pytest.raises(ValueError, match=r"type mismatch: INT output .* FLOAT input 'force_rate'"): + workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "force_rate") From bdbcc1f50839419e1032cda9b31019e20ce29174 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sun, 18 Oct 2026 01:52:22 +0000 Subject: [PATCH 04/11] chore(workflow): drop an internal ticket id from a comment and a test docstring public-repo-hygiene rejects internal tracker ids in this public repo. --- comfy_cli/workflow_ops.py | 2 +- tests/comfy_cli/test_add_node_widget_input_slots.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/comfy_cli/workflow_ops.py b/comfy_cli/workflow_ops.py index c28b22cf3..81f2f61e4 100644 --- a/comfy_cli/workflow_ops.py +++ b/comfy_cli/workflow_ops.py @@ -3730,7 +3730,7 @@ def strip_internal(workflow: dict) -> dict: # primitive can drive. The frontend gives every non-socketless widget input a # socket and serializes it as ``{"name", "type", "widget": {"name"}}``; without # the entry the shared document has no slot for a link a human draws into that -# socket, so the link never reaches the document (PM-1897). COMBO is left on +# socket, so the link never reaches the document. COMBO is left on # the convert-on-connect path: the concrete type check would refuse the STRING # output that commonly drives it. _SOCKETED_WIDGET_TYPES = frozenset({"INT", "FLOAT", "STRING", "BOOLEAN"}) diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index fc66bfd7b..e0cb16f56 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -1,6 +1,6 @@ """Agent-built nodes carry a socket entry for every scalar widget input. -PM-1897: the agent said ``frame_load_cap`` on an agent-built Load Video (VHS) +Reported: the agent said ``frame_load_cap`` on an agent-built Load Video (VHS) and an agent-made custom node was a plain widget = 1000, while the user had wired a PrimitiveInt into both on the canvas. ``_build_node`` wrote only LINK inputs, so the shared document had no ``frame_load_cap`` slot. The frontend From 18e99893ca7ead9ee50a70655a115ddd3ba2f13b Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:24:49 +0000 Subject: [PATCH 05/11] test(workflow): partial widget sockets must not misname saved values without object_info --- .../test_add_node_widget_input_slots.py | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index e0cb16f56..4681a75e5 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -166,3 +166,41 @@ def test_a_widget_socket_refuses_a_link_of_another_scalar_type(graph): with pytest.raises(ValueError, match=r"type mismatch: INT output .* FLOAT input 'force_rate'"): workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "force_rate") + + +def test_a_saved_node_with_partial_widget_sockets_does_not_misname_its_values(graph): + """With no object_info, the widget sockets alone cannot name COMBO-bearing values. + + An agent-built Load Video has sockets for its scalars but not for ``video``, + so the sockets do not account for every value. Pairing them by position + would send the file name as ``force_rate`` and spill a value onto a link + input, so the converter must drop the values and warn instead. + """ + workflow: dict = {"nodes": [], "links": []} + video = _add(workflow, graph, "VHS_LoadVideo") + video["widgets_values"] = ["clip.mp4", 24.0, 1000, 0] + + api = convert_ui_to_api(workflow, object_info={}) + + inputs = api[str(video["id"])]["inputs"] + assert "force_rate" not in inputs + assert "meta_batch" not in inputs + assert "vae" not in inputs + + +def test_a_saved_node_with_a_socket_for_every_widget_still_names_its_values(): + node = { + "id": 7, + "type": "NotInCatalog", + "inputs": [ + {"name": "strength", "type": "FLOAT", "widget": {"name": "strength"}, "link": None}, + {"name": "steps", "type": "INT", "widget": {"name": "steps"}, "link": None}, + ], + "outputs": [], + "widgets_values": [0.5, 20], + } + workflow = {"nodes": [node], "links": []} + + api = convert_ui_to_api(workflow, object_info={}) + + assert api["7"]["inputs"] == {"strength": 0.5, "steps": 20} From 4c5e69014885940d1313c02ba22ce0fc0fabac02 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:33:22 +0000 Subject: [PATCH 06/11] fix(workflow): don't name saved values from widget sockets that don't cover them all --- comfy_cli/workflow_to_api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/comfy_cli/workflow_to_api.py b/comfy_cli/workflow_to_api.py index 6e9a77511..c2f76b757 100644 --- a/comfy_cli/workflow_to_api.py +++ b/comfy_cli/workflow_to_api.py @@ -2208,9 +2208,11 @@ def _fallback_widget_names(node: dict, widget_values: list[Any]) -> list[str | N widget_flagged.append(name) if widget_flagged: + # Sockets name values only when there is one for every value. An + # agent-built node has sockets for its scalars but none for a COMBO, so + # pairing a shorter list by position would misname the values after it. if len(widget_values) > len(widget_flagged): - extras = [n for n in all_inputs if n not in connected and n not in widget_flagged] - return widget_flagged + extras[: len(widget_values) - len(widget_flagged)] + return [] return list(widget_flagged) unconnected = [n for n in all_inputs if n not in connected] From 2ea9d292e1bd2fe86ac9d4606867625dd26c4c62 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:40:32 +0000 Subject: [PATCH 07/11] test(workflow): every widget socket, COMBO included, so saved values keep their names Reverts the converter bail-out: review found it drops correct values on older saves. --- comfy_cli/workflow_to_api.py | 6 +- .../test_add_node_widget_input_slots.py | 70 +++++++++++++++---- 2 files changed, 57 insertions(+), 19 deletions(-) diff --git a/comfy_cli/workflow_to_api.py b/comfy_cli/workflow_to_api.py index c2f76b757..6e9a77511 100644 --- a/comfy_cli/workflow_to_api.py +++ b/comfy_cli/workflow_to_api.py @@ -2208,11 +2208,9 @@ def _fallback_widget_names(node: dict, widget_values: list[Any]) -> list[str | N widget_flagged.append(name) if widget_flagged: - # Sockets name values only when there is one for every value. An - # agent-built node has sockets for its scalars but none for a COMBO, so - # pairing a shorter list by position would misname the values after it. if len(widget_values) > len(widget_flagged): - return [] + extras = [n for n in all_inputs if n not in connected and n not in widget_flagged] + return widget_flagged + extras[: len(widget_values) - len(widget_flagged)] return list(widget_flagged) unconnected = [n for n in all_inputs if n not in connected] diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index 4681a75e5..416cb1675 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -1,4 +1,4 @@ -"""Agent-built nodes carry a socket entry for every scalar widget input. +"""Agent-built nodes carry a socket entry for every widget input. Reported: the agent said ``frame_load_cap`` on an agent-built Load Video (VHS) and an agent-made custom node was a plain widget = 1000, while the user had @@ -45,6 +45,7 @@ def _node(required: dict, outputs: list[str], optional: dict | None = None, name OBJECT_INFO = { "PrimitiveInt": _node({"value": ["INT", {"default": 0}]}, ["INT"]), + "PrimitiveString": _node({"value": ["STRING", {"default": ""}]}, ["STRING"]), "VHS_LoadVideo": _node( { "video": [["clip.mp4"]], @@ -90,7 +91,7 @@ def _built(graph: Graph) -> tuple[dict, dict, dict]: return workflow, primitive, video -def test_add_node_writes_a_widget_socket_for_each_scalar_widget_input(graph): +def test_add_node_writes_a_widget_socket_for_each_widget_input(graph): workflow: dict = {"nodes": [], "links": []} video = _add(workflow, graph, "VHS_LoadVideo") csv = _add(workflow, graph, "CSVCVColumn") @@ -98,7 +99,7 @@ def test_add_node_writes_a_widget_socket_for_each_scalar_widget_input(graph): assert [(i["name"], i["type"]) for i in video["inputs"][:2]] == LOAD_VIDEO_LINK_INPUTS for name, slot_type in [("force_rate", "FLOAT"), ("frame_load_cap", "INT"), ("skip_first_frames", "INT")]: assert _input(video, name) == [{"name": name, "type": slot_type, "widget": {"name": name}, "link": None}] - assert _input(video, "video") == [] + assert _input(video, "video") == [{"name": "video", "type": "COMBO", "widget": {"name": "video"}, "link": None}] for name, slot_type in [("csv_path", "STRING"), ("enabled", "BOOLEAN"), ("frame_load_cap", "INT")]: assert _input(csv, name) == [{"name": name, "type": slot_type, "widget": {"name": name}, "link": None}] @@ -168,24 +169,63 @@ def test_a_widget_socket_refuses_a_link_of_another_scalar_type(graph): workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "force_rate") -def test_a_saved_node_with_partial_widget_sockets_does_not_misname_its_values(graph): - """With no object_info, the widget sockets alone cannot name COMBO-bearing values. - - An agent-built Load Video has sockets for its scalars but not for ``video``, - so the sockets do not account for every value. Pairing them by position - would send the file name as ``force_rate`` and spill a value onto a link - input, so the converter must drop the values and warn instead. - """ +def test_an_agent_built_node_keeps_its_value_names_without_object_info(graph): + """Every widget has a socket, so the sockets alone name the saved values.""" workflow: dict = {"nodes": [], "links": []} video = _add(workflow, graph, "VHS_LoadVideo") video["widgets_values"] = ["clip.mp4", 24.0, 1000, 0] api = convert_ui_to_api(workflow, object_info={}) - inputs = api[str(video["id"])]["inputs"] - assert "force_rate" not in inputs - assert "meta_batch" not in inputs - assert "vae" not in inputs + assert api[str(video["id"])]["inputs"] == { + "video": "clip.mp4", + "force_rate": 24.0, + "frame_load_cap": 1000, + "skip_first_frames": 0, + } + + +def test_a_string_into_a_combo_socket_is_a_concrete_connect_that_converges(graph): + workflow: dict = {"nodes": [], "links": []} + text = _add(workflow, graph, "PrimitiveString") + video = _add(workflow, graph, "VHS_LoadVideo") + base = copy.deepcopy(workflow) + + _, first_op = workflow_ops.connect(copy.deepcopy(base), graph, text["id"], 0, video["id"], "video") + _, second_op = workflow_ops.connect(copy.deepcopy(base), graph, text["id"], 0, video["id"], "video") + + assert "grow" not in first_op + converged = [] + for order in ([first_op, second_op], [second_op, first_op]): + replica = copy.deepcopy(base) + for op in order: + workflow_ops.apply_op(replica, op, graph) + node = next(n for n in replica["nodes"] if n["id"] == video["id"]) + converged.append(_input(node, "video")) + assert converged[0] == converged[1] + assert len(converged[0]) == 1 + + +def test_a_combo_socket_still_refuses_a_link_of_another_type(graph): + workflow, primitive, video = _built(graph) + + with pytest.raises(ValueError, match=r"type mismatch: INT output .* COMBO input 'video'"): + workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "video") + + +def test_a_node_with_a_widget_that_cannot_have_a_socket_gets_none(): + """Sockets for only some widgets would misname saved values, so it is all or none.""" + union = { + "Mixed": _node( + {"strength": ["FLOAT,INT", {"widgetType": "FLOAT"}], "steps": ["INT", {"default": 0}]}, + ["INT"], + ) + } + workflow: dict = {"nodes": [], "links": []} + + node = _add(workflow, Graph.from_object_info(union), "Mixed") + + assert node["inputs"] == [] def test_a_saved_node_with_a_socket_for_every_widget_still_names_its_values(): From 729ffbb6a5e2c57719f9ca850223abd557bd4927 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:41:52 +0000 Subject: [PATCH 08/11] fix(workflow): give agent-built nodes a socket for every widget, COMBO included All or none per node: the converter names saved values from these entries when object_info lacks the class. A STRING may drive a COMBO socket, as it could through convert-on-connect. --- comfy_cli/workflow_ops.py | 46 +++++++++++++------ .../test_workflow_edit_nested_autogrow.py | 8 ++-- 2 files changed, 36 insertions(+), 18 deletions(-) diff --git a/comfy_cli/workflow_ops.py b/comfy_cli/workflow_ops.py index 53cf31f70..415efca4b 100644 --- a/comfy_cli/workflow_ops.py +++ b/comfy_cli/workflow_ops.py @@ -678,6 +678,18 @@ def _slot_types(t: Any) -> set[str]: return {p.strip() for p in str(t or "").split(",") if p.strip()} +def _input_accepts(link_type: Any, input_entry: dict) -> bool: + """Whether an output of ``link_type`` may drive ``input_entry``. + + A COMBO widget socket also takes a STRING: that is how a computed file name + or option reaches a combo. + """ + dst_type = input_entry.get("type") + if dst_type == "COMBO" and input_entry.get("widget") and link_type == "STRING": + return True + return _types_compatible(link_type, dst_type) + + def _types_compatible(link_type: Any, dst_type: Any) -> bool: """Whether an output of ``link_type`` may drive an input of ``dst_type``. @@ -2301,7 +2313,7 @@ def _connect_impl( # link. if in_idx is not None: dst_type = (dst.get("inputs") or [])[in_idx].get("type") - if not _types_compatible(link_type, dst_type): + if not _input_accepts(link_type, (dst.get("inputs") or [])[in_idx]): raise ValueError( f"type mismatch: {link_type} output of node {from_node} cannot connect to " f"{dst_type} input {(dst.get('inputs') or [])[in_idx].get('name')!r} of node {to_node}" @@ -2571,7 +2583,7 @@ def _connect_interior( "the node lists; inside a subgraph connect can only wire an existing input" ) dst_type = (dst.get("inputs") or [])[in_idx].get("type") - if not _types_compatible(link_type, dst_type): + if not _input_accepts(link_type, (dst.get("inputs") or [])[in_idx]): raise ValueError( f"type mismatch: {link_type} output of node {'/'.join(scope['path'])}/{src.get('id')} cannot connect " f"to {dst_type} input {(dst.get('inputs') or [])[in_idx].get('name')!r} of node " @@ -4890,22 +4902,26 @@ def strip_internal(workflow: dict) -> dict: # --------------------------------------------------------------------------- -# Widget inputs a fresh node gets a socket entry for: the scalar types a -# primitive can drive. The frontend gives every non-socketless widget input a -# socket and serializes it as ``{"name", "type", "widget": {"name"}}``; without -# the entry the shared document has no slot for a link a human draws into that -# socket, so the link never reaches the document. COMBO is left on -# the convert-on-connect path: the concrete type check would refuse the STRING -# output that commonly drives it. -_SOCKETED_WIDGET_TYPES = frozenset({"INT", "FLOAT", "STRING", "BOOLEAN"}) +# Widget input types a fresh node gets a socket entry for. The frontend gives +# every non-socketless widget input a socket and serializes it as +# ``{"name", "type", "widget": {"name"}}``; without the entry the shared document +# has no slot for a link a human draws into that socket, so the link never +# reaches the document. +_SOCKETED_WIDGET_TYPES = frozenset({"INT", "FLOAT", "STRING", "BOOLEAN", "COMBO"}) def _widget_input_entries(m) -> list[dict]: - return [ - {"name": p.name, "type": p.type, "widget": {"name": p.name}, "link": None} - for p in m.inputs - if not p.is_link and not p.is_socketless and p.type in _SOCKETED_WIDGET_TYPES - ] + """Socket entries for every widget of ``m``, or none. + + Without object_info the converter names saved values from these entries by + position, so sockets for only some widgets would misname the rest. A node + with a widget that has no entry of its own (a dynamic combo or a union type) + keeps the convert-on-connect path instead. + """ + widgets = [p for p in m.inputs if not p.is_link and not p.is_socketless] + if any(p.type not in _SOCKETED_WIDGET_TYPES for p in widgets): + return [] + return [{"name": p.name, "type": p.type, "widget": {"name": p.name}, "link": None} for p in widgets] def _build_node(node_id: int, class_type: str, m, graph, pos: list, size: list, title: str | None = None) -> dict: diff --git a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py index 88464d21c..c29c617f3 100644 --- a/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py +++ b/tests/comfy_cli/command/test_workflow_edit_nested_autogrow.py @@ -463,14 +463,16 @@ def test_a_real_widget_name_outranks_the_bare_element_guess(): def test_a_real_combo_widget_name_outranks_the_bare_element_guess(): - """A COMBO widget has no socket entry on an agent-built node, so it takes - the widget→input conversion, still ahead of the group's element guess.""" + """A node saved before COMBO widgets had socket entries takes the + widget→input conversion, still ahead of the group's element guess.""" oi = json.loads(FIXTURE.read_text()) oi["BatchImagesNode"]["input"]["required"]["image0"] = [["a", "b"]] oi["BatchImagesNode"]["input_order"]["required"].append("image0") g = Graph.from_object_info(oi) wf, batch = _add_loader(_empty(), g, "BatchImagesNode") - _idx, grow = workflow_ops._resolve_input_target(_node(wf, batch), g, "image0", "STRING") + node = _node(wf, batch) + node["inputs"] = [i for i in node["inputs"] if i["name"] != "image0"] + _idx, grow = workflow_ops._resolve_input_target(node, g, "image0", "STRING") assert grow == {"name": "image0", "type": "STRING", "widget": "image0"} From f81201c10bb81e88536f2499a246bb13ab7aca62 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:51:25 +0000 Subject: [PATCH 09/11] fix(workflow): socket entries are all or none against the widget order, and numbers can drive a numeric combo --- comfy_cli/link_integrity.py | 4 +-- comfy_cli/workflow_ops.py | 29 +++++++++------ .../test_add_node_widget_input_slots.py | 36 +++++++++++++------ 3 files changed, 45 insertions(+), 24 deletions(-) diff --git a/comfy_cli/link_integrity.py b/comfy_cli/link_integrity.py index 305ccf8e1..1c5bfc737 100644 --- a/comfy_cli/link_integrity.py +++ b/comfy_cli/link_integrity.py @@ -47,7 +47,7 @@ def _rows(links: Any) -> list[list]: def _scope_findings(nodes: list, links: Any, prefix: str | None) -> tuple[list[dict], list[dict]]: - from comfy_cli.workflow_ops import _types_compatible + from comfy_cli.workflow_ops import _input_accepts def addr(nid: Any) -> str: return f"{prefix}/{nid}" if prefix else str(nid) @@ -143,7 +143,7 @@ def fed_from(node: dict, src: Any, slot: Any, except_id: Any) -> str | None: candidates = [ str(i.get("name")) for i in inputs - if i.get("link") is None and i.get("name") and _types_compatible(source_type, i.get("type")) + if i.get("link") is None and i.get("name") and _input_accepts(source_type, i) ] where = ( f"link {link_id} from {'the subgraph input' if src_is_proxy else f'node {addr(src_id)} output {src_slot}'} " diff --git a/comfy_cli/workflow_ops.py b/comfy_cli/workflow_ops.py index 415efca4b..188acf891 100644 --- a/comfy_cli/workflow_ops.py +++ b/comfy_cli/workflow_ops.py @@ -678,14 +678,17 @@ def _slot_types(t: Any) -> set[str]: return {p.strip() for p in str(t or "").split(",") if p.strip()} +_COMBO_SOCKET_SOURCE_TYPES = frozenset({"STRING", "INT", "FLOAT"}) + + def _input_accepts(link_type: Any, input_entry: dict) -> bool: """Whether an output of ``link_type`` may drive ``input_entry``. - A COMBO widget socket also takes a STRING: that is how a computed file name - or option reaches a combo. + A COMBO widget socket also takes a scalar: that is how a computed file name + or option reaches a combo, and a combo's options can be numbers. """ dst_type = input_entry.get("type") - if dst_type == "COMBO" and input_entry.get("widget") and link_type == "STRING": + if dst_type == "COMBO" and input_entry.get("widget") and link_type in _COMBO_SOCKET_SOURCE_TYPES: return True return _types_compatible(link_type, dst_type) @@ -4910,24 +4913,27 @@ def strip_internal(workflow: dict) -> dict: _SOCKETED_WIDGET_TYPES = frozenset({"INT", "FLOAT", "STRING", "BOOLEAN", "COMBO"}) -def _widget_input_entries(m) -> list[dict]: - """Socket entries for every widget of ``m``, or none. +def _widget_input_entries(m, order: list[str]) -> list[dict]: + """Socket entries for every widget in ``order``, or none. Without object_info the converter names saved values from these entries by position, so sockets for only some widgets would misname the rest. A node - with a widget that has no entry of its own (a dynamic combo or a union type) - keeps the convert-on-connect path instead. + with a widget that has no entry of its own (a dynamic combo, a union type, a + socketless widget) keeps the convert-on-connect path instead. """ - widgets = [p for p in m.inputs if not p.is_link and not p.is_socketless] - if any(p.type not in _SOCKETED_WIDGET_TYPES for p in widgets): + entries = [ + {"name": p.name, "type": p.type, "widget": {"name": p.name}, "link": None} + for p in m.inputs + if not p.is_link and not p.is_socketless and p.type in _SOCKETED_WIDGET_TYPES + ] + if [e["name"] for e in entries] != [name for name in order if name != "control_after_generate"]: return [] - return [{"name": p.name, "type": p.type, "widget": {"name": p.name}, "link": None} for p in widgets] + return entries def _build_node(node_id: int, class_type: str, m, graph, pos: list, size: list, title: str | None = None) -> dict: # Link inputs first, so their indices are unchanged; widget sockets after. inputs = [{"name": p.name, "type": p.type, "link": None} for p in m.inputs if p.is_link] - inputs += _widget_input_entries(m) outputs = [{"name": p.name, "type": p.type, "links": []} for p in m.outputs] # Widget values in positional order, including dynamic-combo selectors and # their sub-widgets — sourced from the engine so add-node matches the converter. @@ -4938,6 +4944,7 @@ def _build_node(node_id: int, class_type: str, m, graph, pos: list, size: list, # it, so neither does a fresh node — no phantom trailing ``null``. while order and order[-1] not in defaults: order = order[:-1] + inputs += _widget_input_entries(m, order) widgets = [defaults.get(name) for name in order] node = { "id": node_id, diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index 416cb1675..edc74c958 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -206,24 +206,38 @@ def test_a_string_into_a_combo_socket_is_a_concrete_connect_that_converges(graph assert len(converged[0]) == 1 +def test_a_number_can_drive_a_numeric_combo_socket(): + catalog = dict(OBJECT_INFO, BitDepth=_node({"bits": [[8, 16, 32]]}, ["INT"])) + graph = Graph.from_object_info(catalog) + workflow: dict = {"nodes": [], "links": []} + primitive = _add(workflow, graph, "PrimitiveInt") + bits = _add(workflow, graph, "BitDepth") + + workflow_ops.connect(workflow, graph, primitive["id"], 0, bits["id"], "bits") + + assert _input(next(n for n in workflow["nodes"] if n["id"] == bits["id"]), "bits")[0]["link"] is not None + + def test_a_combo_socket_still_refuses_a_link_of_another_type(graph): - workflow, primitive, video = _built(graph) + workflow, _primitive, video = _built(graph) + source = _add(workflow, graph, "VHS_LoadVideo") - with pytest.raises(ValueError, match=r"type mismatch: INT output .* COMBO input 'video'"): - workflow_ops.connect(workflow, graph, primitive["id"], 0, video["id"], "video") + with pytest.raises(ValueError, match=r"type mismatch: IMAGE output .* COMBO input 'video'"): + workflow_ops.connect(workflow, graph, source["id"], 0, video["id"], "video") -def test_a_node_with_a_widget_that_cannot_have_a_socket_gets_none(): +@pytest.mark.parametrize( + "required", + [ + {"strength": ["FLOAT,INT", {"widgetType": "FLOAT"}], "steps": ["INT", {"default": 0}]}, + {"hidden": ["INT", {"default": 0, "socketless": True}], "steps": ["INT", {"default": 0}]}, + ], +) +def test_a_node_with_a_widget_that_cannot_have_a_socket_gets_none(required): """Sockets for only some widgets would misname saved values, so it is all or none.""" - union = { - "Mixed": _node( - {"strength": ["FLOAT,INT", {"widgetType": "FLOAT"}], "steps": ["INT", {"default": 0}]}, - ["INT"], - ) - } workflow: dict = {"nodes": [], "links": []} - node = _add(workflow, Graph.from_object_info(union), "Mixed") + node = _add(workflow, Graph.from_object_info({"Mixed": _node(required, ["INT"])}), "Mixed") assert node["inputs"] == [] From 2acb9c3975c8928a792fe3515453ec9cf0fae134 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 31 Oct 2026 16:58:23 +0000 Subject: [PATCH 10/11] fix(workflow): keep a COMBO value named like a control marker when sockets cover every value --- comfy_cli/workflow_to_api.py | 8 +++++++- .../comfy_cli/test_add_node_widget_input_slots.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/comfy_cli/workflow_to_api.py b/comfy_cli/workflow_to_api.py index 6e9a77511..e37de62c0 100644 --- a/comfy_cli/workflow_to_api.py +++ b/comfy_cli/workflow_to_api.py @@ -2510,7 +2510,13 @@ def emit(name: str, value: Any) -> Any: # No schema, or the schema declares no widget inputs: fall back to the # positional control-marker heuristic + node-input name inspection, which # matches the reference behavior for unknown node types. - filtered = _filter_control_values(widget_values, node_type=node_type, node=node, object_info=object_info) + # A socket for every value leaves no room for a control marker, so a COMBO + # value that reads "fixed" stays a value. + sockets = [i for i in node.get("inputs") or [] if isinstance(i, dict) and i.get("widget")] + if len(sockets) == len(widget_values): + filtered = widget_values + else: + filtered = _filter_control_values(widget_values, node_type=node_type, node=node, object_info=object_info) names = _fallback_widget_names(node, filtered) if not names: if filtered: diff --git a/tests/comfy_cli/test_add_node_widget_input_slots.py b/tests/comfy_cli/test_add_node_widget_input_slots.py index edc74c958..79250ae05 100644 --- a/tests/comfy_cli/test_add_node_widget_input_slots.py +++ b/tests/comfy_cli/test_add_node_widget_input_slots.py @@ -258,3 +258,17 @@ def test_a_saved_node_with_a_socket_for_every_widget_still_names_its_values(): api = convert_ui_to_api(workflow, object_info={}) assert api["7"]["inputs"] == {"strength": 0.5, "steps": 20} + + +def test_a_combo_value_named_like_a_control_marker_survives_without_object_info(): + """A socket for every value means no value is a control_after_generate marker.""" + graph = Graph.from_object_info( + {"Picker": _node({"mode": [["fixed", "random"]], "steps": ["INT", {"default": 0}]}, ["INT"])} + ) + workflow: dict = {"nodes": [], "links": []} + node = _add(workflow, graph, "Picker") + node["widgets_values"] = ["fixed", 5] + + api = convert_ui_to_api(workflow, object_info={}) + + assert api[str(node["id"])]["inputs"] == {"mode": "fixed", "steps": 5} From eb98e7d09cc74ad2c8f8783028527291a4b49ac4 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 31 Oct 2026 18:48:29 +0000 Subject: [PATCH 11/11] docs(changelog): record the widget-socket entries and the COMBO value fix CONTRIBUTING.md asks for notable user-facing changes under `## [Unreleased]` in CHANGELOG.md and this PR had no entry. Adds one Changed bullet for the now-type-checked connect into a widget socket, and two Fixed bullets for the socket entries `add_node` writes and for the converter keeping a COMBO value that reads like a control marker. No code change. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b616d8128..348031027 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,18 @@ history. ## [Unreleased] +### Changed + +- A `connect` into a widget input of an agent-built node is now type-checked. + `comfy workflow add-node` gives every widget input a socket entry (see Fixed + below), so a link into one is an ordinary connect to an existing slot rather + than a `grow` that minted a new slot and took the source's type unchecked. A + mismatched scalar — `INT` into a `FLOAT` widget such as `force_rate`, or + `IMAGE` into a `COMBO` — now fails the existing type check instead of being + accepted silently. A `COMBO` widget socket still accepts `COMBO`, `STRING`, + `INT` and `FLOAT`, because that is how a computed file name or a numeric + option reaches a combo; every other source type is refused. + ### Fixed - `comfy validate` no longer lets a dotted key left over from another @@ -35,6 +47,25 @@ history. same two values adjacently and is now keyword-only for the same reason, before anything is inserted into it. +- `comfy workflow add-node` writes a socket entry for every widget input of the + new node — `INT`, `FLOAT`, `STRING`, `BOOLEAN` and `COMBO` — in the same + `{"name", "type", "widget": {"name"}, "link": null}` shape the frontend + serializes, placed after the link inputs so existing link indices do not move. + Before this, an agent-built node carried no `inputs[]` entry for its widgets, + so a link a human drew into a widget socket on the canvas named a slot the + shared document did not have and was dropped. Sockets are written all or none + per node: a node with a widget that cannot have an entry of its own — a + dynamic combo, a union type such as `FLOAT,INT`, a socketless widget — keeps + the previous convert-on-connect behaviour unchanged. Nodes already present in + existing documents are not migrated. + +- The save-to-API converter no longer drops a `COMBO` value that happens to read + like a control marker. When a node's widget sockets account for every saved + widget value there is no room for a trailing `control_after_generate` marker, + so the positional marker filter is skipped and a value of `"fixed"` stays a + value. Saves with a real marker have one more value than sockets and still go + through the filter. + ## [1.24.0] - 2026-10-29 [Full notes](https://github.com/Comfy-Org/comfy-cli/releases/tag/v1.24.0) · 25 commits since v1.23.0.