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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions browser_tests/assets/vueNodes/agent-inserted-save-image.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"last_node_id": 9,
"last_link_id": 9,
"nodes": [
{
"id": "insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9",
"type": "SaveImage",
"pos": {
"0": 64,
"1": 104
},
"size": {
"0": 210,
"1": 58
},
"flags": {},
"order": 0,
"mode": 0,
"inputs": [
{
"name": "images",
"type": "IMAGE",
"link": null
}
],
"outputs": [],
"properties": {},
"widgets_values": ["ComfyUI"]
}
],
"links": [],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1,
"offset": [0, 0]
}
},
"version": 0.4
}
39 changes: 39 additions & 0 deletions browser_tests/tests/vueNodes/agentInsertedNodeOutputs.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { mergeTests } from '@playwright/test'

import {
comfyExpect as expect,
comfyPageFixture
} from '@e2e/fixtures/ComfyPage'
import { ExecutionHelper } from '@e2e/fixtures/helpers/ExecutionHelper'
import { webSocketFixture } from '@e2e/fixtures/ws'

const test = mergeTests(comfyPageFixture, webSocketFixture)

const INSERTED_NODE_ID = 'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9'

test.describe('Agent-inserted node outputs', { tag: '@vue-nodes' }, () => {
test('shows the executed image in an agent-inserted Save Image node', async ({
comfyPage,
getWebSocket
}) => {
const ws = await getWebSocket()
await comfyPage.workflow.loadWorkflow('vueNodes/agent-inserted-save-image')

const exec = new ExecutionHelper(comfyPage, ws)
const jobId = await exec.run()
exec.executionStart(jobId)
exec.executing(jobId, INSERTED_NODE_ID)
exec.executed(jobId, INSERTED_NODE_ID, {
images: [{ filename: 'example.png', subfolder: '', type: 'input' }]
})
exec.executing(jobId, null)
exec.executionSuccess(jobId)
exec.status(0)

await expect(
comfyPage.vueNodes
.getNodeByTitle('Save Image')
.getByRole('img', { name: 'View image 1 of 1' })
).toBeVisible()
})
})
98 changes: 93 additions & 5 deletions src/platform/workflow/management/stores/workflowStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { defaultGraph, defaultGraphJSON } from '@/scripts/defaultGraph'
import { useExecutionStore } from '@/stores/executionStore'
import { toNodeId } from '@/types/nodeId'
import type { NodeId } from '@/types/nodeId'
import type { NodeLocatorId } from '@/types/nodeIdentification'
import { createNodeLocatorId } from '@/types/nodeIdentification'
import { isValidUuid } from '@/utils/formatUtil'
import { syncEntities } from '@/utils/syncUtil'
Expand Down Expand Up @@ -1075,11 +1076,23 @@ describe('useWorkflowStore', () => {
expect(result).toBe('a1b2c3d4-e5f6-7890-abcd-ef1234567890:456')
})

it('should return simple node ID for root graph nodes', () => {
store.activeSubgraph = undefined
const result = store.nodeIdToNodeLocatorId(toNodeId(123))
expect(result).toBe('123')
})
it.for([
{ rawId: '', locatorId: '~root:' },
{
rawId: 'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9',
locatorId:
'~root:insert%3A0fbd38ecb13037d0b3b0ca78b8a20a5a%3Aroot%3Anode%3A9'
}
])(
'should key root node id $rawId under $locatorId',
({ rawId, locatorId }) => {
store.activeSubgraph = undefined
const result = store.nodeIdToNodeLocatorId(toNodeId(rawId))

expect(result).toBe(locatorId)
expect(store.nodeLocatorIdToNodeId(result)).toBe(rawId)
}
)

