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
148 changes: 148 additions & 0 deletions browser_tests/assets/widgets/image_crop_dynamic_inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
{
"id": "dadf4878-8f8f-41bc-bf4a-53714aaeede1",
"revision": 0,
"last_node_id": 2,
"last_link_id": 1,
"nodes": [
{
"id": 1,
"type": "LoadImage",
"pos": [50, 80],
"size": [282.798828125, 102],
"flags": {},
"order": 0,
"mode": 0,
"inputs": [
{
"localized_name": "image",
"name": "image",
"type": "COMBO",
"widget": {
"name": "image"
},
"link": null
},
{
"localized_name": "choose file to upload",
"name": "upload",
"type": "IMAGEUPLOAD",
"widget": {
"name": "upload"
},
"link": null
}
],
"outputs": [
{
"localized_name": "IMAGE",
"name": "IMAGE",
"type": "IMAGE",
"links": [1]
},
{
"localized_name": "MASK",
"name": "MASK",
"type": "MASK",
"links": null
}
],
"properties": {
"Node name for S&R": "LoadImage"
},
"widgets_values": ["example.png", "image"],
"widgets_values_named": {
"image": "example.png",
"upload": "image"
}
},
{
"id": 2,
"type": "DynamicInputImageCrop",
"pos": [450, 80],
"size": [400, 500],
"flags": {},
"order": 1,
"mode": 0,
"inputs": [
{
"localized_name": "image_1",
"name": "model.images.image_1",
"type": "IMAGE",
"link": 1
},
{
"localized_name": "image_2",
"name": "model.images.image_2",
"shape": 7,
"type": "IMAGE",
"link": null
},
{
"localized_name": "region",
"name": "model.region",
"type": "BOUNDING_BOX",
"widget": {
"name": "model.region"
},
"link": null
},
{
"localized_name": "model",
"name": "model",
"type": "COMFY_DYNAMICCOMBO_V3",
"widget": {
"name": "model"
},
"link": null
}
],
"outputs": [
{
"localized_name": "IMAGE",
"name": "IMAGE",
"type": "IMAGE",
"links": null
}
],
"properties": {
"Node name for S&R": "DynamicInputImageCrop"
},
"widgets_values": [
"Crop",
{
"x": 0,
"y": 0,
"width": 512,
"height": 512
},
0,
0,
512,
512
],
"widgets_values_named": {
"model": "Crop",
"model.region": {
"x": 0,
"y": 0,
"width": 512,
"height": 512
},
"x": 0,
"y": 0,
"width": 512,
"height": 512
}
}
],
"links": [[1, 1, 0, 2, 0, "IMAGE"]],
"groups": [],
"config": {},
"extra": {
"ds": {
"scale": 1,
"offset": [0, 0]
}
},
"version": 0.4
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import {
comfyExpect as expect,
comfyPageFixture
} from '@e2e/fixtures/ComfyPage'
import type { ComfyNodeDef } from '@/schemas/nodeDefSchema'

const test = comfyPageFixture.extend({
page: async ({ page }, use) => {
await page.route('**/object_info', async (route) => {
const response = await route.fetch()
const definitions: Record<string, ComfyNodeDef> = await response.json()
const cropNode: ComfyNodeDef = {
name: 'DynamicInputImageCrop',
display_name: 'Dynamic Input Image Crop',
category: 'testing',
python_module: 'nodes',
description: '',
input: {
required: {
model: [
'COMFY_DYNAMICCOMBO_V3',
{
options: [
{
key: 'Crop',
inputs: {
required: {
images: [
'COMFY_AUTOGROW_V3',
{
template: {
input: { required: { image: ['IMAGE', {}] } },
names: ['image_1', 'image_2'],
min: 1
}
}
],
region: ['BOUNDING_BOX', { component: 'ImageCrop' }]
}
}
}
]
}
]
}
},
output: ['IMAGE'],
output_name: ['IMAGE'],
output_node: false
}
await route.fulfill({
response,
json: { ...definitions, [cropNode.name]: cropNode }
})
})
await use(page)
}
})

test.describe(
'Image Crop with dynamic inputs',
{ tag: ['@widget', '@vue-nodes'] },
() => {
test('shows the connected image after reopening a dynamic-input crop node', async ({
comfyPage
}) => {
await comfyPage.workflow.loadWorkflow('widgets/image_crop_dynamic_inputs')

const cropNode = comfyPage.vueNodes.getNodeLocator('2')
await expect(cropNode).toBeVisible()
await expect.soft(cropNode.getByTestId('crop-overlay')).toBeVisible()
await expect.soft(cropNode.getByTestId('crop-empty-state')).toBeHidden()
})
}
)
89 changes: 81 additions & 8 deletions src/composables/useImageCrop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

import WidgetImageCrop from '@/components/imagecrop/WidgetImageCrop.vue'
import type { LGraphCanvas, LGraphNode } from '@/lib/litegraph/src/litegraph'
import {
createTestSubgraph,

Check warning on line 14 in src/composables/useImageCrop.test.ts

View workflow job for this annotation

GitHub Actions / fallow / fallow

Boundary violation

Import from zone 'image-crop/application' to zone 'subgraphs/integration' is not allowed. src/composables/useImageCrop.test.ts -> src/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers.ts Route the import through an allowed zone or restructure the dependency.
createTestSubgraphNode
} from '@/lib/litegraph/src/subgraph/__fixtures__/subgraphHelpers'
import { useLinkStore } from '@/stores/linkStore'
import { graphScopeOf } from '@comfyorg/graph-model/graphScopeId'
import { toLinkId } from '@comfyorg/graph-model/linkId'
Expand Down Expand Up @@ -240,6 +244,7 @@
})
cropNode = createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => sourceNode),
getInputLink: vi.fn(() => ({ origin_slot: 0 })),
isSubgraphNode: () => false
Expand Down Expand Up @@ -283,14 +288,11 @@
})
}

