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
2 changes: 1 addition & 1 deletion browser_tests/fixtures/data/assetFixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const AGENT_AUDIO_ASSET: Asset = createOutputAsset({
last_access_time: '2026-09-18T00:00:00.000Z'
})

export const STALE_TEMP_FILENAME = 'ComfyUI_temp_thsmm_00001_.png'
const STALE_TEMP_FILENAME = 'ComfyUI_temp_thsmm_00001_.png'
export const STALE_TEMP_CARD_TEXT = STALE_TEMP_FILENAME.replace(/\.[^.]+$/, '')
export const STALE_TEMP_ASSET: Asset = createOutputAsset({
id: '55555555-5555-4555-a555-555555555555',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import {
} from '@e2e/fixtures/ComfyPage'
import {
STALE_TEMP_ASSET,
STALE_TEMP_CARD_TEXT,
STALE_TEMP_FILENAME
STALE_TEMP_CARD_TEXT
} from '@e2e/fixtures/data/assetFixtures'
import { TestIds } from '@e2e/fixtures/selectors'
import { assetPath } from '@e2e/fixtures/utils/paths'
Expand Down Expand Up @@ -50,9 +49,9 @@ test.describe(
const url = new URL(route.request().url())
const filename = url.searchParams.get('filename')
if (
(filename === STALE_TEMP_FILENAME &&
(filename === STALE_TEMP_ASSET.hash &&
(!tempAvailable || url.searchParams.get('type') !== 'temp')) ||
filename === `${STALE_TEMP_FILENAME} [temp]`
filename === `${STALE_TEMP_ASSET.hash} [temp]`
) {
return route.fulfill({ status: 404 })
}
Expand All @@ -64,7 +63,7 @@ test.describe(
const imageWidget = await loadImageNodeRef.getWidgetByName('image')
await expect
.poll(() => imageWidget.getValue())
.toBe(`${STALE_TEMP_FILENAME} [temp]`)
.toBe(`${STALE_TEMP_ASSET.hash} [temp]`)
})

await test.step('Show the dropped asset preview', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ for (const route of [
shape: 'an expanded-stack child at the root folder',
asset: TEMP_STACK_PREVIEW,
reveal: inExpandedStack(1),
written: `${TEMP_STACK_PREVIEW.name} [temp]`,
written: `${TEMP_STACK_PREVIEW.hash} [temp]`,
controls: rootControls(TEMP_STACK_PREVIEW)
},
{
Expand Down Expand Up @@ -242,28 +242,28 @@ for (const route of [
shape: 'an expanded-stack child at the root folder',
asset: TEMP_STACK_PREVIEW,
reveal: inExpandedStack(1),
written: `${TEMP_STACK_PREVIEW.name} [temp]`,
written: `${TEMP_STACK_PREVIEW.hash} [temp]`,
controls: rootControls(TEMP_STACK_PREVIEW)
},
{
shape: 'an expanded-stack child whose metadata names only its subfolder',
asset: TEMP_FOLDER_PREVIEW,
reveal: inExpandedStack(0),
written: `previews/${TEMP_FOLDER_PREVIEW.name} [temp]`,
written: `previews/${TEMP_FOLDER_PREVIEW.hash} [temp]`,
controls: folderControls(TEMP_FOLDER_PREVIEW)
},
{
shape: 'a card with no job at the root folder',
asset: FLAT_TEMP_ASSET,
reveal: asCard,
written: `${FLAT_TEMP_ASSET.name} [temp]`,
written: `${FLAT_TEMP_ASSET.hash} [temp]`,
controls: rootControls(FLAT_TEMP_ASSET)
},
{
shape: 'a card with no job whose metadata names only its subfolder',
asset: FLAT_FOLDER_TEMP_ASSET,
reveal: asCard,
written: `previews/${FLAT_FOLDER_TEMP_ASSET.name} [temp]`,
written: `previews/${FLAT_FOLDER_TEMP_ASSET.hash} [temp]`,
controls: folderControls(FLAT_FOLDER_TEMP_ASSET)
}
]) {
Expand Down
84 changes: 59 additions & 25 deletions src/composables/node/useNodeDragAndDrop.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,31 +222,65 @@ describe('useNodeDragAndDrop', () => {
expect(onDrop.mock.calls[0][0][0].name).toBe('uri.png')
})

it('onDragDrop names a fetched asset-card file after its asset-info filename', async () => {
const onDrop = vi.fn().mockResolvedValue([])
vi.mocked(fetch).mockResolvedValue(
fromAny<Response, unknown>({
ok: true,
blob: vi
.fn()
.mockResolvedValue(new Blob(['uri'], { type: 'audio/wav' }))
})
)

const node = createNode()
useNodeDragAndDrop(node, { onDrop })

const result = await node.onDragDrop?.(
createDragEvent({
uri: `${location.origin}/api/assets/asset-1/content`,
types: ['text/uri-list', MIME_ASSET_INFO],
assetInfo: JSON.stringify({ filename: 'clip.wav' })
})
)

expect(result).toBe(true)
expect(onDrop.mock.calls[0][0][0].name).toBe('clip.wav')
})
it.for([
{ assetInfo: { filename: 'clip.wav' }, name: 'clip.wav' },
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: 'clip.wav' },
name: 'clip.wav'
},
{
assetInfo: { filename: 'clip.wav', display_name: 'renders/clip.wav' },
name: 'clip.wav'
},
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: 'My clip' },
name: 'aa7ecf08.wav'
},
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: 'clip.mp3' },
name: 'aa7ecf08.wav'
},
{ assetInfo: { filename: 'clip.wav', display_name: '' }, name: 'clip.wav' },
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: 'Take.WAV' },
name: 'Take.WAV'
},
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: '..\\clip.wav' },
name: 'aa7ecf08.wav'
},
{
assetInfo: { filename: 'aa7ecf08.wav', display_name: 'Take 1: clip.wav' },
name: 'aa7ecf08.wav'
}
])(
'onDragDrop names a fetched asset-card file $name from asset info $assetInfo',
async ({ assetInfo, name }) => {
const onDrop = vi.fn().mockResolvedValue([])
vi.mocked(fetch).mockResolvedValue(
fromAny<Response, unknown>({
ok: true,
blob: vi
.fn()
.mockResolvedValue(new Blob(['uri'], { type: 'audio/wav' }))
})
)

const node = createNode()
useNodeDragAndDrop(node, { onDrop })

const result = await node.onDragDrop?.(
createDragEvent({
uri: `${location.origin}/api/assets/asset-1/content`,
types: ['text/uri-list', MIME_ASSET_INFO],
assetInfo: JSON.stringify(assetInfo)
})
)

expect(result).toBe(true)
expect(onDrop.mock.calls[0][0][0].name).toBe(name)
}
)

