Skip to content
Open
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
9 changes: 6 additions & 3 deletions frontend-v2/e2e/workflow-agents.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { expect, test } from '@playwright/test'
import { signIn } from './login.ts'
type Executor = { agentId: string; agentName: string; modelId: string; modelName: string }

test('workflow agent: an empty directory retains desktop defaults for a new node', async ({ page }) => {
test('workflow agent: an empty directory leaves a new node executor blank without desktop defaults', async ({ page }) => {
await page.route('**/api/v2/tenants/*/chat/executors', (route) => route.fulfill({ json: { items: [] } }))
await page.goto('/workflows')
await signIn(page)
Expand All @@ -15,11 +15,14 @@ test('workflow agent: an empty directory retains desktop defaults for a new node
await page.reload()
await page.getByRole('complementary', { name: '工作流列表' }).getByRole('button', { name, exact: true }).click()
await page.getByRole('toolbar', { name: '添加工作流节点' }).getByRole('button', { name: 'Agent', exact: true }).click()
await expect(page.getByText('请选择当前可用的 Agent 和模型。')).toBeVisible()
const modelButton = page.getByLabel('Agent 模型', { exact: true })
await expect(modelButton).toContainText('没有可用 Agent 模型')
await expect(modelButton).not.toContainText(' · ')
await expect(page.getByText('请选择当前可用的 Agent 和模型。')).toHaveCount(0)
await expect.poll(async () => {
const draft = (await (await page.request.get(`${base}/${wid}/draft`)).json()).snapshot
return JSON.parse(draft.graph).nodes.find((n: { data: { kind: string } }) => n.data.kind === 'agent')?.data.agentConfig.executor
}).toEqual({ agentCli: 'official/ora-space.codeagentcli', modelId: 'gpt-5' })
}).toEqual({ agentCli: '', modelId: '' })
})

test('workflow agent: replace a legacy demo choice, persist real IDs, and execute the selected binding', async ({ page }, testInfo) => {
Expand Down
72 changes: 72 additions & 0 deletions frontend-v2/e2e/workflow-model-hydration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,75 @@ for (const [label, model, expected] of [
expect(await savedExecutor()).toEqual({ agentCli: agent, modelId: expected })
})
}

test('workflow editor shows empty model placeholder without desktop default when catalog is empty', async ({ page }, testInfo) => {
await page.route('**/api/v2/tenants/*/chat/executors', (route) => route.fulfill({ json: { items: [] } }))
await page.goto('/workflows')
await signIn(page)
const tid = (await (await page.request.get('/api/v1/me/tenants')).json()).items[0].id
const base = `/api/v2/tenants/${tid}/workflows`
const name = `空目录模型 ${Date.now()}`
const graph = JSON.stringify({ nodes: [
{ id: 'start', type: 'workflow', position: { x: 0, y: 0 }, data: { kind: 'start', title: '开始' } },
], edges: [] })
const created = await page.request.post(base, { data: { name, graph } })
expect(created.status()).toBe(201)
const wid = (await created.json()).workflow.id

await page.reload()
await page.getByRole('complementary', { name: '工作流列表' }).getByRole('button', { name, exact: true }).click()
await page.getByRole('button', { name: 'Agent', exact: true }).click()
const addedNode = page.locator('.react-flow__node').filter({ hasNotText: '开始' }).first()
await expect(addedNode).toBeVisible()
await addedNode.click()
const modelButton = page.getByLabel('Agent 模型', { exact: true })
await expect(modelButton).toContainText('没有可用 Agent 模型')
await expect(modelButton).not.toContainText(' · ')
await expect(modelButton).not.toContainText('gpt-5')
await page.screenshot({ path: testInfo.outputPath('model-empty-catalog.png'), animations: 'disabled' })

await page.getByRole('button', { name: '发布', exact: true }).click()
await expect(page.getByRole('alertdialog', { name: '发布工作流' })).toBeVisible()
const savedAgent = JSON.parse((await (await page.request.get(`${base}/${wid}/draft`)).json()).snapshot.graph).nodes
.find((node: { data: { kind: string } }) => node.data.kind === 'agent')
expect(savedAgent.data.agentConfig.executor).toEqual({ agentCli: '', modelId: '' })
})

test('workflow editor repairs stale model when executor catalog arrives late after workflow open', async ({ page }) => {
let releaseCatalog!: () => void
const catalogReady = new Promise<void>((resolve) => {
releaseCatalog = resolve
})
await page.route('**/api/v2/tenants/*/chat/executors', async (route) => {
await catalogReady
await route.fulfill({ json: { items: executors } })
})
await page.goto('/workflows')
await signIn(page)
const tid = (await (await page.request.get('/api/v1/me/tenants')).json()).items[0].id
const base = `/api/v2/tenants/${tid}/workflows`
const name = `迟到目录 ${Date.now()}`
const graph = JSON.stringify({ nodes: [
{ id: 'start', type: 'workflow', position: { x: 0, y: 0 }, data: { kind: 'start', title: '开始' } },
{ id: 'agent', type: 'workflow', position: { x: 320, y: 0 }, data: { kind: 'agent', title: '模型检查', agentConfig: { executor: { agentCli: agent, modelId: 'deepseek/deepseek-v4-flash' }, prompt: 'hello' } } },
], edges: [{ id: 'edge', source: 'start', target: 'agent' }] })
const created = await page.request.post(base, { data: { name, graph } })
expect(created.status()).toBe(201)
const wid = (await created.json()).workflow.id

await page.reload()
await page.getByRole('complementary', { name: '工作流列表' }).getByRole('button', { name, exact: true }).click()
await page.locator('.react-flow__node[data-id="agent"]').click()
const modelButton = page.getByLabel('Agent 模型', { exact: true })
await expect(modelButton).toContainText('official/ora-space.opencode · deepseek/deepseek-v4-flash')
await expect(page.getByText('未保存', { exact: true })).toBeHidden()

releaseCatalog()
await expect(modelButton).toContainText('当前模型')
await expect(page.getByText('未保存', { exact: true })).toBeHidden()
await page.getByRole('button', { name: '发布', exact: true }).click()
await expect(page.getByRole('alertdialog', { name: '发布工作流' })).toBeVisible()
const savedAgent = JSON.parse((await (await page.request.get(`${base}/${wid}/draft`)).json()).snapshot.graph).nodes
.find((node: { id: string }) => node.id === 'agent')
expect(savedAgent.data.agentConfig.executor).toEqual({ agentCli: agent, modelId: 'configured' })
})
38 changes: 38 additions & 0 deletions frontend-v2/e2e/workflow-retry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,41 @@ test('a wait left under a failed run shows neither a countdown nor a scheduled r
await db.end()
}
})

