mirror of
https://github.com/langgenius/dify.git
synced 2026-07-21 02:28:30 +08:00
test(e2e): fix agent build note runtime connection (#38574)
This commit is contained in:
parent
caf1a22020
commit
2b35f48d77
@ -34,6 +34,7 @@ import {
|
||||
} from './configure-helpers'
|
||||
|
||||
const BUILD_DRAFT_RUNTIME_STEP_TIMEOUT_MS = 180_000
|
||||
const BUILD_DRAFT_NOTE_SYNC_TIMEOUT_MS = 30_000
|
||||
const BUILD_NOTE_FILE_NAME = 'build_note.md'
|
||||
const BUILD_NOTE_MARKER = 'E2E_BUILD_DRAFT_PASS'
|
||||
const BUILD_NOTE_GENERATED_BADGE = 'Generated'
|
||||
@ -50,6 +51,17 @@ const getBuildNoteFileButton = (page: Page) =>
|
||||
const getConfigNote = (value: Awaited<ReturnType<typeof getAgentBuildDraft>>) =>
|
||||
value.agent_soul?.config_note ?? ''
|
||||
|
||||
const getLastBuildChatAnswerText = async (page: Page) => {
|
||||
const answer = page.getByTestId('chat-answer-container').last()
|
||||
if (await answer.count() === 0)
|
||||
return ''
|
||||
|
||||
return (await answer.textContent())?.replace(/\s+/g, ' ').trim() ?? ''
|
||||
}
|
||||
|
||||
const formatBuildChatAnswerText = (text: string) =>
|
||||
text.length > 500 ? `${text.slice(0, 500)}...` : text
|
||||
|
||||
Given(
|
||||
'an Agent v2 Build draft adds the supported E2E files, skills, and env',
|
||||
async function (this: DifyWorld) {
|
||||
@ -133,7 +145,7 @@ Given(
|
||||
|
||||
When(
|
||||
'I generate an Agent v2 Build draft from the fixed instruction',
|
||||
{ timeout: 180_000 },
|
||||
{ timeout: BUILD_DRAFT_RUNTIME_STEP_TIMEOUT_MS },
|
||||
async function (this: DifyWorld) {
|
||||
const page = this.getPage()
|
||||
const agentId = getCurrentAgentId(this)
|
||||
@ -153,9 +165,13 @@ When(
|
||||
|
||||
await page.getByRole('button', { name: 'Start build' }).click()
|
||||
expect((await checkoutResponsePromise).ok()).toBe(true)
|
||||
expect((await chatResponsePromise).ok()).toBe(true)
|
||||
await expect(getBuildDraftBar(page)).toBeVisible({ timeout: 120_000 })
|
||||
await expect(page.getByRole('button', { exact: true, name: 'Apply' })).toBeEnabled({ timeout: 120_000 })
|
||||
const chatResponse = await chatResponsePromise
|
||||
expect(chatResponse.ok()).toBe(true)
|
||||
expect(await chatResponse.finished()).toBeNull()
|
||||
|
||||
await expect(page.getByRole('button', { name: 'Stop responding' })).not.toBeVisible()
|
||||
await expect(getBuildDraftBar(page)).toBeVisible()
|
||||
await expect(page.getByRole('button', { exact: true, name: 'Apply' })).toBeEnabled()
|
||||
await expect(page.getByRole('button', { exact: true, name: 'Discard' })).toBeEnabled()
|
||||
},
|
||||
)
|
||||
@ -290,10 +306,19 @@ Then('I should see the Agent v2 Build mode confirmation state', async function (
|
||||
Then(
|
||||
'the Agent v2 Build draft should include the generated build note',
|
||||
async function (this: DifyWorld) {
|
||||
await expect.poll(
|
||||
async () => getConfigNote(await getAgentBuildDraft(getCurrentAgentId(this))),
|
||||
{ timeout: 30_000 },
|
||||
).toContain(BUILD_NOTE_MARKER)
|
||||
try {
|
||||
await expect.poll(
|
||||
async () => getConfigNote(await getAgentBuildDraft(getCurrentAgentId(this))),
|
||||
{ timeout: BUILD_DRAFT_NOTE_SYNC_TIMEOUT_MS },
|
||||
).toContain(BUILD_NOTE_MARKER)
|
||||
}
|
||||
catch (error) {
|
||||
const lastAnswerText = await getLastBuildChatAnswerText(this.getPage())
|
||||
throw new Error(
|
||||
`Agent v2 Build draft note did not include ${BUILD_NOTE_MARKER}. Last Build chat answer: ${formatBuildChatAnswerText(lastAnswerText) || '<empty>'}`,
|
||||
{ cause: error },
|
||||
)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
@ -32,6 +32,7 @@ const webBuildStampPath = path.join(webDir, '.next', 'e2e-web-build.sha256')
|
||||
const apiHost = '127.0.0.1'
|
||||
const apiPort = 5001
|
||||
const agentBackendHost = '127.0.0.1'
|
||||
const agentBackendBindHost = '0.0.0.0'
|
||||
const agentBackendPort = Number(process.env.E2E_AGENT_BACKEND_PORT || 5050)
|
||||
const shellctlHost = '127.0.0.1'
|
||||
const shellctlPort = Number(process.env.E2E_SHELLCTL_PORT || 5004)
|
||||
@ -366,7 +367,7 @@ export const startAgentBackend = async () => {
|
||||
'uvicorn',
|
||||
'dify_agent.server.app:app',
|
||||
'--host',
|
||||
agentBackendHost,
|
||||
agentBackendBindHost,
|
||||
'--port',
|
||||
String(agentBackendPort),
|
||||
],
|
||||
|
||||
Loading…
Reference in New Issue
Block a user