feat(short-drama-agent-front): 完善镜头定位与项目配置

This commit is contained in:
GJ committed 2026-10-08 19:45:26 +08:00
1 parent 470b52e26d
commit 5b134207b8
66 files changed
+2042 -984

No files matched your search

+65 -13
View File
@@ -1,4 +1,8 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { flushPromises } from '@vue/test-utils'
import { effectScope, ref } from 'vue'
import { useWorkflowExecution } from '@/features/workflows/execution'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
import { ApiError, optionalResource, request } from '@/lib/http'
import { projectsApi } from '@/features/projects/api'
import { breakdownApi } from '@/features/breakdown/api'
@@ -184,21 +188,69 @@ describe('后端 API 契约', () => {
])
})
it('长工作流不使用普通查询的超时,不自动重试 POST', async () => {
it('拆解返回 202 观察句柄,后续轮询失败终态不会自动重发 POST', async () => {
vi.useFakeTimers()
let finish!: (value: Response) => void
const fetcher = vi.fn<(url: string, options: RequestInit) => Promise<Response>>().mockImplementation(
() =>
new Promise<Response>(resolve => {
finish = resolve
})
/** 真实执行查询字段,开始回执与失败终态分别由不同接口返回。 */
const record: WorkflowExecution = {
id: 'http-breakdown-execution',
projectId: 'http-breakdown-project',
workflowName: 'breakdown',
status: 'running',
stage: 'breakdown',
current: 0,
total: 1,
currentResourceId: null,
metadata: null,
result: null,
error: null,
startedAt: '2026-10-08T00:00:00Z',
completedAt: null,
createdAt: '2026-10-08T00:00:00Z',
updatedAt: '2026-10-08T00:00:00Z'
}
const fetcher = vi.fn<typeof fetch>().mockImplementation(
async (_url, init) =>
new Response(
JSON.stringify({
data: init?.method === 'POST' ? { executionId: record.id, status: 'pending', total: 1 } : record
}),
{ status: init?.method === 'POST' ? 202 : 200 }
)
)
vi.stubGlobal('fetch', fetcher)
const running = breakdownApi.run('p', 'start', { groupSize: 3, modules: ['prop'] })
await vi.advanceTimersByTimeAsync(120_000)
expect(fetcher).toHaveBeenCalledTimes(1)
expect(fetcher.mock.calls[0]![1].signal?.aborted).toBe(false)
finish(new Response('{"data":{"workflowExecution":{"status":"failed"}}}'))
expect(await running).toMatchObject({ workflowExecution: { status: 'failed' } })
const started = await breakdownApi.run(record.projectId, 'start', { groupSize: 3, modules: ['prop'] })
expect(started).toEqual({ executionId: record.id, status: 'pending', total: 1 })
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/projects/http-breakdown-project/breakdown/start')
expect(JSON.parse(String(fetcher.mock.calls[0]?.[1]?.body))).toEqual({ groupSize: 3, modules: ['prop'] })
const scope = effectScope()
const tracker = scope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
try {
await tracker.track(started.executionId)
await flushPromises()
expect(tracker.active.value).toBe(true)
expect(tracker.query.data.value?.status).toBe('running')
record.status = 'failed'
record.error = '后端抽取失败'
record.completedAt = '2026-10-08T00:01:00Z'
await vi.advanceTimersByTimeAsync(1_500)
await flushPromises()
expect(tracker.query.data.value).toMatchObject({ status: 'failed', error: '后端抽取失败' })
expect(tracker.active.value).toBe(false)
const completedCount = fetcher.mock.calls.length
await vi.advanceTimersByTimeAsync(120_000)
expect(fetcher).toHaveBeenCalledTimes(completedCount)
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
expect(
fetcher.mock.calls
.slice(1)
.every(
([url, init]) =>
url === '/api/workflow-executions/http-breakdown-execution' && init?.method === 'GET'
)
).toBe(true)
} finally {
tracker.dismiss()
scope.stop()
}
})
})