Skip to content
Open
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: 2 additions & 0 deletions src/utils/__tests__/eventUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ describe('eventUtils', () => {

expect(getDroppedAsset(dataTransfer)).toEqual({
name: 'My asset',
filename: 'asset.png',
uri: 'http://localhost/api/view?x=1',
ref: 'stored-asset.png',
kind: 'image',
Expand All @@ -234,6 +235,7 @@ describe('eventUtils', () => {

expect(getDroppedAsset(dataTransfer)).toEqual({
name: 'asset.mp4',
filename: 'asset.mp4',
uri: undefined,
ref: 'stored-asset.mp4',
kind: 'video',
Expand Down
5 changes: 4 additions & 1 deletion src/utils/eventUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { isHdrImageFilename } from '@/utils/hdrFormatUtil'

export interface DroppedAsset {
name: string
filename?: string

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.

P3 Nit. DroppedAsset now has name, which holds the display label (display_name ?? filename ?? ref ?? uri), right next to filename, which holds the stored name. Nothing on the type says which is which, and the bug this PR fixes came from judging a card by name as if it were the file name. Renaming name to label would make the two read differently at every use in AgentPanelRoot.vue (lines 1857-1901). Prose because the rename touches unchanged lines in two files. It would fit in the deferred T7/T8 move.

uri?: string
ref?: string
kind?: MediaKind
Expand All @@ -26,6 +27,7 @@ export function getDroppedAsset(
return uri || ref
? {
name: name ?? ref ?? uri!,
filename: asset?.filename,

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.

P3 Nit. zResultItem.filename is z.string().optional(), so a payload can carry filename: '', for example from another tab, another frontend version, or an asset with an empty name. droppedAssetVerdict then passes '' through ??, gets unknown, and never looks at the label. sourceFileName skips the empty string instead. With label brief.pdf and filename: '', head returns unknown where base returned rejected. Normalizing at the parse gives both readers the same meaning of "no stored name".

Suggested change
filename: asset?.filename,
filename: asset?.filename || undefined,

uri,
ref,
kind: asset?.media_kind,
Expand All @@ -45,13 +47,14 @@ function decodedBasename(pathname: string): string {
}

function sourceFileName(
{ name, ref }: DroppedAsset,
{ name, filename, ref }: DroppedAsset,
uri: string,
responseUrl: string
): string {
const resolvedUrl = new URL(responseUrl || uri, 'http://localhost')
const named = [
resolvedUrl.searchParams.get('filename'),
filename,

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.

P2, question. Putting the stored name first here changes what the user sees on cloud. addDeferredFile stages the chip under the label, and once the download finishes uploadFile runs options.update(id, { name: file.name }) (useAttachment.ts:310-313), so the chip switches to this name. On cloud the stored name is the hash (abcdef0123456789.heic in your own test).

Before this PR, a card labelled Holiday.heic was uploaded as Holiday.heic and kept that chip. Now it is uploaded as the hash, and the chip turns into the hash partway through the upload. Cards staged by ref keep their label, so one turn can mix labels and hashes. I reproduced the naming half with the real startAssetDrag payload: head names the file abc.heic, base named it Holiday.heic. This also contradicts "No screenshots, because no UI changed" in the description.

Which name should the user see? The options I see:

  • keep the label for the chip and the upload when its extension matches the stored one, and fall back to the stored name only when the label has no extension or a different one
  • upload as <label stem>.<stored extension>
  • keep the stored name, and add before/after screenshots of the chip to the description

Prose because this needs a product decision.

ref,
decodedBasename(resolvedUrl.pathname),
name
Expand Down
72 changes: 72 additions & 0 deletions src/workbench/extensions/agent/AgentPanelRoot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4312,6 +4312,78 @@ describe('AgentPanelRoot attach flow', () => {
expect(useToast().toasts).toEqual([])

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.

P2. The test this line closes (line 4290) is the only one that pits a ref with an extension against a different filename, which is the "ref first" half of the order in the PR description. It checks only that a group named renamed.usdz exists and that no toast appeared. A refused chip renders the same group with no toast. So if droppedAssetVerdict judged filename before ref, this test and the other attach-flow tests would still pass (10 passed in my run). Asserting the staged ref catches it: under that mutation it fails with - "ref": "stored.png" + "ref": "".

The title also clashes with this PR's wording. The new tests use "stored file name" for filename, while judges an asset by its stored filename rather than its display label means the ref. A title like judges an asset by its ref ahead of its file name would match what it checks. Line 4290 is outside the diff, so I can't put that in a suggestion.

Suggested change
expect(useToast().toasts).toEqual([])
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({ name: 'renamed.usdz', ref: 'stored.png' })
])
expect(useToast().toasts).toEqual([])

})

it.for(['Flux.dev', 'render.v2', 'Upscale 1.5x'])(
'attaches a hashed image card labelled %s by its stored file name',
Comment on lines +4315 to +4316

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.

P3. The three labels take one path. On main each has an extension the panel does not accept, so agentAttachVerdict(label) returned rejected. With the fix all three are judged by the stored .png. Every mutation I ran failed all three rows together or none of them, so two of the rows add runtime without catching anything the first one misses.

The body also repeats the existing producer-payload table at line 2674 (same assetPanelDrag, drop, attachments equality and empty uploaded), apart from the hash and name overrides. I'd add one row there, for example { displayName: 'Flux.dev', overrides: { name: 'abcdef0123456789.png', hash: 'blake3:abcdef0123456789' }, label: 'Flux.dev', ref: 'blake3:abcdef0123456789' }, give the existing rows overrides: {} and ref: 'stored-library.png', pass overrides to assetPanelDrag, assert ref, and delete this it.for. Prose because the change spans this block and the table at lines 2674-2708.

async (label) => {
const uploaded = stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag(label, {
name: 'abcdef0123456789.png',
hash: 'blake3:abcdef0123456789'
})

dispatchDrag(screen.getByRole('textbox'), 'drop', data)

await screen.findByRole('group', { name: label })
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: label,
ref: 'blake3:abcdef0123456789'
})
])
expect(screen.queryByRole('status')).not.toBeInTheDocument()
await userEvent.type(screen.getByRole('textbox'), 'Describe this')
expect(screen.getByRole('button', { name: 'Send' })).not.toHaveAttribute(
'aria-disabled'
)
expect(uploaded).toEqual([])
Comment on lines +4318 to +4340

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.

P3. If you keep this test, the status check and the uploaded check follow from the attachments equality: a refused chip has ref: '' (your next test asserts that), and an uploaded file would carry the upload's ref instead of the hash. In my mutation runs every failure in these rows landed on line 4329. I'd keep the Send check, since a blocked Send is the symptom the PR fixes and objectContaining does not rule out validationError or uploading.

Suggested change
const uploaded = stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag(label, {
name: 'abcdef0123456789.png',
hash: 'blake3:abcdef0123456789'
})
dispatchDrag(screen.getByRole('textbox'), 'drop', data)
await screen.findByRole('group', { name: label })
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: label,
ref: 'blake3:abcdef0123456789'
})
])
expect(screen.queryByRole('status')).not.toBeInTheDocument()
await userEvent.type(screen.getByRole('textbox'), 'Describe this')
expect(screen.getByRole('button', { name: 'Send' })).not.toHaveAttribute(
'aria-disabled'
)
expect(uploaded).toEqual([])
stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag(label, {
name: 'abcdef0123456789.png',
hash: 'blake3:abcdef0123456789'
})
dispatchDrag(screen.getByRole('textbox'), 'drop', data)
await screen.findByRole('group', { name: label })
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: label,
ref: 'blake3:abcdef0123456789'
})
])
await userEvent.type(screen.getByRole('textbox'), 'Describe this')
expect(screen.getByRole('button', { name: 'Send' })).not.toHaveAttribute(
'aria-disabled'
)

}
)

