From f28f3043dad8791448091ef2d90678a2f0539df3 Mon Sep 17 00:00:00 2001 From: jaeone lee <89377375+jaeone94@users.noreply.github.com> Date: Tue, 6 Oct 2026 08:05:35 +0000 Subject: [PATCH] fix: propagate DynamicGroup row changes through nested promotions (#20181) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## ELI5 Editing or deleting a repeated row now updates its promoted controls through nested subgraphs. Outer labels follow the surviving row, and controls and links disappear when their inner target is removed, while labels renamed by the user are preserved. ## Summary - Propagate DynamicGroup row renumbering and orphaned-promotion cleanup through every enclosing subgraph and its host instances. Inputs with other connected targets keep their promotion. - Preserve per-instance custom labels in the shared `SubgraphNode` rename listener; only labels still matching the previous generated label are updated. - Collect host instances lazily once per row-change operation and reuse that lookup across fields, rows and promotion boundaries. No persistent graph cache is added. - Exercise a remote resize of an already materialized root node through the real document applier, change tracker and outbound minter: frontend workflow serialization updates, one undo entry is recorded, and remote changes do not echo back. A subsequent local edit proves the outbound minter is active. ## Validation - Original regression proof: reverting the nested-promotion fix produced **2 failures / 38 passes**; applying it produced **40 passes**. - New per-instance-label regression: **1 failure / 41 passes** before the label fix. - `pnpm exec vitest run src/core/graph/widgets/dynamicGroupWidget.test.ts src/lib/litegraph/src/subgraph/SubgraphNode.test.ts src/workbench/extensions/agent/crdt/liveGraphApplier.changeTracker.test.ts --maxWorkers=1`: **98 passed**. After narrowing the new fixture's serialization types, its two tests passed again. - The unchanged real-backend regressions in [#17510 — test: verify DynamicGroup in a dedicated backend E2E job](https://github.com/Comfy-Org/ComfyUI_frontend/pull/17510), now stacked here, both pass. The [dedicated Linux job](https://github.com/Comfy-Org/ComfyUI_frontend/actions/runs/37396376241/job/112054534444) reports **18 passed / 1 failed**: the remaining failure is Undo/Redo of a once-promoted row, which also fails after reverting both production files to this PR’s base (`9eaaf261ff`). Local testing matched **18 passed / 1 failed** (one worker, no retries; local Vite-only timeout 60s, CI retains 30s). - Formatting, lint, application typechecking, and commit/push hooks passed, including Knip and the changed-file Fallow gate. ## Separate Undo/Redo follow-up The remaining real-backend E2E failure is tracked in [#20285 — Redo history is cleared after Undo normalizes node size](https://github.com/Comfy-Org/ComfyUI_frontend/issues/20285). Undo changes the restored source-node height, and the next navigation click records that difference as a new edit and clears Redo. The E2E child keeps this test enabled as a real failure; the linked completed Linux run reports 18 passed / 1 failed. No source-size workaround or shared history change is included in this PR. The shared-history fix now has an owned draft: [#20294 — fix: preserve redo after restored node size normalization](https://github.com/Comfy-Org/ComfyUI_frontend/pull/20294), assigned to @jaeone94. Its two normalization regressions fail before the fix, and 140 related unit tests pass with it. Applying only that production patch to the unchanged E2E child makes the promoted-row Undo/Redo case pass locally. The full local run was 17 passed / 2 nested-entry click timeouts; see the draft for that limitation. The child branch and its CI result have not been changed by this verification. ## Remaining remote-edit scope The remote-frame test begins with a correctly materialized root node. It does not certify first catch-up, CLI/catalog integration, or edits inside subgraph definitions: the current collector/applier path handles root-node widget updates. Those broader agent-path checks remain separate from this nested-promotion fix. Fixes #20179 Fixes #20180 ## Provenance The two original nested-promotion regressions pass unchanged with the E2E PR stacked on this fix. The child's [completed Linux job](https://github.com/Comfy-Org/ComfyUI_frontend/actions/runs/37397861046/job/112059272768) reports 18 passed / 1 failed; the remaining shared-history Redo defect has the owned issue and draft linked above. The child subsequently updated its devtool and backend pin for the private API: four focused real-backend cases passed locally, while the new full-suite CI run is pending. The 18/1 result is evidence from before that pin update, not a claim that the latest child head is green. - **Authored by:** interactive session - **Verified:** the unit results and hook checks above. The [real-backend CI job](https://github.com/Comfy-Org/ComfyUI_frontend/actions/runs/37396376241/job/112054534444) and local run both passed the two targeted regressions; the full suite is not green because the baseline Redo failure remains. - **Deviations:** full nested Agent/CLI/document/follower convergence is not covered by the root-node remote-frame test. No backend dependency override is added to this fix PR. --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- .../graph/widgets/dynamicGroupWidget.test.ts | 118 ++++++++++++++ src/core/graph/widgets/dynamicGroupWidget.ts | 115 ++++++++++---- .../litegraph/src/subgraph/SubgraphNode.ts | 10 +- .../liveGraphApplier.changeTracker.test.ts | 145 +++++++++++++++++- 4 files changed, 356 insertions(+), 32 deletions(-) diff --git a/src/core/graph/widgets/dynamicGroupWidget.test.ts b/src/core/graph/widgets/dynamicGroupWidget.test.ts index 3ebc3b112ed..3d26a436204 100644 --- a/src/core/graph/widgets/dynamicGroupWidget.test.ts +++ b/src/core/graph/widgets/dynamicGroupWidget.test.ts @@ -31,6 +31,7 @@ import { useNodeDefStore } from '@/stores/nodeDefStore' import type { ComfyNodeDef } from '@/schemas/nodeDefSchema' import { graphToPrompt } from '@/utils/executionUtil' import { isWidgetVisibleOnSurface } from '@/types/widgetVisibility' +import { renameWidget } from '@/utils/widgetUtil' function setup(min = 0, max = 3) { const graph = new LGraph() @@ -354,6 +355,123 @@ describe('DynamicGroup widgets', () => { } ) + function setupTwiceDeepPromotion() { + const { node, graph, widget } = setup() + graph.remove(node) + const outerSubgraph = createTestSubgraph({ rootGraph: graph }) + const outerHost = createTestSubgraphNode(outerSubgraph) + graph.add(outerHost) + const innerSubgraph = createTestSubgraph({ rootGraph: graph }) + const innerHost = createTestSubgraphNode(innerSubgraph, { + parentGraph: outerSubgraph + }) + outerSubgraph.add(innerHost) + innerSubgraph.add(node) + widget('loras').value = 2 + const strength = widget('loras.1.strength') + expect( + promoteValueWidgetViaSubgraphInput(innerHost, node, strength).ok + ).toBe(true) + const innerPromoted = promotedInputWidget(innerHost.inputs[0]) + if (!innerPromoted) throw new Error('Inner promotion failed') + expect( + promoteValueWidgetViaSubgraphInput(outerHost, innerHost, innerPromoted).ok + ).toBe(true) + const outerInput = outerHost.inputs[0] + expect(promotedInputWidget(outerInput)?.label).toBe('LoRA #2 strength') + return { widget, innerHost, outerHost, outerSubgraph, outerInput } + } + + it.for([ + { label: 'LoRA #2 strength', expected: 'LoRA #1 strength' }, + { label: 'My strength', expected: 'My strength' } + ])( + 'shows $expected through two boundaries after removing a row before the promoted field $label', + ({ label, expected }) => { + const { widget, outerSubgraph, outerInput } = setupTwiceDeepPromotion() + outerSubgraph.renameInput(outerSubgraph.inputs[0], label) + + widget('loras.0').callback?.(undefined) + + expect(promotedInputWidget(outerInput)?.label).toBe(expected) + } + ) + + it.for([ + { + name: 'generated labels', + innerLabel: 'LoRA #2 strength', + outerLabel: 'LoRA #2 strength', + expectedInner: 'LoRA #1 strength', + expectedOuter: 'LoRA #1 strength' + }, + { + name: 'per-instance custom labels', + innerLabel: 'Inner strength', + outerLabel: 'Outer strength', + expectedInner: 'Inner strength', + expectedOuter: 'Outer strength' + } + ])( + 'preserves $name across multiple instances when rows are renumbered', + ({ innerLabel, outerLabel, expectedInner, expectedOuter }) => { + const { widget, innerHost, outerHost, outerInput } = + setupTwiceDeepPromotion() + const rootGraph = innerHost.subgraph.rootGraph + const otherOuterSubgraph = createTestSubgraph({ rootGraph }) + const otherOuterHost = createTestSubgraphNode(otherOuterSubgraph) + rootGraph.add(otherOuterHost) + const otherInnerHost = createTestSubgraphNode(innerHost.subgraph, { + parentGraph: otherOuterSubgraph + }) + otherOuterSubgraph.add(otherInnerHost) + const otherInnerPromoted = promotedInputWidget(otherInnerHost.inputs[0]) + assert.exists(otherInnerPromoted) + expect( + promoteValueWidgetViaSubgraphInput( + otherOuterHost, + otherInnerHost, + otherInnerPromoted + ).ok + ).toBe(true) + const otherOuterInput = otherOuterHost.inputs[0] + expect(promotedInputWidget(otherOuterInput)?.label).toBe( + 'LoRA #2 strength' + ) + const innerPromoted = promotedInputWidget(innerHost.inputs[0]) + const outerPromoted = promotedInputWidget(outerInput) + assert.exists(innerPromoted) + assert.exists(outerPromoted) + renameWidget(innerPromoted, innerHost, innerLabel) + renameWidget(outerPromoted, outerHost, outerLabel) + + widget('loras.0').callback?.(undefined) + + expect( + [ + innerHost.inputs[0], + otherInnerHost.inputs[0], + outerInput, + otherOuterInput + ].map((input) => promotedInputWidget(input)?.label) + ).toEqual([ + expectedInner, + 'LoRA #1 strength', + expectedOuter, + 'LoRA #1 strength' + ]) + } + ) + + it('removes a field promoted through two boundaries when its row is removed', async () => { + const { widget, innerHost, outerInput } = setupTwiceDeepPromotion() + + widget('loras.1').callback?.(undefined) + + expect(innerHost.inputs[0].link).toBeNull() + await vi.waitFor(() => expect(promotedInputWidget(outerInput)).toBeNull()) + }) + it.for([ { label: 'LoRA #2 strength', expected: 'LoRA 1행 strength' }, { label: 'My strength', expected: 'My strength' } diff --git a/src/core/graph/widgets/dynamicGroupWidget.ts b/src/core/graph/widgets/dynamicGroupWidget.ts index 3545f68b68e..afe7ab3a221 100644 --- a/src/core/graph/widgets/dynamicGroupWidget.ts +++ b/src/core/graph/widgets/dynamicGroupWidget.ts @@ -1,10 +1,13 @@ import { t } from '@/i18n' import { SUBGRAPH_INPUT_ID } from '@/lib/litegraph/src/constants' +import type { LGraph, Subgraph } from '@/lib/litegraph/src/LGraph' import type { LGraphNode } from '@/lib/litegraph/src/LGraphNode' +import type { SubgraphNode } from '@/lib/litegraph/src/subgraph/SubgraphNode' import type { IBaseWidget } from '@/lib/litegraph/src/types/widgets' import { VueOnlyWidget } from '@/lib/litegraph/src/widgets/VueOnlyWidget' import { captureInputLayout, + inputLink, replaceNodeInputs } from '@/lib/litegraph/src/node/slotLinks' import { @@ -18,6 +21,7 @@ import { useLitegraphService } from '@/services/litegraphService' import { useNodeDefStore } from '@/stores/nodeDefStore' import { useWidgetValueStore } from '@/stores/widgetValueStore' import { deriveWidgetSurfaces } from '@/types/widgetVisibility' +import { mapUniqueNodes } from '@/utils/graphTraversalUtil' import { isSubgraph } from '@/utils/typeGuardUtil' export function dynamicGroupWidget( @@ -120,14 +124,14 @@ export function dynamicGroupWidget( } } - function removeRow(index: number) { + function removeRow(index: number, hosts = createPromotionHostLookup()) { if (!node.widgets) return false const prefix = `${inputName}.${index}` const removed = node.widgets.filter( (widget) => widget.name === prefix || widget.name.startsWith(`${prefix}.`) ) if (!removed.length) return false - if (!removeRowInputs(prefix)) return false + if (!removeRowInputs(prefix, hosts)) return false for (const widget of removed.reverse()) { if (node.widgets.includes(widget)) node.removeWidget(widget) } @@ -136,16 +140,22 @@ export function dynamicGroupWidget( const row = Number(oldPrefix.slice(inputName.length + 1)) if (row <= index) continue const newPrefix = `${inputName}.${row - 1}` - renameRow(oldPrefix, newPrefix) + renameRow(oldPrefix, newPrefix, hosts) } return true } - function removeRowInputs(prefix: string) { + function removeRowInputs(prefix: string, hosts: PromotionHostLookup) { const previous = captureInputLayout(node) const inputs = previous.inputs.filter( (input) => !input.name.startsWith(`${prefix}.`) ) + const promotedSlots = previous.inputs.flatMap((input) => { + const link = previous.links.get(input) + return !inputs.includes(input) && link?.origin_id === SUBGRAPH_INPUT_ID + ? [link.origin_slot] + : [] + }) const result = replaceNodeInputs( node, previous, @@ -163,6 +173,8 @@ export function dynamicGroupWidget( previous.inputs.forEach((input, slot) => { if (!inputs.includes(input)) node.onInputRemoved?.(slot, input) }) + for (const slot of promotedSlots) + disconnectOrphanedPromotion(node.graph, slot, hosts) return true } @@ -174,22 +186,10 @@ export function dynamicGroupWidget( return `${row} ${fields[field][1]?.display_name ?? field}` } - function renamePromotedInputLabel( - slot: number, - previous: string, - next: string - ) { - const graph = node.graph - if (!graph || !isSubgraph(graph)) return - const link = node.getInputLink(slot) - if (link?.origin_id !== SUBGRAPH_INPUT_ID) return - const promoted = graph.inputs[link.origin_slot] - if (promoted.label === previous) graph.renameInput(promoted, next) - } - function renameRowLabels( oldIndex: number, newIndex: number, + hosts: PromotionHostLookup, rowLabel?: string ) { for (const field of Object.keys(fields)) { @@ -204,11 +204,15 @@ export function dynamicGroupWidget( if (!input) continue if (input.label === previous) input.label = next input.localized_name = next - renamePromotedInputLabel(slot, previous, next) + renamePromotedInputLabel(node, slot, previous, next, hosts) } } - function renameRow(oldPrefix: string, newPrefix: string) { + function renameRow( + oldPrefix: string, + newPrefix: string, + hosts: PromotionHostLookup + ) { const rowLabel = rows().find((row) => row.name === oldPrefix)?.label for (const widget of node.widgets ?? []) { if (widget.name === oldPrefix || widget.name.startsWith(`${oldPrefix}.`)) @@ -222,11 +226,12 @@ export function dynamicGroupWidget( renameRowLabels( Number(oldPrefix.slice(inputName.length + 1)), Number(newPrefix.slice(inputName.length + 1)), + hosts, rowLabel ) } - function addRow(index: number) { + function addRow(index: number, hosts: PromotionHostLookup) { const previousSize: [number, number] = [...node.size] const start = node.widgets?.length ?? 0 const previous = captureInputLayout(node) @@ -249,7 +254,7 @@ export function dynamicGroupWidget( }) } }) - addRowFields(index) + addRowFields(index, hosts) const addedInputs = node.inputs.splice(previous.inputs.length) const inputs = [ ...previous.inputs, @@ -277,18 +282,22 @@ export function dynamicGroupWidget( return true } - function updateInputLabel(name: string, label: string) { + function updateInputLabel( + name: string, + label: string, + hosts: PromotionHostLookup + ) { const slot = node.findInputSlot(name) if (slot === -1) return const input = node.inputs[slot] const previous = input.localized_name if (!input.label || input.label === previous) input.label = label input.localized_name = label - if (previous) renamePromotedInputLabel(slot, previous, label) + if (previous) renamePromotedInputLabel(node, slot, previous, label, hosts) return input } - function addRowFields(index: number) { + function addRowFields(index: number, hosts: PromotionHostLookup) { for (const [fields, isOptional] of [ [template.required, false], [template.optional, true] @@ -302,7 +311,7 @@ export function dynamicGroupWidget( transformInputSpecV1ToV2(spec, { name, isOptional })), display_name: fieldLabel(index, field) }) - const input = updateInputLabel(name, fieldLabel(index, field)) + const input = updateInputLabel(name, fieldLabel(index, field), hosts) let auxiliaryIndex = 0 node.widgets?.slice(fieldStart).forEach((widget) => { const options = widget.options @@ -350,11 +359,12 @@ export function dynamicGroupWidget( const requested = Math.max(0, Math.trunc(value)) validateSavedRowCount(value, requested) const count = Math.max(min, requested) + const hosts = createPromotionHostLookup() for (let index = rows().length - 1; index >= count; index--) { - if (!removeRow(index)) break + if (!removeRow(index, hosts)) break } while (rows().length < count) { - if (!addRow(rows().length)) break + if (!addRow(rows().length, hosts)) break } publish() } @@ -363,6 +373,57 @@ export function dynamicGroupWidget( return { widget: controller } } +type PromotionHostLookup = (subgraph: Subgraph) => SubgraphNode[] + +function createPromotionHostLookup(): PromotionHostLookup { + let hosts: Map | undefined + return (subgraph) => { + if (!hosts) { + hosts = new Map() + for (const host of mapUniqueNodes(subgraph.rootGraph, (node) => + node.isSubgraphNode() ? node : undefined + )) { + const instances = hosts.get(host.subgraph) ?? [] + instances.push(host) + hosts.set(host.subgraph, instances) + } + } + return hosts.get(subgraph) ?? [] + } +} + +function renamePromotedInputLabel( + node: LGraphNode, + slot: number, + previous: string, + next: string, + hosts: PromotionHostLookup +) { + const graph = node.graph + if (!isSubgraph(graph)) return + const link = inputLink(graph, node.id, slot) + if (link?.origin_id !== SUBGRAPH_INPUT_ID) return + const promoted = graph.inputs[link.origin_slot] + if (promoted.label !== previous) return + graph.renameInput(promoted, next) + for (const host of hosts(graph)) + renamePromotedInputLabel(host, link.origin_slot, previous, next, hosts) +} + +function disconnectOrphanedPromotion( + graph: LGraph | Subgraph | null, + slot: number, + hosts: PromotionHostLookup +) { + if (!isSubgraph(graph) || graph.inputs[slot]?.linkIds.length) return + for (const host of hosts(graph)) { + const link = host.graph && inputLink(host.graph, host.id, slot) + if (link?.origin_id !== SUBGRAPH_INPUT_ID) continue + host.disconnectInput(slot) + disconnectOrphanedPromotion(host.graph, link.origin_slot, hosts) + } +} + class DynamicGroupNoticeWidget extends VueOnlyWidget { protected get vueOnlyLabel(): string { return this.label ?? this.name diff --git a/src/lib/litegraph/src/subgraph/SubgraphNode.ts b/src/lib/litegraph/src/subgraph/SubgraphNode.ts index f05672b379e..c0999e1ea8f 100644 --- a/src/lib/litegraph/src/subgraph/SubgraphNode.ts +++ b/src/lib/litegraph/src/subgraph/SubgraphNode.ts @@ -214,20 +214,24 @@ export class SubgraphNode extends LGraphNode implements BaseLGraph { subgraphEvents.addEventListener( 'renaming-input', (e) => { - const { index, newName } = e.detail + const { index, oldName, newName } = e.detail const input = this.inputs.at(index) if (!input) { console.error('Subgraph input not found') return } - input.label = newName + const previousLabel = input.label ?? input.name + if (previousLabel === oldName) input.label = newName // Do NOT change input.widget.name — it is the stable internal // identifier used by onGraphConfigured (widgetInputs.ts) to match // inputs to widgets. Changing it to the display label would cause // collisions when two promoted inputs share the same label. if (input.widgetId) { - useWidgetValueStore().setLabel(input.widgetId, newName) + const store = useWidgetValueStore() + const widgetLabel = + store.getWidget(input.widgetId)?.label ?? previousLabel + if (widgetLabel === oldName) store.setLabel(input.widgetId, newName) } this.invalidatePromotedViews() this.graph?.trigger('node:slot-label:changed', { diff --git a/src/workbench/extensions/agent/crdt/liveGraphApplier.changeTracker.test.ts b/src/workbench/extensions/agent/crdt/liveGraphApplier.changeTracker.test.ts index 329a9e564fd..509fc126e53 100644 --- a/src/workbench/extensions/agent/crdt/liveGraphApplier.changeTracker.test.ts +++ b/src/workbench/extensions/agent/crdt/liveGraphApplier.changeTracker.test.ts @@ -1,7 +1,15 @@ import { applyOps } from '@comfyorg/comfy-multi-player' import type { Op, WidgetCatalog } from '@comfyorg/comfy-multi-player' import { fromPartial } from '@total-typescript/shoehorn' -import { beforeEach, describe, expect, it, onTestFinished, vi } from 'vitest' +import { + assert, + beforeEach, + describe, + expect, + it, + onTestFinished, + vi +} from 'vitest' import { markRaw, ref } from 'vue' import { LGraph, LGraphNode, LiteGraph } from '@/lib/litegraph/src/litegraph' @@ -13,9 +21,12 @@ import type { ComfyApi } from '@/scripts/api' import type { ComfyApp } from '@/scripts/app' import { ChangeTracker } from '@/scripts/changeTracker' import { toNodeId } from '@/types/nodeId' +import { toRootGraphId } from '@/types/graphScopeId' +import { useLitegraphService } from '@/services/litegraphService' import { followedDoc } from './__fixtures__/followedDoc' import { LiveGraphApplier } from './liveGraphApplier' +import { attachDocOpMinter } from './docOpMinter' const appState = vi.hoisted(() => ({ rootGraph: undefined as LGraph | undefined @@ -59,10 +70,37 @@ class TestSink extends LGraphNode { } } +class DynamicGroupTest extends LGraphNode { + constructor() { + super('DynamicGroupTest') + this.comfyClass = 'DynamicGroupTest' + this.serialize_widgets = true + this.addWidget('text', 'before', 'head', () => {}) + useLitegraphService().addNodeInput(this, { + name: 'rows', + type: 'COMFY_DYNAMICGROUP_V3', + isOptional: false, + min: 0, + max: 3, + template: { required: { strength: ['FLOAT', { default: 1 }] } } + }) + this.addWidget('text', 'after', 'tail', () => {}) + } +} + const CATALOG: WidgetCatalog = { types: { TestSource: { widget_order: ['steps'] }, - TestSink: { widget_order: [] } + TestSink: { widget_order: [] }, + DynamicGroupTest: { + widget_order: [ + 'before', + 'rows', + 'rows.0.strength', + 'rows.1.strength', + 'after' + ] + } } } const CONTEXT = { actor: 'agent:test', opIds: ['op-1'] } @@ -94,6 +132,7 @@ async function workflowJson(graph: LGraph): Promise { beforeEach(() => { LiteGraph.registerNodeType('TestSource', TestSource) LiteGraph.registerNodeType('TestSink', TestSink) + LiteGraph.registerNodeType('DynamicGroupTest', DynamicGroupTest) ChangeTracker.isLoadingGraph = false }) @@ -174,4 +213,106 @@ describe('LiveGraphApplier with the real change tracker', () => { expect(tracker.activeState).toEqual(await workflowJson(graph)) expect(tracker.activeState).not.toEqual(beforeFrame) }) + + it('resizes an existing DynamicGroup remotely as one undo unit without outbound echo', async () => { + const graph = new LGraph() + appState.rootGraph = graph + onTestFinished(() => { + appState.rootGraph = undefined + }) + const node = LiteGraph.createNode('DynamicGroupTest') + assert.exists(node) + graph.add(node) + const count = node.widgets?.find((widget) => widget.name === 'rows') + assert.exists(count) + count.value = 2 + const first = node.widgets?.find( + (widget) => widget.name === 'rows.0.strength' + ) + const second = node.widgets?.find( + (widget) => widget.name === 'rows.1.strength' + ) + assert.exists(first) + assert.exists(second) + first.value = 0.5 + second.value = 0.7 + expect(node.serialize().widgets_values).toEqual([ + 'head', + 2, + 0.5, + 0.7, + 'tail' + ]) + const beforeFrame = await workflowJson(graph) + const { flags, ...serialized } = node.serialize() + const { doc, collector } = followedDoc( + { nodes: [{ ...serialized, flags: { ...flags } }], links: [] }, + CATALOG + ) + collector.take() + const applier = new LiveGraphApplier({ getGraph: () => graph }) + const tracker = markRaw( + new ChangeTracker(fromPartial({ path: '/dynamic.json' }), beforeFrame) + ) + useWorkflowStore().activeWorkflow = fromPartial({ changeTracker: tracker }) + graph.list_of_graphcanvas = [ + fromPartial({ + emitBeforeChange: () => tracker.beforeChange(), + emitAfterChange: () => tracker.afterChange(), + setDirty: () => {}, + deselect: () => {}, + checkPanels: () => {} + }) + ] + const enqueue = vi.fn() + const minter = attachDocOpMinter({ + isEnabled: () => true, + isDocBound: () => true, + getGraph: () => graph, + boundRootGraphId: () => toRootGraphId(graph.id), + docInputNames: () => [], + enqueue + }) + onTestFinished(() => minter.detach()) + const resize = op({ + op: 'set_widget', + node_id: 1, + widget: 'rows', + value: 0 + }) + const after = { + ...op({ + op: 'set_widget', + node_id: 1, + widget: 'after', + value: 'remote tail' + }), + op_id: 'op-after'.padEnd(32, '0') + } + + expect( + applyOps(doc, [resize, after], CATALOG).outcomes.map( + ({ outcome }) => outcome + ) + ).toEqual(['applied', 'applied']) + applier.applyChanges(doc, collector.take(), CONTEXT) + + expect(node.serialize().widgets_values).toEqual(['head', 0, 'remote tail']) + expect(tracker.undoQueue).toEqual([beforeFrame]) + expect(tracker.activeState).toEqual(await workflowJson(graph)) + const afterWidget = node.widgets?.find((widget) => widget.name === 'after') + assert.exists(afterWidget) + afterWidget.value = 'human tail' + await vi.waitFor(() => + expect(enqueue).toHaveBeenCalledExactlyOnceWith([ + { + op: 'set_widget', + node_id: '1', + widget: 'after', + value: 'human tail', + old: 'remote tail' + } + ]) + ) + }) })