test('retried node exposes injected previous failure context in node details', async ({ page }, testInfo) => {
const { tid, rid } = await createRun(page)
const db = database()
await db.connect()
try {
const previous = randomUUID(), current = randomUUID(), now = Date.now()
const injected = '## 上一次尝试(第 1 次)失败信息\n\n原因: 结构化输出校验失败:缺少 summary 字段'
const firstFailure = { error_detail: { kind: 'structured_output', message: '缺少 summary 字段', source_chain: [], attempt: 1, auto_retryable: true, recorded_at: now } }
const secondFailure = {
error_detail: { kind: 'structured_output', message: '仍然缺少 summary 字段', source_chain: [], attempt: 2, auto_retryable: false, recorded_at: now + 1000 },
injected_failure_context: injected,
retry_chain: [previous],
}
await db.query(`INSERT INTO v2_workflow_node_runs (tenant_id,run_id,scope_id,node_id,node_type,status,output,started_at,finished_at)
VALUES ($1,$2,$3,'start','start','succeeded','',now(),now())`, [tid, rid, `root:${rid}`])
await db.query(`INSERT INTO v2_workflow_node_runs (id,tenant_id,run_id,scope_id,node_id,node_type,status,error,payload,started_at,finished_at,deleted_at)
VALUES ($1,$2,$3,$4,'agent','agent','failed','缺少 summary 字段',$5,now(),now(),now())`, [previous, tid, rid, `root:${rid}`, JSON.stringify(firstFailure)])
await db.query(`INSERT INTO v2_workflow_node_runs (id,tenant_id,run_id,scope_id,node_id,node_type,status,error,payload,started_at,finished_at)
VALUES ($1,$2,$3,$4,'agent','agent','failed','仍然缺少 summary 字段',$5,now(),now())`, [current, tid, rid, `root:${rid}`, JSON.stringify(secondFailure)])
await db.query(`UPDATE v2_workflow_runs SET status='failed',error='仍然缺少 summary 字段',state='{"current_nodes":["agent"]}',started_at=now(),finished_at=now() WHERE id=$1`, [rid])

await page.goto(`/chat?run=${rid}`)
const pane = page.getByRole('region', { name: '工作流运行' })
await pane.getByRole('button', { name: '全图', exact: true }).click()
await pane.getByLabel('工作流全图俯瞰').getByText('重试任务', { exact: true }).click()
await pane.getByRole('button', { name: '打开节点详情' }).click()
const summary = pane.getByText('本次尝试注入的上次失败信息', { exact: true }).filter({ visible: true }).first()
await expect(summary).toBeVisible()
await summary.click()
const injectedContent = pane.getByText(/缺少 summary 字段/).filter({ visible: true }).first()
await expect(injectedContent).toBeVisible()
await injectedContent.scrollIntoViewIfNeeded()
await page.screenshot({ path: testInfo.outputPath('retry-injected-failure.png'), animations: 'disabled', fullPage: true })
} finally {
await db.end()
}
})
42 changes: 42 additions & 0 deletions frontend-v2/e2e/workflow-runs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ test('workflow runs: v2-server executes a published workflow started from chat',
await page.getByRole('menuitem', { name: new RegExp(name) }).click()
const dialog = page.getByRole('dialog', { name: '运行工作流' })
await dialog.getByLabel('运行名称').fill(runName)
const injectLastFailure = dialog.getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })
await expect(injectLastFailure).toBeVisible()
await expect(injectLastFailure).toBeChecked()
await screenshot(page, testInfo.outputPath('run-dialog-inject-default.png'))
await dialog.getByRole('button', { name: '创建运行' }).click()
const pane = page.getByRole('region', { name: '工作流运行' })
await expect(pane.getByRole('heading', { name: runName })).toBeVisible()
Expand Down Expand Up @@ -180,6 +184,10 @@ test('workflow runs: a Condition takes one branch and the other shows as inactiv
await page.getByRole('menuitem', { name: new RegExp(name) }).click()
const dialog = page.getByRole('dialog', { name: '运行工作流' })
await dialog.getByLabel('运行名称').fill(runName)
const injectLastFailure = dialog.getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })
await expect(injectLastFailure).toBeVisible()
await expect(injectLastFailure).toBeChecked()
await screenshot(page, testInfo.outputPath('run-dialog-inject-default.png'))
await dialog.getByRole('button', { name: '创建运行' }).click()
const pane = page.getByRole('region', { name: '工作流运行' })
await expect(pane.getByRole('heading', { name: runName })).toBeVisible()
Expand Down Expand Up @@ -220,3 +228,37 @@ test('workflow runs: a Condition takes one branch and the other shows as inactiv
await expect(pane.getByLabel('实际执行').filter({ visible: true }).first()).toContainText('· Fixture')
await screenshot(page, testInfo.outputPath('s2-branch-agent-details.png'))
})

