feat(short-drama-agent-front): 接入有限图片授权与候选修订

This commit is contained in:
GJ committed 2026-11-18 11:52:36 +08:00
1 parent f6edc4eb70
commit b15a6011ce
37 files changed
+3569 -76

No files matched your search

@@ -4,6 +4,7 @@ import { afterEach, describe, expect, it, vi } from 'vitest'
import { ApiError } from '@/lib/http'
import { useImageGenerationPreview, type ImageGenerationSubmission } from '@/features/subject-images/generation-preview'
import { imagePreviewFixture } from '../../fixtures/image-preview'
import { imageAuthorizationsFixture } from '../../fixtures/billing'
/** 仅挂载实际状态逻辑,所有请求均为无费用替身。 */
let wrapper: VueWrapper | undefined
@@ -45,6 +46,93 @@ function setup(
}
describe('生图预览与版本确认', () => {
it('规划来源409清除当前成功状态,保留输入并等待确认,不自动重复生成', async () => {
const { flow, prompt, load, generate } = setup(
vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({
accepted: false,
cause: new ApiError('SCENE_CONTINUITY_REVIEW_STALE: 来源已变化', 409, {
code: 'SCENE_CONTINUITY_REVIEW_STALE'
})
})),
undefined,
'scene-stale-project:shot'
)
prompt.value = '保留这份用户输入'
await flow.loadPreview()
flow.acknowledged.value = true
await flow.submit()
expect(flow.preview.value).toBeNull()
expect(prompt.value).toBe('保留这份用户输入')
expect(flow.canSubmit.value).toBe(false)
expect(flow.staleNotice.value).toContain('衔接规划来源已变化')
expect(generate).toHaveBeenCalledOnce()
expect(load).toHaveBeenCalledOnce()
})
it('停留页面期间批准到期也清除成功预检,不把旧费用准入继续用于生成', async () => {
vi.useFakeTimers()
try {
vi.setSystemTime(new Date('2026-11-18T00:00:00Z'))
const list = imageAuthorizationsFixture(),
open = ref(true),
generate = vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({ accepted: true }))
list.authorizations[0]!.input.expiresAt = new Date(Date.now() + 1000).toISOString()
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>(async () =>
Response.json({
data: {
provider: 'openai-image',
model: 'gpt-image-2.5-flare',
context: {
projectId: 'expiry-project',
scope: 'keyframe',
targetId: 'expiry-shot',
sourceFingerprint: 'c'.repeat(64)
},
planFingerprint: 'b'.repeat(64),
authorization: list
}
})
)
)
let flow!: ReturnType<typeof useImageGenerationPreview<object, ReturnType<typeof imagePreviewFixture>>>
wrapper = mount(
defineComponent({
setup() {
flow = useImageGenerationPreview({
open,
target: () => 'expiry-project:expiry-shot',
input: () => ({}),
disabled: () => false,
chargeContext: () => ({
projectId: 'expiry-project',
scope: 'keyframe',
targetId: 'expiry-shot',
exactPreview: true
}),
load: async () => ({
...imagePreviewFixture(),
provider: 'openai-image',
model: 'gpt-image-2.5-flare'
}),
generate
})
return () => null
}
})
)
await flow.loadPreview()
expect(flow.canSubmit.value).toBe(true)
await vi.advanceTimersByTimeAsync(1001)
expect(flow.preview.value).toBeNull()
expect(flow.canSubmit.value).toBe(false)
await flow.submit()
expect(generate).not.toHaveBeenCalled()
expect(flow.staleNotice.value).toContain('授权已到期')
} finally {
vi.useRealTimers()
}
})
it('预览成功且确认后才携带版本提交,修改描述立即清除旧确认', async () => {
const { flow, prompt, generate } = setup()
flow.acknowledged.value = true