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
@@ -0,0 +1,69 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import BreakdownDurationDiagnostics from '@/features/breakdown/components/BreakdownDurationDiagnostics.vue'
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('时长冲突诊断', () => {
|
||||
it('分开显示正式目标与失败候选预算,诊断只发出 GET', async () => {
|
||||
const plan = {
|
||||
episodeNo: 2,
|
||||
targetDurationSeconds: 45,
|
||||
beats: [{ beatNo: 3, title: '拆卸', estimatedDurationSeconds: 9 }]
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>(
|
||||
async url =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: String(url).endsWith('/duration-budget')
|
||||
? {
|
||||
projectId: 'duration-project',
|
||||
episodes: [
|
||||
{ episodeNo: 2, targetDurationSeconds: 60, shotCount: 0, shotSeconds: null }
|
||||
]
|
||||
}
|
||||
: {
|
||||
projectId: 'duration-project',
|
||||
storyboardPlans: [plan],
|
||||
storyboardEpisodeDurationBudgets: [
|
||||
{
|
||||
episodeNo: 2,
|
||||
minimumRequiredSeconds: 10,
|
||||
deficitSeconds: 1,
|
||||
beatSuggestions: [
|
||||
{ beatNo: 3, budgetSeconds: 9, requiredSeconds: 10, deficitSeconds: 1 }
|
||||
]
|
||||
}
|
||||
],
|
||||
failureDetails: {
|
||||
details: [
|
||||
{
|
||||
kind: 'storyboard-duration-failure',
|
||||
episodeNo: 2,
|
||||
candidate: { episodeNo: 2, episodePlan: plan, beatShots: [] },
|
||||
retryAutomatically: false
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(BreakdownDurationDiagnostics, { props: { projectId: 'duration-project' } })
|
||||
try {
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('正式目标 60 秒')
|
||||
expect(wrapper.text()).toContain('正式镜头 未生成')
|
||||
expect(wrapper.text()).toContain('完整失败候选')
|
||||
await wrapper.get('.n-collapse-item__header-main').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toMatch(/拆解时目标\s+45 秒/)
|
||||
expect(wrapper.text()).toContain('正式目标已变化')
|
||||
expect(wrapper.text()).toMatch(/最低需求 10 秒 · 缺口 1 秒/)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -197,44 +197,64 @@ describe('镜头生产数据契约', () => {
|
||||
expect(fetcher.mock.calls[1]?.[1]?.method).toBe('GET')
|
||||
})
|
||||
|
||||
it('所有首帧生成都先成为候选,并要求费用确认', async () => {
|
||||
/** 弹窗打开时只读取模型目录和项目配置,测试不依赖真实后端。 */
|
||||
it('首帧只提交用户核对过的版本,替换也先保存候选', async () => {
|
||||
const fingerprint = 'a'.repeat(64)
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const path = String(url)
|
||||
if (path === '/api/generation-models') return new Response(JSON.stringify({ data: imageCatalog }))
|
||||
if (path === '/api/projects/project-1/creative-profile')
|
||||
return new Response(JSON.stringify({ data: generationProfile('project-1') }))
|
||||
throw new Error(`首帧弹窗出现未预期请求:${path}`)
|
||||
const shotId = path.match(/storyboard-shots\/([^/]+)/)?.[1]
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
shotId,
|
||||
previewFingerprint: fingerprint,
|
||||
provider: 'qwen-image',
|
||||
model: 'qwen-image-3.0-pro',
|
||||
providerPrompt: '完整首帧画面描述',
|
||||
generationConfig: {},
|
||||
referenceImages: []
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(KeyframeDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, shotId: 'shot-1', shotTitle: '开场', projectId: 'project-1', disabled: false }
|
||||
props: {
|
||||
open: true,
|
||||
shotId: 'shot-1',
|
||||
shotTitle: '开场',
|
||||
projectId: 'project-1',
|
||||
disabled: false,
|
||||
submitGeneration
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(button('确认生成首帧').disabled).toBe(true)
|
||||
document.querySelector<HTMLInputElement>('#confirm-keyframe-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成首帧').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
[{ provider: 'qwen-image', generationOptions: { size: '2048*2048' }, setPrimary: false }]
|
||||
])
|
||||
|
||||
await wrapper.setProps({ open: false })
|
||||
await flushPromises()
|
||||
await wrapper.setProps({ open: true, shotId: 'shot-2', replacePrimary: true })
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('生成替代候选')
|
||||
document.querySelector<HTMLInputElement>('#confirm-keyframe-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成首帧').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')?.at(-1)).toEqual([
|
||||
{ provider: 'qwen-image', generationOptions: { size: '2048*2048' }, setPrimary: false }
|
||||
])
|
||||
expect(fetcher).toHaveBeenCalledTimes(4)
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
for (const shotId of ['shot-1', 'shot-2']) {
|
||||
if (shotId === 'shot-2') {
|
||||
await wrapper.setProps({ open: false })
|
||||
await wrapper.setProps({ open: true, shotId, replacePrimary: true })
|
||||
await flushPromises()
|
||||
}
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
expect(button('确认生成首帧').disabled).toBe(true)
|
||||
document.querySelector<HTMLInputElement>('#confirm-keyframe-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成首帧').click()
|
||||
await flushPromises()
|
||||
}
|
||||
expect(submitGeneration).toHaveBeenCalledTimes(2)
|
||||
expect(submitGeneration).toHaveBeenLastCalledWith({
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' },
|
||||
setPrimary: false,
|
||||
expectedPreviewFingerprint: fingerprint
|
||||
})
|
||||
})
|
||||
|
||||
it('首帧生成前可预览后端最终选图规划和 Prompt', async () => {
|
||||
@@ -277,6 +297,8 @@ describe('镜头生产数据契约', () => {
|
||||
model: 'image-model',
|
||||
generationConfig: {},
|
||||
references: [],
|
||||
previewFingerprint: 'a'.repeat(64),
|
||||
referenceImages: ['/storage/preview.png'],
|
||||
referencePlan: {
|
||||
provider: 'seedream',
|
||||
maxReferenceImages: 4,
|
||||
@@ -307,7 +329,14 @@ describe('镜头生产数据契约', () => {
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(KeyframeDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, shotId: 'shot-1', shotTitle: '开场', projectId: 'project-1', disabled: false }
|
||||
props: {
|
||||
open: true,
|
||||
shotId: 'shot-1',
|
||||
shotTitle: '开场',
|
||||
projectId: 'project-1',
|
||||
disabled: false,
|
||||
submitGeneration: vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
button('预览实际生成输入').click()
|
||||
@@ -318,8 +347,8 @@ describe('镜头生产数据契约', () => {
|
||||
provider: 'seedream',
|
||||
generationOptions: {}
|
||||
})
|
||||
expect(document.body.textContent).toContain('已选 1 / 2 张')
|
||||
expect(document.body.textContent).toContain('省略 1 张')
|
||||
expect(document.body.textContent).toContain('1 张参考图')
|
||||
expect(document.body.textContent).toContain('未进入模型的参考图')
|
||||
expect(document.body.textContent).toContain('最终首帧 Prompt')
|
||||
expect(wrapper.emitted('generate')).toBeUndefined()
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { approvedCharacter, imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
@@ -259,6 +259,31 @@ describe('身份图与母版契约', () => {
|
||||
expect(wrapper.emitted('regenerate')).toEqual([['failed-front']])
|
||||
})
|
||||
|
||||
it('角色交付分项失败时不能以总结果通过开启选角', async () => {
|
||||
const candidate = identityImageFixture({ id: 'candidate', isAnchor: false })
|
||||
const failed = approvedCharacter(candidate.id)
|
||||
failed.characterCheckResults![0] = {
|
||||
check: 'presentation',
|
||||
status: 'failed',
|
||||
evidence: '胸口出现未经授权的文字。'
|
||||
}
|
||||
wrapper = mount(IdentityGallery, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
subjectName: '林夏',
|
||||
module: 'character',
|
||||
identityLocked: false,
|
||||
disabled: false,
|
||||
images: [candidate],
|
||||
validationResult: failed
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(button('确认选角并锁定').disabled).toBe(true)
|
||||
expect(wrapper.text()).toContain('胸口出现未经授权的文字。')
|
||||
expect(wrapper.text()).toContain('跨图身份一致性 · 不适用')
|
||||
expect(wrapper.emitted('anchor')).toBeUndefined()
|
||||
})
|
||||
it('明确确认目标后才提交指定候选,刷新同一母版保持管理弹窗,新母版返回后关闭弹窗', async () => {
|
||||
const anchor = identityImageFixture({ id: 'anchor' })
|
||||
const candidate = identityImageFixture({ id: 'candidate', isAnchor: false })
|
||||
@@ -269,7 +294,8 @@ describe('身份图与母版契约', () => {
|
||||
module: 'character',
|
||||
identityLocked: true,
|
||||
disabled: false,
|
||||
images: [anchor, candidate]
|
||||
images: [anchor, candidate],
|
||||
validationResult: approvedCharacter(candidate.id)
|
||||
}
|
||||
})
|
||||
button('管理候选(1)').click()
|
||||
@@ -464,7 +490,8 @@ describe('身份图与母版契约', () => {
|
||||
module: 'character',
|
||||
identityLocked: false,
|
||||
disabled: false,
|
||||
images: [identityImageFixture({ isAnchor: true })]
|
||||
images: [identityImageFixture({ isAnchor: true })],
|
||||
validationResult: approvedCharacter('identity-image-1')
|
||||
}
|
||||
})
|
||||
button('确认选角并锁定').click()
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -1,3 +1,4 @@
|
||||
import { approvedCharacter } from '../../fixtures/image-preview'
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { preparationFixture } from '../storyboard-preparation/fixtures'
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
@@ -1176,6 +1177,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(getOperation(fixture.id).pending).toBe(true)
|
||||
finish(
|
||||
jsonResponse({
|
||||
...approvedCharacter('identity-image-1'),
|
||||
subjectId: 'subject-db-1',
|
||||
imageId: 'identity-image-1',
|
||||
passed,
|
||||
@@ -1203,6 +1205,8 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, init) => {
|
||||
if (String(url).endsWith('/subject-forms')) return jsonResponse([form])
|
||||
if (String(url).endsWith('/visual-style')) return jsonResponse(styleFixture())
|
||||
if (init?.method === 'POST' && String(url).endsWith('/validate'))
|
||||
return jsonResponse(approvedCharacter('candidate'))
|
||||
if (init?.method === 'PUT') {
|
||||
selected = true
|
||||
return jsonResponse({
|
||||
@@ -1219,10 +1223,13 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
stubFetch(fetcher)
|
||||
await mountAssets('identity')
|
||||
expect(wrapper!.find('.identity-anchor-grid').exists()).toBe(true)
|
||||
expect(button('设为身份母版').disabled).toBe(true)
|
||||
wrapper!.findComponent(IdentityGallery).vm.$emit('validate', 'candidate')
|
||||
await flushPromises()
|
||||
button('设为身份母版').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'PUT')).toBe(false)
|
||||
button('确认切换身份母版').click()
|
||||
button('确认费用并切换母版').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe(
|
||||
'/api/subjects/subject-db-1/identity/images/candidate/stable-anchor'
|
||||
@@ -1338,6 +1345,8 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
]
|
||||
})
|
||||
if (path.endsWith('/identity/images')) return jsonResponse([{ ...candidate, isAnchor: selected }])
|
||||
if (init?.method === 'POST' && path.endsWith('/validate'))
|
||||
return jsonResponse(approvedCharacter(candidate.id))
|
||||
if (init?.method === 'PUT' && path.endsWith('/casting')) {
|
||||
locked = true
|
||||
selected = true
|
||||
@@ -1354,6 +1363,9 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
await mountAssets('identity')
|
||||
expect(wrapper!.text()).toContain('待确认选角')
|
||||
expect(wrapper!.find('.identity-anchor-grid').exists()).toBe(true)
|
||||
expect(button('确认选角并锁定').disabled).toBe(true)
|
||||
wrapper!.findComponent(IdentityGallery).vm.$emit('validate', candidate.id)
|
||||
await flushPromises()
|
||||
button('确认选角并锁定').click()
|
||||
await flushPromises()
|
||||
button('确认演员选择').click()
|
||||
|
||||
+1
@@ -206,6 +206,7 @@ export function commitPreview(overrides: Partial<CandidateCommitCheckPreview> =
|
||||
relationRepairTargets: [],
|
||||
checks: {
|
||||
qualityPolicyMatches: true,
|
||||
durationBudgetCurrent: true,
|
||||
episodeNumbersMatch: true,
|
||||
episodeFingerprintsMatch: true,
|
||||
noActiveExecutions: true,
|
||||
|
||||
Vendored
+49
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
characterCheckLabels,
|
||||
type CharacterCheckResult,
|
||||
type ImageValidationResult
|
||||
} from '@/features/subject-images/validation'
|
||||
import type { SubjectImageGenerationPreview } from '@/features/subject-images/types'
|
||||
|
||||
/**
|
||||
@@ -17,3 +22,47 @@ export function imagePreviewFixture(subjectFormId = 'form-db-1'): SubjectImageGe
|
||||
references: []
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回绑定当前图库图像的只读审核来源。
|
||||
* @param url 正式预检路径
|
||||
* @param sourceCurrent 来源是否仍有效
|
||||
* @returns 对应当前图片的预检响应
|
||||
*/
|
||||
export function validationPreviewResponse(url: string, sourceCurrent = true) {
|
||||
const [, subjectFormId, imageId] = url.match(/subject-forms\/([^/]+)\/images\/([^/]+)\/validate\/preview$/) ?? []
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
subjectFormId,
|
||||
imageId,
|
||||
sourceCurrent,
|
||||
canValidate: sourceCurrent,
|
||||
sourceStaleReason: sourceCurrent ? null : '本次机位采用的几何已过期',
|
||||
providerInputSnapshot: null,
|
||||
providerInputFingerprint: null
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
/**
|
||||
* 模拟已通过明确审核的角色候选。
|
||||
* @param imageId 当前候选
|
||||
* @returns 四项完整的像素审核证据
|
||||
*/
|
||||
export function approvedCharacter(imageId: string): ImageValidationResult {
|
||||
return {
|
||||
subjectId: 'subject-db-1',
|
||||
imageId,
|
||||
passed: true,
|
||||
sourceRequirementsPassed: true,
|
||||
sourceVisualRequirements: [],
|
||||
summary: '已核对图像',
|
||||
issues: [],
|
||||
characterCheckResults: (Object.keys(characterCheckLabels) as CharacterCheckResult['check'][]).map(check => ({
|
||||
check,
|
||||
status: check.endsWith('References') ? 'not_applicable' : 'passed',
|
||||
evidence: '具体观察结果'
|
||||
}))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user