fix(short-drama-agent-front): 修复拆解进度展示与问题交互

This commit is contained in:
GJ committed 2026-10-17 10:21:44 +08:00
1 parent 3414cc8232
commit db91a4b871
19 files changed
+870 -150

No files matched your search

+61 -2
View File
@@ -10,13 +10,62 @@ import type { Checkpoint } from '@/features/workflows/types'
import type { BreakdownModule, EpisodePlan } from '@/features/breakdown/types'
import { drawerPanel } from '@/testing/naive'
import { readAllStyles } from '@/testing/styles'
import { effectScope } from 'vue'
import { useWorkflowExecution } from '@/features/workflows/execution'
import { workflowExecutionApi } from '@/features/workflows/execution-api'
let wrapper: VueWrapper | undefined
/** 跨组件后台任务观察器,验证结束时释放。 */
let taskScope: ReturnType<typeof effectScope> | undefined
afterEach(() => {
taskScope?.stop()
taskScope = undefined
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
vi.unstubAllGlobals()
vi.restoreAllMocks()
localStorage.clear()
})
it('后台重新拆解时显示真实运行状态并隐藏所有诊断入口,终态后恢复', async () => {
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
)
const provided = mountPage()
await selectTab('分镜')
const record = {
id: 'external-breakdown-ui',
projectId: 'breakdown-scroll-test',
workflowName: 'breakdown',
status: 'running' as 'running' | 'completed',
stage: 'storyboard_plan_ready',
current: 1,
total: 3,
currentResourceId: null,
metadata: { progressUnit: 'storyboard_episodes' },
result: null,
error: null,
startedAt: '2026-10-17T00:00:00Z',
completedAt: null,
createdAt: '2026-10-17T00:00:00Z',
updatedAt: '2026-10-17T00:01:00Z'
}
vi.spyOn(workflowExecutionApi, 'get').mockImplementation(async () => ({ ...record }))
taskScope = effectScope()
const tracker = taskScope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
await tracker.track(record.id)
await flushPromises()
expect(wrapper!.text()).toContain('拆解进行中')
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(false)
expect(wrapper!.find('.diagnose-hover-action').exists()).toBe(false)
record.status = 'completed'
await tracker.query.refresh()
await flushPromises()
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(true)
expect(provided.refresh).toHaveBeenCalled()
tracker.dismiss()
})
/** 长主体、长分镜与长任务列表,用真实 Naive 滚动组件验证内容边界。 */
@@ -495,7 +544,7 @@ describe('拆解页内容滚动', () => {
expect(fetcher).not.toHaveBeenCalled()
})
it('关闭设置时保留问题入口,详细校验与恢复在面板内,不挤占结果高度', async () => {
it('问题入口打开独立错误弹窗,拆解设置不再包含详细错误', async () => {
const record = checkpoint()
record.state.workflowExecution!.status = 'failed'
record.state.workflowExecution!.errorMessage = '工作流中断'
@@ -509,7 +558,17 @@ describe('拆解页内容滚动', () => {
const action = wrapper!.findAll('button').find(item => item.text() === '查看拆解问题')!
await action.trigger('click')
await flushPromises()
expect(drawerPanel().text()).toContain('缺少形态绑定')
const issues = document.querySelector<HTMLElement>('.app-dialog[aria-label="拆解问题"]')
expect(issues?.textContent).toContain('缺少形态绑定')
expect(issues?.textContent).toContain('工作流中断')
expect(issues?.textContent).not.toContain('重试失败抽取')
await new DOMWrapper(issues!).get('.n-card-header__close').trigger('click')
await flushPromises()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await flushPromises()
expect(drawerPanel().text()).not.toContain('缺少形态绑定')
expect(drawerPanel().text()).not.toContain('工作流中断')
expect(drawerPanel().text()).toContain('查看问题')
expect(drawerPanel().text()).toContain('重试失败抽取')
})
@@ -0,0 +1,40 @@
import { afterEach, describe, expect, it } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import BreakdownIssuesDialog from '@/features/breakdown/components/BreakdownIssuesDialog.vue'
import AppDialog from '@/components/ui/AppDialog.vue'
/** 独立问题弹窗实例,验证后移除 Teleport。 */
let wrapper: VueWrapper | undefined
afterEach(() => {
wrapper?.unmount()
document.body.innerHTML = ''
})
describe('拆解问题弹窗', () => {
it('同镜头问题合并展示并去重,定位等待弹窗离场后发出', async () => {
wrapper = mount(BreakdownIssuesDialog, {
attachTo: document.body,
props: {
open: true,
locatable: true,
issues: [
{ episodeNo: 1, beatNo: 2, shotNo: 3, message: '缺少场景' },
{ episodeNo: 1, beatNo: 2, shotNo: 3, message: '缺少道具' },
{ episodeNo: 1, beatNo: 2, shotNo: 3, message: '缺少场景' },
{ episodeNo: 2, beatNo: 1, shotNo: 1, message: '缺少人物' }
]
}
})
await flushPromises()
expect(document.querySelectorAll('.breakdown-issue-group')).toHaveLength(2)
expect(document.body.textContent).toContain('3 项校验问题 · 2 个位置')
const button = [...document.querySelectorAll<HTMLButtonElement>('button')].find(
item => item.textContent?.trim() === '定位分镜'
)!
button.click()
await flushPromises()
expect(wrapper.emitted('locate')).toBeUndefined()
wrapper.getComponent(AppDialog).vm.$emit('closed')
expect(wrapper.emitted('locate')?.[0]?.[0]).toMatchObject({ episodeNo: 1, beatNo: 2, shotNo: 3 })
})
})
+2
View File
@@ -8,6 +8,7 @@ import ProjectLayout from '@/features/projects/ProjectLayout.vue'
import { isProjectComplete } from '@/features/projects/access'
import { useProjectContext } from '@/features/projects/context'
import { projectsApi } from '@/features/projects/api'
import { workflowExecutionApi } from '@/features/workflows/execution-api'
import { getOperation } from '@/features/workflows/operations'
import type { ProjectDetail, ProjectStageReadiness, ProjectStatus } from '@/features/projects/types'
import { readAllStyles } from '@/testing/styles'
@@ -34,6 +35,7 @@ function readiness(id: string, ready = true): ProjectStageReadiness {
}
beforeEach(() => {
vi.spyOn(workflowExecutionApi, 'latest').mockResolvedValue(null)
vi.spyOn(projectsApi, 'stageReadiness').mockImplementation(async id => readiness(id))
})
let wrapper: VueWrapper | undefined
+113
View File
@@ -0,0 +1,113 @@
import { effectScope, ref } from 'vue'
import { flushPromises } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { useWorkflowExecution } from '@/features/workflows/execution'
import { getOperation } from '@/features/workflows/operations'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
/** 后端自行启动的拆解任务,本地没有保存过句柄。 */
function record(projectId: string, status: WorkflowExecution['status'] = 'running'): WorkflowExecution {
return {
id: `external-${projectId}`,
projectId,
workflowName: 'breakdown',
status,
stage: 'breakdown',
current: 0,
total: 0,
currentResourceId: null,
metadata: {},
result: null,
error: null,
startedAt: '2026-10-17T00:00:00Z',
completedAt: null,
createdAt: '2026-10-17T00:00:00Z',
updatedAt: '2026-10-17T00:00:00Z'
}
}
afterEach(() => {
localStorage.clear()
vi.unstubAllGlobals()
})
describe('服务端任务发现', () => {
it('页面保持打开时通过事件接上新任务,终态不被迟到运行消息重新激活', async () => {
const task = record('discovery-stream')
/** 仅模拟浏览器事件连接,所有任务仍来自测试响应。 */
class TestEventSource extends EventTarget {
static last: TestEventSource
close = vi.fn<() => void>()
constructor() {
super()
TestEventSource.last = this
}
}
vi.stubGlobal('EventSource', TestEventSource)
vi.stubGlobal(
'fetch',
vi
.fn<typeof fetch>()
.mockImplementation(
async url => new Response(JSON.stringify({ data: String(url).includes('/latest?') ? null : task }))
)
)
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(ref(task.projectId), 'breakdown', { discover: true }))!
await flushPromises()
expect(tracker.executionId.value).toBe('')
TestEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
await flushPromises()
expect(tracker.active.value).toBe(true)
task.status = 'completed'
TestEventSource.last.dispatchEvent(new MessageEvent('message', { data: JSON.stringify(task) }))
await flushPromises()
TestEventSource.last.dispatchEvent(
new MessageEvent('message', { data: JSON.stringify({ ...task, status: 'running' }) })
)
await flushPromises()
expect(tracker.active.value).toBe(false)
expect(tracker.query.data.value?.status).toBe('completed')
scope.stop()
expect(TestEventSource.last.close).toHaveBeenCalledOnce()
})
it('没有本地句柄时发现后台任务并立即锁住项目操作', async () => {
const id = ref('discovery-active')
const task = record(id.value)
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: task })))
)
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(id, 'breakdown', { discover: true }))!
await flushPromises()
expect(tracker.executionId.value).toBe(task.id)
expect(tracker.active.value).toBe(true)
expect(getOperation(id.value).pending).toBe(true)
scope.stop()
})
it('切换项目后忽略旧项目迟到的发现响应', async () => {
let resolveOld!: (value: Response) => void
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async url => {
if (String(url).includes('/discovery-old/'))
return new Promise(resolve => {
resolveOld = resolve
})
return new Response(JSON.stringify({ data: null }))
})
)
const id = ref('discovery-old')
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(id, 'breakdown', { discover: true }))!
await flushPromises()
id.value = 'discovery-new'
await flushPromises()
resolveOld(new Response(JSON.stringify({ data: record('discovery-old') })))
await flushPromises()
expect(tracker.executionId.value).toBe('')
expect(getOperation('discovery-new').pending).toBe(false)
scope.stop()
})
})
@@ -30,6 +30,26 @@ afterEach(() => {
})
describe('WorkflowExecution 前端契约', () => {
it('拆解进度区分抽取计数与工作流完成,校验失败不显示全成功', () => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution({
workflowName: 'breakdown',
status: 'completed',
current: 3,
total: 3,
metadata: { progressUnit: 'extraction_tasks' },
result: { storyboardShotValidation: { valid: false, issues: [] } }
}),
loading: false,
error: ''
}
})
expect(wrapper.text()).toContain('抽取任务 3 / 3')
expect(wrapper.text()).toContain('校验未通过')
expect(wrapper.text()).not.toContain('最新镜头资产状态')
wrapper.unmount()
})
it('保留未知阶段并限制真实进度范围', () => {
expect(executionStageLabel('repairing')).toBe('自动修复')
expect(executionStageLabel('new_backend_stage')).toBe('new_backend_stage')