test('workflow runs: unchecking injectLastFailure sends false on create and resets on reopen', async ({ page }) => {
await page.goto('/chat')
await signIn(page)
const tenantId = ((await (await page.request.get('/api/v1/me/tenants')).json()) as { items: { id: string }[] }).items[0]!.id
const suffix = Date.now().toString(36)
const name = `失败注入开关 ${suffix}`
const created = await page.request.post(`/api/v2/tenants/${tenantId}/workflows`, { data: { name, graph: chain } })
expect(created.status()).toBe(201)
const workflowId = ((await created.json()) as { draft: { workflowId: string } }).draft.workflowId
expect((await page.request.post(`/api/v2/tenants/${tenantId}/workflows/${workflowId}/publish`, { data: { version: 'v1' } })).ok()).toBe(true)

await page.reload()
await page.getByRole('button', { name: '运行工作流', exact: true }).click()
await page.getByRole('menuitem', { name: new RegExp(name) }).click()
const dialog = page.getByRole('dialog', { name: '运行工作流' })
const checkbox = dialog.getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })
await expect(checkbox).toBeChecked()
await checkbox.uncheck()
await expect(checkbox).not.toBeChecked()

const createRequest = page.waitForRequest((req) => req.url().includes(`/workflows/${workflowId}/runs`) && req.method() === 'POST')
const createResponse = page.waitForResponse((res) => res.url().includes(`/workflows/${workflowId}/runs`) && res.request().method() === 'POST')
await dialog.getByLabel('运行名称').fill(`关闭注入 ${suffix}`)
await dialog.getByRole('button', { name: '创建运行' }).click()
expect((await createRequest).postDataJSON()).toMatchObject({ injectLastFailure: false })
const createdRun = (await (await createResponse).json()) as { run: { id: string } }
expect((await page.request.delete(`/api/v2/tenants/${tenantId}/workflow-runs/${createdRun.run.id}`)).ok()).toBe(true)

