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
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,90 @@ describe('useWidgetSelectItems', () => {
})
})

describe('option preview URLs', () => {
it.for([
{ value: 'x.png', query: { filename: 'x.png', type: 'input' } },
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
{
value: 'sub/x.png',
query: { filename: 'x.png', type: 'input', subfolder: 'sub' }
},
{
value: 'a\\b\\x.png',
query: { filename: 'x.png', type: 'input', subfolder: 'a/b' }
}
])(
'previews the input option $value from its subfolder and filename',
({ value, query }) => {
const { dropdownItems } = useWidgetSelectItems(
createDefaultOptions({
values: () => [value],
modelValue: ref(value)
})
)

const previewUrl = dropdownItems.value[0].preview_url
assert(previewUrl)
const [path, search] = previewUrl.split('?')
expect(path).toBe('/api/view')
expect(Object.fromEntries(new URLSearchParams(search))).toEqual(query)
}
)

it.for(['../x.png', 'folder/./photo.png', '/abs/x.png', 'C:photo.png'])(
'shows no preview for the input option %s, which is not a plain relative path',
(value) => {
const { dropdownItems } = useWidgetSelectItems(
createDefaultOptions({
values: () => [value],
modelValue: ref(value)
})
)

expect(dropdownItems.value[0].preview_url).toBe('')
}
)

it.for([
{
title: 'an output in a subfolder',
tags: ['output'],
subfolder: 'sub',
query: { filename: 'photo.png', type: 'output', subfolder: 'sub' }
},
{
title: 'a generated temp output',
tags: ['output', 'temp'],
subfolder: 'previews',
query: { filename: 'photo.png', type: 'temp', subfolder: 'previews' }
}
])(
'falls back to a preview of $title from its root and subfolder',
async ({ tags, subfolder, query }) => {
mockMediaAssets.items.value = [
fromPartial({
id: 'asset-no-preview',
name: 'photo.png',
preview_url: '',
tags,
user_metadata: { subfolder }
})
]

const { dropdownItems, filterSelected } = useWidgetSelectItems(
createDefaultOptions({ values: () => [], modelValue: ref(undefined) })
)
filterSelected.value = 'outputs'
await nextTick()

const previewUrl = dropdownItems.value[0].preview_url
assert(previewUrl)
const [path, search] = previewUrl.split('?')
expect(path).toBe('/api/view')
expect(Object.fromEntries(new URLSearchParams(search))).toEqual(query)
}
)
})

describe('FE-228: output dropdown label uses human-readable filename', () => {
it('renders metadata.filename in label when asset.name is a hash', async () => {
mockMediaAssets.items.value = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export function useWidgetSelectItems(options: UseWidgetSelectItemsOptions) {
.filter((value) => !missing.has(String(value)))
.map((value, index) => ({
id: `input-${index}`,
preview_url: getMediaUrl(String(value), 'input', kind),
preview_url: getAnnotatedValueMediaUrl(String(value), kind),

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.

🟢 Low — Every input option now goes through getAnnotatedValueMediaUrl, which calls isPlainRelativePath. That function's drive-letter check /^[^\\/]:/ matches any value whose second character is :, so legal POSIX filenames like 1:1.png or 9:30.png lose their preview. The old getMediaUrl call gave them a working /api/view URL; now they get an empty preview_url. Tightening the check to a real drive prefix such as /^[A-Za-z]:[\\/]/ would keep the guard without this regression.

Raised by 3 of 6 reviewers (claude-opus-5-5-xhigh edge-case, gpt-5.6-sol-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.

Keeping the check as it is. It mirrors how ComfyUI joins the path on Windows: Python's ntpath treats any single character followed by : as a drive (ntpath.splitdrive('1:30.png') is ('1:', '30.png'), and ntpath.join('C:\\ComfyUI\\input', '1:30.png') drops the input folder). Restricting it to ASCII letters would request such names from the wrong place on Windows hosts. The cost is that a POSIX-only name with exactly one character before a colon gets no thumbnail, while 12:30.png and sub/1:30.png still preview. The same rule already applies to the fallback item (see the 1:/x.png case), and the option tests now pin it for input options in 4f34702.

name: String(value),
label: getDisplayLabel(String(value), labelFn)
}))
Expand Down Expand Up @@ -259,7 +259,8 @@ export function useWidgetSelectItems(options: UseWidgetSelectItemsOptions) {
preview_url:
kind === 'mesh'
? ''
: asset.preview_url || getMediaUrl(filenameForUrl, 'output', kind),
: asset.preview_url ||
getMediaUrl(filenameForUrl, rootFolder, kind, subfolder),
name: annotatedPath,
label: getDisplayLabel(displayLabel, labelFn)
})
Expand Down
Loading