feat(short-drama-agent-front): 完善分镜审核与制作准备流程

This commit is contained in:
GJ committed 2026-10-19 21:59:22 +08:00
1 parent c4b43b9725
commit 1da56e0d46
72 files changed
+2801 -528

No files matched your search

@@ -0,0 +1,17 @@
import type { StoryboardRecheck, ReviewBaselinePreview, StoryboardApprovalState, StoryboardApproval, ProductionEntryReadiness } from '@/features/storyboard-preparation/types'
import { policyReceipt } from '../../fixtures/quality-policy'
/**
* 创建符合真实路由形状的独立复检数据,canConfirm 始终为 false。
* @param projectId 当前测试项目
* @returns 可变化的只读回执与确认记录
*/
export function preparationFixture(projectId = 'p') {
const policy = policyReceipt(projectId, { version: 1, physicsMode: 'stylized', allowExaggeratedMotion: true, allowNonPhysicalActions: false, allowSupernaturalAbilities: false, customRules: [] }, { confirmed: true, confirmedRevision: 2, confirmedAt: '2026-10-19T01:00:00Z' })
const quality: StoryboardRecheck = { projectId, status: 'insufficient_evidence', structure: { hasValidation: true, valid: true, reason: null }, coverage: { episodeCount: 1, beatCount: 1, shotCount: 1, issueCount: 0 }, issues: [], actionAudit: { projectId, shotCount: 1, issueCount: 0, blockedCount: 0, needsReviewCount: 0, issues: [] }, sourceAudit: { projectId, checkpointId: 'cp', shotCount: 1, valid: true, issues: [] }, provenance: { checkpointId: 'cp', sourceCommitted: true, qualityPolicyConsistent: true, qualityPolicyChecks: { projectConfirmed: true, checkpointSnapshotPresent: true }, baselineConsistent: false, shotCountsConsistent: true, checkpointConsistent: true }, preflightEligible: true, canConfirm: false }
const record: StoryboardApproval = { id: 'approval', projectId, checkpointId: 'cp', qualityPolicyRevision: 2, qualityPolicyFingerprint: 'a'.repeat(64), shotCount: 1, shotFingerprint: 'b'.repeat(64), reviewer: '复核人', reviewNote: '已逐镜核对动作与主体', confirmedAt: '2026-10-19T01:00:00Z' }
const approval: StoryboardApprovalState = { valid: false, confirmation: null, evidence: { valid: true, checkpointId: 'cp', qualityPolicyRevision: 2, qualityPolicyFingerprint: 'a'.repeat(64), shotCount: 1, shotFingerprint: 'b'.repeat(64) } }
const baseline: ReviewBaselinePreview = { eligible: false, reasons: ['当前记录已有规则来源'], checkpointId: 'cp', shotCount: 1, shotFingerprint: 'b'.repeat(64) }
const entry: ProductionEntryReadiness = { ready: false, hasStoryboardValidation: true, storyboardValid: true, reason: '请先完成分镜审核', derivedAssets: { shotCount: 1, directionCount: 0, directionCoverage: 0, visualStateCount: 0, visualStateCoverage: 0 } }
return { policy, quality, approval, baseline, entry, record }
}
@@ -0,0 +1,31 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { checkPipeline } from '@/features/production/useAdvancedProduction'
import { productionApi } from '@/features/production/api'
import { generationConfigApi } from '@/features/generation-config/api'
import { projectsApi } from '@/features/projects/api'
import { subjectImagesApi } from '@/features/subject-images/api'
import { storyboardApi } from '@/features/storyboard/api'
afterEach(() => { vi.restoreAllMocks(); vi.unstubAllGlobals() })
describe('制作计划之前的正式分镜检查', () => {
it('入口未通过时不查询制作计划,也不调用生成接口', async () => {
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: { ready: false, reason: '请先完成分镜审核', hasStoryboardValidation: true, storyboardValid: true, derivedAssets: { shotCount: 1, directionCount: 0, directionCoverage: 0, visualStateCount: 0, visualStateCoverage: 0 } } }))))
vi.spyOn(generationConfigApi, 'profile').mockResolvedValue(null)
vi.spyOn(projectsApi, 'detail').mockResolvedValue({ id: 'p' } as never)
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
vi.spyOn(subjectImagesApi, 'listForms').mockResolvedValue([])
vi.spyOn(productionApi, 'status').mockResolvedValue({ projectId: 'p' } as never)
const plan = vi.spyOn(productionApi, 'plan').mockRejectedValue(new Error('不应该进入制作计划'))
await expect(checkPipeline('p')).rejects.toThrow('请先完成分镜审核')
expect(plan).not.toHaveBeenCalled()
})
it('设计覆盖完整但已经过期时仍不进入制作计划', async () => {
vi.stubGlobal('fetch', vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: { ready: true, derivedAssets: { shotCount: 1 } } }))))
vi.spyOn(projectsApi, 'detail').mockResolvedValue({ id: 'p', episodes: [{ episode: 1 }] } as never)
vi.spyOn(storyboardApi, 'directions').mockResolvedValue({ projectId: 'p', episodeNo: 1, shotCount: 1, directionCount: 1, staleCount: 1, coverage: 1, beats: [] })
vi.spyOn(storyboardApi, 'visualStates').mockResolvedValue({ projectId: 'p', episodeNo: 1, shotCount: 1, visualStateCount: 1, staleCount: 0, coverage: 1, beats: [] })
const plan = vi.spyOn(productionApi, 'plan')
await expect(checkPipeline('p')).rejects.toThrow('过期')
expect(plan).not.toHaveBeenCalled()
})
})
@@ -0,0 +1,51 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import FormalRepairEditor from '@/features/storyboard-preparation/FormalRepairEditor.vue'
import { preparationApi } from '@/features/storyboard-preparation/api'
import type { FormalShotRepairPreview, BeatSubjectPreview } from '@/features/storyboard-preparation/types'
/** 当前正式镜头有明确可补齐的动作关联,全部旧证据必须保留。 */
const preview = (): FormalShotRepairPreview => ({ projectId: 'p', shotId: 's', expectedFingerprint: 'a'.repeat(64), written: false, willCallModel: false, requiredActions: [{ id: 'a', kind: 'action', description: '左手持铃', mustPerformInShot: true }], durationPlanning: { complexity: 'low', phases: [{ action: '持铃', actionIds: ['a'], estimatedSeconds: 4, resourceOccupancy: [{ actionId: 'a', ownerRef: '@CH1', resource: 'left_hand', usage: 'hold', shareable: false, continuityRef: '@PR1' }] }], transitionSeconds: 0, recommendedDurationSeconds: 4, reason: '原动作时长' }, classification: { status: 'candidate', beforeFingerprint: 'a'.repeat(64), proposed: null, semanticIssues: [], originalIssues: [] } })
let wrapper: VueWrapper | undefined
afterEach(() => { wrapper?.unmount(); vi.restoreAllMocks() })
describe('正式镜头版本化修订', () => {
it('读取当前正式数据,不调用模型;人工确认后保存真实指纹和完整占用证据', async () => {
vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
const model = vi.spyOn(preparationApi, 'repairCandidate')
const save = vi.spyOn(preparationApi, 'repair').mockResolvedValue({ projectId: 'p', shotId: 's', written: true, beforeFingerprint: 'a'.repeat(64), afterFingerprint: 'b'.repeat(64) })
wrapper = mount(FormalRepairEditor, { props: { projectId: 'p', issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', message: '关联待修复' }, disabled: false } })
await flushPromises()
expect(model).not.toHaveBeenCalled(); expect(save).not.toHaveBeenCalled()
await wrapper.get('[aria-label="修订原因"] textarea').setValue('逐项核对并调整动作关联')
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
await wrapper.getComponent(FormalRepairEditor).vm.save(); await flushPromises()
expect(save).toHaveBeenCalledWith('p', expect.objectContaining({ shotId: 's', expectedFingerprint: 'a'.repeat(64), confirmed: true, reason: '逐项核对并调整动作关联', durationPlanning: expect.objectContaining({ phases: [expect.objectContaining({ resourceOccupancy: [expect.objectContaining({ continuityRef: '@PR1' })] })] }) }))
expect(wrapper.emitted('saved')).toHaveLength(1)
})
it('打开时不校验,保存前版本变化不得覆盖新镜头', async () => {
const read = vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
const save = vi.spyOn(preparationApi, 'repair')
wrapper = mount(FormalRepairEditor, { props: { projectId: 'p', issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', message: '关联待修复' }, disabled: false } })
await flushPromises(); expect(wrapper.text()).not.toContain('请填写修订原因')
await wrapper.get('[aria-label="修订原因"] textarea').setValue('明确原因')
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
read.mockResolvedValue({ ...preview(), expectedFingerprint: 'c'.repeat(64) })
await wrapper.getComponent(FormalRepairEditor).vm.save(); await flushPromises()
expect(save).not.toHaveBeenCalled(); expect(wrapper.text()).toContain('已变化')
})
it('主体遗漏先保存段落的真实版本,不把段落指纹当作镜头指纹或自动追加镜头', async () => {
vi.spyOn(preparationApi, 'repairPreview').mockResolvedValue(preview())
const upstream: BeatSubjectPreview = { projectId: 'p', shotId: 's', beatId: 'beat', checkpointId: 'cp', subjectRef: '@PR1', subjectName: '铜铃', subjectDescription: '项目已有铜铃', beat: { title: '取铃', description: '阿皮拿起铜铃', visualFocus: '铜铃', subjectRefs: ['@CH1'] }, shot: { title: '取铃', description: '阿皮拿起铜铃', visualFocus: '铜铃' }, status: 'upstream-missing', written: false, candidate: { checkpointId: 'cp', beatId: 'beat', subjectRef: '@PR1', expectedFingerprint: 'c'.repeat(64), proposed: { upstreamRefs: ['@CH1', '@PR1'], persistedRefs: ['@CH1', '@PR1'] }, requiresHumanReview: true } }
vi.spyOn(preparationApi, 'beatSubjectPreview').mockResolvedValue(upstream)
const beatWrite = vi.spyOn(preparationApi, 'repairBeatSubject').mockResolvedValue({ projectId: 'p', shotId: 's', beatId: 'beat', checkpointId: 'cp', resultFingerprint: 'd'.repeat(64), written: true })
const shotWrite = vi.spyOn(preparationApi, 'repairSubject')
wrapper = mount(FormalRepairEditor, { props: { projectId: 'p', issue: { episodeNo: 1, beatNo: 1, shotNo: 1, shotId: 's', subjectRef: '@PR1', message: '缺少铜铃' }, disabled: false } })
await flushPromises()
expect(beatWrite).not.toHaveBeenCalled(); expect(wrapper.text()).toContain('剧情段落')
await wrapper.get('[aria-label="修订原因"] textarea').setValue('正文明确出现铜铃,补齐段落来源')
await wrapper.get('[role="checkbox"][aria-label="确认正式镜头修订"]').trigger('click')
await wrapper.getComponent(FormalRepairEditor).vm.save(); await flushPromises()
expect(beatWrite).toHaveBeenCalledExactlyOnceWith('p', { shotId: 's', subjectRef: '@PR1', expectedFingerprint: 'c'.repeat(64), confirmed: true, reason: '正文明确出现铜铃,补齐段落来源' })
expect(shotWrite).not.toHaveBeenCalled(); expect(wrapper.emitted('saved')).toHaveLength(1)
})
})
@@ -0,0 +1,82 @@
import { effectScope, ref } from 'vue'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { preparationApi } from '@/features/storyboard-preparation/api'
import { projectsApi } from '@/features/projects/api'
import { useStoryboardPreparation } from '@/features/storyboard-preparation/useStoryboardPreparation'
import { currentStoryboardApproval } from '@/features/storyboard-preparation/model'
import { preparationFixture } from './fixtures'
/** 当前作用域,避免项目切换测试遗留响应式观察器。 */
const scopes: ReturnType<typeof effectScope>[] = []
afterEach(() => { scopes.splice(0).forEach(scope => scope.stop()); vi.restoreAllMocks() })
/** 测试只读回执保留当前已确认规则,所有写入独立模拟。 */
function setup() {
const data = preparationFixture()
vi.spyOn(preparationApi, 'recheck').mockImplementation(async () => structuredClone(data.quality))
vi.spyOn(preparationApi, 'approval').mockImplementation(async () => structuredClone(data.approval))
vi.spyOn(preparationApi, 'baseline').mockImplementation(async () => structuredClone(data.baseline))
vi.spyOn(preparationApi, 'entry').mockImplementation(async () => structuredClone(data.entry))
vi.spyOn(projectsApi, 'qualityPolicy').mockImplementation(async () => structuredClone(data.policy))
const scope = effectScope(); scopes.push(scope)
const id = ref('p'), locked = ref(false)
const flow = scope.run(() => useStoryboardPreparation(id, locked))!
return { data, id, locked, flow }
}
describe('正式分镜审核绑定当前内容', () => {
it('有效标志也必须有同项目同版本的实际审核凭据', () => {
const data = preparationFixture()
const current = { ...data.approval, valid: true, confirmation: data.record }
expect(currentStoryboardApproval(current, 'p')).toBe(true)
expect(currentStoryboardApproval({ ...current, confirmation: null }, 'p')).toBe(false)
expect(currentStoryboardApproval(current, 'other')).toBe(false)
expect(currentStoryboardApproval({ ...current, evidence: { ...current.evidence, shotFingerprint: 'f'.repeat(64) } }, 'p')).toBe(false)
expect(currentStoryboardApproval({ ...current, evidence: { ...current.evidence, qualityPolicyRevision: 3 } }, 'p')).toBe(false)
})
it('只读 canConfirm=false 不代替人工确认;满足实际预检后提交真实版本', async () => {
const { data, flow } = setup()
const confirm = vi.spyOn(preparationApi, 'confirmApproval').mockResolvedValue(data.record)
await flow.load()
expect(flow.reviewable.value).toBe(true)
expect(confirm).not.toHaveBeenCalled()
expect(await flow.confirm('approval', '复核人', '已逐镜核对动作与主体')).toBe(true)
expect(confirm).toHaveBeenCalledExactlyOnceWith('p', { reviewer: '复核人', reviewNote: '已逐镜核对动作与主体', expectedCheckpointId: 'cp', expectedShotFingerprint: 'b'.repeat(64) })
})
it('确认期间镜头版本变化时撤销确认,不自动提交新版本', async () => {
const { data, flow } = setup()
const confirm = vi.spyOn(preparationApi, 'confirmApproval')
await flow.load(); data.approval.evidence.shotFingerprint = 'c'.repeat(64)
expect(await flow.confirm('approval', '复核人', '已核对')).toBe(false)
expect(confirm).not.toHaveBeenCalled()
expect(flow.error.value).toContain('已变化')
})
it('结构通过但动作问题、来源不一致或缺规则确认均不能人工放行', async () => {
const { data, flow } = setup()
data.quality.preflightEligible = false; await flow.load()
expect(flow.reviewable.value).toBe(false)
data.quality.preflightEligible = true; data.quality.actionAudit.issueCount = 1; await flow.load()
expect(flow.reviewable.value).toBe(false)
data.quality.actionAudit.issueCount = 0; data.policy.confirmed = false; await flow.load()
expect(flow.reviewable.value).toBe(false)
})
it('旧分镜来源确认与整体审核分开提交,使用真实镜头内容版本', async () => {
const { data, flow } = setup()
data.quality.provenance.qualityPolicyConsistent = false
data.quality.preflightEligible = false
data.baseline.eligible = true; data.baseline.reasons = []
const baseline = vi.spyOn(preparationApi, 'confirmBaseline').mockResolvedValue(data.record)
const approval = vi.spyOn(preparationApi, 'confirmApproval')
await flow.load(); expect(flow.baselineAllowed.value).toBe(true); expect(flow.reviewable.value).toBe(false)
expect(await flow.confirm('baseline', '复核人', '明确采用当前规则重新核对旧分镜')).toBe(true)
expect(baseline).toHaveBeenCalledExactlyOnceWith('p', { reviewer: '复核人', reviewNote: '明确采用当前规则重新核对旧分镜', expectedCheckpointId: 'cp', expectedShotFingerprint: 'b'.repeat(64) })
expect(approval).not.toHaveBeenCalled()
})
it('确认失败保留可读原因,不能把历史确认存在当作当前有效', async () => {
const { data, flow } = setup()
data.approval.confirmation = data.record
const confirm = vi.spyOn(preparationApi, 'confirmApproval').mockRejectedValue(new Error('版本冲突,请重新核对'))
await flow.load(); expect(flow.approved.value).toBe(false)
expect(await flow.confirm('approval', '复核人', '已核对')).toBe(false)
expect(confirm).toHaveBeenCalledTimes(1); expect(flow.error.value).toContain('版本冲突')
expect(flow.approved.value).toBe(false)
})
})