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
32 changes: 30 additions & 2 deletions browser_tests/fixtures/agentTurnLockFixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { escapeRegExp } from 'es-toolkit'
import { z } from 'zod'

import enMessages from '@/locales/en/main.json' with { type: 'json' }
import { TURN_RECOVERY_DELAYS_MS } from '@/workbench/extensions/agent/services/agent/turnRecoverySchedule'
import type {
AgentWsEvent,
zTurnInProgressError
Expand Down Expand Up @@ -51,7 +52,8 @@ const TURN_IN_PROGRESS: TurnInProgressBody = {
turn_id: TURN_ID
}

const TURN_THINKING_TEXT = 'Wiring the audio output node.'
export const TURN_THINKING_TEXT = 'Wiring the audio output node.'
export const LATE_THINKING_TEXT = 'Back online, so I can finish the wiring.'
export const POST_RECONNECT_TEXT = 'Reconnected, and the graph is ready.'
export const PERSISTED_BEFORE_TOOL_TEXT = 'Prepared the graph. '
export const PERSISTED_AFTER_TOOL_TEXT = 'Audio output connected.'
Expand All @@ -73,6 +75,11 @@ const TURN_TOOL_EVENT: AgentWsEvent = {
}
}

export const LATE_THINKING_EVENT: AgentWsEvent = {
type: 'agent_thinking',
data: { delta: LATE_THINKING_TEXT, message_id: TURN_ID, thread_id: THREAD_ID }
}

export const POST_RECONNECT_EVENT: AgentWsEvent = {
type: 'agent_message_delta',
data: {
Expand Down Expand Up @@ -178,6 +185,7 @@ class TurnLockServer {
private foreignPrompt: string | undefined
private rejected = 0
private posts = 0
private transcriptReads = 0
private readonly answered: string[][] = []
private pendingAsk: AgentPendingAsk | undefined
private heldTranscript:
Expand All @@ -203,6 +211,14 @@ class TurnLockServer {
return this.posts
}

get transcriptReadCount(): number {
return this.transcriptReads
}

countTranscriptRead(): void {
this.transcriptReads++
}

countPost(): void {
this.posts++
}
Expand Down Expand Up @@ -324,6 +340,10 @@ class TurnLockServer {
tool_name: 'add_node',
status: 'success'
}
],
thinking: [
{ text: TURN_THINKING_TEXT, tool_call_id: 'call-add-node' },
{ text: LATE_THINKING_TEXT }
]
}
},
Expand Down Expand Up @@ -438,6 +458,7 @@ async function routeTurnLock(
const path = new URL(route.request().url()).pathname.split('/')
const threadId = decodeURIComponent(path.at(-2) ?? '')
await server.waitForTranscriptRelease(threadId)
server.countTranscriptRead()
return route.fulfill(jsonRoute(server.transcript(threadId)))
}
server.countPost()
Expand Down Expand Up @@ -512,9 +533,9 @@ export class AgentTurnLockHarness {
public readonly liveProgressRow: Locator
public readonly userBubbles: Locator
public readonly turnInProgressNotice: Locator
public readonly agentPanel: AgentPanel
private readonly entryButton: Locator
private readonly dock: Locator
private readonly agentPanel: AgentPanel

constructor(
private readonly page: Page,
Expand Down Expand Up @@ -580,6 +601,13 @@ export class AgentTurnLockHarness {
return this.server.postAttempts
}

async waitForRecoveryExhausted(): Promise<void> {
const hydrationRead = 1
await expect
.poll(() => this.server.transcriptReadCount, { timeout: 90_000 })
.toBeGreaterThanOrEqual(TURN_RECOVERY_DELAYS_MS.length + hydrationRead)
}

/** Opens the panel on a blank workflow and points the composer at that tab. */
async openOnBlankWorkflow(): Promise<void> {
await expect(
Expand Down
9 changes: 8 additions & 1 deletion browser_tests/fixtures/components/AgentPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,14 @@ export class AgentPanel {
name: 'Workflow JSON'
})
this.workSummary = this.root.getByRole('button', {
name: new RegExp(`^${escapeRegExp(enMessages.agent.worked)}`)
name: new RegExp(
`^(${[
enMessages.agent.worked,
enMessages.agent.workedNotConfirmedOnCanvas
]
.map(escapeRegExp)
.join('|')})`
)
})
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect } from '@playwright/test'

import {
LATE_THINKING_EVENT,
LATE_THINKING_TEXT,
PERSISTED_AFTER_TOOL_TEXT,
TURN_THINKING_TEXT,
agentTurnLockTest as test
} from '@e2e/fixtures/agentTurnLockFixture'

test.describe.configure({ timeout: 180_000 })
test.use({ connectWebSocketToServer: false })

test(
'restores the thinking from before a mid-turn reload when the turn finishes',
{
tag: ['@cloud', '@ui'],
annotation: {
type: 'source',
description: 'https://linear.app/comfyorg/issue/FRONT-3659'
}
},
async ({ turnLock, getAgentSocket }) => {
const prompt = 'add an audio output node'

await test.step('narrate a round, then reload mid-turn', async () => {
await turnLock.openOnBlankWorkflow()
await turnLock.startTurn(prompt)

await turnLock.agentPanel.reload()
await expect(turnLock.userBubbles).toHaveText([prompt])
await expect(turnLock.stopButton).toBeVisible()
})

const socket =
await test.step('narrate another round after the reload', async () => {
await turnLock.waitForRecoveryExhausted()

const live = await getAgentSocket()
turnLock.push(live, LATE_THINKING_EVENT)
await expect(turnLock.panel.getByText(LATE_THINKING_TEXT)).toBeVisible()
return live
})

await test.step('finishing the turn shows both rounds beside the tool call', async () => {
turnLock.finishTurn(socket)

await expect(turnLock.sendButton).toBeVisible({ timeout: 30_000 })

await turnLock.agentPanel.openWorkSummary()
await expect(turnLock.agentPanel.activityRows).toHaveText([
TURN_THINKING_TEXT,
/Add node/,
LATE_THINKING_TEXT
])
await expect(
turnLock.panel.getByText(PERSISTED_AFTER_TOOL_TEXT)
).toBeVisible()
})
}
)
Loading
Loading