48 lines
2.5 KiB
TypeScript
48 lines
2.5 KiB
TypeScript
import { afterEach, describe, expect, expectTypeOf, it, vi } from 'vitest'
|
|
import { storyboardApi } from '@/features/storyboard/api'
|
|
import { productionApi } from '@/features/production/api'
|
|
import type { WorkflowExecutionStart } from '@/features/workflows/execution.types'
|
|
|
|
/** 清除网络替身,保证边界用例相互隔离。 */
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
|
|
/** 既有批处理入口只接收真实 202 句柄,不产生最终回执或重复请求。 */
|
|
describe('既有生成入口异步契约', () => {
|
|
it('所有启动入口返回202句柄并保留原请求范围', async () => {
|
|
const start = { executionId: 'execution-1', status: 'running' as const }
|
|
const fetcher = vi
|
|
.fn<typeof fetch>()
|
|
.mockImplementation(async () => new Response(JSON.stringify({ data: start }), { status: 202 }))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
const batch = { concurrency: 2, force: false }
|
|
const calls = [
|
|
storyboardApi.regenerateEpisodeShots('project-1', 3),
|
|
storyboardApi.generateDirections('project-1', batch),
|
|
storyboardApi.generateVisualStates('project-1', { ...batch, maxRepairAttempts: 2 }),
|
|
storyboardApi.generatePrompts('project-1', batch),
|
|
productionApi.generateKeyframes('project-1', { ...batch, episodeNo: 3, limit: 1 })
|
|
]
|
|
for (const result of await Promise.all(calls)) expect(result).toEqual(start)
|
|
expect(fetcher).toHaveBeenCalledTimes(5)
|
|
expect(fetcher.mock.calls[0]?.[1]?.body).toBe(JSON.stringify({ episodeNo: 3 }))
|
|
expect(fetcher.mock.calls[4]?.[1]?.body).toBe(JSON.stringify({ ...batch, episodeNo: 3, limit: 1 }))
|
|
})
|
|
it('启动类型与最终批量回执严格分开', () => {
|
|
expectTypeOf<
|
|
Awaited<ReturnType<typeof storyboardApi.regenerateEpisodeShots>>
|
|
>().toEqualTypeOf<WorkflowExecutionStart>()
|
|
expectTypeOf<
|
|
Awaited<ReturnType<typeof storyboardApi.generateDirections>>
|
|
>().toEqualTypeOf<WorkflowExecutionStart>()
|
|
expectTypeOf<
|
|
Awaited<ReturnType<typeof storyboardApi.generateVisualStates>>
|
|
>().toEqualTypeOf<WorkflowExecutionStart>()
|
|
expectTypeOf<
|
|
Awaited<ReturnType<typeof storyboardApi.generatePrompts>>
|
|
>().toEqualTypeOf<WorkflowExecutionStart>()
|
|
expectTypeOf<
|
|
Awaited<ReturnType<typeof productionApi.generateKeyframes>>
|
|
>().toEqualTypeOf<WorkflowExecutionStart>()
|
|
})
|
|
})
|