/**
* Resolves the image input through the link store, the way
* `LGraphNode.getInputLink` does, so link edits drive the preview.
*/
function useLinkedCropNode() {
function useLinkedCropNode(inputs = [{ name: 'image', type: 'IMAGE' }]) {
const linkStore = useLinkStore()
cropNode = createMockLGraphNode({
id: CROP_NODE_ID,
inputs,
isSubgraphNode: () => false,
getInputLink: (slot: number) =>
linkStore.getInputSlotLink(GRAPH_SCOPE, CROP_NODE_ID, slot) ?? null,
Expand All @@ -302,15 +304,15 @@
mockResolveNode.mockReturnValue(cropNode)
}

function connectImageInput() {
function connectImageInput(targetSlot = 0, type = 'IMAGE') {
useLinkStore().registerLink(GRAPH_SCOPE, {
id: toLinkId(1),
graphId: GRAPH_SCOPE.owningGraphId,
originNodeId: toNodeId(99),
originSlot: 0,
targetNodeId: CROP_NODE_ID,
targetSlot: 0,
type: 'IMAGE'
targetSlot,
type
})
}

Expand All @@ -336,6 +338,7 @@
it('returns null image URL when there is no input node', async () => {
const alone = createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => null),
getInputLink: vi.fn(),
isSubgraphNode: () => false
Expand All @@ -352,6 +355,7 @@
})
const sgCrop = createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => subgraphInput),
getInputLink: vi.fn(() => null),
isSubgraphNode: () => false
Expand All @@ -373,6 +377,7 @@

const sgCrop = createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => subgraphInput),
getInputLink: vi.fn(() => ({ origin_slot: 0 })),
isSubgraphNode: () => false
Expand Down Expand Up @@ -420,6 +425,7 @@
mockResolveNode.mockReturnValue(
createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => reloadedSource),
getInputLink: vi.fn(() => ({ origin_slot: 0 })),
isSubgraphNode: () => false
Expand All @@ -446,6 +452,72 @@
expect(vm.imageUrl).toBe('https://example.com/a.png')
})

