feat(short-drama-agent-front): 同步拆解候选审核与安全提交
This commit is contained in:
1 parent
cc27d463e0
commit
190333d4f9
26 files changed
+1495
-249
No files matched your search
@@ -13,6 +13,8 @@ import { readAllStyles } from '@/testing/styles'
|
||||
import { effectScope } from 'vue'
|
||||
import { useWorkflowExecution } from '@/features/workflows/execution'
|
||||
import { workflowExecutionApi } from '@/features/workflows/execution-api'
|
||||
import { breakdownApi } from '@/features/breakdown/api'
|
||||
import { candidateCheckpoint, candidateReview, candidateState } from '../../fixtures/breakdown-candidate'
|
||||
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** 跨组件后台任务观察器,验证结束时释放。 */
|
||||
@@ -68,6 +70,48 @@ it('后台重新拆解时显示真实运行状态并隐藏所有诊断入口,
|
||||
tracker.dismiss()
|
||||
})
|
||||
|
||||
it('候选审核通过后只展示候选,修复后的正式结果不再被嵌套历史五个错误污染', async () => {
|
||||
const old = Array.from({ length: 5 }, (_, index) => ({ episodeNo: 1, message: `历史错误 ${index}` }))
|
||||
const current = candidateCheckpoint(candidateState({ projectId: 'breakdown-scroll-test', breakdownResult: { storyboardShotValidation: { valid: false, issues: old } } }))
|
||||
const read = vi.spyOn(breakdownApi, 'revalidateCandidate').mockResolvedValue(candidateReview({ projectId: 'breakdown-scroll-test', previousIssues: old }))
|
||||
const provided = mountPage([current])
|
||||
expect(wrapper!.text()).not.toContain('分镜校验未通过')
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).toContain('拆解候选 · 尚未提交正式结果')
|
||||
expect(wrapper!.find('button.breakdown-desktop-issues').exists()).toBe(false)
|
||||
expect(wrapper!.find('.subject-record-actions router-link-stub').exists()).toBe(false)
|
||||
await selectTab('分镜')
|
||||
expect(wrapper!.find('.storyboard-diagnosis-summary').exists()).toBe(false)
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
provided.data.value!.checkpoints = [{ ...current, state: { ...current.state, storyboardPersisted: true, candidateCommitted: true } }]
|
||||
await selectTab('人物')
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).toContain('正式拆解结果')
|
||||
expect(wrapper!.text()).toContain('已提交正式结果')
|
||||
expect(wrapper!.text()).not.toContain('分镜校验未通过')
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('历史修复元数据不能掩盖之后新任务的真实失败', async () => {
|
||||
const current = candidateCheckpoint(candidateState({ projectId: 'breakdown-scroll-test', storyboardPersisted: true, candidateCommitted: true }))
|
||||
mountPage([current])
|
||||
const record = {
|
||||
id: 'new-failed-breakdown', projectId: 'breakdown-scroll-test', workflowName: 'breakdown',
|
||||
status: 'failed' as const, stage: 'failed', current: 0, total: 3, currentResourceId: null,
|
||||
metadata: null, result: null, error: '新任务执行失败',
|
||||
startedAt: '2026-10-17T10:00:00Z', completedAt: '2026-10-17T10:01:00Z',
|
||||
createdAt: '2026-10-17T10:00:00Z', updatedAt: '2026-10-17T10:01:00Z'
|
||||
}
|
||||
vi.spyOn(workflowExecutionApi, 'get').mockResolvedValue(record)
|
||||
taskScope = effectScope()
|
||||
const tracker = taskScope.run(() => useWorkflowExecution(ref(record.projectId), 'breakdown'))!
|
||||
await tracker.track(record.id)
|
||||
await flushPromises()
|
||||
expect(wrapper!.text()).toContain('工作流失败')
|
||||
expect(wrapper!.find('button.breakdown-desktop-issues').exists()).toBe(true)
|
||||
tracker.dismiss()
|
||||
})
|
||||
|
||||
/** 长主体、长分镜与长任务列表,用真实 Naive 滚动组件验证内容边界。 */
|
||||
function checkpoint(): Checkpoint {
|
||||
const plan: EpisodePlan = {
|
||||
|
||||
@@ -1,92 +1,115 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import BreakdownCandidatePanel from '@/features/breakdown/components/BreakdownCandidatePanel.vue'
|
||||
import ConfirmAction from '@/features/workflows/ConfirmAction.vue'
|
||||
import { projectsApi } from '@/features/projects/api'
|
||||
import { breakdownApi } from '@/features/breakdown/api'
|
||||
import { breakdownQuality, selectBreakdownSource } from '@/features/breakdown/quality'
|
||||
import { getOperation } from '@/features/workflows/operations'
|
||||
import { candidateCheckpoint, candidateReview, candidateState, commitPreview } from '../../fixtures/breakdown-candidate'
|
||||
import type { CandidateCommitPreview } from '@/features/breakdown/candidate.types'
|
||||
|
||||
/** 候选完整性只使用最新原始状态。 */
|
||||
const state = {
|
||||
candidateOnly: true,
|
||||
storyboardShotValidation: { valid: true, issues: [] },
|
||||
expectedEpisodeFingerprints: { 1: 'fingerprint' },
|
||||
runConfig: { groupSize: 3, modules: [] as [], episodeGroups: [], sourceEpisodes: [{ episodeNo: 1 }] },
|
||||
subjectCandidates: [
|
||||
{
|
||||
profileId: 'p',
|
||||
name: '人物',
|
||||
ref: '@人物',
|
||||
module: 'character' as const,
|
||||
description: '',
|
||||
appearance_prompt: ''
|
||||
}
|
||||
],
|
||||
subjectForms: [],
|
||||
storyboardEpisodeShots: [
|
||||
{
|
||||
episodeNo: 1,
|
||||
episodePlan: { episodeNo: 1 } as never,
|
||||
beatShots: [
|
||||
{
|
||||
beatNo: 1,
|
||||
shots: [
|
||||
{ shotNo: 1, title: '', description: '', visualFocus: '', subjectRefs: [], durationSeconds: 2 }
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
/** 真实确认弹窗挂载于 body,验证完成后清理。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.restoreAllMocks()
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
beforeEach(() => { vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([candidateCheckpoint()]) })
|
||||
afterEach(() => { wrapper?.unmount(); wrapper = undefined; document.body.innerHTML = ''; vi.restoreAllMocks() })
|
||||
|
||||
describe('候选版本与提交保护', () => {
|
||||
it('当前版本仍有效时仅提交一次并刷新正式结果', async () => {
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([
|
||||
{ checkpointId: 'ready', createdAt: '', workflowName: 'breakdown', state }
|
||||
])
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate').mockResolvedValue({
|
||||
projectId: 'candidate-ready-test',
|
||||
subjectCount: 1,
|
||||
subjectFormCount: 0,
|
||||
episodeCount: 1,
|
||||
beatCount: 1,
|
||||
shotCount: 1,
|
||||
shotSubjectCount: 0
|
||||
})
|
||||
wrapper = mount(BreakdownCandidatePanel, {
|
||||
props: { projectId: 'candidate-ready-test', checkpointId: 'ready', state, disabled: false }
|
||||
})
|
||||
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
|
||||
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith('candidate-ready-test')
|
||||
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
||||
/** 创建质量已通过但尚未经过安全预检查的面板。 */
|
||||
function openPanel() {
|
||||
wrapper = mount(BreakdownCandidatePanel, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: 'candidate-project', checkpointId: 'candidate-current', state: candidateState(), quality: breakdownQuality(selectBreakdownSource([candidateCheckpoint()]), candidateReview()), disabled: false }
|
||||
})
|
||||
it('确认之后发现服务端版本已变化时禁止提交正式替换', async () => {
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([
|
||||
{ checkpointId: 'new', createdAt: '', workflowName: 'breakdown', state }
|
||||
])
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
|
||||
wrapper = mount(BreakdownCandidatePanel, {
|
||||
props: { projectId: 'candidate-version-test', checkpointId: 'old', state, disabled: false }
|
||||
})
|
||||
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
/** 点击只读预检查入口,不直接提交。 */
|
||||
async function checkCandidate() {
|
||||
await wrapper!.findAll('button').find(button => button.text() === '提交候选为正式结果')!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 用户勾选并点击最终确认按钮。 */
|
||||
async function confirmCandidate() {
|
||||
const dialog = new DOMWrapper(document.querySelector<HTMLElement>('.app-dialog'))
|
||||
await dialog.get('[role="checkbox"]').trigger('click')
|
||||
await dialog.findAll('button').find(button => button.text() === '确认提交候选为正式结果')!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
describe('候选预检查与最终提交门禁', () => {
|
||||
it('审核通过不会直接提交;预检查及最终确认均通过后只提交一次并刷新', async () => {
|
||||
const preview = vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(commitPreview())
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate').mockResolvedValue({ projectId: 'candidate-project', subjectCount: 2, subjectFormCount: 2, episodeCount: 1, beatCount: 1, shotCount: 2, shotSubjectCount: 2 })
|
||||
openPanel()
|
||||
expect(preview).not.toHaveBeenCalled()
|
||||
expect(commit).not.toHaveBeenCalled()
|
||||
expect(wrapper.text()).toContain('候选版本已变化')
|
||||
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
||||
await checkCandidate()
|
||||
expect(commit).not.toHaveBeenCalled()
|
||||
expect(document.querySelector('.app-dialog')?.textContent).toContain('确认提交候选为正式结果')
|
||||
await confirmCandidate()
|
||||
expect(preview).toHaveBeenCalledTimes(2)
|
||||
expect(commit).toHaveBeenCalledExactlyOnceWith('candidate-project')
|
||||
expect(wrapper!.emitted('refresh')).toHaveLength(1)
|
||||
expect(wrapper!.text()).toContain('候选已提交')
|
||||
await wrapper!.setProps({ state: candidateState({ storyboardPersisted: true, candidateCommitted: true }), quality: breakdownQuality(selectBreakdownSource([candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true }))]), null) })
|
||||
expect(wrapper!.findAll('button').some(button => button.text() === '提交候选为正式结果')).toBe(false)
|
||||
})
|
||||
it('新快照无明确候选标记时不恢复旧候选提交入口', async () => {
|
||||
wrapper = mount(BreakdownCandidatePanel, {
|
||||
props: { projectId: 'candidate-marker-test', checkpointId: 'old', state, disabled: false }
|
||||
})
|
||||
expect(wrapper.text()).toContain('提交候选为正式结果')
|
||||
await wrapper.setProps({ checkpointId: 'new', state: {} })
|
||||
expect(wrapper.findComponent(ConfirmAction).exists()).toBe(false)
|
||||
it('ready=false 显示未通过项且不打开最终确认', async () => {
|
||||
const result = commitPreview()
|
||||
result.ready = false
|
||||
result.checks.noProtectedShots = false
|
||||
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(result)
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
|
||||
openPanel()
|
||||
await checkCandidate()
|
||||
expect(wrapper!.text()).toContain('没有需要保护的镜头资产')
|
||||
expect(document.querySelector('.app-dialog')).toBeNull()
|
||||
expect(commit).not.toHaveBeenCalled()
|
||||
})
|
||||
it('即使 ready=true,缺少一项安全门禁也禁止确认', async () => {
|
||||
const result = commitPreview()
|
||||
result.checks.noSubjectImages = false
|
||||
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(result)
|
||||
openPanel()
|
||||
await checkCandidate()
|
||||
expect(document.querySelector('.app-dialog')).toBeNull()
|
||||
expect(wrapper!.text()).toContain('主体图片')
|
||||
})
|
||||
it('最终确认重新发现版本变化时禁止替换并要求刷新', async () => {
|
||||
vi.mocked(projectsApi.checkpoints).mockResolvedValue([candidateCheckpoint(candidateState(), 'new')])
|
||||
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValue(commitPreview())
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
|
||||
openPanel()
|
||||
await checkCandidate()
|
||||
await confirmCandidate()
|
||||
expect(commit).not.toHaveBeenCalled()
|
||||
expect(getOperation('candidate-project').error).toContain('版本已变化')
|
||||
expect(wrapper!.emitted('refresh')).toHaveLength(1)
|
||||
})
|
||||
it('最终确认时安全条件改变,原先通过的预检查不能继续使用', async () => {
|
||||
vi.spyOn(breakdownApi, 'candidateCommitPreview').mockResolvedValueOnce(commitPreview()).mockResolvedValueOnce(commitPreview({ ready: false }))
|
||||
const commit = vi.spyOn(breakdownApi, 'commitCandidate')
|
||||
openPanel()
|
||||
await checkCandidate()
|
||||
await confirmCandidate()
|
||||
expect(commit).not.toHaveBeenCalled()
|
||||
expect(getOperation('candidate-project').error).toContain('安全条件已变化')
|
||||
})
|
||||
it('版本变化后晚到的预检查响应不会重新打开确认窗口', async () => {
|
||||
let resolve!: (value: CandidateCommitPreview) => void
|
||||
const preview = vi.spyOn(breakdownApi, 'candidateCommitPreview').mockImplementation(() => new Promise(done => { resolve = done }))
|
||||
openPanel()
|
||||
await checkCandidate()
|
||||
await wrapper!.findAll('button').find(button => button.text() === '提交候选为正式结果')!.trigger('click')
|
||||
expect(preview).toHaveBeenCalledTimes(1)
|
||||
await wrapper!.setProps({ checkpointId: 'new' })
|
||||
resolve(commitPreview())
|
||||
await flushPromises()
|
||||
expect(document.querySelector('.app-dialog')).toBeNull()
|
||||
})
|
||||
it('新快照没有候选标记时不会复用旧候选入口', async () => {
|
||||
openPanel()
|
||||
await wrapper!.setProps({ checkpointId: 'new', state: {} })
|
||||
expect(wrapper!.text()).not.toContain('提交候选为正式结果')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,80 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { NCheckbox, NSelect } from 'naive-ui'
|
||||
import CandidateRepairs from '@/features/breakdown/components/CandidateRepairs.vue'
|
||||
import ConfirmAction from '@/features/workflows/ConfirmAction.vue'
|
||||
import { breakdownApi } from '@/features/breakdown/api'
|
||||
import { candidateReview, candidateState } from '../../fixtures/breakdown-candidate'
|
||||
import type { CandidateRevalidation } from '@/features/breakdown/candidate.types'
|
||||
|
||||
/** 候选修复组件实例,禁止真实写入。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); document.body.innerHTML = '' })
|
||||
|
||||
/**
|
||||
* 只将真实阻断镜头的原始动作放入审核响应。
|
||||
* @returns 两个动作阻断与原始阶段规划
|
||||
*/
|
||||
function blockedReview(): CandidateRevalidation {
|
||||
const state = candidateState()
|
||||
const blocks = [1, 2].map(shotNo => ({ episodeNo: 1, beatNo: 1, shotNo, status: 'blocked' as const, blockingCodes: ['state_used_as_action_phase'], warningCodes: [], isPendingEpisode: true }))
|
||||
return candidateReview({ actionQualityBlocks: blocks, actionRepairTargets: blocks.map(block => ({ ...block, shot: { ...state.storyboardEpisodeShots![0]!.beatShots[0]!.shots[block.shotNo - 1]!, requiredActions: state.storyboardEpisodeShots![0]!.beatShots[0]!.shots[block.shotNo - 1]!.requiredActions!, durationPlanning: state.storyboardEpisodeShots![0]!.beatShots[0]!.shots[block.shotNo - 1]!.durationPlanning! } })), pendingQualityEpisodeNos: [1] })
|
||||
}
|
||||
|
||||
describe('人工候选修复', () => {
|
||||
it('主体和形态只能来自当前候选,错误归属的形态不能提交;成功请求刷新新版本', async () => {
|
||||
const state = candidateState()
|
||||
const review = candidateReview({ missingSubjectRefs: [{ episodeNo: 1, beatNo: 1, shotNo: 1, message: '缺少铜铃 @PR0001', shot: state.storyboardEpisodeShots![0]!.beatShots[0]!.shots[0]!, beatSubjectRefs: ['@PR0001'], subject: state.subjectCandidates![1]!, availableForms: [state.subjectForms![1]!] }] })
|
||||
const repair = vi.spyOn(breakdownApi, 'repairCandidateSubject').mockResolvedValue({ checkpointId: 'repaired', storyboardShotValidation: { valid: true, issues: [] }, candidateValidation: { valid: true, issues: [] } })
|
||||
wrapper = mount(CandidateRepairs, { props: { projectId: 'candidate-project', checkpointId: 'candidate-current', state, review, disabled: false } })
|
||||
wrapper.findAllComponents(NSelect)[0]!.vm.$emit('update:value', '1/1/1')
|
||||
await flushPromises()
|
||||
wrapper.findAllComponents(NSelect)[1]!.vm.$emit('update:value', '@PR0001')
|
||||
await flushPromises()
|
||||
expect(wrapper.findAllComponents(NSelect)[2]!.props('options')).toEqual([{ label: '铜铃形态', value: 'prop-form' }])
|
||||
wrapper.findAllComponents(NSelect)[2]!.vm.$emit('update:value', 'person-form')
|
||||
await flushPromises()
|
||||
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
expect(repair).not.toHaveBeenCalled()
|
||||
wrapper.findAllComponents(NSelect)[2]!.vm.$emit('update:value', 'prop-form')
|
||||
await flushPromises()
|
||||
wrapper.getComponent(ConfirmAction).vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
expect(repair).toHaveBeenCalledExactlyOnceWith('candidate-project', { expectedCheckpointId: 'candidate-current', episodeNo: 1, beatNo: 1, shotNo: 1, subjectRef: '@PR0001', formId: 'prop-form' })
|
||||
expect(wrapper.emitted('refresh')).toHaveLength(1)
|
||||
})
|
||||
it('多个动作必须经过选择和描述编辑,批量失败保留全部草稿且不发送 kind', async () => {
|
||||
const repair = vi.spyOn(breakdownApi, 'repairCandidateActions').mockRejectedValue(new Error('目标动作处于并行阶段,不能自动覆盖其他动作描述'))
|
||||
wrapper = mount(CandidateRepairs, { props: { projectId: 'candidate-project', checkpointId: 'candidate-current', state: candidateState(), review: blockedReview(), disabled: false } })
|
||||
const confirm = () => wrapper!.getComponent(ConfirmAction)
|
||||
confirm().vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
expect(repair).not.toHaveBeenCalled()
|
||||
for (const [index, checkbox] of wrapper.findAllComponents(NCheckbox).entries()) {
|
||||
checkbox.vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
await wrapper.findAll('textarea')[index]!.setValue(`人物伸手握住并拿起铜铃 ${index + 1}`)
|
||||
}
|
||||
expect(wrapper.get('[aria-label="批量修复摘要"]').text()).toContain('共 2 个动作')
|
||||
confirm().vm.$emit('confirm')
|
||||
await flushPromises()
|
||||
expect(repair).toHaveBeenCalledTimes(1)
|
||||
const input = repair.mock.calls[0]![1]
|
||||
expect(input.expectedCheckpointId).toBe('candidate-current')
|
||||
expect(input.repairs).toHaveLength(2)
|
||||
expect(input.repairs.every(item => !('kind' in item))).toBe(true)
|
||||
expect(wrapper.findAll('textarea').map(field => field.element.value)).toEqual(['人物伸手握住并拿起铜铃 1', '人物伸手握住并拿起铜铃 2'])
|
||||
expect(wrapper.text()).toContain('并行阶段')
|
||||
expect(wrapper.emitted('refresh')).toBeUndefined()
|
||||
})
|
||||
it('版本过期后旧编辑内容不能提交,正式模式也不能写候选', async () => {
|
||||
const repair = vi.spyOn(breakdownApi, 'repairCandidateActions')
|
||||
wrapper = mount(CandidateRepairs, { props: { projectId: 'candidate-project', checkpointId: 'new-version', state: candidateState(), review: blockedReview(), disabled: false } })
|
||||
expect(wrapper.findAll('textarea')).toHaveLength(0)
|
||||
expect(repair).not.toHaveBeenCalled()
|
||||
await wrapper.setProps({ checkpointId: 'candidate-current', state: candidateState({ storyboardPersisted: true }) })
|
||||
await flushPromises()
|
||||
expect(wrapper.findAllComponents(NCheckbox).every(item => item.props('disabled'))).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -71,4 +71,24 @@ describe('候选提交资格', () => {
|
||||
expect(fetcher.mock.calls[1]![0]).toContain('/projects/p%2Fid/breakdown/commit-candidate')
|
||||
expect(JSON.parse(fetcher.mock.calls[1]![1]!.body as string)).toEqual({ confirmed: true })
|
||||
})
|
||||
it('候选新接口使用真实端点并携带版本,不把人工草稿扩展成正式资产请求', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: {} })))
|
||||
// 每次返回独立响应,模拟四个实际端点,不运行任何模型或真实写入。
|
||||
fetcher.mockImplementation(async () => new Response(JSON.stringify({ data: {} })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await breakdownApi.revalidateCandidate('p/id')
|
||||
await breakdownApi.candidateCommitPreview('p/id')
|
||||
await breakdownApi.repairCandidateSubject('p/id', { expectedCheckpointId: 'current', episodeNo: 1, beatNo: 2, shotNo: 3, subjectRef: '@PR0001', formId: 'existing-form' })
|
||||
await breakdownApi.repairCandidateActions('p/id', { expectedCheckpointId: 'current', repairs: [{ episodeNo: 1, beatNo: 2, shotNo: 3, actionId: 'action-1', description: '人物伸手拿起铜铃' }] })
|
||||
expect(fetcher.mock.calls.map(call => call[0])).toEqual([
|
||||
'/api/projects/p%2Fid/breakdown/candidate-revalidation',
|
||||
'/api/projects/p%2Fid/breakdown/candidate-commit-preview',
|
||||
'/api/projects/p%2Fid/breakdown/candidate-subject-repair',
|
||||
'/api/projects/p%2Fid/breakdown/candidate-action-batch-repair'
|
||||
])
|
||||
expect(fetcher.mock.calls.map(call => call[1]?.method)).toEqual(['GET', 'GET', 'POST', 'POST'])
|
||||
const body = fetcher.mock.calls[3]?.[1]?.body
|
||||
if (typeof body !== 'string') throw new Error('请求缺少 JSON 正文')
|
||||
expect(JSON.parse(body)).toEqual({ expectedCheckpointId: 'current', repairs: [{ episodeNo: 1, beatNo: 2, shotNo: 3, actionId: 'action-1', description: '人物伸手拿起铜铃' }] })
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,122 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { effectScope, ref } from 'vue'
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { assertCandidateReview, breakdownQuality, normalizeBreakdownState, selectBreakdownSource } from '@/features/breakdown/quality'
|
||||
import { useBreakdownQuality } from '@/features/breakdown/useBreakdownQuality'
|
||||
import { breakdownApi } from '@/features/breakdown/api'
|
||||
import { candidateCheckpoint, candidateReview, candidateState } from '../../fixtures/breakdown-candidate'
|
||||
import type { CandidateRevalidation } from '@/features/breakdown/candidate.types'
|
||||
|
||||
/** 测试后释放自动版本观察,避免跨用例请求。 */
|
||||
let scope: ReturnType<typeof effectScope> | undefined
|
||||
afterEach(() => { scope?.stop(); scope = undefined; vi.restoreAllMocks() })
|
||||
|
||||
describe('拆解当前质量与来源隔离', () => {
|
||||
it('新版候选缺少顶层成果时不借用完整的旧嵌套成果充数', () => {
|
||||
const previous = candidateState()
|
||||
const current = normalizeBreakdownState({ candidateOnly: true, breakdownResult: previous })
|
||||
expect(current.subjectCandidates).toBeUndefined()
|
||||
expect(current.storyboardEpisodeShots).toBeUndefined()
|
||||
expect(current.breakdownResult?.storyboardShotValidation).toBeUndefined()
|
||||
})
|
||||
it('主体补齐后使用镜头快照中的最新 Beat 引用,不重新显示旧规划中的缺失道具', () => {
|
||||
const state = candidateState()
|
||||
state.storyboardPlans = structuredClone(state.storyboardPlans)
|
||||
state.storyboardPlans![0]!.beats[0]!.subjectRefs = ['@CH0001']
|
||||
const result = normalizeBreakdownState(state)
|
||||
expect(result.storyboardPlans![0]!.beats[0]!.subjectRefs).toContain('@PR0001')
|
||||
expect(state.storyboardPlans![0]!.beats[0]!.subjectRefs).not.toContain('@PR0001')
|
||||
})
|
||||
it('最新候选通过时不显示历史五个错误,也不把候选当作正式结果', () => {
|
||||
const old = Array.from({ length: 5 }, (_, index) => ({ episodeNo: 1, message: `历史错误 ${index}` }))
|
||||
const record = candidateCheckpoint(candidateState({ breakdownResult: { storyboardShotValidation: { valid: false, issues: old } } }))
|
||||
const source = selectBreakdownSource([record])
|
||||
const quality = breakdownQuality(source, candidateReview({ previousIssues: old }))
|
||||
expect(source.kind).toBe('candidate')
|
||||
expect(source.state?.storyboardShotValidation?.valid).toBe(true)
|
||||
expect(quality.issueCount).toBe(0)
|
||||
expect(quality.historyIssues).toHaveLength(5)
|
||||
expect(quality.committed).toBe(false)
|
||||
expect(quality.canRequestCommitPreview).toBe(true)
|
||||
})
|
||||
it('真实结构问题与动作阻断分别统计,正常道具检查不会变成错误', () => {
|
||||
const block = { episodeNo: 1, beatNo: 1, shotNo: 2, status: 'blocked' as const, blockingCodes: ['state_used_as_action_phase'], warningCodes: [], isPendingEpisode: true }
|
||||
const quality = breakdownQuality(selectBreakdownSource([candidateCheckpoint()]), candidateReview({ currentIssues: [{ episodeNo: 1, beatNo: 1, shotNo: 1, message: '主体引用缺失' }], actionQualityBlocks: [block], pendingQualityEpisodeNos: [1], candidateValidation: { valid: false, issues: ['Storyboard 质量审核未通过', '仍存在待处理的分镜质量问题'] }, propReferenceDiagnostics: [{ episodeNo: 1, beatNo: 1, shotNo: 1, subjectRef: '@PR0001', shotTitle: '', shotDescription: '', beatAllowsSubject: true, shotHasSubject: true, shotHasBinding: true, subjectName: '铜铃', availableForms: [] }] }))
|
||||
expect(quality.structuralIssues).toHaveLength(1)
|
||||
expect(quality.actionBlocks).toHaveLength(1)
|
||||
expect(quality.issueCount).toBe(2)
|
||||
expect(quality.canRequestCommitPreview).toBe(false)
|
||||
})
|
||||
it('审核读取中、失败和版本过期均不回退到历史质量', () => {
|
||||
const source = selectBreakdownSource([candidateCheckpoint()])
|
||||
expect(breakdownQuality(source, candidateReview(), true).structureValid).toBeNull()
|
||||
expect(breakdownQuality(source, null, false, '读取失败').canRequestCommitPreview).toBe(false)
|
||||
expect(breakdownQuality(source, candidateReview({ checkpointId: 'old' })).needsRefresh).toBe(true)
|
||||
expect(() => assertCandidateReview(candidateReview({ checkpointId: 'old' }), 'candidate-project', 'candidate-current')).toThrow('过期')
|
||||
})
|
||||
it('完整性审核中的 Form 绑定异常计入结构问题,不能标记结构通过', () => {
|
||||
const quality = breakdownQuality(selectBreakdownSource([candidateCheckpoint()]), candidateReview({ candidateValidation: { valid: false, issues: ['剧集 1 Shot 2 主体 @CH0001 形态绑定无效'] } }))
|
||||
expect(quality.structuralCount).toBe(1)
|
||||
expect(quality.structureValid).toBe(false)
|
||||
expect(quality.problems[0]?.type).toBe('binding')
|
||||
expect(quality.canRequestCommitPreview).toBe(false)
|
||||
})
|
||||
it('正式提交的持久化标记优先,不继承嵌套旧错误;新候选不覆盖已有正式结果', () => {
|
||||
const formal = candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true, breakdownResult: { storyboardShotValidation: { valid: false, issues: [{ episodeNo: 1, message: '旧错误' }] } } }), 'formal')
|
||||
const source = selectBreakdownSource([formal])
|
||||
expect(breakdownQuality(source, null).source).toBe('formal')
|
||||
expect(breakdownQuality(source, null).issueCount).toBe(0)
|
||||
expect(selectBreakdownSource([formal, candidateCheckpoint()]).formal?.checkpointId).toBe('formal')
|
||||
})
|
||||
it('只有错误的最新记录可以回看成果,但不能继承候选提交资格或旧错误', () => {
|
||||
const source = selectBreakdownSource([candidateCheckpoint(), { ...candidateCheckpoint({}, 'failed'), createdAt: '2026-10-17T10:00:00Z' }])
|
||||
const quality = breakdownQuality(source, null)
|
||||
expect(source.kind).toBe('history')
|
||||
expect(quality.isCandidate).toBe(false)
|
||||
expect(quality.structureValid).toBeNull()
|
||||
expect(quality.canRequestCommitPreview).toBe(false)
|
||||
})
|
||||
it('相同版本并发审核只请求一次,版本变化取消旧请求并拒绝晚到响应', async () => {
|
||||
let resolveOld!: (value: CandidateRevalidation) => void
|
||||
const signals: AbortSignal[] = []
|
||||
const read = vi.spyOn(breakdownApi, 'revalidateCandidate').mockImplementation(async (_id, signal) => {
|
||||
signals.push(signal!)
|
||||
if (signals.length === 1) return new Promise(resolve => { resolveOld = resolve })
|
||||
return candidateReview({ checkpointId: 'new' })
|
||||
})
|
||||
const records = ref([candidateCheckpoint()])
|
||||
scope = effectScope()
|
||||
const state = scope.run(() => useBreakdownQuality(ref('candidate-project'), records))!
|
||||
void state.refresh()
|
||||
void state.refresh()
|
||||
expect(read).toHaveBeenCalledTimes(1)
|
||||
records.value = [candidateCheckpoint(candidateState(), 'new')]
|
||||
await flushPromises()
|
||||
expect(signals[0]?.aborted).toBe(true)
|
||||
expect(state.review.value?.checkpointId).toBe('new')
|
||||
resolveOld(candidateReview())
|
||||
await flushPromises()
|
||||
expect(state.review.value?.checkpointId).toBe('new')
|
||||
expect(read).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
it.each(['failure', 'stale'] as const)('候选审核 %s 保持未知并禁止进入提交安全检查', async mode => {
|
||||
vi.spyOn(breakdownApi, 'revalidateCandidate').mockImplementation(async () => {
|
||||
if (mode === 'failure') throw new Error('服务不可用')
|
||||
return candidateReview({ checkpointId: 'old' })
|
||||
})
|
||||
scope = effectScope()
|
||||
const state = scope.run(() => useBreakdownQuality(ref('candidate-project'), ref([candidateCheckpoint()])))!
|
||||
await flushPromises()
|
||||
expect(state.error.value).not.toBe('')
|
||||
expect(state.quality.value.structureValid).toBeNull()
|
||||
expect(state.quality.value.canRequestCommitPreview).toBe(false)
|
||||
})
|
||||
it('正式提交后刷新或重新进入,不重新请求候选接口', async () => {
|
||||
const read = vi.spyOn(breakdownApi, 'revalidateCandidate')
|
||||
scope = effectScope()
|
||||
const state = scope.run(() => useBreakdownQuality(ref('candidate-project'), ref([candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true }))])))!
|
||||
await state.refresh()
|
||||
expect(read).not.toHaveBeenCalled()
|
||||
expect(state.quality.value.committed).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -56,6 +56,14 @@ describe('分镜正式数据与生成依赖', () => {
|
||||
expect(storyboardPrerequisites([checkpoint], 1).visualEpisode).toBe(false)
|
||||
expect(directionLabel('future-camera-mode')).toBe('future-camera-mode')
|
||||
})
|
||||
it('未提交候选不能作为正式导演设计和画面状态生成输入', () => {
|
||||
const record = storyboardCheckpoint()
|
||||
record.state.candidateOnly = true
|
||||
record.state.storyboardPersisted = false
|
||||
expect(storyboardPrerequisites([record], 1)).toMatchObject({ directionProject: false, visualProject: false })
|
||||
record.state.storyboardPersisted = true
|
||||
expect(storyboardPrerequisites([record], 1)).toMatchObject({ directionProject: true, visualProject: true })
|
||||
})
|
||||
|
||||
it('参考图只允许 http(s) 或后端 storage 地址,拦截不可信协议和路径逃逸', () => {
|
||||
vi.stubEnv('VITE_API_BASE_URL', 'https://api.example.test/api')
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { breakdownSnapshot, recoveryOptions, workflowCheckpoints } from '@/features/workflows/selectors'
|
||||
import { breakdownSnapshot, formalBreakdownSnapshot, recoveryOptions, workflowCheckpoints } from '@/features/workflows/selectors'
|
||||
import type { Checkpoint } from '@/features/workflows/types'
|
||||
import type { BreakdownState } from '@/features/breakdown/types'
|
||||
|
||||
@@ -9,6 +9,22 @@ function checkpoint(index: number, state: BreakdownState, workflowName = 'breakd
|
||||
}
|
||||
|
||||
describe('Checkpoint 选择与恢复', () => {
|
||||
it('正式工作区不会读取未提交候选,已有正式成果也不会被新候选覆盖', () => {
|
||||
const candidate = checkpoint(2, { candidateOnly: true, subjectCandidates: [] })
|
||||
expect(formalBreakdownSnapshot([candidate])).toBeNull()
|
||||
const formal = checkpoint(1, { candidateOnly: true, candidateCommitted: true, storyboardPersisted: true, subjectCandidates: [], storyboardShotValidation: { valid: true, issues: [] } })
|
||||
expect(formalBreakdownSnapshot([formal, candidate])?.candidateCommitted).toBe(true)
|
||||
})
|
||||
it('顶层修复和正式提交结果覆盖同一检查点内的旧嵌套质量状态', () => {
|
||||
const result = breakdownSnapshot([checkpoint(1, {
|
||||
candidateOnly: true,
|
||||
candidateCommitted: true,
|
||||
storyboardPersisted: true,
|
||||
storyboardShotValidation: { valid: true, issues: [] },
|
||||
breakdownResult: { storyboardShotValidation: { valid: false, issues: [{ episodeNo: 1, message: '旧错误' }] } }
|
||||
})])
|
||||
expect(result?.breakdownResult?.storyboardShotValidation).toEqual({ valid: true, issues: [] })
|
||||
})
|
||||
it('按 graph 隔离并保持输入不可变', () => {
|
||||
const records = [checkpoint(2, {}), checkpoint(1, {}, 'create-drama')]
|
||||
expect(workflowCheckpoints(records, 'breakdown').map(item => item.checkpointId)).toEqual(['2'])
|
||||
|
||||
+64
@@ -0,0 +1,64 @@
|
||||
import type { BreakdownState, EpisodePlan } from '@/features/breakdown/types'
|
||||
import type { CandidateCommitPreview, CandidateRevalidation } from '@/features/breakdown/candidate.types'
|
||||
import type { Checkpoint } from '@/features/workflows/types'
|
||||
|
||||
/**
|
||||
* 创建含两个主体和两个动作镜头的独立候选,全部内容仅用于测试。
|
||||
* @param overrides 本次测试状态差异
|
||||
* @returns 完整候选状态
|
||||
*/
|
||||
export function candidateState(overrides: Partial<BreakdownState> = {}): BreakdownState {
|
||||
const plan: EpisodePlan = {
|
||||
episodeNo: 1, episodeTitle: '第一集', storyGoal: '', centralConflict: '', emotionalArc: '', pacing: '', endingHook: '',
|
||||
beats: [{ beatNo: 1, title: '取物', purpose: 'action', description: '', visualFocus: '', narrativeGoal: '', emotionalTone: '', estimatedDurationSeconds: 8, subjectRefs: ['@CH0001', '@PR0001'], isKeyBeat: false }]
|
||||
}
|
||||
return {
|
||||
projectId: 'candidate-project', candidateOnly: true, storyboardPersisted: false,
|
||||
expectedEpisodeFingerprints: { 1: 'fingerprint' },
|
||||
runConfig: { groupSize: 3, modules: ['character', 'prop'], episodeGroups: [], sourceEpisodes: [{ episodeNo: 1 }] },
|
||||
subjectCandidates: [
|
||||
{ profileId: 'person', name: '人物', ref: '@CH0001', module: 'character', description: '', appearance_prompt: '' },
|
||||
{ profileId: 'prop', name: '铜铃', ref: '@PR0001', module: 'prop', description: '', appearance_prompt: '' }
|
||||
],
|
||||
subjectForms: [
|
||||
{ formId: 'person-form', profileId: 'person', type: 'character', name: '人物形态', isDefault: true, description: '', appearancePrompt: '' },
|
||||
{ formId: 'prop-form', profileId: 'prop', type: 'prop', name: '铜铃形态', isDefault: true, description: '', appearancePrompt: '' }
|
||||
],
|
||||
storyboardPlans: [plan],
|
||||
storyboardEpisodeShots: [{ episodeNo: 1, episodePlan: plan, beatShots: [{ beatNo: 1, shots: [1, 2].map(shotNo => ({
|
||||
shotNo, title: `动作镜头 ${shotNo}`, description: '人物拿起铜铃', visualFocus: '', durationSeconds: 4,
|
||||
subjectRefs: ['@CH0001'], subjectBindings: [{ subjectRef: '@CH0001', profileId: 'person', formId: 'person-form', formName: '人物形态' }],
|
||||
requiredActions: [{ id: `action-${shotNo}`, description: '铜铃已经在手中', kind: 'state', mustPerformInShot: false }],
|
||||
durationPlanning: { complexity: 'low', phases: [{ action: '铜铃已经在手中', actionIds: [`action-${shotNo}`], estimatedSeconds: 4 }], transitionSeconds: 0, recommendedDurationSeconds: 4, reason: '测试' }
|
||||
})) }] }],
|
||||
storyboardShotValidation: { valid: true, issues: [] }, storyboardPendingQualityEpisodeNos: [], ...overrides
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造稳定的当前候选检查点。
|
||||
* @param state 当前候选状态
|
||||
* @param checkpointId 当前版本
|
||||
* @returns 检查点记录
|
||||
*/
|
||||
export function candidateCheckpoint(state = candidateState(), checkpointId = 'candidate-current'): Checkpoint {
|
||||
return { checkpointId, createdAt: '2026-10-17T09:28:59Z', workflowName: 'breakdown', metadata: { nodeName: 'candidate_action_batch_repair', sourceCheckpointId: 'old' }, state }
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建完整的只读审核响应,canCommit 固定为 false。
|
||||
* @param overrides 本次审核差异
|
||||
* @returns 候选重新审核响应
|
||||
*/
|
||||
export function candidateReview(overrides: Partial<CandidateRevalidation> = {}): CandidateRevalidation {
|
||||
return { projectId: 'candidate-project', checkpointId: 'candidate-current', episodeCount: 1, shotCount: 2, previousIssues: [], currentIssues: [], missingSubjectRefs: [], pendingQualityEpisodeNos: [], actionQualityBlocks: [], actionRepairTargets: [], propReferenceDiagnostics: [], pendingWithoutActionBlocks: [], candidateValidation: { valid: true, issues: [] }, canCommit: false, ...overrides }
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建七项门禁均通过的安全预检查响应。
|
||||
* @param overrides 本次检查差异
|
||||
* @returns 只读安全检查
|
||||
*/
|
||||
export function commitPreview(overrides: Partial<CandidateCommitPreview> = {}): CandidateCommitPreview {
|
||||
return { projectId: 'candidate-project', checkpointId: 'candidate-current', ready: true, readOnly: true, checks: { episodeNumbersMatch: true, episodeFingerprintsMatch: true, noActiveExecutions: true, noActiveVideos: true, noSubjectIdentities: true, noSubjectImages: true, noProtectedShots: true }, counts: { episodes: 1, existingStoryboards: 0, activeExecutions: 0, activeVideos: 0, subjectIdentities: 0, subjectImages: 0, protectedShots: 0 }, ...overrides }
|
||||
}
|
||||
Reference in new issue
Block a user