feat(short-drama-agent-front): 接入分阶段镜头生产与摄影修订

This commit is contained in:
GJ committed 2026-11-15 20:55:51 +08:00
1 parent 1e9ef33d1d
commit 87427d9d43
29 files changed
+2787 -136

No files matched your search

@@ -0,0 +1,656 @@
import { defineComponent, h } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { NCheckbox, NInput, NTag } from 'naive-ui'
import { testProjectContext } from '@/testing/project-context'
import { projectContextKey } from '@/features/projects/context'
import { useStoryboard } from '@/features/storyboard/useStoryboard'
import { derivedBatchInput, derivedState, derivedTaskState } from '@/features/storyboard/staged-derived'
import {
designedShot,
directionsResult,
visualStatesResult,
storyboardCheckpoint
} from '@/features/storyboard/testing/fixtures'
import { preparationFixture } from '../storyboard-preparation/fixtures'
import ShotDerivedReview from '@/features/storyboard/components/ShotDerivedReview.vue'
import { imagePreviewFixture } from '../../fixtures/image-preview'
import { billingCatalog, billingProfile } from '../../fixtures/billing'
import StagedShotPreparation from '@/features/storyboard/components/StagedShotPreparation.vue'
import ConfirmAction from '@/features/workflows/ConfirmAction.vue'
import DirectionStageReview from '@/features/storyboard/components/DirectionStageReview.vue'
import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
import { workflowExecutionApi } from '@/features/workflows/execution-api'
/** 每个用例独立项目,避免共享活动锁污染其它范围。 */
let serial = 0
/** 已挂载实例统一释放轮询与取消信号。 */
const wrappers: VueWrapper[] = []
afterEach(() => {
wrappers.splice(0).forEach(wrapper => wrapper.unmount())
localStorage.clear()
})
/**
* 不接触真实数据的公开 API 响应。
* @param data 隔离业务数据
* @returns 公开接口形状的独立响应
*/
function response(data: unknown) {
return new Response(JSON.stringify({ data }))
}
/**
* 构造后端持久化任务,领取信息与业务结果分别保留。
* @param projectId 隔离项目身份
* @param overrides 当前用例的任务状态
* @returns 独立任务记录
*/
function execution(projectId: string, overrides: Partial<WorkflowExecution> = {}): WorkflowExecution {
return {
id: 'execution-1',
projectId,
workflowName: 'storyboard-direction',
status: 'completed',
stage: 'completed',
current: 1,
total: 1,
currentResourceId: null,
metadata: { episodeNo: 1, shotIds: ['shot-db-1-1', 'shot-db-1-2'] },
result: null,
error: null,
startedAt: null,
completedAt: null,
createdAt: '2026-11-15T00:00:00Z',
updatedAt: '2026-11-15T00:00:00Z',
...overrides
}
}
/**
* 挂载真实编排 Hook,所有生产 POST 由内存模拟明确隔离。
* @param projectId 隔离项目身份
* @returns 编排状态与明确的模拟控制
*/
async function harness(projectId = `staged-${++serial}`) {
const context = testProjectContext(projectId)
context.data.value!.checkpoints = [storyboardCheckpoint()]
const fixture = preparationFixture(projectId)
let directions = directionsResult(projectId)
directions.beats[1]!.shots[0]!.direction = null
directions.directionCount = 1
let visuals = visualStatesResult(projectId)
let current = execution(projectId)
let failTransport = false
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
const path = String(url)
if (path.endsWith('/storyboard-quality-confirmation'))
return response({ ...fixture.approval, valid: true, confirmation: fixture.record })
if (path.includes('/storyboard-directions?')) return response(directions)
if (path.includes('/storyboard-visual-states?')) return response(visuals)
if (path.endsWith('/production/entry-readiness'))
return response({
...fixture.entry,
derivedAssets: {
...fixture.entry.derivedAssets,
shotCount: 2,
directionCount: directions.directionCount,
staleDirectionCount: directions.staleCount,
staleVisualStateCount: visuals.staleCount
}
})
if (path.endsWith('/stop')) {
current = {
...current,
status: 'failed',
stage: 'stopped',
result: { stoppedByUser: true, retryAutomatically: false },
updatedAt: '2026-11-15T00:02:00Z'
}
return response(current)
}
if (path.includes('/workflow-executions/latest')) return response(current)
if (path.includes('/workflow-executions/')) return response(current)
if (path.endsWith('/storyboard-directions/generate')) {
if (failTransport) throw new Error('断线')
directions = directionsResult(projectId)
current = execution(projectId)
return response({ executionId: current.id, projectId, status: 'running' })
}
if (path.endsWith('/storyboard-visual-states/generate')) {
visuals = visualStatesResult(projectId, 1, true)
current = execution(projectId, { id: 'execution-vs', workflowName: 'storyboard-visual-state' })
return response({ executionId: current.id, projectId, status: 'running' })
}
throw new Error(`没有模拟 ${init?.method ?? 'GET'} ${path}`)
})
vi.stubGlobal('fetch', fetcher)
let state!: ReturnType<typeof useStoryboard>
const component = defineComponent({
setup() {
state = useStoryboard()
return () => h('div')
}
})
const options = { global: { provide: { [projectContextKey as symbol]: context } } }
const wrapper = mount(component, options)
wrappers.push(wrapper)
await flushPromises()
return {
state,
context,
fetcher,
wrapper,
remount: async () => {
const next = mount(component, options)
wrappers.push(next)
await flushPromises()
return state
},
setTransportFailure: () => {
failTransport = true
},
setCurrent: (record: WorkflowExecution) => {
current = record
}
}
}
/**
* 提取实际收费派生请求,免费读取不计入。
* @param fetcher 隔离请求记录
* @returns 模拟派生生成请求
*/
function posts(fetcher: ReturnType<typeof vi.fn<typeof fetch>>) {
return fetcher.mock.calls.filter(
([url, init]) => init?.method === 'POST' && /storyboard-(directions|visual-states)\/generate/.test(String(url))
)
}
describe('按正式镜头定向派生', () => {
it.each([{ ids: [] }, { ids: ['one', 'one'] }, { ids: ['outside'] }])('拒绝空、重复和跨集范围 %j', ({ ids }) => {
expect(() => derivedBatchInput('selected', ids, [designedShot('one')], 1, 1, false)).toThrow(/请选择|所选镜头/)
})
it('旧批量省略 shotIds,所选范围保留 force=false 与正式集号', () => {
expect(derivedBatchInput('selected', ['one'], [designedShot('one')], 1, 1, false)).toEqual({
episodeNo: 1,
shotIds: ['one'],
concurrency: 1,
force: false
})
expect(derivedBatchInput('project', [], [], 1, 1, false)).toEqual({ concurrency: 1, force: false })
expect(derivedBatchInput('episode', [], [], 1, 1, false)).toEqual({
episodeNo: 1,
concurrency: 1,
force: false
})
})
it('正式存在、缺失、过期与无法定位的过期来源分别显示', () => {
const shot = designedShot('one')
expect(derivedState(shot, 'direction', 0)).toBe('current')
expect(derivedState({ ...shot, direction: null }, 'direction', 0)).toBe('missing')
expect(derivedState(shot, 'direction', 1)).toBe('unknown')
const entry = preparationFixture().entry
entry.derivedAssetShotGaps = [{ episode: 1, shotId: 'one', direction: 'stale', visualState: 'current' }]
expect(derivedState(shot, 'direction', 1, entry)).toBe('stale')
expect(derivedState(shot, 'visualState', 1, entry)).toBe('current')
})
it('混合范围复用已有结果,摄影完成后仅显式提交画面状态,刷新不重复 POST', async () => {
const { state, fetcher } = await harness()
expect(state.allowed.value['direction-all']).toBe(false)
state.toggleShots(['shot-db-1-1', 'shot-db-1-2'])
expect(state.allowed.value['visual-all']).toBe(false)
await state.run('visual-all')
expect(posts(fetcher)).toHaveLength(0)
await state.run('direction-all')
await flushPromises()
expect(posts(fetcher)).toHaveLength(1)
expect(JSON.parse(String(posts(fetcher)[0]![1]?.body))).toEqual({
episodeNo: 1,
shotIds: ['shot-db-1-1', 'shot-db-1-2'],
concurrency: 1,
force: false
})
expect(state.allowed.value['visual-all']).toBe(true)
await state.query.refresh()
expect(posts(fetcher)).toHaveLength(1)
await state.run('visual-all')
expect(JSON.parse(String(posts(fetcher)[1]![1]?.body))).toMatchObject({
maxRepairAttempts: 0,
force: false,
shotIds: ['shot-db-1-1', 'shot-db-1-2']
})
await state.run('visual-all')
expect(posts(fetcher)).toHaveLength(2)
})
it('有效镜头默认禁用重复生成;覆盖是明确切换,切集清空选择及覆盖', async () => {
const { state, fetcher } = await harness()
state.toggleShots(['shot-db-1-1'])
expect(state.allowed.value['direction-all']).toBe(false)
state.force.value = true
expect(state.allowed.value['direction-all']).toBe(true)
await state.run('direction-all')
expect(JSON.parse(String(posts(fetcher)[0]![1]?.body)).force).toBe(true)
state.selectedEpisode.value = 2
await flushPromises()
expect(state.checkedShotIds.value).toEqual([])
expect(state.force.value).toBe(false)
})
it('提交回执断线后持久保护,重新挂载只免费核对原范围,不重新 POST', async () => {
const setup = await harness()
setup.state.toggleShots(['shot-db-1-2'])
setup.setTransportFailure()
await setup.state.run('direction-all')
expect(setup.state.submissionUnknown.value).toBe(true)
setup.wrapper.unmount()
const restored = await setup.remount()
restored.toggleShots(['shot-db-1-2'])
await restored.run('direction-all')
expect(posts(setup.fetcher)).toHaveLength(1)
setup.setCurrent(
execution(restored.id.value, {
id: 'accepted-original',
metadata: { episodeNo: 1, shotIds: ['shot-db-1-2'] }
})
)
await restored.inspectSubmission()
expect(restored.submissionUnknown.value).toBe(false)
expect(restored.executions[1]!.observer.executionId.value).toBe('accepted-original')
expect(posts(setup.fetcher)).toHaveLength(1)
})
it('停止后保留终态,免费刷新接收在途回执,不重新发生成', async () => {
const setup = await harness()
const current = execution(setup.state.id.value, {
status: 'running',
metadata: {
episodeNo: 1,
shotIds: ['shot-db-1-1'],
claims: [{ state: 'submitted', shotIds: ['shot-db-1-1'] }]
}
})
setup.setCurrent(current)
const observer = setup.state.executions[1]!.observer
await observer.track(current.id, setup.state.id.value)
expect(observer.canStop.value).toBe(true)
await observer.stop()
expect(observer.query.data.value?.stage).toBe('stopped')
expect(observer.active.value).toBe(false)
setup.setCurrent({
...observer.query.data.value!,
metadata: { claims: [{ state: 'received' }] },
updatedAt: '2026-11-15T00:03:00Z'
})
await observer.query.refresh()
expect(observer.query.data.value?.metadata?.claims).toEqual([{ state: 'received' }])
expect(observer.query.data.value?.status).toBe('failed')
expect(posts(setup.fetcher)).toHaveLength(0)
expect(setup.fetcher.mock.calls.filter(([url]) => String(url).endsWith('/stop'))).toHaveLength(1)
})
it('已停止但原请求仍在途时,force也不能绕过所选范围费用核对', async () => {
const setup = await harness()
const record = execution(setup.state.id.value, {
status: 'failed',
stage: 'stopped',
result: { stoppedByUser: true },
metadata: {
episodeNo: 1,
shotIds: ['shot-db-1-1'],
claims: [{ episodeNo: 1, shotIds: ['shot-db-1-1'], state: 'submitted' }]
}
})
setup.setCurrent(record)
await setup.state.executions[1]!.observer.track(record.id, setup.state.id.value)
setup.state.toggleShots(['shot-db-1-1'])
setup.state.force.value = true
expect(setup.state.allowed.value['direction-all']).toBe(false)
await setup.state.run('direction-all')
expect(posts(setup.fetcher)).toHaveLength(0)
setup.state.toggleShots(['shot-db-1-1', 'shot-db-1-2'])
setup.state.toggleShots(['shot-db-1-1'])
expect(setup.state.allowed.value['direction-all']).toBe(true)
})
it('停止按项目原执行 POST,未知请求与范围外镜头分开', async () => {
const record = execution('p', {
status: 'failed',
stage: 'stopped',
error: 'STORYBOARD_DERIVED_REQUEST_UNRESOLVED'
})
expect(derivedTaskState(record, 'shot-db-1-1', 1)).toBe('unresolved')
expect(derivedTaskState(record, 'outside', 1)).toBeNull()
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockResolvedValue(response(record)))
await workflowExecutionApi.stop('original/1', 'p')
expect(fetch).toHaveBeenCalledWith(
'/api/workflow-executions/original%2F1/stop',
expect.objectContaining({ method: 'POST', body: '{"projectId":"p"}' })
)
})
})
describe('独立摄影沿原采用入口', () => {
/**
* 挂载原字段编辑与独立阶段,模拟端只返回正式契约。
* @param conflict 是否制造正式采用并发冲突
* @returns 真实编辑器与隔离请求记录
*/
async function editor(conflict = false) {
const projectId = `direction-review-${++serial}`
const fixture = preparationFixture(projectId)
const directions = directionsResult(projectId)
directions.beats[0]!.shots[0]!.direction = {
...directions.beats[0]!.shots[0]!.direction!,
id: 'direction-original',
updatedAt: '2026-11-15T01:00:00.000Z',
rawJson: null
}
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
const path = String(url)
if (path.endsWith('/storyboard-quality-confirmation'))
return response({ ...fixture.approval, valid: true, confirmation: fixture.record })
if (path.includes('/storyboard-directions?')) return response(directions)
if (path.includes('/storyboard-visual-states?')) return response(visualStatesResult(projectId))
if (path.endsWith('/storyboard-derived-reviews/confirm')) {
const body = JSON.parse(String(init?.body))
if (conflict && !body.preview)
return new Response(
JSON.stringify({ message: 'STORYBOARD_DERIVED_STALE: 原摄影版本已变化,请重新读取。' }),
{ status: 409 }
)
return response({
projectId,
phase: 'direction',
preview: body.preview,
sourceFingerprint: 'c'.repeat(64),
changed: false,
shots: [
{
shotId: 'shot-db-1-1',
directionId: 'direction-original',
updatedAt: '2026-11-15T01:00:00.000Z',
changed: false,
alreadyApplied: !body.preview
}
]
})
}
throw new Error('没有模拟 ' + path)
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(DirectionStageReview, {
props: { projectId, episodeNo: 1, shot: { ...designedShot(), visualState: null }, disabled: false }
})
wrappers.push(wrapper)
await flushPromises()
return { wrapper, fetcher }
}
it('免费预检冻结完整原版本,changed=false仍可采用,同草案支持幂等回执', async () => {
const { wrapper, fetcher } = await editor()
const inputs = wrapper.findAllComponents(NInput)
inputs[0]!.vm.$emit('update:value', '修订构图,保持已绑定主体')
inputs[2]!.vm.$emit('update:value', '实际审核人')
await flushPromises()
await wrapper
.findAll('button')
.find(button => button.text() === '免费预检摄影修改')!
.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('预检通过')
expect(wrapper.vm.canAdopt).toBe(false)
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
await flushPromises()
expect(wrapper.vm.canAdopt).toBe(true)
await wrapper.vm.adopt()
const calls = fetcher.mock.calls.filter(([url]) => String(url).endsWith('/confirm'))
expect(calls).toHaveLength(2)
const preview = JSON.parse(String(calls[0]![1]?.body))
const adopt = JSON.parse(String(calls[1]![1]?.body))
expect(preview).toMatchObject({
phase: 'direction',
preview: true,
reviewer: '实际审核人',
expectedShotFingerprint: 'b'.repeat(64),
shots: [
{
expectedDirectionId: 'direction-original',
expectedDirectionRawJson: null,
expectedDirectionUpdatedAt: '2026-11-15T01:00:00.000Z',
direction: { shotSize: 'medium', cameraAngle: 'eye-level', composition: '修订构图,保持已绑定主体' }
}
]
})
expect(adopt).toEqual({ ...preview, preview: false, expectedSourceFingerprint: 'c'.repeat(64) })
expect(preview.shots[0]).not.toHaveProperty('visualState')
expect(wrapper.emitted('adopted')).toHaveLength(1)
})
it('修改署名或内容撤销预检;并发409保留输入且不自动覆盖', async () => {
const { wrapper, fetcher } = await editor(true)
const inputs = wrapper.findAllComponents(NInput)
inputs[2]!.vm.$emit('update:value', '审核人')
await flushPromises()
await wrapper
.findAll('button')
.find(button => button.text() === '免费预检摄影修改')!
.trigger('click')
await flushPromises()
wrapper.getComponent(NCheckbox).vm.$emit('update:checked', true)
await flushPromises()
await wrapper.vm.adopt()
expect(wrapper.vm.canAdopt).toBe(false)
expect(wrapper.emitted('adopted')).toBeUndefined()
expect(fetcher.mock.calls.filter(([url]) => String(url).endsWith('/confirm'))).toHaveLength(2)
expect(inputs[2]!.props('value')).toBe('审核人')
await wrapper
.findAll('button')
.find(button => button.text() === '重新读取正式来源')!
.trigger('click')
await flushPromises()
await wrapper
.findAll('button')
.find(button => button.text() === '免费预检摄影修改')!
.trigger('click')
await flushPromises()
inputs[0]!.vm.$emit('update:value', '又一次修改')
await flushPromises()
expect(wrapper.text()).not.toContain('预检通过')
})
})
describe('已有下游的原组合摄影修订', () => {
it('保留画面状态、原预览指纹和正式来源,不绕入独立摄影 phase', async () => {
const projectId = `combined-${++serial}`
const fixture = preparationFixture(projectId)
const shot = designedShot()
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
const path = String(url)
if (path.includes('/keyframe-review-draft')) return response(null)
if (path.endsWith('/preflight'))
return response({
current: { ...fixture.approval, valid: true, confirmation: fixture.record },
quality: fixture.quality
})
if (path.includes('/keyframe-spec'))
return response({ shotId: shot.shotId, formalSourceFingerprint: 'e'.repeat(64), references: [] })
if (path.includes('/generation-spec')) return response({ shotId: shot.shotId, subjects: [] })
if (path.includes('/storyboard-directions?')) return response(directionsResult(projectId))
if (path.includes('/storyboard-visual-states?')) return response(visualStatesResult(projectId, 1, true))
if (path.endsWith('/generation-models')) return response(billingCatalog)
if (path.endsWith('/creative-profile')) return response({ ...billingProfile, projectId })
if (path.includes('/keyframe/preview'))
return response({
...imagePreviewFixture(),
shotId: shot.shotId,
draftFingerprint: 'd'.repeat(64),
productionReady: false,
productionGate: { ready: false, reason: '项目尚未完成' },
sceneSources: []
})
if (path.endsWith('/storyboard-derived-reviews/confirm'))
return response({ shots: [{ shotId: shot.shotId }] })
throw new Error(`未模拟 ${init?.method ?? 'GET'} ${path}`)
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(ShotDerivedReview, {
attachTo: document.body,
props: { projectId, episodeNo: 1, shot, shots: [shot], disabled: false }
})
wrappers.push(wrapper)
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.findComponent(DirectionStageReview).exists()).toBe(false)
const preview = [...document.querySelectorAll<HTMLButtonElement>('.app-drawer button')].find(
button => button.textContent?.trim() === '免费预览摄影草案'
)!
expect(preview.disabled).toBe(false)
preview.click()
await flushPromises()
const reviewer = wrapper.findAllComponents(NInput).find(input => input.attributes('aria-label') === '审核人')!
reviewer.vm.$emit('update:value', '组合审核人')
wrapper.findAllComponents(NCheckbox).at(-1)!.vm.$emit('update:checked', true)
await flushPromises()
const adopt = [...document.querySelectorAll<HTMLButtonElement>('.app-drawer button')].find(
button => button.textContent?.trim() === '正式采用本镜'
)!
expect(adopt.disabled).toBe(false)
adopt.click()
await flushPromises()
const call = fetcher.mock.calls.find(([url]) => String(url).endsWith('/storyboard-derived-reviews/confirm'))!
const body = JSON.parse(String(call[1]?.body))
expect(body).not.toHaveProperty('phase')
expect(body.shots[0]).toMatchObject({
expectedDraftFingerprint: 'd'.repeat(64),
expectedCurrentFormalSourceFingerprint: 'e'.repeat(64),
draft: { visualState: { shotNo: shot.shotNo }, expectedShotFingerprint: 'b'.repeat(64) }
})
expect(wrapper.emitted('changed')).toHaveLength(1)
})
})
describe('原失败、停止及免费恢复展示', () => {
it('停止不显示普通质量失败或成功,收到结果不暗示通过', () => {
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution('stopped-ui', {
status: 'failed',
stage: 'stopped',
result: { stoppedByUser: true },
metadata: { claims: [{ state: 'submitted' }, { state: 'received' }] }
}),
loading: false,
error: ''
}
})
wrappers.push(wrapper)
expect(wrapper.getComponent(NTag).text()).toBe('已停止')
expect(wrapper.getComponent(NTag).props('type')).toBe('default')
expect(wrapper.text()).toContain('请求结果未知 1 步')
expect(wrapper.text()).not.toContain('制作任务执行失败')
})
it('免费恢复关联原失败历史,只有免费 GET,不出现重新生成成功', async () => {
const original = execution('recovery-ui', {
id: 'failed-original',
workflowName: 'storyboard-visual-state',
status: 'failed',
error: '原结果校验未通过'
})
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(response(original))
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(WorkflowExecutionPanel, {
props: {
execution: execution('recovery-ui', {
workflowName: 'storyboard-visual-state',
metadata: { recoveryOf: original.id },
result: { recovered: true, actualModelRequests: 0 }
}),
loading: false,
error: ''
}
})
wrappers.push(wrapper)
await flushPromises()
expect(wrapper.text()).toContain('新增模型请求 0 次')
expect(wrapper.text()).toContain('原失败执行仍保留为失败')
expect(wrapper.text()).toContain('原结果校验未通过')
expect(wrapper.text()).not.toContain('重新生成成功')
expect(fetcher.mock.calls.every(([, options]) => options?.method === 'GET')).toBe(true)
})
})
describe('免费准备与精确范围确认', () => {
it('未点击不请求,参考、计划和资产错误分开,不把失败当尚未生成', async () => {
const fetcher = vi.fn<typeof fetch>(async url => {
if (String(url).endsWith('/references'))
return new Response(JSON.stringify({ message: '参考数据读取失败' }), { status: 500 })
if (String(url).endsWith('/production/plan'))
return new Response(JSON.stringify({ message: '计划读取失败' }), { status: 500 })
return response({ projectId: 'preparation-errors', completed: false })
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(StagedShotPreparation, {
props: { projectId: 'preparation-errors', active: true, shots: [designedShot('one')] }
})
wrappers.push(wrapper)
await flushPromises()
expect(fetcher).not.toHaveBeenCalled()
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('参考数据读取失败')
expect(wrapper.text()).toContain('计划读取失败')
expect(wrapper.text()).toContain('尚未完成')
expect(wrapper.text()).not.toContain('参考素材缺失')
expect(fetcher.mock.calls.map(([url]) => String(url))).toEqual([
'/api/storyboard-shots/one/references',
'/api/projects/preparation-errors/production/plan',
'/api/projects/preparation-errors/production/status'
])
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
expect(JSON.parse(String(fetcher.mock.calls[1]![1]?.body))).toEqual({})
})
it('关闭抽屉取消完整计划,迟到响应不回填也不再读取资产状态', async () => {
let resolvePlan!: (value: Response) => void
let planSignal: AbortSignal | null = null
const fetcher = vi.fn<typeof fetch>(async (url, init) => {
if (String(url).endsWith('/references')) return response({ shotId: 'one', references: [], missing: [] })
planSignal = init?.signal as AbortSignal
return new Promise(resolve => {
resolvePlan = resolve
})
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(StagedShotPreparation, {
props: { projectId: 'cancel-plan', active: true, shots: [designedShot('one')] }
})
wrappers.push(wrapper)
await flushPromises()
await wrapper.get('button').trigger('click')
await flushPromises()
expect(fetcher).toHaveBeenCalledTimes(2)
await wrapper.setProps({ active: false })
await flushPromises()
expect((planSignal as AbortSignal | null)?.aborted).toBe(true)
resolvePlan(response({ projectId: 'cancel-plan', entryReadiness: { ready: true }, stageReadiness: {} }))
await flushPromises()
expect(wrapper.text()).not.toContain('项目生产入口:已就绪')
expect(fetcher).toHaveBeenCalledTimes(2)
})
it('同镜头数量但身份改变时撤销旧费用确认', async () => {
const wrapper = mount(ConfirmAction, {
attachTo: document.body,
props: {
label: '补齐所选 1 镜',
description: '收费文本模型与覆盖影响说明',
confirmationKey: 'shot-one',
acknowledgement: true
}
})
wrappers.push(wrapper)
await wrapper.get('button').trigger('click')
await flushPromises()
const checkbox = document.querySelector<HTMLElement>('.app-dialog [role="checkbox"]')!
checkbox.click()
await flushPromises()
const confirm = [...document.querySelectorAll<HTMLButtonElement>('.app-dialog button')].find(
button => button.textContent?.trim() === '确认补齐所选 1 镜'
)!
expect(confirm.disabled).toBe(false)
await wrapper.setProps({ confirmationKey: 'shot-two' })
await flushPromises()
expect(confirm.disabled).toBe(true)
expect(wrapper.emitted('confirm')).toBeUndefined()
})
})