Skip to content
Closed
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 browser_tests/fixtures/components/AgentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export class AgentPanel {
public readonly workflowPicker: Locator
public readonly fileInput: Locator
public readonly composerAssetSection: Locator
public readonly composerUploadStatus: Locator
public readonly attachmentChips: Locator
public readonly composer: Locator
public readonly composerPromptArea: Locator
Expand Down Expand Up @@ -64,6 +65,7 @@ export class AgentPanel {
})
this.fileInput = this.root.getByTestId('agent-file-input')
this.composerAssetSection = this.root.getByTestId('composer-asset-section')
this.composerUploadStatus = this.root.getByTestId('composer-upload-status')
this.attachmentChips = this.root.getByTestId('agent-attachment-chip')
this.composer = this.root.getByRole('textbox', { name: /^Describe ideas/ })
this.composerPromptArea = this.root.getByTestId('composer-inline-input')
Expand Down
104 changes: 104 additions & 0 deletions browser_tests/tests/agent/agentComposerUploadGating.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { expect } from '@playwright/test'
import { zAgentPostMessageRequest } from '@comfyorg/ingest-types/zod'

import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'
import { agentTest as test } from '@e2e/tests/agent/agentPanelMocks'

// Regression for https://linear.app/comfyorg/issue/PM-1954
//
// `canSend` is false while any attachment is still uploading, and
// `useAttachment` uploads at most three at a time, so attaching a batch blocks
// sending for a window that grows with the batch. `onEnter` calls
// `preventDefault()` before that check, so during the window Enter produced no
// send, no newline and no message — the composer just went dead, which is what
// the reporter hit after attaching dozens of images. Blocking the send is
// correct (the refs are not resolved yet); doing it without saying so is not.
const ATTACHMENT_COUNT = 5

function pngAttachments(count: number) {
return Array.from({ length: count }, (_, index) => ({
name: `attachment-${index + 1}.png`,
mimeType: 'image/png',
buffer: Buffer.from('image')
}))
}

test.describe(
'Agent composer while attachments upload',
{ tag: ['@cloud', '@agent', '@ui'] },
() => {
test('says why sending is blocked, and sends once uploads settle', async ({
agentPanel,
comfyPage,
postedMessages
}) => {
const page = comfyPage.page
let releaseUploads = () => {}
const uploadsHeld = new Promise<void>((resolve) => {
releaseUploads = resolve
})
let uploadNumber = 0
await page.route('**/api/upload/image', async (route) => {
const currentUpload = ++uploadNumber
await uploadsHeld
await route.fulfill(
jsonRoute({
name: `uploaded-${currentUpload}.png`,
subfolder: '',
type: 'input'
})
)
})

try {
await agentPanel.open()
await agentPanel.selectWorkflow()
await agentPanel.composer.fill('Use these images')
await expect(agentPanel.sendButton).toBeEnabled()

await agentPanel.fileInput.setInputFiles(
pngAttachments(ATTACHMENT_COUNT)
)
await expect(agentPanel.attachmentChips).toHaveCount(ATTACHMENT_COUNT)
await expect(agentPanel.sendButton).toBeDisabled()

// The composer has to account for the dead Send, naming how many
// uploads it is waiting on rather than leaving the user to guess.
await expect(agentPanel.composerUploadStatus).toHaveText(
`Uploading ${ATTACHMENT_COUNT} attachments`
)

// Enter stays a no-op by design while refs are unresolved; what changes
// is that the reason is now on screen instead of nowhere.
await agentPanel.composer.press('Enter')

releaseUploads()

// Empty, not absent: the live region stays mounted so the next batch's
// first message lands in a region the screen reader already knows.
await expect(agentPanel.composerUploadStatus).toHaveText('')
await expect(agentPanel.sendButton).toBeEnabled()
// Check only after the upload requests and reactive UI have settled, so
// a POST leaked by the first Enter cannot still be in flight.
expect(postedMessages).toHaveLength(0)

await agentPanel.composer.press('Enter')
await expect.poll(() => postedMessages).toHaveLength(1)
// Asserting the refs, not just the count: a send that leaked past the
// gate would carry the staged empty refs and still be three long.
expect(
zAgentPostMessageRequest.parse(JSON.parse(postedMessages[0]))
.attachments
).toEqual(
Array.from(
{ length: ATTACHMENT_COUNT },
(_, index) => `uploaded-${index + 1}.png`
)
)
} finally {
releaseUploads()
await page.unrouteAll({ behavior: 'wait' })
}
})
}
)
1 change: 1 addition & 0 deletions src/locales/en/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -5506,6 +5506,7 @@
"focusNodeLabel": "Show {node} on canvas",
"removeNodeLabel": "Remove {node} reference",
"uploading": "Uploading",
"uploadingAttachments": "Uploading {count} attachment | Uploading {count} attachments",
"noNodesToMention": "No nodes in this workflow",
"friend": "there",
"sendFailed": "Message failed to send",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1559,6 +1559,60 @@ describe('Composer', () => {
)
})