it('refuses a hashed card whose stored file is a refused type behind an extensionless label', 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.

P3. This is the existing stages an opaque asset card with a rejected label as an invalid chip test (line 4185) plus a display label: the same hashed ref with no extension, the same .usdz stored file, the same refusal status. The older test hand-builds a payload with no display_name, which is why it passed on main. One it.for over displayName: [null, 'My scene'], expecting abcdef0123456789.usdz or My scene as the label and driven by assetPanelDrag, would cover both cases and retire the hand-built payload. Prose because it merges two separate tests.

const uploaded = stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag('My scene', {
name: 'abcdef0123456789.usdz',
hash: 'blake3:abcdef0123456789'
})

dispatchDrag(screen.getByRole('textbox'), 'drop', data)

expect(
await screen.findByRole('status', {
name: unsupportedTypeMessage('My scene')
})
).toBeVisible()
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: 'My scene',
ref: '',
validationError: 'unsupported-type'
})
])
expect(fetchRequests(data.getData('text/uri-list'))).toEqual([])
expect(uploaded).toEqual([])
Comment on lines +4345 to +4368

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.

P3 Nit. A dropped card can only be uploaded after fetchDroppedAsset fetches it (AgentPanelRoot.vue:1894-1898), so an empty fetchRequests(...) already shows nothing was uploaded. The fetchRequests check is the one to keep, since it also catches a design that downloads before judging.

