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

@@ -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) =>