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()
@@ -135,6 +135,30 @@ describe('生图预览与版本确认', () => {
expect(restored.recoveryNotice.value).toContain('费用待核对')
expect(generate).toHaveBeenCalledOnce()
})
it('发出生成请求前先持久化标记,未回执时重开不能再次提交', async () => {
const key = 'short-drama:image-request-unknown:form:in-flight'
let finish!: (value: ImageGenerationSubmission) => void
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(
() =>
new Promise(resolve => {
finish = resolve
})
)
const first = setup(generate, undefined, 'form:in-flight').flow
await first.loadPreview()
first.acknowledged.value = true
const request = first.submit()
expect(sessionStorage.getItem(key)).not.toBeNull()
wrapper?.unmount()
const restored = setup(generate, undefined, 'form:in-flight').flow
await restored.loadPreview()
restored.acknowledged.value = true
await restored.submit()
expect(generate).toHaveBeenCalledTimes(1)
finish({ accepted: true })
await request
expect(sessionStorage.getItem(key)).toBeNull()
})
it('关闭再打开相同参数后,旧预览响应不得回填', async () => {
let resolve!: (value: ReturnType<typeof imagePreviewFixture>) => void
const { flow, open } = setup(
@@ -1,5 +1,6 @@
import { validationPreviewResponse } from '../../fixtures/image-preview'
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
import { defineComponent, h } from 'vue'
import { afterEach, describe, expect, it, vi } from 'vitest'
import ImageGalleryDialog from '@/features/subject-images/components/ImageGalleryDialog.vue'
import { getOperation } from '@/features/workflows/operations'
@@ -97,6 +98,65 @@ describe('候选质量与主图门禁', () => {
expect(button('设为主参考图').disabled).toBe(true)
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
})
it.each([504, 409])('审核回执 %s 后锁定同一候选的付费操作,重开图库仍保持锁定', async status => {
const image = imageFixture({ id: 'unknown-review-' + status, isPrimary: false, qualityPassed: true })
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
if (String(url).endsWith('/validate/preview')) return validationPreviewResponse(String(url))
if (init?.method === 'POST') return new Response(JSON.stringify({ message: '审核结果待核对' }), { status })
return Response.json({ data: [image] })
})
vi.stubGlobal('fetch', fetcher)
const props = { projectId: 'quality-flow', form: formFixture(), disabled: false, open: true }
/** 正式父页在项目请求进行中会同步禁用图库写入。 */
const parent = defineComponent({
setup: () => () => h(ImageGalleryDialog, { ...props, disabled: getOperation(props.projectId).pending })
})
wrapper = mount(parent, { attachTo: document.body })
await flushPromises()
button('审核此图片').click()
await flushPromises()
button('确认费用并审核').click()
await flushPromises()
wrapper.unmount()
wrapper = mount(parent, { attachTo: document.body })
await flushPromises()
expect(document.body.textContent).toContain('费用待核对')
expect(button('审核此图片').disabled).toBe(true)
expect(button('审核与修复').disabled).toBe(true)
expect(button('设为主参考图').disabled).toBe(true)
button('刷新图片').click()
await flushPromises()
expect(button('审核此图片').disabled).toBe(true)
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
})
it.each(['刷新图片', '确认费用并审核'])('同一候选来源变化后,%s 重新预检并阻止付费请求', async action => {
let current = true
const image = imageFixture({ id: 'stale-after-open', isPrimary: false, qualityPassed: true })
const fetcher = vi
.fn<typeof fetch>()
.mockImplementation(async url =>
String(url).endsWith('/validate/preview')
? validationPreviewResponse(String(url), current)
: Response.json({ data: [image] })
)
vi.stubGlobal('fetch', fetcher)
wrapper = mount(ImageGalleryDialog, {
attachTo: document.body,
props: { projectId: 'quality-flow', form: formFixture(), disabled: false, open: true }
})
await flushPromises()
expect(button('审核此图片').disabled).toBe(false)
button('审核此图片').click()
await flushPromises()
current = false
button(action).click()
await flushPromises()
expect(document.body.textContent).toContain('本次机位采用的几何已过期')
expect(button('审核此图片').disabled).toBe(true)
expect(button('设为主参考图').disabled).toBe(true)
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
})
it('主图晋升 409 保留原主图,不乐观切换或自动重试', async () => {
const original = imageFixture({ id: 'old' })
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) =>