Suggested change
const uploaded = stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag('My scene', {
name: 'abcdef0123456789.usdz',
hash: 'blake3:abcdef0123456789'
})
dispatchDrag(screen.getByRole('textbox'), 'drop', data)
expect(
await screen.findByRole('status', {
name: unsupportedTypeMessage('My scene')
})
).toBeVisible()
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: 'My scene',
ref: '',
validationError: 'unsupported-type'
})
])
expect(fetchRequests(data.getData('text/uri-list'))).toEqual([])
expect(uploaded).toEqual([])
stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag('My scene', {
name: 'abcdef0123456789.usdz',
hash: 'blake3:abcdef0123456789'
})
dispatchDrag(screen.getByRole('textbox'), 'drop', data)
expect(
await screen.findByRole('status', {
name: unsupportedTypeMessage('My scene')
})
).toBeVisible()
expect(useAgentComposerStore().attachments).toEqual([
expect.objectContaining({
name: 'My scene',
ref: '',
validationError: 'unsupported-type'
})
])
expect(fetchRequests(data.getData('text/uri-list'))).toEqual([])

})

it('uploads a hashed card it has to fetch under its stored file name', async () => {
const uploaded = stubUploadFetch()
renderWithSelectedTarget()
await nextTick()
const data = assetPanelDrag('Holiday.v2', {
name: 'abcdef0123456789.heic',
hash: 'blake3:abcdef0123456789'
})

dispatchDrag(screen.getByRole('textbox'), 'drop', data)

await vi.waitFor(() => expect(uploaded).toEqual(['abcdef0123456789.heic']))
expect(fetchRequests(data.getData('text/uri-list'))).toHaveLength(1)
expect(screen.queryByRole('status')).not.toBeInTheDocument()

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.

P3 Nit. Once uploaded equals ['abcdef0123456789.heic'], there can be no refusal status, because the panel uploads only accepted files. None of my mutations reached this line; the ones that broke this test failed at line 4382.

Suggested change
expect(screen.queryByRole('status')).not.toBeInTheDocument()

})

it('attaches a dropped workflow json to the chat instead of the graph loader', async () => {
stubUploadFetch()
renderWithSelectedTarget()
Expand Down
4 changes: 3 additions & 1 deletion src/workbench/extensions/agent/AgentPanelRoot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -1843,7 +1843,9 @@ function warnAttachment(message: string): void {

function droppedAssetVerdict(asset: DroppedAsset): AgentAttachVerdict {
const fromRef = asset.ref ? agentAttachRefVerdict(asset.ref) : 'unknown'
return fromRef === 'unknown' ? agentAttachVerdict(asset.name) : fromRef
return fromRef === 'unknown'
? agentAttachVerdict(asset.filename ?? asset.name)

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.

P3, question. The verdict and the upload name now rank the stored name differently. Here the ref wins when it has a recognized extension and filename comes second. In sourceFileName (eventUtils.ts:55-61) filename comes before ref.

With { name: 'Label', filename: 'stored.pdf', ref: 'hash.png' } on the fetch path, the panel accepts the card because of hash.png and uploads it as stored.pdf. I ran the real agentAttachRefVerdict, agentAttachVerdict and fetchDroppedAsset on that input and got verdict= accepted uploadName= stored.pdf. The two only disagree when both names carry different extensions, which today takes a multi-output card or a dotted hash, so this is minor.

No test pins either order. Moving filename after ref in sourceFileName passes the attach-flow tests and both eventUtils test files, and so does checking filename before ref here. Which order do you intend? If the ref should win in both places, moving filename below ref in sourceFileName gives the same name for extensionless cloud hashes and makes the two orders match. Prose because the fix is in the other file and depends on that answer.

: fromRef
}

function stageAcceptedAssetCard(
Expand Down
Loading