Files
ComfyUI_frontend/src/utils/graphConfigureUtil.test.ts
Alexander Brown 0b8cc7f3ca fix: address CodeRabbit review findings for subgraph lifecycle parity
- Emit dispatchNodeConnectionChange in SubgraphInputNode stale-link fallback
- Balance beforeChange/afterChange with try/finally in SubgraphOutput.connect
- Emit disconnect event when SubgraphOutput.connect replaces existing link
- Guard connectSubgraphOutputSlot return and skip dispatch on falsy link
- Move onAfterGraphConfigured to finally block in graphConfigureUtil
- Add dispatchSlotLinkChanged to connectSubgraphOutputSlot for parity
- Guard remapProxyWidgets call with explicit map-entry check
- Harden LinkStore restore test assertions with existence checks
- Use dispatchDisconnectNodePair in disconnectOutput for consistency

Amp-Thread-ID: https://ampcode.com/threads/T-019cb1e7-a18e-712a-b8c7-4448f603c8b1
Co-authored-by: Amp <amp@ampcode.com>
2026-03-03 01:20:30 -08:00

73 lines
1.8 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { LGraph } from '@/lib/litegraph/src/litegraph'
import { fixLinkInputSlots } from '@/utils/litegraphUtil'
import { triggerCallbackOnAllNodes } from '@/utils/graphTraversalUtil'
import { addAfterConfigureHandler } from './graphConfigureUtil'
vi.mock('@/utils/litegraphUtil', () => ({
fixLinkInputSlots: vi.fn()
}))
vi.mock('@/utils/graphTraversalUtil', () => ({
triggerCallbackOnAllNodes: vi.fn()
}))
vi.mock('@/renderer/core/layout/store/layoutStore', () => ({
layoutStore: { setPendingSlotSync: vi.fn() }
}))
vi.mock(
'@/renderer/extensions/vueNodes/composables/useSlotElementTracking',
() => ({
flushScheduledSlotLayoutSync: vi.fn()
})
)
function createConfigureGraph(): LGraph {
return {
nodes: [],
onConfigure: vi.fn()
} satisfies Partial<LGraph> as unknown as LGraph
}
describe('addAfterConfigureHandler', () => {
beforeEach(() => {
vi.clearAllMocks()
})
it('runs legacy slot repair on configure', () => {
const graph = createConfigureGraph()
addAfterConfigureHandler(graph, () => undefined)
graph.onConfigure!.call(
graph,
{} as Parameters<NonNullable<LGraph['onConfigure']>>[0]
)
expect(fixLinkInputSlots).toHaveBeenCalledWith(graph)
})
it('runs onAfterGraphConfigured even if onConfigure throws', () => {
const graph = createConfigureGraph()
graph.onConfigure = vi.fn(() => {
throw new Error('onConfigure failed')
})
addAfterConfigureHandler(graph, () => undefined)
expect(() =>
graph.onConfigure!.call(
graph,
{} as Parameters<NonNullable<LGraph['onConfigure']>>[0]
)
).toThrow('onConfigure failed')
expect(triggerCallbackOnAllNodes).toHaveBeenCalledWith(
graph,
'onAfterGraphConfigured'
)
})
})