it('should use provided subgraph instead of active one', () => {
const customSubgraphId = '11111111-2222-4333-8444-555555555555'
Expand Down Expand Up @@ -1146,6 +1159,25 @@ describe('useWorkflowStore', () => {
)
expect(stringResult).toBe('node_1')
})

it('should decode an encoded root-leaf locator to its node id', () => {
const locatorId = createNodeLocatorId(
null,
'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9'
)
const result = store.nodeLocatorIdToNodeId(locatorId)
expect(result).toBe(
'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9'
)
})

it('should return null for an unparseable locator', () => {
const locatorId = fromAny<NodeLocatorId, string>(
'~subgraph:not-a-uuid:5'
)

expect(store.nodeLocatorIdToNodeId(locatorId)).toBeNull()
})
})

describe('nodeLocatorIdToNodeExecutionId', () => {
Expand Down Expand Up @@ -1179,6 +1211,62 @@ describe('useWorkflowStore', () => {
)
expect(result).toBeNull()
})

it('should return null for an unparseable locator', () => {
const locatorId = fromAny<NodeLocatorId, string>(
'~subgraph:not-a-uuid:5'
)

expect(store.nodeLocatorIdToNodeExecutionId(locatorId)).toBeNull()
})

it('should mint a leaf execution id from an encoded root-leaf locator', () => {
const locatorId = createNodeLocatorId(
null,
'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9'
)
const result = store.nodeLocatorIdToNodeExecutionId(locatorId)
expect(result).toBe(
'insert:0fbd38ecb13037d0b3b0ca78b8a20a5a:root:node:9'
)
})

it('should append an encoded subgraph leaf to its execution path', () => {
vi.mocked(isSubgraph).mockImplementation((obj): obj is Subgraph => {
return obj === store.activeSubgraph
})
const locatorId = createNodeLocatorId(
'a1b2c3d4-e5f6-7890-abcd-ef1234567890',
'insert:abc123:root:node:5'
)

const result = store.nodeLocatorIdToNodeExecutionId(locatorId)

expect(result).toBe('123:insert:abc123:root:node:5')
})

it('should preserve a colon-bearing subgraph host in the execution path', () => {
const subgraphUuid = '11111111-2222-4333-8444-555555555555'
const subgraph = fromPartial<Subgraph>({ id: subgraphUuid })
vi.mocked(comfyApp).rootGraph = fromPartial<LGraph>({
_nodes: [
createMockLGraphNode({
id: toNodeId('insert:op:root:node:3'),
isSubgraphNode: () => true,
subgraph
})
]
})
vi.mocked(isSubgraph).mockImplementation(
(graph): graph is Subgraph => graph === subgraph
)

expect(
store.nodeLocatorIdToNodeExecutionId(
createNodeLocatorId(subgraphUuid, toNodeId(7))
)
).toBe('insert:op:root:node:3:7')
})
})
})