await page.getByRole('button', { name: '新建对话', exact: true }).click()
await page.getByRole('button', { name: '运行工作流', exact: true }).click()
await page.getByRole('menuitem', { name: new RegExp(name) }).click()
await expect(page.getByRole('dialog', { name: '运行工作流' }).getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })).toBeChecked()
})
30 changes: 30 additions & 0 deletions frontend-v2/src/features/chat/workflow-run/run-flow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,34 @@ describe('workflow runs in chat', () => {
expect(screen.getByRole('heading', { level: 2, name: '梳理 v2 接口缺口' })).toBeInTheDocument()
expect(within(project()).getByRole('button', { name: '工作流运行 临时运行(未运行)' })).not.toHaveAttribute('aria-current')
})

it('sends injectLastFailure true by default, false when unchecked, and resets on reopen', async () => {
const user = userEvent.setup()
await renderPage()
const openDialog = async () => {
await user.click(within(project()).getByRole('button', { name: '在 ora-space/cloud 新建对话' }))
await user.click(await screen.findByRole('menuitem', { name: '运行工作流' }))
fireEvent.click(await screen.findByRole('menuitem', { name: /示例:代码审查/ }))
return screen.findByRole('dialog', { name: '运行工作流' })
}

let dialog = await openDialog()
let checkbox = within(dialog).getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })
expect(checkbox).toBeChecked()
await user.click(within(dialog).getByRole('button', { name: '创建运行' }))
await waitFor(() => expect(runs.createdBodies).toHaveLength(1))
expect(runs.createdBodies[0]?.injectLastFailure).toBe(true)

dialog = await openDialog()
checkbox = within(dialog).getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })
expect(checkbox).toBeChecked()
await user.click(checkbox)
expect(checkbox).not.toBeChecked()
await user.click(within(dialog).getByRole('button', { name: '创建运行' }))
await waitFor(() => expect(runs.createdBodies).toHaveLength(2))
expect(runs.createdBodies[1]?.injectLastFailure).toBe(false)

dialog = await openDialog()
expect(within(dialog).getByRole('checkbox', { name: '节点重跑时把上次失败原因告诉智能体' })).toBeChecked()
})
})
Loading
Loading