484 lines
21 KiB
TypeScript
484 lines
21 KiB
TypeScript
import { testCheckpointSummaries } from '@/testing/project-context'
|
||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||
import { flushPromises, mount } from '@vue/test-utils'
|
||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||
import QualityResult from '@/features/production/components/QualityResult.vue'
|
||
import { expandSections } from '@/testing/naive'
|
||
import ShotProductionAssets from '@/features/production/components/ShotProductionAssets.vue'
|
||
import { primaryKeyframe } from '@/features/production/model'
|
||
import {
|
||
qualityKey,
|
||
qualitySession,
|
||
sessionKeyframePassed,
|
||
sessionVideoValidation
|
||
} from '@/features/production/quality'
|
||
import { keyframeFixture, videoFixture } from '@/features/production/testing/fixtures'
|
||
import { storyboardApi } from '@/features/storyboard/api'
|
||
import { hasRunningWorkflow } from '@/features/workflows/selectors'
|
||
import type { DesignedShot } from '@/features/storyboard/types'
|
||
import type { VideoValidation } from '@/features/production/quality.types'
|
||
import type { Checkpoint } from '@/features/workflows/types'
|
||
|
||
const shot: DesignedShot = {
|
||
shotId: 'shot-1',
|
||
shotNo: 1,
|
||
beatNo: 1,
|
||
title: '测试镜头',
|
||
description: '',
|
||
visualFocus: '',
|
||
direction: null,
|
||
visualState: null
|
||
}
|
||
const validation: VideoValidation = {
|
||
shotId: 'shot-1',
|
||
videoId: 'video-1',
|
||
videoUrl: '/storage/videos/video-1.mp4',
|
||
isPrimary: false,
|
||
passed: true,
|
||
summary: '通过',
|
||
subjects: [],
|
||
subjectCountConsistent: true,
|
||
unauthorizedText: { detected: false, texts: [] },
|
||
issues: [],
|
||
sampleFrames: [],
|
||
allowedTexts: [],
|
||
validatedAt: '2026-09-10T00:00:00Z'
|
||
}
|
||
afterEach(() => {
|
||
vi.unstubAllGlobals()
|
||
})
|
||
|
||
/** 构造带完整执行字段的后端 checkpoint。 */
|
||
const record = (workflowName: string, day: number, status: 'running' | 'completed'): Checkpoint => ({
|
||
checkpointId: `${workflowName}-${day}`,
|
||
workflowName,
|
||
createdAt: `2026-09-0${day}T00:00:00Z`,
|
||
state: {
|
||
workflowExecution: {
|
||
status,
|
||
executionId: `${workflowName}-${day}`,
|
||
startedAt: `2026-09-0${day}T00:00:00Z`
|
||
}
|
||
}
|
||
})
|
||
|
||
/**
|
||
* 定位候选弹窗内的真实按钮。
|
||
* @param label 按钮文本
|
||
* @returns 对应的按钮
|
||
*/
|
||
function recoveryButton(label: string) {
|
||
return [...document.querySelectorAll('button')].find(item => item.textContent?.trim() === label)!
|
||
}
|
||
|
||
/**
|
||
* 在实际弹窗中定位当前可操作的按钮。
|
||
* @param label 完整按钮文字
|
||
* @returns 对应按钮
|
||
*/
|
||
function dialogButton(label: string) {
|
||
return [...document.querySelectorAll<HTMLButtonElement>('button')].find(item => item.textContent?.trim() === label)
|
||
}
|
||
|
||
describe('精简公开资产回归', () => {
|
||
it('无内部字段的视频可播放,晋升使用后端权限,会话通过不能授权', async () => {
|
||
const projectId = 'public-video-contract'
|
||
const video = videoFixture({ isPrimary: false })
|
||
expect(video).not.toHaveProperty('rawJson')
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||
async url =>
|
||
new Response(
|
||
JSON.stringify({
|
||
data: String(url).endsWith('/generation-models')
|
||
? imageCatalog
|
||
: String(url).endsWith('/creative-profile')
|
||
? generationProfile(projectId)
|
||
: String(url).endsWith('/videos')
|
||
? [video]
|
||
: []
|
||
})
|
||
)
|
||
)
|
||
vi.stubGlobal('fetch', fetcher)
|
||
const wrapper = mount(ShotProductionAssets, { props: { projectId, shot, disabled: false } })
|
||
try {
|
||
await flushPromises()
|
||
/** 未确认的候选不出现在主区,只在管理弹窗中播放和检查。 */
|
||
expect(wrapper.find('video').exists()).toBe(false)
|
||
expect(wrapper.text()).toContain('尚无已确认主视频')
|
||
await wrapper
|
||
.findAll('button')
|
||
.find(button => button.text() === '管理候选(1)')!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(document.querySelector('video')).not.toBeNull()
|
||
expect(wrapper.text()).not.toContain('自动校验中')
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(button => button.textContent?.trim() === '设为主视频')
|
||
).toBe(false)
|
||
const session = qualitySession(
|
||
qualityKey(projectId, { kind: 'video', shotId: shot.shotId, assetId: video.id, title: '' })
|
||
)
|
||
session.videoValidation = validation
|
||
await flushPromises()
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(button => button.textContent?.trim() === '设为主视频')
|
||
).toBe(false)
|
||
expect(sessionVideoValidation('other-project', shot.shotId, video.id)).toBeNull()
|
||
session.videoValidation = { ...validation, passed: false }
|
||
await flushPromises()
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(button => button.textContent?.trim() === '设为主视频')
|
||
).toBe(false)
|
||
expect(fetcher.mock.calls.every(([, options]) => options?.method === 'GET')).toBe(true)
|
||
} finally {
|
||
wrapper.unmount()
|
||
}
|
||
})
|
||
|
||
it('模型输入变体可以预览,但不能设为业务主首帧', async () => {
|
||
const variant = keyframeFixture({ source: 'provider_variant', isPrimary: false })
|
||
expect(primaryKeyframe([{ ...variant, isPrimary: true }])).toBeUndefined()
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn<typeof fetch>().mockImplementation(
|
||
async url =>
|
||
new Response(
|
||
JSON.stringify({
|
||
data: String(url).endsWith('/generation-models')
|
||
? imageCatalog
|
||
: String(url).endsWith('/creative-profile')
|
||
? generationProfile('public-variant-contract')
|
||
: String(url).endsWith('/keyframes')
|
||
? [variant]
|
||
: []
|
||
})
|
||
)
|
||
)
|
||
)
|
||
const wrapper = mount(ShotProductionAssets, {
|
||
props: { projectId: 'public-variant-contract', shot, disabled: false }
|
||
})
|
||
try {
|
||
await flushPromises()
|
||
await wrapper
|
||
.findAll('button')
|
||
.find(item => item.text().includes('管理候选'))!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(document.body.textContent).toContain('视频参考图')
|
||
expect([...document.querySelectorAll('button')].some(button => button.textContent === '设为主首帧')).toBe(
|
||
false
|
||
)
|
||
} finally {
|
||
wrapper.unmount()
|
||
}
|
||
})
|
||
|
||
it.each([false, true])('只为本次恢复成功的首帧解锁(恢复回执丢失 %s)', async lostReceipt => {
|
||
const projectId = 'keyframe-download-guard'
|
||
const targetShot = { ...shot, shotId: 'download-guard-shot-' + lostReceipt }
|
||
const fingerprint = 'a'.repeat(64)
|
||
/** 已保存的失败候选,恢复目标绑定相同指纹及正式镜头。 */
|
||
const failed = keyframeFixture({
|
||
id: 'recover-current',
|
||
shotId: targetShot.shotId,
|
||
status: 'failed',
|
||
isPrimary: false,
|
||
imageUrl: null,
|
||
providerInputFingerprint: fingerprint,
|
||
recoveryRequired: true,
|
||
canRecoverSavedResult: true
|
||
})
|
||
const historical = keyframeFixture({
|
||
id: 'recover-history',
|
||
shotId: targetShot.shotId,
|
||
status: 'failed',
|
||
isPrimary: false,
|
||
imageUrl: null,
|
||
providerInputFingerprint: fingerprint,
|
||
recoveryRequired: false,
|
||
canRecoverSavedResult: true
|
||
})
|
||
let rows = [historical]
|
||
let attempts = 0
|
||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||
const path = String(url)
|
||
if (path.endsWith('/generation-models')) return Response.json({ data: imageCatalog })
|
||
if (path.endsWith('/creative-profile')) return Response.json({ data: generationProfile(projectId) })
|
||
if (path.endsWith('/generation-config/image/resolve'))
|
||
return Response.json({
|
||
data: {
|
||
provider: 'qwen-image',
|
||
model: 'qwen-image-3.0-pro',
|
||
options: generationProfile(projectId).imageOptions
|
||
}
|
||
})
|
||
if (path.endsWith('/keyframes')) return Response.json({ data: rows })
|
||
if (path.endsWith('/keyframe/preview'))
|
||
return Response.json({
|
||
data: {
|
||
shotId: targetShot.shotId,
|
||
provider: 'qwen-image',
|
||
model: 'qwen-image-3.0-pro',
|
||
generationConfig: {},
|
||
referenceImages: [],
|
||
providerPrompt: '已确认预览',
|
||
previewFingerprint: fingerprint
|
||
}
|
||
})
|
||
if (path.endsWith('/keyframe') && init?.method === 'POST') {
|
||
rows = [historical, failed]
|
||
if (lostReceipt) return Response.json({ data: { shotId: targetShot.shotId } })
|
||
return Response.json({ message: '图片已生成但下载失败' }, { status: 500 })
|
||
}
|
||
if (path.endsWith('/recover-saved-result')) {
|
||
const target = path.includes(historical.id) ? historical : failed
|
||
if (target.id === failed.id && ++attempts === 1)
|
||
return Response.json({ message: '本次下载恢复失败' }, { status: 503 })
|
||
const recovered = {
|
||
...target,
|
||
status: 'completed' as const,
|
||
imageUrl: '/storage/recovered.png',
|
||
recoveryRequired: false,
|
||
canRecoverSavedResult: false,
|
||
recoveryReason: 'provider_result_recovered'
|
||
}
|
||
rows = rows.map(item => (item.id === target.id ? recovered : item))
|
||
if (target.id === failed.id && lostReceipt)
|
||
return Response.json({ message: '下载已恢复,回执连接中断' }, { status: 504 })
|
||
return Response.json({ data: recovered })
|
||
}
|
||
return Response.json({ data: [] })
|
||
})
|
||
vi.stubGlobal('fetch', fetcher)
|
||
const wrapper = mount(ShotProductionAssets, {
|
||
attachTo: document.body,
|
||
props: {
|
||
projectId,
|
||
shot: targetShot,
|
||
disabled: false,
|
||
keyframeReadiness: {
|
||
shotId: targetShot.shotId,
|
||
status: 'ready',
|
||
issues: [],
|
||
episodeNo: 1,
|
||
beatNo: 1,
|
||
shotNo: 1
|
||
}
|
||
}
|
||
})
|
||
/** 模拟同标签页刷新时仍可读取的提交标记。 */
|
||
const lock = () => sessionStorage.getItem('short-drama:image-request-unknown:keyframe:' + targetShot.shotId)
|
||
try {
|
||
await flushPromises()
|
||
recoveryButton('生成首帧候选').click()
|
||
await flushPromises()
|
||
recoveryButton('预览实际生成输入').click()
|
||
await flushPromises()
|
||
document.querySelector<HTMLInputElement>('#confirm-keyframe-cost')!.click()
|
||
await flushPromises()
|
||
recoveryButton('确认生成首帧').click()
|
||
await flushPromises()
|
||
expect(lock()).not.toBeNull()
|
||
recoveryButton('取消').click()
|
||
await flushPromises()
|
||
recoveryButton('管理候选(2)').click()
|
||
await flushPromises()
|
||
recoveryButton('恢复已生成图片').click()
|
||
await flushPromises()
|
||
expect(lock()).not.toBeNull()
|
||
recoveryButton('恢复已生成图片').click()
|
||
await flushPromises()
|
||
expect(lock()).not.toBeNull()
|
||
recoveryButton('恢复已生成图片').click()
|
||
await flushPromises()
|
||
expect(lock()).toBeNull()
|
||
recoveryButton('关闭').click()
|
||
await flushPromises()
|
||
recoveryButton('生成首帧候选').click()
|
||
await flushPromises()
|
||
recoveryButton('预览实际生成输入').click()
|
||
await flushPromises()
|
||
document.querySelector<HTMLInputElement>('#confirm-keyframe-cost')!.click()
|
||
await flushPromises()
|
||
expect(recoveryButton('确认生成首帧').disabled).toBe(false)
|
||
expect(
|
||
fetcher.mock.calls.filter(([url, init]) => String(url).endsWith('/keyframe') && init?.method === 'POST')
|
||
).toHaveLength(1)
|
||
} finally {
|
||
wrapper.unmount()
|
||
sessionStorage.removeItem('short-drama:image-request-unknown:keyframe:' + targetShot.shotId)
|
||
}
|
||
})
|
||
|
||
it('主页面只展示主首帧,候选通过质量检查后才允许晋升', async () => {
|
||
const projectId = 'keyframe-promotion-contract'
|
||
const primary = keyframeFixture()
|
||
const candidate = keyframeFixture({ id: 'keyframe-2', isPrimary: false })
|
||
let persistedQuality = 'unknown'
|
||
const primaryRequests: string[] = []
|
||
vi.stubGlobal(
|
||
'fetch',
|
||
vi.fn<typeof fetch>().mockImplementation(async (url, options) => {
|
||
if (options?.method === 'PUT') {
|
||
primaryRequests.push(String(url))
|
||
return new Response(JSON.stringify({ data: { ...candidate, isPrimary: true } }))
|
||
}
|
||
return new Response(
|
||
JSON.stringify({
|
||
data: String(url).endsWith('/generation-models')
|
||
? imageCatalog
|
||
: String(url).endsWith('/creative-profile')
|
||
? generationProfile(projectId)
|
||
: String(url).endsWith('/keyframes')
|
||
? [primary, candidate]
|
||
: String(url).includes('/quality-review')
|
||
? {
|
||
shotId: shot.shotId,
|
||
keyframeId: String(url).includes(candidate.id) ? candidate.id : primary.id,
|
||
effectiveQualityStatus: String(url).includes(candidate.id)
|
||
? persistedQuality
|
||
: 'passed'
|
||
}
|
||
: []
|
||
})
|
||
)
|
||
})
|
||
)
|
||
let wrapper = mount(ShotProductionAssets, {
|
||
attachTo: document.body,
|
||
props: { projectId, shot, disabled: false }
|
||
})
|
||
try {
|
||
await flushPromises()
|
||
expect(wrapper.findAll('.keyframe-card')).toHaveLength(1)
|
||
expect(wrapper.find('.keyframe-card').text()).toContain('主首帧')
|
||
expect(wrapper.findAll('button').some(item => item.text().includes('设为主首帧'))).toBe(false)
|
||
|
||
await wrapper
|
||
.findAll('button')
|
||
.find(item => item.text().includes('管理候选'))!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
expect(document.body.textContent).toContain('首帧候选管理')
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||
).toBe(false)
|
||
|
||
const session = qualitySession(
|
||
qualityKey(projectId, { kind: 'keyframe', shotId: shot.shotId, assetId: candidate.id, title: '' })
|
||
)
|
||
session.receipt = {
|
||
kind: 'keyframe',
|
||
result: {
|
||
shotId: shot.shotId,
|
||
keyframeId: candidate.id,
|
||
validationTaskId: 'validation-2',
|
||
imageUrl: candidate.imageUrl!,
|
||
isPrimary: false,
|
||
passed: false,
|
||
summary: '人物身份不一致',
|
||
subjects: [],
|
||
subjectCountConsistent: true,
|
||
unauthorizedText: { detected: false, texts: [] },
|
||
issues: []
|
||
}
|
||
}
|
||
await flushPromises()
|
||
expect(sessionKeyframePassed(projectId, shot.shotId, candidate.id)).toBe(false)
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||
).toBe(false)
|
||
|
||
session.receipt.result.passed = true
|
||
await flushPromises()
|
||
expect(sessionKeyframePassed(projectId, shot.shotId, candidate.id)).toBe(true)
|
||
expect(
|
||
[...document.querySelectorAll('button')].some(item => item.textContent?.includes('设为主首帧'))
|
||
).toBe(false)
|
||
|
||
wrapper.unmount()
|
||
persistedQuality = 'passed'
|
||
wrapper = mount(ShotProductionAssets, {
|
||
attachTo: document.body,
|
||
props: { projectId, shot, disabled: false }
|
||
})
|
||
await flushPromises()
|
||
await wrapper
|
||
.findAll('button')
|
||
.find(item => item.text().includes('管理候选'))!
|
||
.trigger('click')
|
||
await flushPromises()
|
||
const promote = dialogButton('设为主首帧')
|
||
expect(promote).toBeDefined()
|
||
promote?.click()
|
||
await flushPromises()
|
||
dialogButton('确认切换')?.click()
|
||
await flushPromises()
|
||
expect(primaryRequests).toEqual([
|
||
'/api/storyboard-shots/' + shot.shotId + '/keyframes/' + candidate.id + '/primary'
|
||
])
|
||
} finally {
|
||
wrapper.unmount()
|
||
}
|
||
})
|
||
|
||
it('提示词返回使用 shotId,保留正文、状态和更新时间', async () => {
|
||
const result = {
|
||
shotId: 'shot/db',
|
||
videoPrompt: '镜头正文',
|
||
negativePrompt: null,
|
||
status: 'prompt_ready',
|
||
updatedAt: '2026-09-10T00:00:00Z'
|
||
}
|
||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: result })))
|
||
vi.stubGlobal('fetch', fetcher)
|
||
expect(await storyboardApi.generatePrompt('shot/db', false)).toEqual(result)
|
||
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/storyboard-shots/shot%2Fdb/video-prompt')
|
||
expect(JSON.parse(String(fetcher.mock.calls[0]?.[1]?.body))).toEqual({ force: false })
|
||
})
|
||
|
||
it('视频专项检查区分通过、失败和未执行,并保留后端摘要', async () => {
|
||
const wrapper = mount(QualityResult, {
|
||
attachTo: document.body,
|
||
props: {
|
||
receipt: {
|
||
kind: 'video',
|
||
promoted: false,
|
||
result: {
|
||
...validation,
|
||
passed: false,
|
||
motionRealism: { enabled: true, passed: false, summary: '运动发生跳变' },
|
||
spatialInteraction: { enabled: true, passed: true, summary: '空间关系一致' },
|
||
physicalStructure: { enabled: false, reason: 'missing_prop_subject' }
|
||
}
|
||
}
|
||
}
|
||
})
|
||
try {
|
||
await expandSections()
|
||
expect(wrapper.text()).toContain('运动真实性:未通过')
|
||
expect(wrapper.text()).toContain('运动发生跳变')
|
||
expect(wrapper.text()).toContain('空间交互:通过')
|
||
expect(wrapper.text()).toContain('物理结构:未执行')
|
||
} finally {
|
||
wrapper.unmount()
|
||
}
|
||
})
|
||
|
||
it('项目不再提供任务数组时,从每条工作流最新 checkpoint 判断运行状态', () => {
|
||
expect(hasRunningWorkflow([])).toBe(false)
|
||
expect(
|
||
hasRunningWorkflow(
|
||
testCheckpointSummaries([record('breakdown', 1, 'running'), record('breakdown', 2, 'completed')])
|
||
)
|
||
).toBe(false)
|
||
expect(
|
||
hasRunningWorkflow(
|
||
testCheckpointSummaries([record('breakdown', 1, 'running'), record('other', 2, 'completed')])
|
||
)
|
||
).toBe(true)
|
||
})
|
||
})
|