feat(short-drama-agent-front): 完善视觉资产审核流程
This commit is contained in:
1 parent
dc8bb17a23
commit
b88ad8770f
45 files changed
+2258
-352
No files matched your search
@@ -20,7 +20,8 @@ function setup(
|
||||
generate = vi.fn<() => Promise<ImageGenerationSubmission>>(
|
||||
async (): Promise<ImageGenerationSubmission> => ({ accepted: true })
|
||||
),
|
||||
load = vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(async () => imagePreviewFixture())
|
||||
load = vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(async () => imagePreviewFixture()),
|
||||
target = 'form-1'
|
||||
) {
|
||||
const open = ref(true),
|
||||
prompt = ref('初始描述')
|
||||
@@ -30,7 +31,7 @@ function setup(
|
||||
setup() {
|
||||
flow = useImageGenerationPreview({
|
||||
open,
|
||||
target: () => 'form-1',
|
||||
target: () => target,
|
||||
input: () => ({ prompt: prompt.value }),
|
||||
disabled: () => false,
|
||||
load,
|
||||
@@ -65,7 +66,7 @@ describe('生图预览与版本确认', () => {
|
||||
it('明确的预览过期 409 只重新预览,不自动重复收费请求', async () => {
|
||||
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({
|
||||
accepted: false,
|
||||
cause: new ApiError('过期', 409, undefined, 'IMAGE_PREVIEW_STALE')
|
||||
cause: new ApiError('IMAGE_PREVIEW_STALE: 来源已变化', 409, { code: 'IMAGE_PREVIEW_STALE' })
|
||||
}))
|
||||
const { flow, open, load } = setup(generate)
|
||||
await flow.loadPreview()
|
||||
@@ -93,6 +94,47 @@ describe('生图预览与版本确认', () => {
|
||||
expect(flow.error.value).toContain('活动任务')
|
||||
expect(flow.acknowledged.value).toBe(false)
|
||||
})
|
||||
it.each(['IMAGE_REQUIRED_REFERENCE_MISSING', 'IMAGE_REFERENCE_CAPACITY_EXCEEDED'])(
|
||||
'参考图阻断 %s 时禁止生成',
|
||||
async code => {
|
||||
const { flow, generate } = setup(
|
||||
undefined,
|
||||
vi.fn(async () => {
|
||||
throw new ApiError(code, 409, { code })
|
||||
})
|
||||
)
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(flow.canSubmit.value).toBe(false)
|
||||
expect(generate).not.toHaveBeenCalled()
|
||||
}
|
||||
)
|
||||
it('计费未知后即使重读免费预览也不重复发起同一目标', async () => {
|
||||
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({
|
||||
accepted: false,
|
||||
cause: new ApiError('连接中断', 0)
|
||||
}))
|
||||
const { flow, open, prompt } = setup(generate, undefined, 'form-unknown')
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
open.value = false
|
||||
open.value = true
|
||||
prompt.value = '新参数'
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(flow.canSubmit.value).toBe(false)
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
wrapper?.unmount()
|
||||
const restored = setup(generate, undefined, 'form-unknown').flow
|
||||
await restored.loadPreview()
|
||||
restored.acknowledged.value = true
|
||||
await restored.submit()
|
||||
expect(restored.recoveryNotice.value).toContain('费用待核对')
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
})
|
||||
it('关闭再打开相同参数后,旧预览响应不得回填', async () => {
|
||||
let resolve!: (value: ReturnType<typeof imagePreviewFixture>) => void
|
||||
const { flow, open } = setup(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { validationPreviewResponse } from '../../fixtures/image-preview'
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
@@ -48,7 +49,13 @@ describe('形态图片选择与操作', () => {
|
||||
imageFixture({ id: 'candidate', isPrimary: false, imageUrl: '/storage/candidate.png' }),
|
||||
imageFixture({ id: 'failed', isPrimary: false, status: 'failed', imageUrl: null, error: '生成失败详情' })
|
||||
]
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: rows })))
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async url =>
|
||||
String(url).endsWith('/validate/preview')
|
||||
? validationPreviewResponse(String(url))
|
||||
: new Response(JSON.stringify({ data: rows }))
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
attachTo: document.body,
|
||||
@@ -74,8 +81,8 @@ describe('形态图片选择与操作', () => {
|
||||
await flushPromises()
|
||||
expect(document.querySelector('.asset-image-preview')?.textContent).toContain('本次生成失败')
|
||||
expect(button('设为主参考图').disabled).toBe(true)
|
||||
expect(fetcher).toHaveBeenCalledOnce()
|
||||
expect(fetcher.mock.calls[0]![1]?.method).toBe('GET')
|
||||
expect(fetcher.mock.calls.filter(([url]) => String(url).endsWith('/images'))).toHaveLength(1)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
expect(wrapper.emitted('changed')).toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -253,7 +260,8 @@ describe('形态图片选择与操作', () => {
|
||||
it('图库不自动生图,主图切换经确认后 PUT,失败图片不能设主图', async () => {
|
||||
vi.useFakeTimers()
|
||||
let primary = false
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, init) => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||||
if (String(url).endsWith('/validate/preview')) return validationPreviewResponse(String(url))
|
||||
if (init?.method === 'PUT') {
|
||||
primary = true
|
||||
return new Response(JSON.stringify({ data: imageFixture() }))
|
||||
@@ -261,7 +269,7 @@ describe('形态图片选择与操作', () => {
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: [
|
||||
imageFixture({ isPrimary: primary }),
|
||||
imageFixture({ isPrimary: primary, qualityPassed: true }),
|
||||
imageFixture({
|
||||
id: 'failed',
|
||||
isPrimary: false,
|
||||
@@ -279,15 +287,15 @@ describe('形态图片选择与操作', () => {
|
||||
props: { projectId: 'gallery-test', form: formFixture('gallery-test'), open: true, disabled: false }
|
||||
})
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls).toHaveLength(1)
|
||||
expect(fetcher.mock.calls).toHaveLength(2)
|
||||
await vi.advanceTimersByTimeAsync(30_000)
|
||||
expect(fetcher.mock.calls).toHaveLength(1)
|
||||
expect(fetcher.mock.calls).toHaveLength(2)
|
||||
await expandSections()
|
||||
expect(document.body.textContent).not.toContain('本次实际提示词')
|
||||
expect(document.querySelector('[role="dialog"] script')).toBeNull()
|
||||
button('设为主参考图').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls).toHaveLength(1)
|
||||
expect(fetcher.mock.calls).toHaveLength(2)
|
||||
button('确认费用并设为主图').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe(
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { validationPreviewResponse } from '../../fixtures/image-preview'
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import ImageGalleryDialog from '@/features/subject-images/components/ImageGalleryDialog.vue'
|
||||
@@ -34,25 +35,26 @@ describe('候选质量与主图门禁', () => {
|
||||
qualityPassed: false,
|
||||
qualityIssues: [{ type: 'form_mismatch', severity: 'error', description: '原始数量不一致' }]
|
||||
})
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async (_url, init) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data:
|
||||
init?.method === 'POST'
|
||||
? {
|
||||
subjectId: 'subject-db-1',
|
||||
subjectFormId: 'form-db-1',
|
||||
imageId: 'candidate',
|
||||
passed: false,
|
||||
sourceRequirementsPassed: false,
|
||||
sourceVisualRequirements: [],
|
||||
summary: '需核对数量',
|
||||
issues: []
|
||||
}
|
||||
: [candidate, original]
|
||||
})
|
||||
)
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) =>
|
||||
String(url).endsWith('/validate/preview')
|
||||
? validationPreviewResponse(String(url))
|
||||
: new Response(
|
||||
JSON.stringify({
|
||||
data:
|
||||
init?.method === 'POST'
|
||||
? {
|
||||
subjectId: 'subject-db-1',
|
||||
subjectFormId: 'form-db-1',
|
||||
imageId: 'candidate',
|
||||
passed: false,
|
||||
sourceRequirementsPassed: false,
|
||||
sourceVisualRequirements: [],
|
||||
summary: '需核对数量',
|
||||
issues: []
|
||||
}
|
||||
: [candidate, original]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
@@ -67,7 +69,7 @@ describe('候选质量与主图门禁', () => {
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
button('审核此图片').click()
|
||||
await flushPromises()
|
||||
expect(fetcher).toHaveBeenCalledOnce()
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
button('确认费用并审核').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
|
||||
@@ -75,16 +77,38 @@ describe('候选质量与主图门禁', () => {
|
||||
expect(original.isPrimary).toBe(true)
|
||||
expect(document.body.textContent).toContain('需核对数量')
|
||||
})
|
||||
it('来源过期禁止发起审核与主图确认,保留该候选', async () => {
|
||||
const image = imageFixture({ isPrimary: false, qualityPassed: true })
|
||||
const fetcher = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockImplementation(async url =>
|
||||
String(url).endsWith('/validate/preview')
|
||||
? validationPreviewResponse(String(url), false)
|
||||
: new Response(JSON.stringify({ 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(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) =>
|
||||
init?.method === 'PUT'
|
||||
? new Response(JSON.stringify({ message: '审核证据已过期,请明确重新审核' }), { status: 409 })
|
||||
: new Response(
|
||||
JSON.stringify({
|
||||
data: [imageFixture({ id: 'candidate', isPrimary: false, qualityPassed: true }), original]
|
||||
})
|
||||
)
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) =>
|
||||
String(url).endsWith('/validate/preview')
|
||||
? validationPreviewResponse(String(url))
|
||||
: init?.method === 'PUT'
|
||||
? new Response(JSON.stringify({ message: '审核证据已过期,请明确重新审核' }), { status: 409 })
|
||||
: new Response(
|
||||
JSON.stringify({
|
||||
data: [imageFixture({ id: 'candidate', isPrimary: false, qualityPassed: true }), original]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
@@ -105,26 +129,27 @@ describe('候选质量与主图门禁', () => {
|
||||
})
|
||||
it('质量处理默认预算为零,只有明确确认后发出一次请求', async () => {
|
||||
const image = imageFixture({ isPrimary: false })
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async (_url, init) =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data:
|
||||
init?.method === 'POST'
|
||||
? {
|
||||
subjectFormId: 'form-db-1',
|
||||
initialImageId: image.id,
|
||||
finalImageId: image.id,
|
||||
passed: false,
|
||||
repaired: false,
|
||||
repairAttempts: 0,
|
||||
maxRepairAttempts: 0,
|
||||
primaryChanged: false,
|
||||
attempts: []
|
||||
}
|
||||
: [image]
|
||||
})
|
||||
)
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) =>
|
||||
String(url).endsWith('/validate/preview')
|
||||
? validationPreviewResponse(String(url))
|
||||
: new Response(
|
||||
JSON.stringify({
|
||||
data:
|
||||
init?.method === 'POST'
|
||||
? {
|
||||
subjectFormId: 'form-db-1',
|
||||
initialImageId: image.id,
|
||||
finalImageId: image.id,
|
||||
passed: false,
|
||||
repaired: false,
|
||||
repairAttempts: 0,
|
||||
maxRepairAttempts: 0,
|
||||
primaryChanged: false,
|
||||
attempts: []
|
||||
}
|
||||
: [image]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { NCollapse } from 'naive-ui'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import FormSourceDiagnostics from '@/features/subject-images/components/FormSourceDiagnostics.vue'
|
||||
import { formFixture } from '@/features/subject-images/testing/fixtures'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('道具与场景来源诊断', () => {
|
||||
it.each([
|
||||
['missing', '尚未准备结构规格'],
|
||||
['stale', '结构来源已过期']
|
||||
])('道具 %s 只读取原文和历史,不调用生成', async (status, label) => {
|
||||
const form = formFixture('source-project')
|
||||
form.subject.module = 'prop'
|
||||
const fetcher = vi.fn<typeof fetch>(
|
||||
async () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
subjectFormId: form.id,
|
||||
status,
|
||||
spec: null,
|
||||
sourceEpisodes: [
|
||||
{ episodeId: 'origin', episode: 1, title: '基础形态' },
|
||||
{ episodeId: 'change', episode: 2, title: '拆卸' }
|
||||
],
|
||||
ownershipEvidence: [
|
||||
{
|
||||
name: '搭扣',
|
||||
quantity: 2,
|
||||
episodeId: 'origin',
|
||||
sourceQuote: '工具箱有两个搭扣',
|
||||
relationEpisodeId: 'change',
|
||||
relationQuote: '搭扣从工具箱脱落'
|
||||
}
|
||||
],
|
||||
lastGenerationAttempt: {
|
||||
status: 'failed',
|
||||
sourceCurrent: false,
|
||||
error: '无法核对归属',
|
||||
evidence: { candidates: [{ semanticClass: '工具箱' }] },
|
||||
inputSnapshot: {}
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(FormSourceDiagnostics, { props: { form, projectId: 'source-project' } })
|
||||
try {
|
||||
await flushPromises()
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
wrapper.getComponent(NCollapse).vm.$emit('update:expandedNames', ['source'])
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain(label)
|
||||
expect(wrapper.text()).toContain('数量来源 · 第 1 集')
|
||||
expect(wrapper.text()).toContain('拆装来源 · 第 2 集')
|
||||
expect(wrapper.text()).toContain('准备时的来源已过期')
|
||||
expect(fetcher.mock.calls).toHaveLength(1)
|
||||
expect(fetcher.mock.calls[0]?.[1]?.method).toBe('GET')
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user