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
@@ -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('提交候选为正式结果')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user