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
3 changes: 3 additions & 0 deletions browser_tests/tests/assetDeleteClearsLoadImage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,14 @@ baseTest.describe(

// Re-baseline the change tracker so the deletion-side mutation is the
// only thing that can flip `isModified` later.
// `reset()` re-baselines `initialState`; only `updateModified()`
// recomputes `isModified` from it.
await comfyPage.page.evaluate(() => {
const tracker =
window.app?.extensionManager?.workflow?.activeWorkflow
?.changeTracker
tracker?.reset?.()
tracker?.updateModified?.()
})
await expect
.poll(() => comfyPage.workflow.isCurrentWorkflowModified())
Expand Down
70 changes: 70 additions & 0 deletions browser_tests/tests/loadImageUploadPersistence.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* FE-1425: dropping an image on a Load Image node must survive a browser
* reload without an explicit save. `Comfy.Workflow.Persist` defaults to true
* and writes a localStorage draft on every `graphChanged`, but the upload
* commit never nudged the change tracker — and HTML5 drag-and-drop emits no
* mouseup for its global hook to catch — so the draft kept the previous image.
*/
import { expect } from '@playwright/test'

import { comfyPageFixture as test } from '@e2e/fixtures/ComfyPage'

const DROPPED_FILE = 'image64x64.webp'

test.describe('Load Image upload persistence', () => {
test('keeps a dropped image across a reload without saving', async ({
comfyPage,
comfyFiles
}) => {
test.setTimeout(60000)

await comfyPage.settings.setSetting('Comfy.Workflow.Persist', true)
await comfyPage.nodeOps.clearGraph()
await comfyPage.searchBoxV2.addNode('Load Image')

const [loadImageNode] =
await comfyPage.nodeOps.getNodeRefsByType('LoadImage')
const { x, y } = await loadImageNode.getPosition()

const readImageWidgetValue = () =>
comfyPage.page.evaluate(
() =>
window.app?.graph?.nodes
.find((node) => node.type === 'LoadImage')
?.widgets?.find((widget) => widget.name === 'image')?.value
)

// The server keeps the filename when the same bytes are uploaded again, so
// asserting on the name rather than on "the value changed" keeps this test
// correct whether or not a previous run already left the file behind.
await comfyPage.dragDrop.dragAndDropFile(DROPPED_FILE, {
dropPosition: { x, y },
waitForUpload: true
})
comfyFiles.deleteAfterTest({ filename: DROPPED_FILE, type: 'input' })

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggestion: drop this deleteAfterTest call. image64x64.webp is a shared fixture uploaded by six other specs (imagePreview, glslPreview, subgraphPromotion, maskEditorLoadSave, load3d, assetDeleteClearsLoadImage), and CI runs fullyParallel with 2 workers — deleting it from the server-global input folder mid-run can 404 another worker's preview-image fetch. The comment above already notes this test stays correct whether or not the file is left behind, so the deletion buys nothing here.


await expect.poll(readImageWidgetValue).toBe(DROPPED_FILE)

// The draft carrying the new value is what survives the reload, so waiting
// on it also covers the 512ms persist debounce.
await expect
.poll(
() =>
comfyPage.page.evaluate((expected) => {
for (let i = 0; i < window.localStorage.length; i++) {
const key = window.localStorage.key(i)
if (!key?.startsWith('Comfy.Workflow.Draft.v2:')) continue
if (window.localStorage.getItem(key)?.includes(expected))
return true
}
return false
}, DROPPED_FILE),
{ timeout: 10_000 }
)
.toBe(true)

await comfyPage.workflow.reloadAndWaitForApp()

await expect.poll(readImageWidgetValue).toBe(DROPPED_FILE)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ const mocks = vi.hoisted(() => ({
capturedUploadOptions: undefined as CapturedImageUploadOptions | undefined,
openFileSelection: vi.fn(),
setNodeOutputs: vi.fn(),
showPreview: vi.fn()
showPreview: vi.fn(),
captureCanvasState: vi.fn()
}))

vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
useWorkflowStore: () => ({
activeWorkflow: {
changeTracker: { captureCanvasState: mocks.captureCanvasState }
}
})
}))

vi.mock('@/composables/node/useNodeImage', () => ({
Expand Down Expand Up @@ -96,6 +105,7 @@ const outputFolderCases: {
describe('useImageUploadWidget', () => {
beforeEach(() => {
mocks.capturedUploadOptions = undefined
mocks.captureCanvasState.mockClear()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggestion: this line is redundant — vite.config.mts sets mockReset: true globally (line 744), so every mock is reset before each test. The sibling vi.fn()s in mocks don't get this treatment either.

vi.stubGlobal('requestAnimationFrame', vi.fn())
})

Expand Down Expand Up @@ -149,4 +159,47 @@ describe('useImageUploadWidget', () => {

expect(fileComboWidget.value).toBe(expected)
})

it('captures canvas state after upload so the draft persists the new value', () => {
const { fileComboWidget, node } = createUploadNode()
const constructor = useImageUploadWidget()

constructor(
node,
'upload',
[
'IMAGEUPLOAD',
{ imageInputName: 'image', image_upload: true }
] as InputSpec,
fromPartial({})
)

mocks.capturedUploadOptions?.onUploadComplete(['uploaded.png'])

expect(fileComboWidget.value).toBe('uploaded.png')
expect(mocks.captureCanvasState).toHaveBeenCalled()
})

it('captures canvas state when the server keeps the optimistic filename', () => {
const { fileComboWidget, node } = createUploadNode()
const constructor = useImageUploadWidget()

constructor(
node,
'upload',
[
'IMAGEUPLOAD',
{ imageInputName: 'image', image_upload: true }
] as InputSpec,
fromPartial({})
)

mocks.capturedUploadOptions?.onUploadStart?.([
new File([], 'uploaded.png', { type: 'image/png' })
])
mocks.capturedUploadOptions?.onUploadComplete(['uploaded.png'])

expect(fileComboWidget.value).toBe('uploaded.png')
expect(mocks.captureCanvasState).toHaveBeenCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import type { IComboWidget } from '@/lib/litegraph/src/types/widgets'
import type { ResultItem, ResultItemType } from '@/schemas/apiSchema'
import type { InputSpec } from '@/schemas/nodeDefSchema'
import { useWorkflowStore } from '@/platform/workflow/management/stores/workflowStore'
import type { ComfyWidgetConstructor } from '@/scripts/widgets'
import { useNodeOutputStore } from '@/stores/nodeOutputStore'
import { isImageUploadInput } from '@/types/nodeDefAugmentation'
Expand Down Expand Up @@ -97,6 +98,7 @@ export const useImageUploadWidget = () => {
oldValue,
fileComboWidget
)
useWorkflowStore().activeWorkflow?.changeTracker?.captureCanvasState()
}
})

Expand Down
Loading