describe('attachment upload status', () => {
function mountUploading(count: number) {
const composer = ref<InstanceType<typeof Composer> | null>(null)
const Host = defineComponent({
setup: () => () => h(Composer, { ref: composer })
})
render(Host, { global: { plugins: [i18n] } })
for (let index = 1; index <= count; index += 1)
composer.value?.addAttachment({
id: `attachment-${index}`,
name: `shot-${index}.png`,
ref: '',
uploading: true
})
return composer
}

// Anchored: 'Uploading 1 attachment' is a substring of the plural form, so
// an unanchored singular case passes under either plural branch.
it.for([
{ name: 'one upload', uploads: 1, expected: /^Uploading 1 attachment$/ },
{
name: 'three uploads',
uploads: 3,
expected: /^Uploading 3 attachments$/
}
])('accounts for the blocked Send with $name', async (testCase) => {
mountUploading(testCase.uploads)
await nextTick()

expect(screen.getByTestId('composer-upload-status')).toHaveTextContent(
testCase.expected
)
})

it('clears the status once the last upload settles', async () => {
const composer = mountUploading(2)
await nextTick()
expect(screen.getByTestId('composer-upload-status')).toHaveTextContent(
/^Uploading 2 attachments$/
)

composer.value?.updateAttachment('attachment-1', { uploading: false })
await nextTick()
expect(screen.getByTestId('composer-upload-status')).toHaveTextContent(
/^Uploading 1 attachment$/
)

composer.value?.updateAttachment('attachment-2', { uploading: false })
await nextTick()
expect(screen.getByTestId('composer-upload-status')).toBeEmptyDOMElement()
})
})

it('keeps uploaded attachments when navigating from a staged workflow', async () => {
useAgentComposerStore().setWorkflowReferences([
{ id: 'wf-1', name: 'Water world', textOffset: 0 }
Expand Down
26 changes: 26 additions & 0 deletions src/workbench/extensions/agent/components/agent/Composer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ function onEnter(event: KeyboardEvent): void {
composer.submit()
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
}

const uploadingAttachmentCount = computed(
() => composer.attachments.value.filter((item) => item.uploading).length
)

const primaryActionTooltip = computed(() =>
running.value ? t('agent.stop') : t('agent.send')
)
Expand Down Expand Up @@ -512,6 +516,28 @@ defineExpose({
/>
</div>

<!-- Mounted empty rather than v-if'd: a live region created in the same
mutation as its first message is not reliably announced, and that
announcement is the whole point of this row. `aria-live` rather than
`role="status"` so an always-present node does not widen what the
run-mode popover's own status announcer matches. -->
<div
data-testid="composer-upload-status"
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
aria-live="polite"
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
aria-atomic="true"
:class="
cn(
'flex items-center gap-1 text-xs text-muted-foreground',
uploadingAttachmentCount && 'px-3 pb-3'
)
"
>
<template v-if="uploadingAttachmentCount">
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
<span class="icon-[lucide--loader-circle] size-3 animate-spin" />
{{ t('agent.uploadingAttachments', uploadingAttachmentCount) }}
</template>
</div>

<div
data-testid="composer-inline-input"
class="flex max-h-100 min-h-16 flex-col overflow-x-hidden overflow-y-auto"
Expand Down
Loading