feat(short-drama-agent-front): 适配故事规划并优化任务弹窗

This commit is contained in:
GJ committed 2026-10-28 11:47:05 +08:00
1 parent 48fce3975f
commit 5836b90934
12 files changed
+960 -133

No files matched your search

@@ -31,6 +31,50 @@ afterEach(() => {
})
describe('服务端任务发现', () => {
it('创作任务无本地句柄也能发现,SSE 不按旧节点顺序过滤阶段,失败终态拒绝迟到事件', async () => {
const task = { ...record('story-plan-discovery'), workflowName: 'create-drama', stage: 'generateStoryPlan' }
/** 只模拟浏览器连接,查询和事件均使用正式任务结构。 */
class StoryEventSource extends EventTarget {
/** 本次任务订阅。 */
static last: StoryEventSource
/** 组件销毁时关闭连接。 */
close = vi.fn<() => void>()
/** 登记当前订阅供测试发送服务端事件。 */
constructor() {
super()
StoryEventSource.last = this
}
}
vi.stubGlobal('EventSource', StoryEventSource)
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: task })))
)
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(ref(task.projectId), 'create-drama', { discover: true }))!
await flushPromises()
expect(tracker.query.data.value?.stage).toBe('generateStoryPlan')
expect(tracker.active.value).toBe(true)
for (const stage of ['generateWorld', 'generateEpisode', 'generateCharacter', 'reviewDrama']) {
task.stage = stage
StoryEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
await flushPromises()
expect(tracker.query.data.value?.stage).toBe(stage)
}
task.status = 'failed'
task.stage = 'failed'
StoryEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
await flushPromises()
StoryEventSource.last.dispatchEvent(
new MessageEvent('message', {
data: JSON.stringify({ ...task, status: 'running', stage: 'generateStoryPlan' })
})
)
await flushPromises()
expect(tracker.query.data.value?.status).toBe('failed')
expect(tracker.active.value).toBe(false)
scope.stop()
})
it('页面保持打开时通过事件接上新任务,终态不被迟到运行消息重新激活', async () => {
const task = record('discovery-stream')
/** 仅模拟浏览器事件连接,所有任务仍来自测试响应。 */
@@ -1,7 +1,9 @@
import { flushPromises, mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { effectScope, ref } from 'vue'
import { NTag } from 'naive-ui'
import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue'
import ContextNotice from '@/components/ui/ContextNotice.vue'
import { executionPercentage, executionStageLabel, useWorkflowExecution } from '@/features/workflows/execution'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
@@ -30,6 +32,54 @@ afterEach(() => {
})
describe('WorkflowExecution 前端契约', () => {
it.each([
{ projectStatus: 'need_review', type: 'warning', role: 'alert' },
{ projectStatus: 'completed', type: 'success', role: undefined },
{ projectStatus: undefined, type: 'info', role: undefined }
])(
'弹窗提示按实际结果突出注意事项,不将待审或未知结果显示为成功:$projectStatus',
({ projectStatus, type, role }) => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution({
workflowName: 'create-drama',
status: 'completed',
result: { projectStatus }
}),
loading: false,
error: '',
embedded: true
}
})
const notice = wrapper.getComponent(ContextNotice)
expect(notice.props('type')).toBe(type)
expect(notice.attributes('role')).toBe(role)
expect(notice.find('strong').exists()).toBe(true)
expect(notice.find('svg').exists()).toBe(true)
wrapper.unmount()
}
)
it.each([
{ projectStatus: 'completed', color: 'success', label: '已完成' },
{ projectStatus: 'need_review', color: 'warning', label: '待修订' },
{ projectStatus: undefined, color: 'default', label: '结果待确认' }
])('创作任务结束按明确项目审核结果展示:$projectStatus', ({ projectStatus, color, label }) => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution({
workflowName: 'create-drama',
status: 'completed',
stage: 'completed',
result: { projectStatus }
}),
loading: false,
error: ''
}
})
expect(wrapper.getComponent(NTag).props('type')).toBe(color)
expect(wrapper.getComponent(NTag).text()).toContain(label)
wrapper.unmount()
})
it('拆解进度区分抽取计数与工作流完成,校验失败不显示全成功', () => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {