fix(short-drama-agent-front): 修复图片重复提交与首帧恢复

This commit is contained in:
GJ committed 2026-11-04 15:10:20 +08:00
1 parent b88ad8770f
commit ecb0423153
8 files changed
+508 -85

No files matched your search

@@ -61,6 +61,15 @@ const record = (workflowName: string, day: number, status: 'running' | 'complete
}
})
/**
* 定位候选弹窗内的真实按钮。
* @param label 按钮文本
* @returns 对应的按钮
*/
function recoveryButton(label: string) {
return [...document.querySelectorAll('button')].find(item => item.textContent?.trim() === label)!
}
describe('精简公开资产回归', () => {
it('无内部字段的视频可播放,晋升使用后端权限,会话通过不能授权', async () => {
const projectId = 'public-video-contract'
@@ -156,6 +165,135 @@ describe('精简公开资产回归', () => {
}
})
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('/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()