feat: 接入持久化工作流执行状态

This commit is contained in:
GouJ committed 2026-09-23 19:53:55 +08:00
1 parent 7d2900c705
commit 3caea26924
14 files changed
+532 -44

No files matched your search

@@ -332,7 +332,13 @@ describe('首帧批量参数', () => {
await service.run('keyframes')
expect(posts()).toHaveLength(1)
await service.run('prompts')
expect(JSON.parse(String(posts()[1]?.[1]?.body))).toEqual({ concurrency: 2, force: false })
expect(posts()[1]?.[0]).toBe('/api/projects/capability-test/video-prompts/generate/start')
expect(JSON.parse(String(posts()[1]?.[1]?.body))).toEqual({
concurrency: 2,
force: false,
episodeNo: 1,
limit: 1
})
service.keyframeLimit.value = ''
service.keyframeWidth.value = ''
service.keyframeHeight.value = ''
+2 -2
View File
@@ -128,14 +128,14 @@ describe('镜头生产数据契约', () => {
})
vi.stubGlobal('fetch', fetcher)
await productionApi.videoReadiness('project/1', true)
await productionApi.generateQualityVideos('project/1', {
await productionApi.startQualityVideoExecution('project/1', {
concurrency: 3,
force: true,
limit: 2,
maxRepairAttempts: 2
})
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/projects/project%2F1/videos/readiness?force=true')
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/projects/project%2F1/videos/generate-quality')
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/projects/project%2F1/videos/generate-quality/start')
expect(JSON.parse(String(fetcher.mock.calls[1]?.[1]?.body))).toEqual({
concurrency: 3,
force: true,
@@ -0,0 +1,74 @@
import { flushPromises, mount } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { effectScope, ref } from 'vue'
import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue'
import { executionPercentage, executionStageLabel, useWorkflowExecution } from '@/features/workflows/execution'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
const execution = (overrides: Partial<WorkflowExecution> = {}): WorkflowExecution => ({
id: 'execution-1',
projectId: 'project-1',
workflowName: 'video-quality',
status: 'running',
stage: 'validating',
current: 1,
total: 2,
currentResourceId: 'shot-1',
metadata: null,
result: null,
error: null,
startedAt: '2026-09-23T00:00:00Z',
completedAt: null,
createdAt: '2026-09-23T00:00:00Z',
updatedAt: '2026-09-23T00:01:00Z',
...overrides
})
afterEach(() => {
localStorage.clear()
vi.unstubAllGlobals()
})
describe('WorkflowExecution 前端契约', () => {
it('保留未知阶段并限制真实进度范围', () => {
expect(executionStageLabel('repairing')).toBe('自动修复')
expect(executionStageLabel('new_backend_stage')).toBe('new_backend_stage')
expect(executionPercentage(1, 2)).toBe(50)
expect(executionPercentage(4, 2)).toBe(100)
expect(executionPercentage(1, 0)).toBe(0)
})
it('刷新页面后使用保存的 executionId 读取后端权威状态', async () => {
localStorage.setItem('short-drama:workflow-execution:project-1:video-quality', 'execution-1')
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
new Response(JSON.stringify({ data: execution() }))
)
vi.stubGlobal('fetch', fetcher)
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(ref('project-1'), 'video-quality'))!
await flushPromises()
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/workflow-executions/execution-1')
expect(tracker.query.data.value?.stage).toBe('validating')
tracker.dismiss()
expect(localStorage.getItem('short-drama:workflow-execution:project-1:video-quality')).toBeNull()
scope.stop()
})
it('完成面板展示质量汇总和下一步状态', () => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution({
status: 'completed',
stage: 'completed',
current: 2,
result: { targetCount: 2, passed: 1, exhausted: 1, providerFailed: 0, submissionFailed: 0 }
}),
loading: false,
error: ''
}
})
expect(wrapper.text()).toContain('本轮任务已结束')
expect(wrapper.text()).toContain('通过 1')
expect(wrapper.text()).toContain('修复耗尽 1')
})
})