it('shows the image connected after mount to a first input not typed IMAGE', async () => {
useLinkedCropNode([{ name: 'image', type: '*' }])
const vm = await mountHarness()

connectImageInput(0)
await flushTicks()

expect(vm.imageUrl).toBe('https://example.com/a.png')
})

it('shows the upstream image when the image input is not the first input, as after reopening a dynamic-input node', async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 High — This regression test links the image at target slot 1, but the diff contains no production change. useImageCrop.ts still calls resolveInputSourceNode(cropNode, IMAGE_INPUT_SLOT) with IMAGE_INPUT_SLOT = 0, and slot 0 is the unlinked model input here, so imageUrl stays null. That fails this test and the new E2E assertion in imageCropDynamicInputs.spec.ts (crop overlay visible / empty state hidden), and the bug itself is still there: a reopened dynamic-input crop node shows the empty state. The inputs arrays added to every mock are also unused by the current source. Resolve the image slot by input type (for example, the first linked IMAGE input) in useImageCrop.ts before merging. If this is meant as the red step of a red-then-green sequence, the fix still has to land in this PR. Raised by 4 of 6 reviewers (claude-opus-5-5-xhigh adversarial, gpt-5.6-sol-xhigh adversarial, claude-opus-5-5-xhigh edge-case, kimi-k3-high edge-case).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed by 6e8229a. That was the test-only red commit on purpose; the fix resolves the first IMAGE input and the new tests pass in CI. The "first linked" variant is not adopted: it keeps the input a freshly created node used (see the round 2 thread).

useLinkedCropNode([
{ name: 'model', type: 'COMFY_DYNAMICCOMBO_V3' },
{ name: 'model.images.image_1', type: 'IMAGE' },
{ name: 'model.images.image_2', type: 'IMAGE' },
{ name: 'model.region', type: 'BOUNDING_BOX' }
])
connectImageInput(1)

const vm = await mountHarness()

expect(vm.imageUrl).toBe('https://example.com/a.png')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})

it('shows the image from a union input before a later IMAGE input', async () => {
useLinkedCropNode([
{ name: 'image', type: 'IMAGE,MASK' },
{ name: 'reference', type: 'IMAGE' }
])
connectImageInput(0)

const vm = await mountHarness()

expect(vm.imageUrl).toBe('https://example.com/a.png')
})

it('shows an empty preview on a subgraph host with a later image input', async () => {
const subgraph = createTestSubgraph({
inputs: [
{ name: 'prompt', type: 'STRING' },
{ name: 'image', type: 'IMAGE' }
],
outputs: [{ name: 'out', type: 'IMAGE' }]
})
const host = createTestSubgraphNode(subgraph, { id: 2 })
mockResolveNode.mockReturnValue(host)

const vm = await mountHarness()

expect(vm.imageUrl).toBeNull()
})

it('shows the image connected to a custom input type through the slot-0 fallback', async () => {
sourceNode = createMockLGraphNode({
id: 99,
isSubgraphNode: () => false,
outputs: [{ name: 'image', type: 'CUSTOM_IMAGE' }]
})
useLinkedCropNode([{ name: 'image', type: 'CUSTOM_IMAGE' }])
connectImageInput(0, 'CUSTOM_IMAGE')

const vm = await mountHarness()

expect(vm.imageUrl).toBe('https://example.com/a.png')
})

Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
it('clears the preview when the image input is disconnected', async () => {
useLinkedCropNode()
connectImageInput()
Expand Down Expand Up @@ -790,6 +862,7 @@
const source = createMockLGraphNode({ id: 99, isSubgraphNode: () => false })
const crop = createMockLGraphNode({
id: 2,
inputs: [{ name: 'image', type: 'IMAGE' }],
getInputNode: vi.fn(() => source),
getInputLink: vi.fn(),
isSubgraphNode: () => false
Expand Down
Loading
Loading