From eb0fb4b3b7174d643d870595a22f04e32fda1811 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 23 Sep 2026 21:34:34 +0000 Subject: [PATCH 01/13] test: flatten the FE-258 node definition fixtures The three ComfyNodeDefV1 literals nested up to 13 levels. Build them from dynamicCombo/autogrow/testNodeDef instead, which caps the region at 5. --- src/core/graph/widgets/dynamicWidgets.test.ts | 202 ++++++++---------- 1 file changed, 92 insertions(+), 110 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 2454553508b..6f53ed7dac1 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -16,7 +16,10 @@ import { liveAutogrowGroupOf } from '@/core/graph/widgets/dynamicWidgets' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import { realignGroupWidgetChildLinks } from '@/lib/litegraph/src/linkDeduplication' import type { SerialisableGraph } from '@/lib/litegraph/src/types/serialisation' -import type { ComfyNodeDef as ComfyNodeDefV1 } from '@/schemas/nodeDefSchema' +import type { + ComfyNodeDef as ComfyNodeDefV1, + InputSpec +} from '@/schemas/nodeDefSchema' import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' import { toLinkId } from '@/types/linkId' @@ -668,41 +671,68 @@ class SourceNode extends LGraphNode { } } +type ChildInputs = Record + +function dynamicCombo( + childInputsByOptionKey: Record +): InputSpec { + return [ + 'COMFY_DYNAMICCOMBO_V3', + { + options: Object.entries(childInputsByOptionKey).map(([key, inputs]) => ({ + key, + inputs: { required: inputs } + })) + } + ] +} + +function autogrow(template: { + names: string[] + min: number + input: ChildInputs +}): InputSpec { + const { names, min, input } = template + return [ + 'COMFY_AUTOGROW_V3', + { template: { input: { required: input }, names, min } } + ] +} + +function testNodeDef( + name: string, + required: ChildInputs, + output: string[] +): ComfyNodeDefV1 { + return { + name, + display_name: name, + category: 'testing', + python_module: 'nodes', + description: '', + input: { required }, + output, + output_name: output, + output_node: false + } +} + /** * A reduced `ResizeImageMaskNode` (FE-258): a dynamic combo whose default * option lays out a `width` child, and whose other option lays out a * `multiplier` child instead. */ -const resizeNodeDef: ComfyNodeDefV1 = { - name: RESIZE_NODE_TYPE, - display_name: 'Resize Image Mask', - category: 'testing', - python_module: 'nodes', - description: '', - input: { - required: { - image: ['IMAGE', {}], - resize_type: [ - 'COMFY_DYNAMICCOMBO_V3', - { - options: [ - { - key: 'scale dimensions', - inputs: { required: { width: ['INT', {}] } } - }, - { - key: 'scale by multiplier', - inputs: { required: { multiplier: ['FLOAT', {}] } } - } - ] - } - ] - } +const resizeNodeDef = testNodeDef( + RESIZE_NODE_TYPE, + { + image: ['IMAGE', {}], + resize_type: dynamicCombo({ + 'scale dimensions': { width: ['INT', {}] }, + 'scale by multiplier': { multiplier: ['FLOAT', {}] } + }) }, - output: ['IMAGE'], - output_name: ['resized'], - output_node: false -} + ['IMAGE'] +) /** * The node saved on `scale by multiplier`, so its serialized inputs carry @@ -740,7 +770,7 @@ function savedDynamicComboChildWorkflow(): SerialisableGraph { { name: 'image', type: 'IMAGE', link: null }, { name: 'resize_type.multiplier', type: 'FLOAT', link: 1 } ], - outputs: [{ name: 'resized', type: 'IMAGE', links: [] }], + outputs: [{ name: 'IMAGE', type: 'IMAGE', links: [] }], properties: {}, widgets_values: ['scale by multiplier', 4] } @@ -791,47 +821,22 @@ const REFERENCE_NODE_TYPE = 'test/AutogrowInsideCombo' * are named `model.reference_images.` and its registry key is * `model.reference_images`. */ -const referenceNodeDef: ComfyNodeDefV1 = { - name: REFERENCE_NODE_TYPE, - display_name: 'Autogrow Inside Combo', - category: 'testing', - python_module: 'nodes', - description: '', - input: { - required: { - model: [ - 'COMFY_DYNAMICCOMBO_V3', - { - options: [ - { - key: 'Seedance', - inputs: { - required: { - generate_audio: ['BOOLEAN', { default: true }], - reference_images: [ - 'COMFY_AUTOGROW_V3', - { - template: { - input: { - required: { reference_image: ['IMAGE', {}] } - }, - names: ['image_1', 'image_2', 'image_3'], - min: 2 - } - } - ] - } - } - } - ] - } - ] - } +const referenceNodeDef = testNodeDef( + REFERENCE_NODE_TYPE, + { + model: dynamicCombo({ + Seedance: { + generate_audio: ['BOOLEAN', { default: true }], + reference_images: autogrow({ + names: ['image_1', 'image_2', 'image_3'], + min: 2, + input: { reference_image: ['IMAGE', {}] } + }) + } + }) }, - output: ['VIDEO'], - output_name: ['VIDEO'], - output_node: false -} + ['VIDEO'] +) describe('Autogrow nested inside a group widget (FE-258)', () => { beforeEach(async () => { @@ -871,46 +876,23 @@ const GROWN_NODE_TYPE = 'test/AutogrowBeforeOrdinaryChild' * group is followed by an ordinary child input. Reloading such a node replays * both links, and the group grows a slot while doing so. */ -const grownNodeDef: ComfyNodeDefV1 = { - name: GROWN_NODE_TYPE, - display_name: 'Autogrow Before Ordinary Child', - category: 'testing', - python_module: 'nodes', - description: '', - input: { - required: { - model: [ - 'COMFY_DYNAMICCOMBO_V3', - { - options: [ - { - key: 'gpt-image-1', - inputs: { - required: { - seed: ['INT', { default: 0 }], - images: [ - 'COMFY_AUTOGROW_V3', - { - template: { - input: { required: { image: ['IMAGE', {}] } }, - names: ['image_1', 'image_2', 'image_3', 'image_4'], - min: 0 - } - } - ], - mask: ['MASK', { forceInput: true }] - } - } - } - ] - } - ] - } +const grownNodeDef = testNodeDef( + GROWN_NODE_TYPE, + { + model: dynamicCombo({ + 'gpt-image-1': { + seed: ['INT', { default: 0 }], + images: autogrow({ + names: ['image_1', 'image_2', 'image_3', 'image_4'], + min: 0, + input: { image: ['IMAGE', {}] } + }), + mask: ['MASK', { forceInput: true }] + } + }) }, - output: ['IMAGE'], - output_name: ['IMAGE'], - output_node: false -} + ['IMAGE'] +) class ImageMaskSourceNode extends LGraphNode { constructor(title?: string) { From 11e62b590f271bb5df40094b6b27b800a39e1e19 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Wed, 23 Sep 2026 21:35:32 +0000 Subject: [PATCH 02/13] docs(litegraph): trim the realign docs to what the code cannot say 40 lines of added commentary down to 12. Rationale that belongs in the PR description, and text restating an adjacent guard clause, are gone. --- src/core/graph/widgets/dynamicWidgets.ts | 4 +- src/lib/litegraph/src/linkDeduplication.ts | 49 +++++----------------- 2 files changed, 12 insertions(+), 41 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.ts b/src/core/graph/widgets/dynamicWidgets.ts index 0e6b23d50e9..b99f9892ac7 100644 --- a/src/core/graph/widgets/dynamicWidgets.ts +++ b/src/core/graph/widgets/dynamicWidgets.ts @@ -243,8 +243,8 @@ function dynamicComboWidget( } const result = commitMutatedInputs(node, previous, inputLinks) if (!result.ok) return - //A callback can grow the group it lands on, shifting every input after - //it, so the slot captured before the batch is stale for later entries. + //A callback can grow the group it lands on, so slots captured before the + //batch are stale for every entry after it. for (const { input, link } of result.replacements) { const slot = node.inputs.indexOf(input) if (slot === -1) continue diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index be0359220f7..afb8cc57a6c 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -182,11 +182,7 @@ function groupNameOf(inputName: string): string | undefined { return separator < 1 ? undefined : inputName.slice(0, separator) } -/** - * Whether a group widget on `node` owns `inputName`'s slot. Group widgets - * (dynamic combos) name their child inputs `.` and - * replace the whole set whenever their own value changes. - */ +/** Group widgets (dynamic combos) name children `.`. */ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) if (groupName === undefined) return false @@ -195,25 +191,10 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { } /** - * Whether a registered autogrow group owns `inputName`'s slot. - * - * Autogrow groups grow and renumber their own slots while the graph - * configures, and realigning their links by name that early destroys them - * (see `browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts`, - * "loads with both reference images connected"). - * - * Ownership comes from the registry `applyAutogrow` populates, under the same - * key autogrow's own connection handler resolves a slot's group by. A group - * is not a widget, so there is no widget name to match a prefix against as - * {@link isGroupWidgetChildInput} does, and the dotted name alone will not - * serve: `INodeInputSlot.name` is an arbitrary string, so an ordinary input - * may be dotted without belonging to any group. - * - * The registry only covers groups the selected option laid out. Children of - * an option that is not selected still reach this filter, because - * `ComfyNode.configure` appends every serialized input the definition lacks. - * Realigning those is harmless: their group's handler bails on the same - * missing key, so nothing renumbers behind the move. + * Autogrow groups renumber their own slots as the graph configures, so their + * links belong to {@link LGraph.configure}'s final pass rather than to an + * early realignment. A group is not a widget; ownership comes from the + * registry `applyAutogrow` populates. */ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) @@ -226,21 +207,11 @@ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { } /** - * Realigns a node's input links by name before its group widget values are - * applied, for nodes that have a group widget child input. - * - * Applying a group widget's value rebuilds every child input of the group and - * hands each surviving link to the new input of the same name. A link sitting - * on the wrong slot — the node definition lays out the default option's - * children, while `target_slot` counts the serialized layout — is handed to an - * input that the selected option does not define, and is dropped. Through a - * subgraph boundary that demotes the promoted widget to a disconnected input - * slot. - * - * The node's ordinary inputs join the batch so that a link still occupying a - * child's destination slot is moved in the same atomic update instead of - * blocking it. Links owned by an autogrow group are left to - * {@link LGraph.configure}'s final pass. + * Re-points a node's group widget child links at the slot their name will map + * to, before applying the widget's value rebuilds those inputs and drops any + * link left on a slot the selected option does not lay out. Ordinary inputs + * join the batch so an occupied destination slot is vacated in the same atomic + * update instead of blocking the move. */ export function realignGroupWidgetChildLinks( node: LGraphNode, From c75109669856858743d4653d520a2af07dbbaf3b Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 00:34:04 +0000 Subject: [PATCH 03/13] test: guarantee dynamic combo option order by construction dynamicCombo took a record, so option order rode Object.entries and an integer-like key would silently displace the default option. Take the default option as its own parameter instead. Also stop aliasing output_name to the output array, and restore the two clauses the doc trim cut too deep: why a saved link lands on the wrong slot, and why unselected-option children are safe to realign. --- src/core/graph/widgets/dynamicWidgets.test.ts | 31 +++++++++++-------- src/lib/litegraph/src/linkDeduplication.ts | 13 +++++--- 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 6f53ed7dac1..baf303b39db 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -673,13 +673,16 @@ class SourceNode extends LGraphNode { type ChildInputs = Record +type ComboOption = [key: string, childInputs: ChildInputs] + function dynamicCombo( - childInputsByOptionKey: Record + defaultOption: ComboOption, + ...remainingOptions: ComboOption[] ): InputSpec { return [ 'COMFY_DYNAMICCOMBO_V3', { - options: Object.entries(childInputsByOptionKey).map(([key, inputs]) => ({ + options: [defaultOption, ...remainingOptions].map(([key, inputs]) => ({ key, inputs: { required: inputs } })) @@ -712,7 +715,7 @@ function testNodeDef( description: '', input: { required }, output, - output_name: output, + output_name: [...output], output_node: false } } @@ -726,10 +729,10 @@ const resizeNodeDef = testNodeDef( RESIZE_NODE_TYPE, { image: ['IMAGE', {}], - resize_type: dynamicCombo({ - 'scale dimensions': { width: ['INT', {}] }, - 'scale by multiplier': { multiplier: ['FLOAT', {}] } - }) + resize_type: dynamicCombo( + ['scale dimensions', { width: ['INT', {}] }], + ['scale by multiplier', { multiplier: ['FLOAT', {}] }] + ) }, ['IMAGE'] ) @@ -824,8 +827,9 @@ const REFERENCE_NODE_TYPE = 'test/AutogrowInsideCombo' const referenceNodeDef = testNodeDef( REFERENCE_NODE_TYPE, { - model: dynamicCombo({ - Seedance: { + model: dynamicCombo([ + 'Seedance', + { generate_audio: ['BOOLEAN', { default: true }], reference_images: autogrow({ names: ['image_1', 'image_2', 'image_3'], @@ -833,7 +837,7 @@ const referenceNodeDef = testNodeDef( input: { reference_image: ['IMAGE', {}] } }) } - }) + ]) }, ['VIDEO'] ) @@ -879,8 +883,9 @@ const GROWN_NODE_TYPE = 'test/AutogrowBeforeOrdinaryChild' const grownNodeDef = testNodeDef( GROWN_NODE_TYPE, { - model: dynamicCombo({ - 'gpt-image-1': { + model: dynamicCombo([ + 'gpt-image-1', + { seed: ['INT', { default: 0 }], images: autogrow({ names: ['image_1', 'image_2', 'image_3', 'image_4'], @@ -889,7 +894,7 @@ const grownNodeDef = testNodeDef( }), mask: ['MASK', { forceInput: true }] } - }) + ]) }, ['IMAGE'] ) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index afb8cc57a6c..ae5d57e699e 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -194,7 +194,9 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { * Autogrow groups renumber their own slots as the graph configures, so their * links belong to {@link LGraph.configure}'s final pass rather than to an * early realignment. A group is not a widget; ownership comes from the - * registry `applyAutogrow` populates. + * registry `applyAutogrow` populates, which only covers groups the selected + * option laid out — children of an unselected option reach this filter and are + * safe to realign, since their group's handler bails on the same missing key. */ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) @@ -208,10 +210,11 @@ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { /** * Re-points a node's group widget child links at the slot their name will map - * to, before applying the widget's value rebuilds those inputs and drops any - * link left on a slot the selected option does not lay out. Ordinary inputs - * join the batch so an occupied destination slot is vacated in the same atomic - * update instead of blocking the move. + * to. A saved link arrives on the wrong slot because the definition lays out + * the default option's children while `target_slot` counts the serialized + * layout, so applying the widget's value would rebuild those inputs and drop + * it. Ordinary inputs join the batch so an occupied destination slot is + * vacated in the same atomic update instead of blocking the move. */ export function realignGroupWidgetChildLinks( node: LGraphNode, From e507d7b8ee4e77d3e34d374c26a17dc9f76862c5 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 00:53:12 +0000 Subject: [PATCH 04/13] test: make the default combo option guarantee enforceable The defaultOption parameter promised something Object.keys does not honour: an array-index key is hoisted ahead of insertion order, so '0' would displace it. The sibling addDynamicCombo helper keys its options '0'/'1'/'2', so the next fixture author would hit this. Reject array-index keys instead. Also restore the fixture display names and resize's 'resized' output label, which testNodeDef had collapsed. --- src/core/graph/widgets/dynamicWidgets.test.ts | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index baf303b39db..a218158ecf7 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -675,14 +675,23 @@ type ChildInputs = Record type ComboOption = [key: string, childInputs: ChildInputs] +const ARRAY_INDEX_KEY = /^(0|[1-9]\d*)$/ + function dynamicCombo( defaultOption: ComboOption, ...remainingOptions: ComboOption[] ): InputSpec { + const options = [defaultOption, ...remainingOptions] + const hoisted = options.find(([key]) => ARRAY_INDEX_KEY.test(key)) + if (hoisted) + throw new Error( + `Option key '${hoisted[0]}' is an array index, so applying the combo would order it ahead of '${defaultOption[0]}' and change which option is the default.` + ) + return [ 'COMFY_DYNAMICCOMBO_V3', { - options: [defaultOption, ...remainingOptions].map(([key, inputs]) => ({ + options: options.map(([key, inputs]) => ({ key, inputs: { required: inputs } })) @@ -704,18 +713,20 @@ function autogrow(template: { function testNodeDef( name: string, + displayName: string, required: ChildInputs, - output: string[] + output: string[], + outputName: string[] = [...output] ): ComfyNodeDefV1 { return { name, - display_name: name, + display_name: displayName, category: 'testing', python_module: 'nodes', description: '', input: { required }, output, - output_name: [...output], + output_name: outputName, output_node: false } } @@ -727,6 +738,7 @@ function testNodeDef( */ const resizeNodeDef = testNodeDef( RESIZE_NODE_TYPE, + 'Resize Image Mask', { image: ['IMAGE', {}], resize_type: dynamicCombo( @@ -734,7 +746,8 @@ const resizeNodeDef = testNodeDef( ['scale by multiplier', { multiplier: ['FLOAT', {}] }] ) }, - ['IMAGE'] + ['IMAGE'], + ['resized'] ) /** @@ -773,7 +786,7 @@ function savedDynamicComboChildWorkflow(): SerialisableGraph { { name: 'image', type: 'IMAGE', link: null }, { name: 'resize_type.multiplier', type: 'FLOAT', link: 1 } ], - outputs: [{ name: 'IMAGE', type: 'IMAGE', links: [] }], + outputs: [{ name: 'resized', type: 'IMAGE', links: [] }], properties: {}, widgets_values: ['scale by multiplier', 4] } @@ -826,6 +839,7 @@ const REFERENCE_NODE_TYPE = 'test/AutogrowInsideCombo' */ const referenceNodeDef = testNodeDef( REFERENCE_NODE_TYPE, + 'Autogrow Inside Combo', { model: dynamicCombo([ 'Seedance', @@ -882,6 +896,7 @@ const GROWN_NODE_TYPE = 'test/AutogrowBeforeOrdinaryChild' */ const grownNodeDef = testNodeDef( GROWN_NODE_TYPE, + 'Autogrow Before Ordinary Child', { model: dynamicCombo([ 'gpt-image-1', From 502c94ea43c644f627352b7d35c67496ee1bfbd3 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 01:15:32 +0000 Subject: [PATCH 05/13] test: check the realized combo option order, not the key shape The regex rejected any numeric key, but JS only hoists array indices below 2^32-1, and a numeric default option lands first anyway. Build the record production builds and compare its first key instead, which is exact in both directions and also catches duplicate keys. --- src/core/graph/widgets/dynamicWidgets.test.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index a218158ecf7..a5751fc7c3c 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -675,17 +675,20 @@ type ChildInputs = Record type ComboOption = [key: string, childInputs: ChildInputs] -const ARRAY_INDEX_KEY = /^(0|[1-9]\d*)$/ - function dynamicCombo( defaultOption: ComboOption, ...remainingOptions: ComboOption[] ): InputSpec { const options = [defaultOption, ...remainingOptions] - const hoisted = options.find(([key]) => ARRAY_INDEX_KEY.test(key)) - if (hoisted) + const declaredKeys = options.map(([key]) => key) + const realizedKeys = Object.keys( + Object.fromEntries(declaredKeys.map((key) => [key, null])) + ) + if (realizedKeys.length !== declaredKeys.length) + throw new Error(`Duplicate option keys: ${declaredKeys.join(', ')}`) + if (realizedKeys[0] !== defaultOption[0]) throw new Error( - `Option key '${hoisted[0]}' is an array index, so applying the combo would order it ahead of '${defaultOption[0]}' and change which option is the default.` + `Applying the combo would order option '${realizedKeys[0]}' ahead of '${defaultOption[0]}', changing which option is the default.` ) return [ From db883b7c5fba71f9b2017be98ac8d9f2f5215e80 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 01:39:52 +0000 Subject: [PATCH 06/13] test: pin the combo option order guard, restore the ordering precondition The guard had no test holding it in place, so a future cleanup could drop it as a redundant expression and silently change which option a fixture defaults to. Deleting it now fails a named test. Also restore 'before the node's group widget values are applied' to realignGroupWidgetChildLinks, dropped by accident in c751096 while restoring a different clause. The realign runs ahead of the widget value restoration in LGraphNode.configure; reordering them would reintroduce FE-258. --- src/core/graph/widgets/dynamicWidgets.test.ts | 16 ++++++++++++++++ src/lib/litegraph/src/linkDeduplication.ts | 11 ++++++----- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index a5751fc7c3c..5f28b4ddb7e 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -702,6 +702,22 @@ function dynamicCombo( ] } +describe('dynamicCombo fixture builder', () => { + test('rejects option keys that would not survive the round trip through a record', () => { + const option = (key: string): ComboOption => [key, {}] + + expect(() => dynamicCombo(option('Seedance'), option('0'))).toThrow( + /ahead of 'Seedance'/ + ) + expect(() => dynamicCombo(option('a'), option('b'), option('a'))).toThrow( + /Duplicate option keys/ + ) + expect(() => + dynamicCombo(option('0'), option('Seedance'), option('4294967295')) + ).not.toThrow() + }) +}) + function autogrow(template: { names: string[] min: number diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index ae5d57e699e..f49517c0635 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -210,11 +210,12 @@ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { /** * Re-points a node's group widget child links at the slot their name will map - * to. A saved link arrives on the wrong slot because the definition lays out - * the default option's children while `target_slot` counts the serialized - * layout, so applying the widget's value would rebuild those inputs and drop - * it. Ordinary inputs join the batch so an occupied destination slot is - * vacated in the same atomic update instead of blocking the move. + * to, before the node's group widget values are applied. A saved link arrives + * on the wrong slot because the definition lays out the default option's + * children while `target_slot` counts the serialized layout, so applying the + * widget's value would rebuild those inputs and drop it. Ordinary inputs join + * the batch so an occupied destination slot is vacated in the same atomic + * update instead of blocking the move. */ export function realignGroupWidgetChildLinks( node: LGraphNode, From 1ad9ec756972564619a05d15426a0811fc0ea0d6 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 01:58:29 +0000 Subject: [PATCH 07/13] test: compare the whole realized option sequence, not just the head A tail reorder like ['0','2','1'] is exactly a key set that does not survive the round trip, but the head-only check accepted it, so the test pinning the guard claimed more than the guard delivered. --- src/core/graph/widgets/dynamicWidgets.test.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 5f28b4ddb7e..329e67d9625 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -686,9 +686,9 @@ function dynamicCombo( ) if (realizedKeys.length !== declaredKeys.length) throw new Error(`Duplicate option keys: ${declaredKeys.join(', ')}`) - if (realizedKeys[0] !== defaultOption[0]) + if (realizedKeys.some((key, index) => key !== declaredKeys[index])) throw new Error( - `Applying the combo would order option '${realizedKeys[0]}' ahead of '${defaultOption[0]}', changing which option is the default.` + `Applying the combo would order options as [${realizedKeys.join(', ')}] instead of [${declaredKeys.join(', ')}].` ) return [ @@ -707,7 +707,10 @@ describe('dynamicCombo fixture builder', () => { const option = (key: string): ComboOption => [key, {}] expect(() => dynamicCombo(option('Seedance'), option('0'))).toThrow( - /ahead of 'Seedance'/ + /\[0, Seedance\] instead of \[Seedance, 0\]/ + ) + expect(() => dynamicCombo(option('0'), option('2'), option('1'))).toThrow( + /\[0, 1, 2\] instead of \[0, 2, 1\]/ ) expect(() => dynamicCombo(option('a'), option('b'), option('a'))).toThrow( /Duplicate option keys/ From 72cb115bb38e34df85027356c71b98fab9a6ce48 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Thu, 24 Sep 2026 02:20:41 +0000 Subject: [PATCH 08/13] test: pin the premise the FE-258 case rests on Nothing asserted that the definition's default option lays out width, so if that flipped the realign would become a no-op and the test would stay green while testing nothing. Also report only the actual duplicate keys, and name the guard test for both directions it asserts. --- src/core/graph/widgets/dynamicWidgets.test.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index 329e67d9625..fb667026e7e 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -685,7 +685,9 @@ function dynamicCombo( Object.fromEntries(declaredKeys.map((key) => [key, null])) ) if (realizedKeys.length !== declaredKeys.length) - throw new Error(`Duplicate option keys: ${declaredKeys.join(', ')}`) + throw new Error( + `Duplicate option keys: ${declaredKeys.filter((key, index) => declaredKeys.indexOf(key) !== index).join(', ')}` + ) if (realizedKeys.some((key, index) => key !== declaredKeys[index])) throw new Error( `Applying the combo would order options as [${realizedKeys.join(', ')}] instead of [${declaredKeys.join(', ')}].` @@ -703,7 +705,7 @@ function dynamicCombo( } describe('dynamicCombo fixture builder', () => { - test('rejects option keys that would not survive the round trip through a record', () => { + test('rejects option keys that a record reorders, and accepts those it does not', () => { const option = (key: string): ComboOption => [key, {}] expect(() => dynamicCombo(option('Seedance'), option('0'))).toThrow( @@ -832,6 +834,18 @@ describe('Dynamic combo child links on workflow load (FE-258)', () => { await useLitegraphService().registerNodeDef(RESIZE_NODE_TYPE, resizeNodeDef) }) + test('lays out the default option, which the saved workflow does not select', () => { + const graph = new LGraph() + const node = LiteGraph.createNode(RESIZE_NODE_TYPE) + assert.ok(node, 'resize node') + graph.add(node) + + const children = node.inputs + .map((input) => input.name) + .filter((name) => name.startsWith('resize_type.')) + expect(children).toEqual(['resize_type.width']) + }) + test('keeps the link on the child the selected option lays out', () => { const graph = new LGraph() graph.configure(savedDynamicComboChildWorkflow()) From 587187725a4ecb7fcfe9005b6a13b8d829af856e Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 25 Sep 2026 08:31:59 +0000 Subject: [PATCH 09/13] test: derive dynamic combo fixture types from the node def schemas --- src/core/graph/widgets/dynamicWidgets.test.ts | 59 ++++++++++++++----- src/lib/litegraph/src/linkDeduplication.ts | 1 - 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/core/graph/widgets/dynamicWidgets.test.ts b/src/core/graph/widgets/dynamicWidgets.test.ts index fb667026e7e..a2cdcbb77b6 100644 --- a/src/core/graph/widgets/dynamicWidgets.test.ts +++ b/src/core/graph/widgets/dynamicWidgets.test.ts @@ -7,6 +7,7 @@ import { test, vi } from 'vitest' +import type { z } from 'zod' import { useChainCallback } from '@/composables/functional/useChainCallback' import { addAutogrow, @@ -17,8 +18,10 @@ import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' import { realignGroupWidgetChildLinks } from '@/lib/litegraph/src/linkDeduplication' import type { SerialisableGraph } from '@/lib/litegraph/src/types/serialisation' import type { + ComfyInputsSpec, ComfyNodeDef as ComfyNodeDefV1, - InputSpec + zAutogrowOptions, + zDynamicComboInputSpec } from '@/schemas/nodeDefSchema' import { useLitegraphService } from '@/services/litegraphService' import { useLinkStore } from '@/stores/linkStore' @@ -671,14 +674,21 @@ class SourceNode extends LGraphNode { } } -type ChildInputs = Record +type ChildInputs = NonNullable + +type DynamicComboInputSpec = z.infer + +type AutogrowInputSpec = [ + type: 'COMFY_AUTOGROW_V3', + options: z.infer +] type ComboOption = [key: string, childInputs: ChildInputs] function dynamicCombo( defaultOption: ComboOption, ...remainingOptions: ComboOption[] -): InputSpec { +): DynamicComboInputSpec { const options = [defaultOption, ...remainingOptions] const declaredKeys = options.map(([key]) => key) const realizedKeys = Object.keys( @@ -705,18 +715,37 @@ function dynamicCombo( } describe('dynamicCombo fixture builder', () => { - test('rejects option keys that a record reorders, and accepts those it does not', () => { - const option = (key: string): ComboOption => [key, {}] + function option(key: string): ComboOption { + return [key, {}] + } - expect(() => dynamicCombo(option('Seedance'), option('0'))).toThrow( - /\[0, Seedance\] instead of \[Seedance, 0\]/ - ) - expect(() => dynamicCombo(option('0'), option('2'), option('1'))).toThrow( - /\[0, 1, 2\] instead of \[0, 2, 1\]/ - ) - expect(() => dynamicCombo(option('a'), option('b'), option('a'))).toThrow( - /Duplicate option keys/ - ) + const rejectedCases: { + name: string + options: [ComboOption, ...ComboOption[]] + message: RegExp + }[] = [ + { + name: 'a numeric key after a named one', + options: [option('Seedance'), option('0')], + message: /\[0, Seedance\] instead of \[Seedance, 0\]/ + }, + { + name: 'numeric keys out of ascending order', + options: [option('0'), option('2'), option('1')], + message: /\[0, 1, 2\] instead of \[0, 2, 1\]/ + }, + { + name: 'a key declared twice', + options: [option('a'), option('b'), option('a')], + message: /Duplicate option keys: a/ + } + ] + + test.for(rejectedCases)('rejects $name', ({ options, message }) => { + expect(() => dynamicCombo(...options)).toThrow(message) + }) + + test('accepts a numeric key too large to be an array index', () => { expect(() => dynamicCombo(option('0'), option('Seedance'), option('4294967295')) ).not.toThrow() @@ -727,7 +756,7 @@ function autogrow(template: { names: string[] min: number input: ChildInputs -}): InputSpec { +}): AutogrowInputSpec { const { names, min, input } = template return [ 'COMFY_AUTOGROW_V3', diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index f49517c0635..786a2c98c0d 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -182,7 +182,6 @@ function groupNameOf(inputName: string): string | undefined { return separator < 1 ? undefined : inputName.slice(0, separator) } -/** Group widgets (dynamic combos) name children `.`. */ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) if (groupName === undefined) return false From 38e9137e170feac16437af5d89d6022dbdaf4a82 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 25 Sep 2026 08:49:36 +0000 Subject: [PATCH 10/13] docs(litegraph): restore the pointer to the autogrow realignment test --- src/lib/litegraph/src/linkDeduplication.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 786a2c98c0d..0f5daca8b8a 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -196,6 +196,10 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { * registry `applyAutogrow` populates, which only covers groups the selected * option laid out — children of an unselected option reach this filter and are * safe to realign, since their group's handler bails on the same missing key. + * + * @see browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts + * "loads with both reference images connected" — the only test that fails when + * autogrow links are realigned early. */ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) From a450301e83929645c84bb648aae8f6ba576f9aa2 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 25 Sep 2026 09:05:34 +0000 Subject: [PATCH 11/13] docs(litegraph): keep the rejected dotted-name alternative on the autogrow filter --- src/lib/litegraph/src/linkDeduplication.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 0f5daca8b8a..5c1938d8fe0 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -192,14 +192,17 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { /** * Autogrow groups renumber their own slots as the graph configures, so their * links belong to {@link LGraph.configure}'s final pass rather than to an - * early realignment. A group is not a widget; ownership comes from the - * registry `applyAutogrow` populates, which only covers groups the selected - * option laid out — children of an unselected option reach this filter and are - * safe to realign, since their group's handler bails on the same missing key. + * early realignment. A group is not a widget, and the dotted name alone will + * not serve — `INodeInputSlot.name` is arbitrary, so an ordinary input may be + * dotted without belonging to any group — so ownership comes from the registry + * `applyAutogrow` populates. That registry only covers groups the selected + * option laid out; children of an unselected option still reach this filter, + * because `ComfyNode.configure` appends every serialized input the definition + * lacks, and are safe to realign since their group's handler bails on the same + * missing key. * * @see browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts - * "loads with both reference images connected" — the only test that fails when - * autogrow links are realigned early. + * "loads with both reference images connected" */ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName) From 08c2c82094ea941d5c9343092cf16741e48f3a68 Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 25 Sep 2026 09:23:17 +0000 Subject: [PATCH 12/13] docs(litegraph): split the autogrow filter rationale into two sentences --- src/lib/litegraph/src/linkDeduplication.ts | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 5c1938d8fe0..66012388f11 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -192,14 +192,15 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { /** * Autogrow groups renumber their own slots as the graph configures, so their * links belong to {@link LGraph.configure}'s final pass rather than to an - * early realignment. A group is not a widget, and the dotted name alone will - * not serve — `INodeInputSlot.name` is arbitrary, so an ordinary input may be - * dotted without belonging to any group — so ownership comes from the registry - * `applyAutogrow` populates. That registry only covers groups the selected - * option laid out; children of an unselected option still reach this filter, - * because `ComfyNode.configure` appends every serialized input the definition - * lacks, and are safe to realign since their group's handler bails on the same - * missing key. + * early realignment, which destroys them. A group is not a widget, and the + * dotted name alone will not serve — `INodeInputSlot.name` is arbitrary, so an + * ordinary input may be dotted without belonging to any group — so ownership + * comes from the registry `applyAutogrow` populates. + * + * That registry only covers groups the selected option laid out. Children of + * an unselected option still reach this filter, because `ComfyNode.configure` + * appends every serialized input the definition lacks. Realigning those is + * safe: their group's handler bails on the same missing key. * * @see browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts * "loads with both reference images connected" From 685c323a60c351f6d01477ef0485ec7de14f9b1f Mon Sep 17 00:00:00 2001 From: Glary-Bot Date: Fri, 25 Sep 2026 10:47:14 +0000 Subject: [PATCH 13/13] docs(litegraph): drop the test-file pointer from the autogrow filter --- src/lib/litegraph/src/linkDeduplication.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/litegraph/src/linkDeduplication.ts b/src/lib/litegraph/src/linkDeduplication.ts index 66012388f11..53ac5d98b9d 100644 --- a/src/lib/litegraph/src/linkDeduplication.ts +++ b/src/lib/litegraph/src/linkDeduplication.ts @@ -201,9 +201,6 @@ function isGroupWidgetChildInput(node: LGraphNode, inputName: string): boolean { * an unselected option still reach this filter, because `ComfyNode.configure` * appends every serialized input the definition lacks. Realigning those is * safe: their group's handler bails on the same missing key. - * - * @see browser_tests/tests/subgraph/subgraphConvertAutogrowInputs.spec.ts - * "loads with both reference images connected" */ function isAutogrowGroupInput(node: LGraphNode, inputName: string): boolean { const groupName = groupNameOf(inputName)