feat(short-drama-agent-front): 补齐后端生产与质量功能
This commit is contained in:
1 parent
967c4ebea1
commit
470b52e26d
52 files changed
+3754
-1075
No files matched your search
@@ -0,0 +1,117 @@
|
||||
import { effectScope, ref } from 'vue'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useWorkflowExecution } from '@/features/workflows/execution'
|
||||
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
||||
|
||||
/** 每个测试恢复句柄和网络依赖,避免项目任务泄漏到下一次验证。 */
|
||||
afterEach(() => {
|
||||
localStorage.clear()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
describe('异步任务启动后的项目归属', () => {
|
||||
it('原项目的启动回执到达时,只保存原项目句柄,不切换当前项目的观察目标', async () => {
|
||||
const loader = vi.spyOn(workflowExecutionApi, 'get')
|
||||
const scope = effectScope()
|
||||
const projectId = ref('project-b')
|
||||
const execution = scope.run(() => useWorkflowExecution(projectId, 'production'))!
|
||||
await execution.track('execution-a', 'project-a')
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:project-a:production')).toBe('execution-a')
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:project-b:production')).toBeNull()
|
||||
expect(execution.executionId.value).toBe('')
|
||||
expect(loader).not.toHaveBeenCalled()
|
||||
scope.stop()
|
||||
})
|
||||
})
|
||||
|
||||
it('同项目首帧后台任务在各观察器间同步,并阻止其它付费操作直到真实终态', async () => {
|
||||
const { getOperation } = await import('@/features/workflows/operations')
|
||||
const id = ref('shared-quality-project')
|
||||
const record = {
|
||||
id: 'quality-exec',
|
||||
projectId: id.value,
|
||||
workflowName: 'keyframe-quality',
|
||||
status: 'running' as 'running' | 'completed',
|
||||
stage: 'keyframe_quality',
|
||||
current: 0,
|
||||
total: 1,
|
||||
currentResourceId: null,
|
||||
metadata: {},
|
||||
result: null,
|
||||
error: null,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
createdAt: '2026-10-08',
|
||||
updatedAt: '2026-10-08'
|
||||
}
|
||||
vi.spyOn(workflowExecutionApi, 'get').mockImplementation(async () => ({ ...record }))
|
||||
const scope = effectScope()
|
||||
const [first, second] = scope.run(() => [
|
||||
useWorkflowExecution(id, 'keyframe-quality'),
|
||||
useWorkflowExecution(id, 'keyframe-quality')
|
||||
])!
|
||||
await first!.track(record.id, id.value)
|
||||
expect(getOperation(id.value).pending).toBe(true)
|
||||
expect(second!.executionId.value).toBe(record.id)
|
||||
expect(second!.active.value).toBe(true)
|
||||
record.status = 'completed'
|
||||
await first!.query.refresh()
|
||||
expect(getOperation(id.value).pending).toBe(false)
|
||||
scope.stop()
|
||||
})
|
||||
|
||||
it('已卸载观察器的迟到 running 记录不能重新锁住其它观察器已确认结束的任务', async () => {
|
||||
const { getOperation } = await import('@/features/workflows/operations')
|
||||
const id = ref('terminal-monotonic-project')
|
||||
const record = {
|
||||
id: 'terminal-exec',
|
||||
projectId: id.value,
|
||||
workflowName: 'keyframe-quality',
|
||||
status: 'running' as 'running' | 'completed',
|
||||
stage: 'keyframe_quality',
|
||||
current: 0,
|
||||
total: 1,
|
||||
currentResourceId: null,
|
||||
metadata: {},
|
||||
result: null,
|
||||
error: null,
|
||||
startedAt: null,
|
||||
completedAt: null,
|
||||
createdAt: '2026-10-08',
|
||||
updatedAt: '2026-10-08'
|
||||
}
|
||||
let delayed = false
|
||||
let finish!: (value: typeof record) => void
|
||||
vi.spyOn(workflowExecutionApi, 'get').mockImplementation(async () => {
|
||||
if (delayed) {
|
||||
delayed = false
|
||||
return new Promise(resolve => {
|
||||
finish = resolve
|
||||
})
|
||||
}
|
||||
return { ...record }
|
||||
})
|
||||
const firstScope = effectScope()
|
||||
const secondScope = effectScope()
|
||||
const first = firstScope.run(() => useWorkflowExecution(id, 'keyframe-quality'))!
|
||||
const second = secondScope.run(() => useWorkflowExecution(id, 'keyframe-quality'))!
|
||||
await first.track(record.id, id.value)
|
||||
delayed = true
|
||||
const lateResponse = first.query.refresh()
|
||||
firstScope.stop()
|
||||
record.status = 'completed'
|
||||
await second.query.refresh()
|
||||
expect(getOperation(id.value).pending).toBe(false)
|
||||
finish({ ...record, status: 'running' })
|
||||
await lateResponse
|
||||
expect(getOperation(id.value).pending).toBe(false)
|
||||
secondScope.stop()
|
||||
})
|
||||
|
||||
it('后台启动未返回编号时不静默当作已跟踪,也不保存虚假句柄', async () => {
|
||||
const scope = effectScope()
|
||||
const execution = scope.run(() => useWorkflowExecution(ref('missing-execution-id-project'), 'production'))!
|
||||
await expect(execution.track('', 'missing-execution-id-project')).rejects.toThrow('任务编号')
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:missing-execution-id-project:production')).toBeNull()
|
||||
scope.stop()
|
||||
})
|
||||
@@ -40,9 +40,7 @@ describe('WorkflowExecution 前端契约', () => {
|
||||
|
||||
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() }))
|
||||
)
|
||||
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'))!
|
||||
@@ -50,6 +48,11 @@ describe('WorkflowExecution 前端契约', () => {
|
||||
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')).toBe('execution-1')
|
||||
expect(tracker.active.value).toBe(true)
|
||||
fetcher.mockResolvedValue(new Response(JSON.stringify({ data: execution({ status: 'completed' }) })))
|
||||
await tracker.query.refresh()
|
||||
tracker.dismiss()
|
||||
expect(localStorage.getItem('short-drama:workflow-execution:project-1:video-quality')).toBeNull()
|
||||
scope.stop()
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user