From cd4d2e68c4da3b97cfe508d53af48e1f740a7c00 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Sat, 26 Sep 2026 03:45:43 +0000 Subject: [PATCH 1/5] test: cover reference-only attachment history previews (#18247) Cover image/video attachment previews after reload and chat switching, including reference-only history.
Full context for agent readers - Follow up the non-blocking coverage suggestions on [attachment-history coverage PR18244](https://github.com/Comfy-Org/ComfyUI_frontend/pull/18244). - Keep the single-image case and two distinct image fixtures. Add history containing only `attachment_refs`, so `attachments` cannot hide a broken fallback. - Four cases cover one image, two images with filenames/references, reference-only images, and mixed image/video references. Each verifies reload, an empty new chat and restoration of the original chat. - Assert exact filenames, decoded dimensions and Playwright visibility. Empty video `currentSrc` returns a retryable mismatch; preview assertions retain a ten-second timeout. - No production changes. [Attachment restoration PM-1148](https://linear.app/comfyorg/issue/PM-1148) and [original regression acceptance PM-1149](https://linear.app/comfyorg/issue/PM-1149) remain open for unavailable media, raw-reference presentation, storage identity, video playback and real-service persistence. Controlled-response video and chat-switch coverage are now established. The history response is independently specified rather than copied from the outgoing attachments. The outgoing request still has an exact filename assertion. Two images have different decoded widths (64 and 32), so duplicate-image recovery fails. September 21 review-repair verification: all four cases passed with zero retries against the preserved Cloud build from main `35524d57b8`, whose served index matched SHA256 `23a259c26b2af1638d1018be346bf4d8da30cd36786aea403601399aff24bccd`. The tested helper is byte-identical to [the published repair](https://github.com/Comfy-Org/ComfyUI_frontend/commit/507c17240d53be06c64ad5f500d10dbb46dd7e4a). Application/browser typechecks and mandatory commit/push hooks passed. Fresh hosted checks and human re-review remain required. Earlier sensitivity control: replacing only the `attachment_refs` fallback with an empty list made the reference-only case fail after reload, expecting two previews and receiving zero. Restoring production code and rebuilding returned the then-three cases to green. That counterfactual was not rerun for this helper repair and is not included in the PR. Each case emits before-reload, after-reload and after-chat-switch screenshots. The inspected mixed-media after-chat-switch capture shows the image and video preview together; full filenames and decoded dimensions are established by the browser assertions, not the truncated text. Playback is not tested. Glossary: reference-only history contains resolved `attachment_refs` without an `attachments` filename list; counterfactual means deliberately disabling one behavior to verify test sensitivity.
--------- Co-authored-by: GitHub Action --- .../fixtures/utils/agentAttachmentHelpers.ts | 94 +++++ .../agentAttachmentHistoryPersistence.spec.ts | 349 +++++++++++------- 2 files changed, 307 insertions(+), 136 deletions(-) create mode 100644 browser_tests/fixtures/utils/agentAttachmentHelpers.ts diff --git a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts new file mode 100644 index 00000000000..aa30d606708 --- /dev/null +++ b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts @@ -0,0 +1,94 @@ +import { expect } from '@playwright/test' +import type { Locator, Page } from '@playwright/test' + +import { MIME_ASSET_INFO } from '@/platform/assets/schemas/mediaAssetSchema' +import type { + MediaKind, + parseAssetInfo +} from '@/platform/assets/schemas/mediaAssetSchema' + +type DraggedAssetInfo = NonNullable> + +export interface ExpectedAssetPreview { + filename: string + kind: Extract + width: number + height: number + visible: boolean +} + +export async function dropAssets( + page: Page, + panel: Locator, + assets: ExpectedAssetPreview[] +) { + for (const { filename, kind } of assets) { + const payload: DraggedAssetInfo = { + filename, + subfolder: '', + type: 'output', + attachment_ref: filename, + media_kind: kind + } + const dataTransfer = await page.evaluateHandle( + ({ mime, payload }) => { + const transfer = new DataTransfer() + transfer.setData(mime, JSON.stringify(payload)) + return transfer + }, + { mime: MIME_ASSET_INFO, payload } + ) + await panel.dispatchEvent('drop', { dataTransfer }) + await dataTransfer.dispose() + } +} + +export async function expectAssets( + panel: Locator, + assets: ExpectedAssetPreview[], + timeout = 10_000 +) { + const previews = panel.getByTestId(/^reply-(image|video)-preview$/) + await expect(previews).toHaveCount(assets.length, { timeout }) + for (const [index, { visible }] of assets.entries()) { + await expect(previews.nth(index)).toBeVisible({ visible, timeout }) + } + await expect + .poll( + () => + previews.evaluateAll((elements) => + elements.map((element) => { + if (element instanceof HTMLImageElement) { + return { + filename: element.alt, + kind: 'image', + width: element.naturalWidth, + height: element.naturalHeight + } + } + if (element instanceof HTMLVideoElement) { + return { + filename: element.currentSrc + ? new URL(element.currentSrc, location.href).searchParams.get( + 'filename' + ) + : null, + kind: 'video', + width: element.videoWidth, + height: element.videoHeight + } + } + return null + }) + ), + { timeout } + ) + .toEqual( + assets.map(({ filename, kind, width, height }) => ({ + filename, + kind, + width, + height + })) + ) +} diff --git a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts index 4b4d55979dc..89eaab63694 100644 --- a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts +++ b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts @@ -3,9 +3,13 @@ import { expect } from '@playwright/test' import type { AgentMessage } from '@comfyorg/ingest-types' import enMessages from '@/locales/en/main.json' with { type: 'json' } -import { MIME_ASSET_INFO } from '@/platform/assets/schemas/mediaAssetSchema' import { promptHistoryTest as test } from '@e2e/fixtures/agentPromptHistoryFixture' +import { + dropAssets, + expectAssets +} from '@e2e/fixtures/utils/agentAttachmentHelpers' +import type { ExpectedAssetPreview } from '@e2e/fixtures/utils/agentAttachmentHelpers' import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute' import { assetPath } from '@e2e/fixtures/utils/paths' @@ -29,142 +33,215 @@ import { assetPath } from '@e2e/fixtures/utils/paths' test.describe.configure({ timeout: 120_000 }) test.use({ connectWebSocketToServer: false }) -test( - 'keeps a user message asset preview after a browser refresh', - { tag: ['@cloud', '@ui'] }, - async ({ page, promptHistory, workflowSelection }, testInfo) => { - const droppedFilename = 'ComfyUI_00002_.png' - - await page.route( - `**/view?filename=${droppedFilename}&type=input`, - (route) => route.fulfill({ path: assetPath('image64x64.webp') }) - ) - - // The real ingest API returns the message row's `content` map verbatim, - // including `attachment_refs` once a turn's attachments resolve - // server-side (services/agent/server/agent_handler.go's getMessages sets - // messageResponse.Content = m.Content directly). Stand in for that GET - // response here since the shared prompt-history fixture's own mock does - // not yet carry attachments through to `content` at all. POST still goes - // through the fixture's handler unmodified (route.fallback()). - await page.route('**/api/agent/threads/*/messages', (route) => { - if (route.request().method() !== 'GET') return route.fallback() - const request = promptHistory.requests.at(0) - if (!request) return route.fallback() - const threadId = new URL(route.request().url()).pathname - .split('/') - .at(-2)! - const turnId = 'e2e-attachment-turn' - const messages: AgentMessage[] = [ - { - id: 'e2e-attachment-user', - thread_id: threadId, - turn_id: turnId, - seq: 1, - role: 'user', - status: 'complete', - workflow_id: request.workflow_id, - content: { - text: request.content, - attachments: request.attachments, - attachment_refs: (request.attachments ?? []).map((name) => ({ - name, - id: 'asset-e2e-attachment', - kind: 'image' - })) - } - }, - { - id: turnId, - thread_id: threadId, - turn_id: turnId, - seq: 2, - role: 'assistant', - status: 'complete', - content: { text: 'Looks good.' } - } +const firstImage = { + filename: 'ComfyUI_00002_.png', + kind: 'image', + width: 64, + height: 64, + visible: true +} satisfies ExpectedAssetPreview +const secondImage = { + filename: 'ComfyUI_00003_.png', + kind: 'image', + width: 32, + height: 32, + visible: true +} satisfies ExpectedAssetPreview +const video = { + filename: 'ComfyUI_00004_.mp4', + kind: 'video', + width: 128, + height: 128, + visible: true +} satisfies ExpectedAssetPreview +const references = [ + { name: firstImage.filename, id: 'asset-first', kind: 'image' }, + { name: secondImage.filename, id: 'asset-second', kind: 'image' } +] + +for (const scenario of [ + { + name: 'one image from filenames', + assets: [firstImage], + historyContent: { attachments: [firstImage.filename] } + }, + { + name: 'two distinct images from filenames and references', + assets: [firstImage, secondImage], + historyContent: { + attachments: [firstImage.filename, secondImage.filename], + attachment_refs: references + } + }, + { + name: 'two distinct images from references only', + assets: [firstImage, secondImage], + historyContent: { attachment_refs: references } + }, + { + name: 'an image and video from references only', + assets: [firstImage, video], + historyContent: { + attachment_refs: [ + references[0], + { name: video.filename, id: 'asset-video', kind: 'video' } ] - return route.fulfill(jsonRoute(messages)) - }) + } + } +]) { + test( + `keeps ${scenario.name} after refresh and chat switching`, + { tag: ['@cloud', '@ui'] }, + async ({ page, promptHistory, workflowSelection }, testInfo) => { + const filenames = scenario.assets.map((asset) => asset.filename) + let attachmentThreadId: string | undefined + + await page.route( + `**/view?filename=${firstImage.filename}&type=input`, + (route) => route.fulfill({ path: assetPath('image64x64.webp') }) + ) + await page.route( + `**/view?filename=${secondImage.filename}&type=input`, + (route) => route.fulfill({ path: assetPath('image32x32.webp') }) + ) + await page.route( + `**/view?filename=${video.filename}&type=input`, + (route) => + route.fulfill({ + path: assetPath('workflowInMedia/workflow.mp4'), + contentType: 'video/mp4' + }) + ) + + // The real ingest API returns the message row's `content` map verbatim, + // including `attachment_refs` once a turn's attachments resolve + // server-side (services/agent/server/agent_handler.go's getMessages sets + // messageResponse.Content = m.Content directly). Stand in for that GET + // response here since the shared prompt-history fixture's own mock does + // not yet carry attachments through to `content` at all. POST still goes + // through the fixture's handler unmodified (route.fallback()). + await page.route('**/api/agent/threads/*/messages', (route) => { + const threadId = new URL(route.request().url()).pathname + .split('/') + .at(-2)! + if (route.request().method() === 'POST') { + attachmentThreadId = threadId + return route.fallback() + } + if (route.request().method() !== 'GET') return route.fallback() + if (threadId !== attachmentThreadId) { + return route.fulfill(jsonRoute([])) + } + const request = promptHistory.requests.at(0) + if (!request) return route.fallback() + const turnId = 'e2e-attachment-turn' + const messages: AgentMessage[] = [ + { + id: 'e2e-attachment-user', + thread_id: threadId, + turn_id: turnId, + seq: 1, + role: 'user', + status: 'complete', + workflow_id: request.workflow_id, + content: { + text: request.content, + ...scenario.historyContent + } + }, + { + id: turnId, + thread_id: threadId, + turn_id: turnId, + seq: 2, + role: 'assistant', + status: 'complete', + content: { text: 'Looks good.' } + } + ] + return route.fulfill(jsonRoute(messages)) + }) + + await page + .getByRole('button', { + name: enMessages.agent.entryButton, + exact: true + }) + .click() + await page + .getByRole('button', { + name: enMessages.sideToolbar.newBlankWorkflow, + exact: true + }) + .click() + const panel = page.locator('#agent-panel-root') + await expect(panel).toBeVisible() + await panel + .getByRole('button', { name: enMessages.agent.switchWorkflow }) + .click() + await page + .getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true }) + .click() + await expect.poll(() => workflowSelection.savedPaths.length).toBe(1) + workflowSelection.finishSave(true) + + // Simulate dropping a generated asset card into the composer, the same + // way agentBatchOutputAttachment.spec.ts does: the real drag source puts + // this shape on the DataTransfer. + await dropAssets(page, panel, scenario.assets) + + const composer = panel.getByRole('textbox', { name: /^Describe ideas/ }) + await composer.pressSequentially('compare these attachments') + await panel + .getByRole('button', { name: enMessages.agent.send, exact: true }) + .click() + await expect.poll(() => promptHistory.requests.length).toBe(1) + expect(promptHistory.requests[0].attachments).toEqual(filenames) + + await expectAssets(panel, scenario.assets) + await panel.screenshot({ path: testInfo.outputPath('before-reload.png') }) - await page - .getByRole('button', { - name: enMessages.agent.entryButton, - exact: true + // Settle the (WS-less) turn so the reload below is not racing a + // permanently-streaming assistant message. + await panel + .getByRole('button', { name: enMessages.agent.stop, exact: true }) + .click() + + await page.reload() + await expect( + page.getByTestId('integrated-tab-bar-actions') + ).toHaveAttribute('data-agent-gate-settled', 'true', { timeout: 30_000 }) + const reopenedPanel = page.locator('#agent-panel-root') + await expect(reopenedPanel).toBeVisible({ timeout: 30_000 }) + + await expectAssets(reopenedPanel, scenario.assets) + await reopenedPanel.screenshot({ + path: testInfo.outputPath('after-reload.png') }) - .click() - await page - .getByRole('button', { - name: enMessages.sideToolbar.newBlankWorkflow, - exact: true + + await reopenedPanel + .getByRole('button', { name: enMessages.agent.newChat }) + .click() + await expect( + reopenedPanel.getByTestId('user-message-bubble') + ).toHaveCount(0) + await expectAssets(reopenedPanel, []) + await reopenedPanel + .getByRole('button', { name: enMessages.agent.showChatHistory }) + .click() + await reopenedPanel + .getByRole('button', { + name: 'Inline reference round trip', + exact: true + }) + .click() + await expect( + reopenedPanel.getByTestId('user-message-bubble') + ).toContainText('compare these attachments') + await expectAssets(reopenedPanel, scenario.assets) + await reopenedPanel.screenshot({ + path: testInfo.outputPath('after-chat-switch.png') }) - .click() - const panel = page.locator('#agent-panel-root') - await expect(panel).toBeVisible() - await panel - .getByRole('button', { name: enMessages.agent.switchWorkflow }) - .click() - await page - .getByRole('menuitemradio', { name: 'Unsaved Workflow', exact: true }) - .click() - await expect.poll(() => workflowSelection.savedPaths.length).toBe(1) - workflowSelection.finishSave(true) - - // Simulate dropping a generated asset card into the composer, the same - // way agentBatchOutputAttachment.spec.ts does: the real drag source puts - // this shape on the DataTransfer. - await panel.dispatchEvent('drop', { - dataTransfer: await page.evaluateHandle( - ({ mime, filename }) => { - const dataTransfer = new DataTransfer() - dataTransfer.setData( - mime, - JSON.stringify({ - filename, - subfolder: '', - type: 'output', - attachment_ref: filename, - media_kind: 'image' - }) - ) - return dataTransfer - }, - { mime: MIME_ASSET_INFO, filename: droppedFilename } - ) - }) - - const composer = panel.getByRole('textbox', { name: /^Describe ideas/ }) - await composer.pressSequentially('check this image') - await panel - .getByRole('button', { name: enMessages.agent.send, exact: true }) - .click() - await expect.poll(() => promptHistory.requests.length).toBe(1) - - const image = panel.getByRole('img', { name: droppedFilename }) - await expect(image).toBeVisible() - await expect(image).toHaveJSProperty('naturalWidth', 64) - await panel.screenshot({ path: testInfo.outputPath('before-reload.png') }) - - // Settle the (WS-less) turn so the reload below is not racing a - // permanently-streaming assistant message. - await panel - .getByRole('button', { name: enMessages.agent.stop, exact: true }) - .click() - - await page.reload() - await expect( - page.getByTestId('integrated-tab-bar-actions') - ).toHaveAttribute('data-agent-gate-settled', 'true', { timeout: 30_000 }) - const reopenedPanel = page.locator('#agent-panel-root') - await expect(reopenedPanel).toBeVisible({ timeout: 30_000 }) - - const reopenedImage = reopenedPanel.getByRole('img', { - name: droppedFilename - }) - await expect(reopenedImage).toBeVisible({ timeout: 10_000 }) - await expect(reopenedImage).toHaveJSProperty('naturalWidth', 64) - await reopenedPanel.screenshot({ - path: testInfo.outputPath('after-reload.png') - }) - } -) + } + ) +} From 3f9dbedd8adc22e0a253a8c7b222c055172f68af Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 04:31:43 +0000 Subject: [PATCH 2/5] test: use stable attachment preview selector --- browser_tests/fixtures/utils/agentAttachmentHelpers.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts index aa30d606708..e0c3d779c29 100644 --- a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts +++ b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts @@ -48,7 +48,11 @@ export async function expectAssets( assets: ExpectedAssetPreview[], timeout = 10_000 ) { - const previews = panel.getByTestId(/^reply-(image|video)-preview$/) + // core/1.54 predates the per-image test id, but both image and video + // previews are children of the stable reply asset group contract. + const previews = panel + .getByTestId('reply-asset-group') + .locator('img:not([alt=""]), video') await expect(previews).toHaveCount(assets.length, { timeout }) for (const [index, { visible }] of assets.entries()) { await expect(previews.nth(index)).toBeVisible({ visible, timeout }) From 241e718e811a33f0fc35a9f873cf7b5f5d7abc59 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 06:38:04 +0000 Subject: [PATCH 3/5] test(agent): harden attachment history coverage Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020289 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020295 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020299 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020305 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020307 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020311 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020314 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020317 Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020323 --- .../fixtures/utils/agentAttachmentHelpers.ts | 69 +++++++++++++------ .../agentAttachmentHistoryPersistence.spec.ts | 55 ++++++++++----- .../services/agent/agentTranscript.test.ts | 15 ++++ .../agent/services/agent/agentTranscript.ts | 8 ++- 4 files changed, 108 insertions(+), 39 deletions(-) diff --git a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts index e0c3d779c29..dddfd56293d 100644 --- a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts +++ b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts @@ -11,23 +11,25 @@ type DraggedAssetInfo = NonNullable> export interface ExpectedAssetPreview { filename: string + ref?: string kind: Extract - width: number - height: number - visible: boolean + width?: number + height?: number } export async function dropAssets( page: Page, - panel: Locator, - assets: ExpectedAssetPreview[] + target: Locator, + assets: ExpectedAssetPreview[], + type: DraggedAssetInfo['type'] = 'output' ) { - for (const { filename, kind } of assets) { + for (const { filename, ref = filename, kind } of assets) { const payload: DraggedAssetInfo = { filename, subfolder: '', - type: 'output', - attachment_ref: filename, + type, + display_name: filename, + attachment_ref: ref, media_kind: kind } const dataTransfer = await page.evaluateHandle( @@ -38,7 +40,7 @@ export async function dropAssets( }, { mime: MIME_ASSET_INFO, payload } ) - await panel.dispatchEvent('drop', { dataTransfer }) + await target.dispatchEvent('drop', { dataTransfer }) await dataTransfer.dispose() } } @@ -48,14 +50,33 @@ export async function expectAssets( assets: ExpectedAssetPreview[], timeout = 10_000 ) { - // core/1.54 predates the per-image test id, but both image and video - // previews are children of the stable reply asset group contract. - const previews = panel + const userMessage = panel + .getByTestId('user-message-bubble') + .last() + .locator('..') + const previews = userMessage .getByTestId('reply-asset-group') - .locator('img:not([alt=""]), video') + .locator('img, video') await expect(previews).toHaveCount(assets.length, { timeout }) - for (const [index, { visible }] of assets.entries()) { - await expect(previews.nth(index)).toBeVisible({ visible, timeout }) + for (const [index, asset] of assets.entries()) { + const preview = previews.nth(index) + await expect(preview).toBeVisible({ timeout }) + await expect(preview.locator('..')).toHaveAccessibleName(asset.filename, { + timeout + }) + await expect + .poll( + () => + preview.evaluate((element) => + element instanceof HTMLImageElement + ? element.naturalWidth > 0 && element.naturalHeight > 0 + : element instanceof HTMLVideoElement + ? element.videoWidth > 0 && element.videoHeight > 0 + : false + ), + { timeout } + ) + .toBe(true) } await expect .poll( @@ -64,15 +85,20 @@ export async function expectAssets( elements.map((element) => { if (element instanceof HTMLImageElement) { return { - filename: element.alt, kind: 'image', + label: element.alt, + ref: new URL( + element.currentSrc, + location.href + ).searchParams.get('filename'), width: element.naturalWidth, height: element.naturalHeight } } if (element instanceof HTMLVideoElement) { return { - filename: element.currentSrc + label: element.parentElement?.getAttribute('aria-label'), + ref: element.currentSrc ? new URL(element.currentSrc, location.href).searchParams.get( 'filename' ) @@ -88,11 +114,12 @@ export async function expectAssets( { timeout } ) .toEqual( - assets.map(({ filename, kind, width, height }) => ({ - filename, + assets.map(({ filename, ref = filename, kind, width, height }) => ({ kind, - width, - height + label: filename, + ref, + width: width ?? expect.any(Number), + height: height ?? expect.any(Number) })) ) } diff --git a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts index 89eaab63694..0db8d6177bf 100644 --- a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts +++ b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts @@ -37,22 +37,18 @@ const firstImage = { filename: 'ComfyUI_00002_.png', kind: 'image', width: 64, - height: 64, - visible: true + height: 64 } satisfies ExpectedAssetPreview const secondImage = { filename: 'ComfyUI_00003_.png', kind: 'image', width: 32, - height: 32, - visible: true + height: 32 } satisfies ExpectedAssetPreview const video = { filename: 'ComfyUI_00004_.mp4', - kind: 'video', - width: 128, - height: 128, - visible: true + ref: 'asset-video.mp4', + kind: 'video' } satisfies ExpectedAssetPreview const references = [ { name: firstImage.filename, id: 'asset-first', kind: 'image' }, @@ -60,6 +56,11 @@ const references = [ ] for (const scenario of [ + { + name: 'references when filenames are present but empty', + assets: [firstImage], + historyContent: { attachments: [], attachment_refs: [references[0]] } + }, { name: 'one image from filenames', assets: [firstImage], @@ -81,6 +82,7 @@ for (const scenario of [ { name: 'an image and video from references only', assets: [firstImage, video], + historyAssets: [firstImage, { ...video, ref: video.filename }], historyContent: { attachment_refs: [ references[0], @@ -104,6 +106,12 @@ for (const scenario of [ `**/view?filename=${secondImage.filename}&type=input`, (route) => route.fulfill({ path: assetPath('image32x32.webp') }) ) + await page.route(`**/view?filename=${video.ref}&type=input`, (route) => + route.fulfill({ + path: assetPath('workflowInMedia/workflow.mp4'), + contentType: 'video/mp4' + }) + ) await page.route( `**/view?filename=${video.filename}&type=input`, (route) => @@ -125,15 +133,17 @@ for (const scenario of [ .split('/') .at(-2)! if (route.request().method() === 'POST') { - attachmentThreadId = threadId - return route.fallback() + return route.fallback().then(() => { + attachmentThreadId = threadId + }) } if (route.request().method() !== 'GET') return route.fallback() + if (!attachmentThreadId) return route.fallback() if (threadId !== attachmentThreadId) { return route.fulfill(jsonRoute([])) } const request = promptHistory.requests.at(0) - if (!request) return route.fallback() + if (!request) throw new Error('Attachment request was not recorded') const turnId = 'e2e-attachment-turn' const messages: AgentMessage[] = [ { @@ -188,15 +198,24 @@ for (const scenario of [ // Simulate dropping a generated asset card into the composer, the same // way agentBatchOutputAttachment.spec.ts does: the real drag source puts // this shape on the DataTransfer. - await dropAssets(page, panel, scenario.assets) - const composer = panel.getByRole('textbox', { name: /^Describe ideas/ }) + await dropAssets(page, composer, scenario.assets, 'input') + for (const filename of filenames) { + await expect(panel.getByTestId('composer-asset-section')).toContainText( + filename + ) + } + await composer.pressSequentially('compare these attachments') await panel .getByRole('button', { name: enMessages.agent.send, exact: true }) .click() await expect.poll(() => promptHistory.requests.length).toBe(1) - expect(promptHistory.requests[0].attachments).toEqual(filenames) + expect(promptHistory.requests[0].attachments).toEqual( + scenario.assets.map((asset) => + 'ref' in asset && asset.ref ? asset.ref : asset.filename + ) + ) await expectAssets(panel, scenario.assets) await panel.screenshot({ path: testInfo.outputPath('before-reload.png') }) @@ -214,7 +233,11 @@ for (const scenario of [ const reopenedPanel = page.locator('#agent-panel-root') await expect(reopenedPanel).toBeVisible({ timeout: 30_000 }) - await expectAssets(reopenedPanel, scenario.assets) + const historyAssets = + 'historyAssets' in scenario && scenario.historyAssets + ? scenario.historyAssets + : scenario.assets + await expectAssets(reopenedPanel, historyAssets) await reopenedPanel.screenshot({ path: testInfo.outputPath('after-reload.png') }) @@ -238,7 +261,7 @@ for (const scenario of [ await expect( reopenedPanel.getByTestId('user-message-bubble') ).toContainText('compare these attachments') - await expectAssets(reopenedPanel, scenario.assets) + await expectAssets(reopenedPanel, historyAssets) await reopenedPanel.screenshot({ path: testInfo.outputPath('after-chat-switch.png') }) diff --git a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts index 649e263652e..4201d0a3206 100644 --- a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts +++ b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts @@ -156,6 +156,21 @@ describe('normalizeAgentTranscript', () => { ]) }) + it('falls back to attachment_refs when content.attachments is empty', () => { + const message = row(1, 'user', 'turn-a', 'check this image', 'row-1') + message.content = { + text: 'check this image', + attachments: [], + attachment_refs: [{ name: 'ComfyUI_00002_.png', kind: 'image' }] + } + + const transcript = normalizeAgentTranscript([message]) + + expect(transcript.userAttachments.get(toTurnId('turn-a'))).toEqual([ + { name: 'ComfyUI_00002_.png', ref: 'ComfyUI_00002_.png' } + ]) + }) + it('leaves userAttachments empty for a turn with no attachment fields', () => { const message = row(1, 'user', 'turn-a', 'no attachments here', 'row-1') diff --git a/src/workbench/extensions/agent/services/agent/agentTranscript.ts b/src/workbench/extensions/agent/services/agent/agentTranscript.ts index dc2e266fec8..ee80b3f067b 100644 --- a/src/workbench/extensions/agent/services/agent/agentTranscript.ts +++ b/src/workbench/extensions/agent/services/agent/agentTranscript.ts @@ -52,11 +52,15 @@ function attachmentRefNames(value: unknown): string[] { function parseUserAttachments( content: Record | undefined ): UserAttachment[] | undefined { - const names = Array.isArray(content?.attachments) + const attachmentNames = Array.isArray(content?.attachments) ? content.attachments.filter( (name): name is string => typeof name === 'string' ) - : attachmentRefNames(content?.attachment_refs) + : [] + const names = + attachmentNames.length > 0 + ? attachmentNames + : attachmentRefNames(content?.attachment_refs) return names.length > 0 ? names.map((name) => ({ name, ref: name })) : undefined From a13bf8eaca3a68f8a071d29007453f69b6b17639 Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 06:39:15 +0000 Subject: [PATCH 4/5] test(agent): share the preview assertion deadline Addresses https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#discussion_r4130020311 --- .../fixtures/utils/agentAttachmentHelpers.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts index dddfd56293d..d914434d477 100644 --- a/browser_tests/fixtures/utils/agentAttachmentHelpers.ts +++ b/browser_tests/fixtures/utils/agentAttachmentHelpers.ts @@ -50,6 +50,8 @@ export async function expectAssets( assets: ExpectedAssetPreview[], timeout = 10_000 ) { + const deadline = Date.now() + timeout + const remaining = () => Math.max(1, deadline - Date.now()) const userMessage = panel .getByTestId('user-message-bubble') .last() @@ -57,12 +59,12 @@ export async function expectAssets( const previews = userMessage .getByTestId('reply-asset-group') .locator('img, video') - await expect(previews).toHaveCount(assets.length, { timeout }) + await expect(previews).toHaveCount(assets.length, { timeout: remaining() }) for (const [index, asset] of assets.entries()) { const preview = previews.nth(index) - await expect(preview).toBeVisible({ timeout }) + await expect(preview).toBeVisible({ timeout: remaining() }) await expect(preview.locator('..')).toHaveAccessibleName(asset.filename, { - timeout + timeout: remaining() }) await expect .poll( @@ -74,7 +76,7 @@ export async function expectAssets( ? element.videoWidth > 0 && element.videoHeight > 0 : false ), - { timeout } + { timeout: remaining() } ) .toBe(true) } @@ -111,7 +113,7 @@ export async function expectAssets( return null }) ), - { timeout } + { timeout: remaining() } ) .toEqual( assets.map(({ filename, ref = filename, kind, width, height }) => ({ From ec7893a038a4df9665ba8b17f5dde1601b6abcfe Mon Sep 17 00:00:00 2001 From: bymyself Date: Tue, 29 Sep 2026 21:54:26 -0700 Subject: [PATCH 5/5] fix: keep core 1.54 attachment backport test-only Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19342#pullrequestreview-5350035544 --- .../agentAttachmentHistoryPersistence.spec.ts | 5 ----- .../agent/services/agent/agentTranscript.test.ts | 15 --------------- .../agent/services/agent/agentTranscript.ts | 8 ++------ 3 files changed, 2 insertions(+), 26 deletions(-) diff --git a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts index 0db8d6177bf..6392822a26b 100644 --- a/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts +++ b/browser_tests/tests/agent/agentAttachmentHistoryPersistence.spec.ts @@ -56,11 +56,6 @@ const references = [ ] for (const scenario of [ - { - name: 'references when filenames are present but empty', - assets: [firstImage], - historyContent: { attachments: [], attachment_refs: [references[0]] } - }, { name: 'one image from filenames', assets: [firstImage], diff --git a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts index 04849ddd7df..f698ee632bb 100644 --- a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts +++ b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts @@ -182,21 +182,6 @@ describe('normalizeAgentTranscript', () => { ]) }) - it('falls back to attachment_refs when content.attachments is empty', () => { - const message = row(1, 'user', 'turn-a', 'check this image', 'row-1') - message.content = { - text: 'check this image', - attachments: [], - attachment_refs: [{ name: 'ComfyUI_00002_.png', kind: 'image' }] - } - - const transcript = normalizeAgentTranscript([message]) - - expect(transcript.userAttachments.get(toTurnId('turn-a'))).toEqual([ - { name: 'ComfyUI_00002_.png', ref: 'ComfyUI_00002_.png' } - ]) - }) - it('does not treat an attachment MIME type as an upload location', () => { const message = row(1, 'user', 'turn-a', 'check this image', 'row-1') message.content = { diff --git a/src/workbench/extensions/agent/services/agent/agentTranscript.ts b/src/workbench/extensions/agent/services/agent/agentTranscript.ts index d640d2a5651..ea5503632f0 100644 --- a/src/workbench/extensions/agent/services/agent/agentTranscript.ts +++ b/src/workbench/extensions/agent/services/agent/agentTranscript.ts @@ -99,12 +99,8 @@ function parseUserAttachments( ): UserAttachment[] | undefined { const attachments = Array.isArray(content?.attachments) ? parseAttachments(content.attachments) - : [] - const normalized = - attachments.length > 0 - ? attachments - : parseAttachments(content?.attachment_refs) - return normalized.length > 0 ? normalized : undefined + : parseAttachments(content?.attachment_refs) + return attachments.length > 0 ? attachments : undefined } /**