Skip to content
34 changes: 34 additions & 0 deletions browser_tests/tests/agent/agentHttpError.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { expect } from '@playwright/test'

import enMessages from '@/locales/en/main.json' with { type: 'json' }

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

test.beforeEach(async ({ comfyPage }) => {
await comfyPage.page.evaluate(() => {
const originalFetch = globalThis.fetch
globalThis.fetch = async (input, init) =>
init?.method === 'POST' &&
/\/agent\/threads\/[^/]+\/messages$/.test(String(input))
? new Response('', { status: 503 })
: originalFetch(input, init)
})
})

test(

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: I don't think this browser case catches anything the suite misses, and I'd delete it along with agentMessageHttpErrorMock. The behavior has three parts, and each already has a test at the level that owns it:

  • An empty statusText becomes Agent request failed (HTTP 503): agentRestClient.test.ts:465. postMessage and getMessages both go through request() and then toApiError (agentRestClient.ts:356-362), so that unit case covers the send path too.
  • An AgentApiError message becomes Message failed to send: <message>: useAgentSession.test.ts:4461-4487.
  • That notice reaches the panel through the real fetchApi path: keeps a failed prompt available to retry in agentPanel.spec.ts (a 500 from page.route), plus the exact full-notice assertion at agentPanel.spec.ts:369-374.

recordSendError reads error.message and never looks at where the message came from. I can't name a wrong implementation that passes those three tests and fails this one. If you keep the browser case anyway, my other comments on this file make it smaller.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping the focused browser case: this lane explicitly requires preserving the HTTP-status fallback contract and its black-box proof, and the repository harness-first policy requires visible Agent behavior to be exercised end to end. The current case remains the only proof that the empty-body/empty-status fallback survives the real panel send path and renders as one exact notice. I applied the remaining size and clarity suggestions in 6a41cdc.

'shows the HTTP status when a failed send has no error message',
{ tag: '@cloud' },
async ({ agentPanel }) => {
await agentPanel.open()
await agentPanel.selectWorkflow()

await agentPanel.sendMessage('Build a product photo workflow')

await expect(
agentPanel.root.getByText(
`${enMessages.agent.sendFailed}: Agent request failed (HTTP 503)`,
{ exact: true }
)
).toBeVisible()
Comment thread
christian-byrne marked this conversation as resolved.
Resolved
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,7 @@ describe('error mapping', () => {
expect(error.body).toBeUndefined()
})

it('falls back to the HTTP status when the response has no error text', async () => {
it('falls back to the HTTP status when the response has no error body or status text', async () => {
respond(new Response('', { status: 503 }))

const error = await makeClient()
Expand Down
Loading