Expand Down
19 changes: 9 additions & 10 deletions src/platform/workflow/management/stores/workflowStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ import { defaultGraph } from '@/scripts/defaultGraph'
import { useExecutionStore } from '@/stores/executionStore'
import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification'
import {
createNodeExecutionId,
createLeafNodeExecutionId,
createNodeLocatorId,
parseNodeExecutionId,
parseNodeLocatorId
parseNodeLocatorId,
tryNormalizeNodeExecutionId
} from '@/types/nodeIdentification'
import { parseNodeId } from '@/types/nodeId'
import type { NodeId } from '@/types/nodeId'
Expand Down Expand Up @@ -88,7 +89,7 @@ interface WorkflowStore {
executionIdToCurrentId: (id: string) => string | undefined
nodeIdToNodeLocatorId: (nodeId: NodeId, subgraph?: Subgraph) => NodeLocatorId
nodeToNodeLocatorId: (node: LGraphNode) => NodeLocatorId
nodeLocatorIdToNodeId: (locatorId: NodeLocatorId) => NodeId
nodeLocatorIdToNodeId: (locatorId: NodeLocatorId) => NodeId | null
nodeLocatorIdToNodeExecutionId: (
locatorId: NodeLocatorId,
targetSubgraph?: Subgraph
Expand Down Expand Up @@ -635,15 +636,14 @@ export const useWorkflowStore = defineStore('workflow', () => {
* Convert a node ID to a NodeLocatorId
* @param nodeId The local node ID
* @param subgraph The subgraph containing the node (defaults to active subgraph)
* @returns The NodeLocatorId (for root graph nodes, returns the node ID as-is)
* @returns The NodeLocatorId
*/
const nodeIdToNodeLocatorId = (
nodeId: NodeId,
subgraph?: Subgraph
): NodeLocatorId => {
const targetSubgraph = subgraph ?? activeSubgraph.value
if (!targetSubgraph) {
// Node is in the root graph, return the node ID as-is
return createNodeLocatorId(null, nodeId)
}

Expand All @@ -666,9 +666,8 @@ export const useWorkflowStore = defineStore('workflow', () => {
* @param locatorId The NodeLocatorId
* @returns The local node ID
*/
const nodeLocatorIdToNodeId = (locatorId: NodeLocatorId): NodeId => {
return parseNodeLocatorId(locatorId)!.localNodeId
}
const nodeLocatorIdToNodeId = (locatorId: NodeLocatorId): NodeId | null =>
parseNodeLocatorId(locatorId)?.localNodeId ?? null

/**
* Convert a NodeLocatorId to an execution ID for a specific context
Expand All @@ -687,7 +686,7 @@ export const useWorkflowStore = defineStore('workflow', () => {

// If no subgraph UUID, this is a root graph node
if (!subgraphUuid) {
return createNodeExecutionId([localNodeId])
return createLeafNodeExecutionId(localNodeId)
}

// Find the path from root to the subgraph with this UUID
Expand Down Expand Up @@ -730,7 +729,7 @@ export const useWorkflowStore = defineStore('workflow', () => {
return null
}

return createNodeExecutionId([...path, localNodeId])
return tryNormalizeNodeExecutionId([...path, localNodeId].join(':'))
}

return {
Expand Down
11 changes: 3 additions & 8 deletions src/renderer/extensions/vueNodes/components/LGraphNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ import { useRightSidePanelStore } from '@/stores/workspace/rightSidePanelStore'
import { isVideoOutput } from '@/utils/litegraphUtil'
import {
getNodeByLocatorId,
locatorIdFromState,
subgraphIdFromState
locatorIdFromState
} from '@/utils/graphTraversalUtil'
import { cn } from '@comfyorg/tailwind-utils'
import { toNodeId } from '@/types/nodeId'
Expand Down Expand Up @@ -637,11 +636,6 @@ const handleEnterSubgraph = () => {

const nodeOutputs = useNodeOutputStore()

const nodeOutputLocatorId = computed(() => {
const subgraphId = subgraphIdFromState(nodeData, canvasStore.rootGraphId)
return subgraphId ? `${subgraphId}:${nodeData.id}` : nodeData.id
})

function resolveLGraphNode() {
const locatorId = nodeLocatorId.value
if (!locatorId) return null
Expand Down Expand Up @@ -723,7 +717,8 @@ const hasVideoEditWidget = computed(() =>
)

const nodeMedia = computed(() => {
const newOutputs = nodeOutputs.nodeOutputs[nodeOutputLocatorId.value]
const locatorId = nodeLocatorId.value
const newOutputs = locatorId ? nodeOutputs.nodeOutputs[locatorId] : undefined
const node = lgraphNode.value

if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import {
useWidgetValueStore
} from '@/stores/widgetValueStore'
import {
createLeafNodeLocatorId,
createNodeExecutionId
createNodeExecutionId,
createNodeLocatorId
} from '@/types/nodeIdentification'
import type { NodeExecutionId, NodeLocatorId } from '@/types/nodeIdentification'
import type { NodeId } from '@/types/nodeId'
Expand Down Expand Up @@ -363,7 +363,7 @@ function widgetNodeLocatorId(
// prefix to collide with, so it can be kept whole (comfy-multi-player's
// insert_workflow remapped ids, PM-1580) via the leaf-tolerant path.
if (subgraphId && bareWidgetId.includes(':')) return undefined
return createLeafNodeLocatorId(subgraphId, bareWidgetId) ?? undefined
return createNodeLocatorId(subgraphId, bareWidgetId)
}

interface WidgetProcessingContext {
Expand Down
Loading
Loading