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
@@ -0,0 +1,55 @@
import { expect } from '@playwright/test'

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

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

test.describe(
'Agent standing credits-exhaustion on an empty thread',
{ tag: ['@cloud', '@ui'] },
() => {
test('waits for the first user message before showing the out-of-credits card', async ({
agentBilling,
agentPanel,
page
}) => {
const paywall = agentPanel.creditsExhaustedPaywall

agentBilling.setFundingState('exhausted')
const exhaustedStatus = page.waitForResponse(
(response) =>
response.request().method() === 'GET' &&
new URL(response.url()).pathname === '/api/billing/status'
)
await page.reload()
await waitForCloudApp(page)
await exhaustedStatus
await agentPanel.open()
await agentPanel.selectWorkflow()

await test.step('stay hidden on the empty thread', async () => {
await expect(agentPanel.composer).toBeVisible()
await expect(paywall).toHaveCount(0)
})

await test.step('show once the first message activates the thread', async () => {
await agentPanel.sendMessage('Build a red fox workflow')
await expect(
agentPanel.root.getByTestId('user-message-bubble')
).toHaveText(['Build a red fox workflow'])
await expect(paywall).toBeVisible()
})

await test.step('hide again on a new empty thread', async () => {
await agentPanel.root
.getByRole('button', { name: enMessages.agent.newChat })
.click()
await expect(
agentPanel.root.getByTestId('user-message-bubble')
).toHaveCount(0)
await expect(paywall).toHaveCount(0)
})
})
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ test.describe(
agentBilling.failSubsequentRefreshes()
await expect(
agentPanel.root.getByTestId('user-message-bubble')
).toHaveText(['Make the lighting warmer'])
).toHaveText(['Build a red fox workflow', 'Make the lighting warmer'])
await agentPanel.close()
heldRefresh.release()
await heldRefresh.completed
Expand All @@ -78,7 +78,11 @@ test.describe(
await expect(paywall).toBeVisible()
await expect(
agentPanel.root.getByTestId('user-message-bubble')
).toHaveText(['Add shallow depth of field'])
).toHaveText([
'Build a red fox workflow',
'Make the lighting warmer',
'Add shallow depth of field'
])
})

await test.step('recover again and preserve the conversation', async () => {
Expand All @@ -89,7 +93,12 @@ test.describe(
await expect(paywall).toHaveCount(0)
await expect(
agentPanel.root.getByTestId('user-message-bubble')
).toHaveText(['Add shallow depth of field', 'Finish the workflow'])
).toHaveText([
'Build a red fox workflow',
'Make the lighting warmer',
'Add shallow depth of field',
'Finish the workflow'
])
})

await test.step('warn once the Agent grant alone runs out', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { Page, WebSocketRoute } from '@playwright/test'
import { expect, mergeTests } from '@playwright/test'

import type { AgentMessage } from '@comfyorg/ingest-types'

import type {
AgentTurnAccepted,
AgentWsEvent
Expand All @@ -10,8 +12,39 @@ import { webSocketFixture } from '@e2e/fixtures/ws'
import { hostTelemetryFixture } from '@e2e/fixtures/hostTelemetryFixture'
import type { AgentFundingState } from '@e2e/tests/agent/agentPanelMocks'
import { agentTest } from '@e2e/tests/agent/agentPanelMocks'
import { jsonRoute } from '@e2e/fixtures/utils/jsonRoute'

interface CompletedTurn {
prompt: string
accepted: AgentTurnAccepted
}

function toThreadHistory(turns: CompletedTurn[]): AgentMessage[] {
return turns.flatMap(({ prompt, accepted }, index) => [
{
id: `${accepted.message_id}-user`,
thread_id: accepted.thread_id,
turn_id: accepted.message_id,
seq: index * 2 + 1,
role: 'user',
status: 'complete',
content: { text: prompt }
},
{
id: accepted.message_id,
thread_id: accepted.thread_id,
turn_id: accepted.message_id,
seq: index * 2 + 2,
role: 'assistant',
status: 'complete',
content: { text: '' }
}
])
}

class AgentCreditsLifecycleFixture {
readonly completedTurns: CompletedTurn[] = []

constructor(
private readonly page: Page,
private readonly agentPanel: AgentPanel,
Expand Down Expand Up @@ -57,6 +90,7 @@ class AgentCreditsLifecycleFixture {
}
const ws = await this.getAgentSocket()
ws.send(JSON.stringify(doneEvent))
this.completedTurns.push({ prompt, accepted })
await billingRefresh
}
}
Expand All @@ -70,14 +104,18 @@ export const test = base.extend<{
{ acceptedTurns, agentBilling, agentPanel, getAgentSocket, page },
use
) => {
await use(
new AgentCreditsLifecycleFixture(
page,
agentPanel,
acceptedTurns,
getAgentSocket,
(state) => agentBilling.setFundingState(state)
)
const lifecycle = new AgentCreditsLifecycleFixture(
page,
agentPanel,
acceptedTurns,
getAgentSocket,
(state) => agentBilling.setFundingState(state)
)
await page.route('**/api/agent/threads/*/messages', (route) =>
route.request().method() === 'GET'
? route.fulfill(jsonRoute(toThreadHistory(lifecycle.completedTurns)))
: route.fallback()
)
await use(lifecycle)
}
})
Loading
Loading