it('onDragDrop returns false for cross-origin uri drops', async () => {
const node = createNode()
Expand Down
23 changes: 22 additions & 1 deletion src/composables/node/useNodeDragAndDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,29 @@ import type { LGraphNode } from '@/lib/litegraph/src/litegraph'
import { parseAssetInfo } from '@/platform/assets/schemas/mediaAssetSchema'
import type { ResultItem } from '@comfyorg/api-client/executionTypes'
import { withHdrImageType } from '@/utils/eventUtils'
import { getPathDetails } from '@/utils/formatUtil'
import { parseUrl } from '@/utils/urlSafety'

const UNSAFE_FILENAME_CHARACTERS = /[\\:*?"<>|]/
Comment thread
jaeone94 marked this conversation as resolved.
Resolved

function getLowercaseSuffix(filename: string): string | undefined {
return getPathDetails(filename).suffix?.toLowerCase()
}

function getFetchedAssetFileName({
filename,
display_name
}: ResultItem): string | undefined {
if (!filename || !display_name) return filename
const label = getPathDetails(display_name).fullFilename
const labelSuffix = getLowercaseSuffix(label)
return labelSuffix &&
labelSuffix === getLowercaseSuffix(filename) &&
!UNSAFE_FILENAME_CHARACTERS.test(label)
? label
: filename
}

type DragHandler = (e: DragEvent) => boolean
type DropHandler<T> = (files: File[]) => Promise<T[]>

Expand Down Expand Up @@ -77,7 +98,7 @@ export const useNodeDragAndDrop = <T>(
try {
const resp = await fetch(uri)
const fileName =
asset?.filename ??
(asset && getFetchedAssetFileName(asset)) ??
uri.searchParams.get('filename') ??
baseUri.split('/').at(-1)
if (!fileName || !resp.ok) return false
Expand Down
4 changes: 3 additions & 1 deletion src/platform/assets/components/MediaAssetCard.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ describe('MediaAssetCard', () => {
})

it('includes the asset metadata with display_name in the drag payload', () => {
const { container } = renderCard()
const { container } = renderCard({
asset: { ...asset, display_name: 'Display A', tags: ['output'] }
})

const { event, add } = dispatchDragStart(container)

Expand Down
78 changes: 74 additions & 4 deletions src/platform/assets/composables/useMediaAssetActions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2619,7 +2619,7 @@ describe('useMediaAssetActions', () => {
'tag temp',
insertAsNode,
() => tempAsset,
'previews/ComfyUI_temp_00001_.png [temp]'
'previews/aa7ecf08.png [temp]'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
],
[
'inserted as a node',
Expand All @@ -2633,7 +2633,7 @@ describe('useMediaAssetActions', () => {
'tag temp',
dropOnLoadImage,
() => atRoot(tempAsset),
'ComfyUI_temp_00001_.png [temp]'
'aa7ecf08.png [temp]'
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
],
[
'dropped on Load Image',
Expand All @@ -2647,7 +2647,7 @@ describe('useMediaAssetActions', () => {
'tag temp in a subfolder',
dropOnLoadImage,
() => tempAsset,
'previews/ComfyUI_temp_00001_.png [temp]'
'previews/aa7ecf08.png [temp]'
],
[
'dropped on Load Image',
Expand All @@ -2657,7 +2657,7 @@ describe('useMediaAssetActions', () => {
'previews/ComfyUI_temp_00003_.png [temp]'
]
] as const)(
'writes the temp root for a child %s from an asset with %s, so deleting the child clears it',
'writes the temp root and stored filename for a child %s from an asset with %s, so deleting the child clears it',
async ([, , writeReference, source, written]) => {
const child = await expandedChildOf(source())
const { actions, node } = await writeReference(child)
Expand All @@ -2669,6 +2669,76 @@ describe('useMediaAssetActions', () => {
expect(referenceState(node)).toEqual(cleared(written))
}
)

describe('of a job with several outputs', () => {
const firstOutput = createMockAsset({
job_id: 'job-3',
created_at: '2026-01-01T00:00:00Z',
id: 'first-output',
name: 'ComfyUI_00001_.png',
hash: '1a2b3c4d.png',
tags: ['output'],
user_metadata: { jobId: 'job-3', subfolder: '' }
})
const coverOutput = createMockAsset({
job_id: 'job-3',
created_at: '2026-01-01T00:00:01Z',
id: 'cover-output',
name: 'ComfyUI_00002_.png',
hash: '5e6f7a8b.png',
tags: ['output'],
user_metadata: { jobId: 'job-3', subfolder: '' }
})

async function expandedFirstOutput() {
mockResolveOutputAssetItems.mockRestore()
vi.mocked(api.getJobAssets).mockResolvedValue({
assets: [firstOutput, coverOutput].map((output) =>
fromPartial({ id: output.id, name: output.name })
),
complete: true
})
const [group] = unflattenOutputAssets([firstOutput, coverOutput])
const groupMetadata = getOutputAssetMetadata(group.user_metadata)
assert.exists(groupMetadata)
const children = await resolveOutputAssetItems(groupMetadata)
const child = children.find(({ id }) => id === firstOutput.id)
assert.exists(child)
return child
}

it.for([
['inserted as a node', insertAsNode],
['dropped on Load Image', dropOnLoadImage]
] as const)(
'writes a non-cover output %s by its own hash',
async ([, writeReference]) => {
const { node } = await writeReference(await expandedFirstOutput())

expect(serializedImageValue(node)).toBe('1a2b3c4d.png [output]')
}
)

it('drags a non-cover output with its hash as the attachment reference', async () => {
const dataTransfer = new DataTransfer()
const event = new DragEvent('dragstart')
Object.defineProperty(event, 'dataTransfer', { value: dataTransfer })

startAssetDrag(event, await expandedFirstOutput())

expect(parseAssetInfo(dataTransfer)?.attachment_ref).toBe(
'1a2b3c4d.png'
)
})

it('drops the cover card as the cover output by its hash', async () => {
const [group] = unflattenOutputAssets([firstOutput, coverOutput])

const { node } = await dropOnLoadImage(group)

expect(serializedImageValue(node)).toBe('5e6f7a8b.png [output]')
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
})
})
})

it('ignores stored identity fields supplied in server metadata', async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/platform/assets/composables/useMediaAssetActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ function createAssetWidgetPath(asset: AssetItem): string {
: getAssetType(asset, 'input')

return createAnnotatedPath({
filename: getAssetStoredFilename(asset),
filename: getAssetStoredFilename(
Comment thread
jaeone94 marked this conversation as resolved.
Resolved
asset,
asset.hash ?? getStoredOutputIdentity(asset)?.hash
),
subfolder: getOutputSubfolder(asset) ?? '',
type: isResultItemType(assetType) ? assetType : undefined
})
Expand Down
30 changes: 11 additions & 19 deletions src/platform/assets/utils/assetDragUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ import {
getAssetType,
isGeneratedTempOutput
} from '@/platform/assets/composables/media/assetMappers'
import { getOutputAssetMetadata } from '@/platform/assets/schemas/assetMetadataSchema'
import type { AssetItem } from '@/platform/assets/schemas/assetSchema'
import { MIME_ASSET_INFO } from '@/platform/assets/schemas/mediaAssetSchema'
import { getAssetUrlFilename, getOutputSubfolder } from './assetMetadataUtils'
import { getStoredOutputIdentity } from '@/platform/assets/utils/outputAssetUtil'
import {
getAssetStoredFilename,
getOutputSubfolder
} from './assetMetadataUtils'
import { resolvePreviewUrl } from './assetPreviewUtil'
import { getAssetFileUrl } from './assetUrlUtil'
import { parseUrl } from '@/utils/urlSafety'
Expand Down Expand Up @@ -76,24 +79,13 @@ export function startAssetDrag(
const { dataTransfer } = event
if (!dataTransfer) return

const output = getOutputAssetMetadata(asset.user_metadata)?.allOutputs?.[0]
const storedHash = asset.hash ?? getStoredOutputIdentity(asset)?.hash
const assetInfo = {
...(output?.filename
? {
filename: output.filename,
subfolder: output.subfolder,
type: output.type,
display_name: output.display_name
}
: {
filename: asset.name,
subfolder: getOutputSubfolder(asset),
type: isGeneratedTempOutput(asset)
? 'temp'
: getAssetType(asset.tags),
display_name: asset.display_name ?? undefined
}),
attachment_ref: getAssetUrlFilename(asset),
filename: getAssetStoredFilename(asset, storedHash),

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.

issue: [CONFIRMED from existing CI] This changes Cloud drag values to stored hashes, but the browser regressions still expect human filenames. Current Cloud shard 4 fails seven cases in assetPanelDragOntoLoadImageWidget.spec.ts and tempAssetWorkflowRoutesThenDelete.spec.ts; for example, the former expects ComfyUI_temp_thsmm_00001_.png [temp] and receives blake3:222… [temp]. The expanded-child insertion case is affected by the matching change in createAssetWidgetPath too. Could we update the Cloud fixtures, expected widget values and /view route matching together, preserving the temp-root, preview and deletion assertions? In particular, the unavailable-temp mock currently rejects only STALE_TEMP_FILENAME, so updating the value assertion alone would stop exercising the intended 404 path. Existing failure log: https://github.com/Comfy-Org/ComfyUI_frontend/actions/runs/42861169062/job/129989949572 . No tests were run for this review.

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.

Thanks, confirmed. The writes are right and the expectations were stale: Cloud /view (ViewFile) looks a file up by hash only and ignores type and subfolder, so stack_temp.png [temp] would not load on a real Cloud backend, while the group-card insert and dropdown routes on main already wrote <hash> [temp]. 0bc0de90e9 updates the seven cases in tempAssetWorkflowRoutesThenDelete.spec.ts and assetPanelDragOntoLoadImageWidget.spec.ts to the stored hash, including the /view route match in the latter, and unexports the now-unused STALE_TEMP_FILENAME. Both specs pass locally on a build:cloud dist (13/13), including the delete and survivor assertions.

subfolder: getOutputSubfolder(asset),
type: isGeneratedTempOutput(asset) ? 'temp' : getAssetType(asset.tags),
Comment thread
jaeone94 marked this conversation as resolved.
Resolved
display_name: asset.display_name || asset.name,
Comment thread
jaeone94 marked this conversation as resolved.
Resolved
attachment_ref: storedHash ?? asset.name,
...assetMediaSources(asset)
}
dataTransfer.setData(MIME_ASSET_INFO, JSON.stringify(assetInfo))
Expand Down
Loading
Loading