feat(short-drama-agent-front): 接入素材预览审核并完善创作流程
This commit is contained in:
1 parent
f8b0fbb8ca
commit
dc8bb17a23
66 files changed
+2864
-632
No files matched your search
@@ -549,6 +549,7 @@ function mountPage(records = [checkpoint()], episodes = 1): ReturnType<typeof us
|
||||
projectId: project.id,
|
||||
script: { ready: true, reason: null },
|
||||
breakdown: { ready: true, reason: null },
|
||||
preparation: { ready: true, reason: null },
|
||||
visualStyle: { ready: true, reason: null },
|
||||
identity: { ready: true, reason: null },
|
||||
subjectAssets: { ready: true, reason: null },
|
||||
@@ -971,7 +972,7 @@ describe('拆解页内容滚动', () => {
|
||||
await flushPromises()
|
||||
const issues = new DOMWrapper(document.querySelector<HTMLElement>('.app-drawer[aria-label="拆解问题"]')!)
|
||||
expect(issues.text()).toContain('待修复问题')
|
||||
for (const label of ['读取修复清单', '重试失败抽取', '补齐缺失镜头', '修复分镜绑定']) {
|
||||
for (const label of ['读取修复清单', '重试失败抽取', '继续整理镜头', '修复分镜绑定']) {
|
||||
const action = issues.findAll('button').find(button => button.text() === label)!
|
||||
expect((action.element as HTMLButtonElement).disabled).toBe(true)
|
||||
}
|
||||
|
||||
@@ -109,6 +109,36 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('故事规划创作进度与恢复', () => {
|
||||
it('只恢复审核时沿用已核对的正文和派生进度,不显示重新生成前序节点', async () => {
|
||||
context = testProjectContext('resume-system-review')
|
||||
context.data.value!.project.status = 'need_review'
|
||||
const saved = {
|
||||
...checkpoint(
|
||||
{
|
||||
storyPlan,
|
||||
episodes: context.project.value!.episodes,
|
||||
characters: { characters: [] },
|
||||
world: {},
|
||||
reviewPassed: false
|
||||
},
|
||||
'reviewDrama'
|
||||
),
|
||||
createdAt: '2026-10-27T00:00:00Z'
|
||||
}
|
||||
context.data.value!.checkpoints = [saved]
|
||||
const page = await open(
|
||||
execution(context.project.value!.id, {
|
||||
stage: 'resumeReview',
|
||||
metadata: { action: 'resume-review', checkpointId: saved.checkpointId }
|
||||
})
|
||||
)
|
||||
expect(page.get('[data-stage="generateEpisode"]').text()).toContain('已完成')
|
||||
expect(page.get('[data-stage="generateCharacter"]').text()).toContain('已完成')
|
||||
expect(page.get('[data-stage="generateWorld"]').text()).toContain('已完成')
|
||||
expect(page.get('[data-stage="reviewDrama"]').text()).toContain('进行中')
|
||||
expect(page.get('.script-task-summary').text()).toContain('系统核查剧本')
|
||||
})
|
||||
|
||||
it('人工审核已完成时,旧任务的待修订回执只作为历史记录展示', async () => {
|
||||
context = testProjectContext('manual-review-current-complete')
|
||||
context.data.value!.checkpoints = [
|
||||
|
||||
@@ -29,9 +29,9 @@ describe('审核记录中的人工问题处理', () => {
|
||||
it.each([
|
||||
{
|
||||
episodes: [],
|
||||
title: '请先核对审核问题',
|
||||
description: '点击“人工确认”对照原文逐项处理',
|
||||
actions: [['人工确认', 'primary']]
|
||||
title: '可由系统继续核查',
|
||||
description: '点击“系统重新核查”检查已保存正文',
|
||||
actions: [['人工确认', 'default']]
|
||||
},
|
||||
{
|
||||
episodes: [2],
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import DramaReviewPanel from '@/features/create-drama/review/DramaReviewPanel.vue'
|
||||
import { dramaReviewApi } from '@/features/create-drama/review/api'
|
||||
import { projectContextKey } from '@/features/projects/context'
|
||||
import { testProjectContext } from '@/testing/project-context'
|
||||
import { confirmationPreview, latestReview, rewritePreview } from './fixtures'
|
||||
|
||||
/** 当前挂载的真实审核面板。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
|
||||
/**
|
||||
* 挂载审核面板并从系统核查入口打开真实确认弹窗。
|
||||
* @param id 当前测试项目
|
||||
* @returns 系统核查弹窗
|
||||
*/
|
||||
async function openSystemReview(id: string) {
|
||||
vi.spyOn(dramaReviewApi, 'latest').mockResolvedValue(latestReview(id))
|
||||
vi.spyOn(dramaReviewApi, 'preview').mockResolvedValue(confirmationPreview(id))
|
||||
vi.spyOn(dramaReviewApi, 'rewritePreview').mockResolvedValue({
|
||||
...rewritePreview(id),
|
||||
ready: false,
|
||||
status: 'needs_review',
|
||||
rewriteCharacters: false,
|
||||
rewriteWorld: false,
|
||||
rewriteEpisodes: false,
|
||||
episodeNumbers: []
|
||||
})
|
||||
wrapper = mount(DramaReviewPanel, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: id },
|
||||
global: { provide: { [projectContextKey as symbol]: testProjectContext(id) } }
|
||||
})
|
||||
await flushPromises()
|
||||
const entry = wrapper.findAll('button').find(button => button.text() === '系统重新核查')
|
||||
expect(entry).toBeDefined()
|
||||
await entry!.trigger('click')
|
||||
await flushPromises()
|
||||
return new DOMWrapper(document.querySelector<HTMLElement>('.app-dialog[aria-label="系统重新核查"]')!)
|
||||
}
|
||||
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
localStorage.clear()
|
||||
})
|
||||
|
||||
describe('系统核查已保存剧本', () => {
|
||||
it('打开或取消仅预检,不自动调用模型', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
projectId: 'system-cancel',
|
||||
checkpointId: 'cp1',
|
||||
episodeCount: 2,
|
||||
ready: true,
|
||||
readOnly: true
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const dialog = await openSystemReview('system-cancel')
|
||||
expect(dialog.text()).toContain('已保存的 2 集')
|
||||
expect(dialog.text()).toContain('不会重写正文')
|
||||
await dialog
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '取消')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.every(([, options]) => !options?.method || options.method === 'GET')).toBe(true)
|
||||
})
|
||||
|
||||
it('确认前版本变化时禁止发起收费审核请求', async () => {
|
||||
let reads = 0
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(
|
||||
async () =>
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
projectId: 'system-stale',
|
||||
checkpointId: ++reads === 1 ? 'cp1' : 'cp2',
|
||||
episodeCount: 2,
|
||||
ready: true,
|
||||
readOnly: true
|
||||
}
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const dialog = await openSystemReview('system-stale')
|
||||
await dialog
|
||||
.findAll('button')
|
||||
.find(button => button.text() === '开始系统核查')!
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
expect(dialog.text()).toContain('已变化')
|
||||
expect(fetcher.mock.calls.every(([, options]) => !options?.method || options.method === 'GET')).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -27,6 +27,7 @@ function readiness(id: string, ready = true): ProjectStageReadiness {
|
||||
projectId: id,
|
||||
script: stage(),
|
||||
breakdown: stage(),
|
||||
preparation: stage(),
|
||||
visualStyle: stage(),
|
||||
identity: stage(),
|
||||
subjectAssets: stage(),
|
||||
@@ -133,6 +134,7 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
const state = readiness(id, false)
|
||||
state.script = { ready: true, reason: null }
|
||||
state.breakdown = { ready: true, reason: null }
|
||||
state.preparation = { ready: true, reason: null }
|
||||
state.storyboard = { ready: true, reason: null }
|
||||
vi.mocked(projectsApi.stageReadiness).mockImplementation(async () => structuredClone(state))
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
|
||||
@@ -149,11 +151,12 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/visual-style"]`).exists()).toBe(true)
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/subject-identity"]`).exists()).toBe(false)
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
|
||||
state.breakdown = { ready: false, reason: '当前分镜审核已失效,请重新核对。' }
|
||||
state.breakdown = { ready: false, reason: '当前分镜来源已变化,请重新核对。' }
|
||||
state.preparation = { ready: false, reason: '当前分镜来源已变化,请重新核对。' }
|
||||
await wrapper!.get('.probe-refresh').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
|
||||
expect(wrapper!.get('.project-access-gate').text()).toContain('当前分镜审核已失效')
|
||||
expect(wrapper!.get('.project-access-gate').text()).toContain('当前分镜来源已变化')
|
||||
})
|
||||
it('身份请求不使用全局加载消息,完成和失败使用临时消息且不遗留横幅', async () => {
|
||||
vi.useFakeTimers()
|
||||
@@ -403,6 +406,38 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('storyboard')
|
||||
})
|
||||
|
||||
it('自动检查已就绪但整体审核待完成时可先进入风格准备,镜头制作仍保持限制', async () => {
|
||||
const id = 'prepare-before-approval'
|
||||
const state = {
|
||||
...readiness(id),
|
||||
preparation: { ready: true, reason: null },
|
||||
breakdown: { ready: false, reason: '整体审核待完成' }
|
||||
}
|
||||
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
const { mounted } = await openProject(`/projects/${id}/visual-style`)
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('visual-style')
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/visual-style"]`).exists()).toBe(true)
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('部分身份未齐备时可以逐项准备形态资料,但不能提前进入镜头设计或生产', async () => {
|
||||
const id = 'partial-asset-preparation'
|
||||
const state = readiness(id)
|
||||
state.identity = { ready: false, reason: '还有角色尚未确认选角' }
|
||||
state.subjectAssets = { ready: false, reason: '素材尚未准备完整' }
|
||||
state.breakdown = { ready: false, reason: '整体审核待完成' }
|
||||
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
|
||||
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
|
||||
vi.spyOn(projectsApi, 'checkpoints').mockResolvedValue([])
|
||||
const { mounted } = await openProject(`/projects/${id}/subject-images`)
|
||||
expect(mounted).toHaveBeenCalledExactlyOnceWith('subject-images')
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/subject-images"]`).exists()).toBe(true)
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/storyboard"]`).exists()).toBe(false)
|
||||
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('剧本完成仍按服务端前置步骤逐步解锁,不能直接进入生产', async () => {
|
||||
const state = readiness('staged', false)
|
||||
state.script = { ready: true, reason: null }
|
||||
@@ -419,6 +454,7 @@ describe('剧本完成前的下游访问限制', () => {
|
||||
await flushPromises()
|
||||
expect(router.currentRoute.value.path).toBe('/projects/staged/breakdown')
|
||||
state.breakdown = { ready: true, reason: null }
|
||||
state.preparation = { ready: true, reason: null }
|
||||
state.subjectAssets = { ready: true, reason: null }
|
||||
state.storyboard = { ready: false, reason: '请先完成分镜设计' }
|
||||
await wrapper!.get('.probe-refresh').trigger('click')
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { NButton, NImage } from 'naive-ui'
|
||||
import { AppDialog } from '@/components/ui'
|
||||
import IdentityImageDialog from '@/features/subject-identity/components/IdentityImageDialog.vue'
|
||||
@@ -19,8 +20,21 @@ import { identityImageFixture } from '@/features/subject-identity/testing/fixtur
|
||||
import { formFixture } from '@/features/subject-images/testing/fixtures'
|
||||
import { selectControl } from '@/testing/naive'
|
||||
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** 每次生成用例只返回无副作用的预览夹具。 */
|
||||
beforeEach(() =>
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const formId = String(url).match(/subject-forms\/([^/]+)/)?.[1] ?? 'form-db-1'
|
||||
return new Response(JSON.stringify({ data: imagePreviewFixture(formId) }))
|
||||
})
|
||||
)
|
||||
)
|
||||
afterEach(() => {
|
||||
submitGeneration.mockClear()
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
@@ -333,6 +347,7 @@ describe('身份图与母版契约', () => {
|
||||
wrapper = mount(IdentityImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
subjectId: 's1',
|
||||
subjectName: '林夏',
|
||||
@@ -352,13 +367,16 @@ describe('身份图与母版契约', () => {
|
||||
expect(button('确认生成身份图').disabled).toBe(true)
|
||||
input('#identity-image-prompt', ' 自定义身份提示词 ')
|
||||
await flushPromises()
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#identity-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成身份图').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
expect(submitGeneration.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
expectedPreviewFingerprint: 'a'.repeat(64),
|
||||
viewType: 'three-quarter',
|
||||
referenceImageId: 'identity-image-1',
|
||||
provider: 'qwen-image',
|
||||
@@ -373,6 +391,7 @@ describe('身份图与母版契约', () => {
|
||||
wrapper = mount(IdentityImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
subjectId: 's1',
|
||||
subjectName: '林夏',
|
||||
@@ -385,6 +404,8 @@ describe('身份图与母版契约', () => {
|
||||
})
|
||||
await flushPromises()
|
||||
input('#identity-reference', 'identity-image-1')
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#identity-image-cost')!.click()
|
||||
await flushPromises()
|
||||
await wrapper.setProps({ images: [] })
|
||||
@@ -398,6 +419,7 @@ describe('身份图与母版契约', () => {
|
||||
wrapper = mount(IdentityImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
subjectId: 's1',
|
||||
subjectName: '林夏',
|
||||
@@ -491,6 +513,7 @@ describe('身份图与母版契约', () => {
|
||||
wrapper = mount(CastingCandidateDialog, {
|
||||
attachTo: document.body,
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
subjectId: 'subject-1',
|
||||
subjectName: '林夏',
|
||||
@@ -529,12 +552,20 @@ describe('身份图与母版契约', () => {
|
||||
})
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('不会复用当前身份母版')
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#casting-candidate-cost')!.click()
|
||||
await flushPromises()
|
||||
button('AI 生成角色候选图').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
[{ provider: 'qwen-image', generationOptions: { size: '1536*2688' } }]
|
||||
expect(submitGeneration.mock.calls).toEqual([
|
||||
[
|
||||
{
|
||||
expectedPreviewFingerprint: 'a'.repeat(64),
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '1536*2688' }
|
||||
}
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
|
||||
@@ -203,7 +203,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
})
|
||||
const card = wrapper!.findAll('.form-image-card').find(item => item.attributes('data-form-id') === first.id)!
|
||||
expect(card.get('.asset-image').classes()).not.toContain('form-image-has-source')
|
||||
expect(card.get('.asset-image-empty').text()).toContain('确认并锁定身份母版后自动复用')
|
||||
expect(card.get('.asset-image-empty').text()).toContain('请先确认并锁定身份母版')
|
||||
expect(card.find('img').exists()).toBe(false)
|
||||
})
|
||||
|
||||
@@ -224,7 +224,7 @@ describe('过期首帧到具体素材定位', () => {
|
||||
.get('.gallery-layout-switch')
|
||||
.findAll('button')
|
||||
.map(button => button.attributes('aria-label'))
|
||||
).toEqual(['网格布局', '瀑布流布局', '批量生图'])
|
||||
).toEqual(['图片准备检查', '网格布局', '瀑布流布局', '批量生图'])
|
||||
await wrapper!.get('[aria-label="网格布局"]').trigger('click')
|
||||
expect(wrapper!.find('.form-image-masonry').exists()).toBe(false)
|
||||
expect(wrapper!.get('[aria-label="网格布局"]').attributes('aria-pressed')).toBe('true')
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import { defineComponent, ref } from 'vue'
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
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'
|
||||
|
||||
/** 仅挂载实际状态逻辑,所有请求均为无费用替身。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** 每个用例释放监听与未完成预览。 */
|
||||
afterEach(() => wrapper?.unmount())
|
||||
|
||||
/**
|
||||
* 建立受控表单,测试确认、版本和异步边界。
|
||||
* @param generate 生成请求的确定性替身
|
||||
* @param load 只读预览的确定性替身
|
||||
* @returns 表单状态及真实共用逻辑
|
||||
*/
|
||||
function setup(
|
||||
generate = vi.fn<() => Promise<ImageGenerationSubmission>>(
|
||||
async (): Promise<ImageGenerationSubmission> => ({ accepted: true })
|
||||
),
|
||||
load = vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(async () => imagePreviewFixture())
|
||||
) {
|
||||
const open = ref(true),
|
||||
prompt = ref('初始描述')
|
||||
let flow!: ReturnType<typeof useImageGenerationPreview<{ prompt: string }, ReturnType<typeof imagePreviewFixture>>>
|
||||
wrapper = mount(
|
||||
defineComponent({
|
||||
setup() {
|
||||
flow = useImageGenerationPreview({
|
||||
open,
|
||||
target: () => 'form-1',
|
||||
input: () => ({ prompt: prompt.value }),
|
||||
disabled: () => false,
|
||||
load,
|
||||
generate
|
||||
})
|
||||
return () => null
|
||||
}
|
||||
})
|
||||
)
|
||||
return { flow, open, prompt, generate, load }
|
||||
}
|
||||
|
||||
describe('生图预览与版本确认', () => {
|
||||
it('预览成功且确认后才携带版本提交,修改描述立即清除旧确认', async () => {
|
||||
const { flow, prompt, generate } = setup()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(generate).not.toHaveBeenCalled()
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
prompt.value = '新描述'
|
||||
expect(flow.preview.value).toBeNull()
|
||||
expect(flow.acknowledged.value).toBe(false)
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(generate).toHaveBeenCalledExactlyOnceWith({
|
||||
prompt: '新描述',
|
||||
expectedPreviewFingerprint: 'a'.repeat(64)
|
||||
})
|
||||
})
|
||||
it('明确的预览过期 409 只重新预览,不自动重复收费请求', async () => {
|
||||
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({
|
||||
accepted: false,
|
||||
cause: new ApiError('过期', 409, undefined, 'IMAGE_PREVIEW_STALE')
|
||||
}))
|
||||
const { flow, open, load } = setup(generate)
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(open.value).toBe(true)
|
||||
expect(load).toHaveBeenCalledTimes(2)
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
expect(flow.acknowledged.value).toBe(false)
|
||||
expect(flow.canSubmit.value).toBe(false)
|
||||
expect(flow.staleNotice.value).toContain('重新确认')
|
||||
})
|
||||
it('普通 409 和未知网络结果均不自动预览或重新提交', async () => {
|
||||
const { flow, load, generate } = setup(
|
||||
vi.fn<() => Promise<ImageGenerationSubmission>>(async () => ({
|
||||
accepted: false,
|
||||
cause: new ApiError('活动任务冲突', 409)
|
||||
}))
|
||||
)
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
await flow.submit()
|
||||
expect(load).toHaveBeenCalledOnce()
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
expect(flow.error.value).toContain('活动任务')
|
||||
expect(flow.acknowledged.value).toBe(false)
|
||||
})
|
||||
it('关闭再打开相同参数后,旧预览响应不得回填', async () => {
|
||||
let resolve!: (value: ReturnType<typeof imagePreviewFixture>) => void
|
||||
const { flow, open } = setup(
|
||||
undefined,
|
||||
vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(
|
||||
() =>
|
||||
new Promise(done => {
|
||||
resolve = done
|
||||
})
|
||||
)
|
||||
)
|
||||
const request = flow.loadPreview()
|
||||
open.value = false
|
||||
open.value = true
|
||||
resolve(imagePreviewFixture())
|
||||
await request
|
||||
expect(flow.preview.value).toBeNull()
|
||||
expect(flow.loading.value).toBe(false)
|
||||
})
|
||||
it('提交期间重复点击不会重复创建任务,参数变化后不关闭新表单', async () => {
|
||||
let resolve!: (value: ImageGenerationSubmission) => void
|
||||
const generate = vi.fn<() => Promise<ImageGenerationSubmission>>(
|
||||
() =>
|
||||
new Promise<ImageGenerationSubmission>(done => {
|
||||
resolve = done
|
||||
})
|
||||
)
|
||||
const { flow, prompt, open } = setup(generate)
|
||||
await flow.loadPreview()
|
||||
flow.acknowledged.value = true
|
||||
const request = flow.submit()
|
||||
await flow.submit()
|
||||
expect(generate).toHaveBeenCalledOnce()
|
||||
prompt.value = '另一个目标的草稿'
|
||||
resolve({ accepted: true })
|
||||
await request
|
||||
expect(open.value).toBe(true)
|
||||
})
|
||||
it('缺失预览版本不能被确认成有效输入', async () => {
|
||||
const { flow } = setup(
|
||||
undefined,
|
||||
vi.fn<() => Promise<ReturnType<typeof imagePreviewFixture>>>(async () => ({
|
||||
...imagePreviewFixture(),
|
||||
previewFingerprint: ''
|
||||
}))
|
||||
)
|
||||
await flow.loadPreview()
|
||||
await flushPromises()
|
||||
expect(flow.preview.value).toBeNull()
|
||||
expect(flow.error.value).toContain('不完整')
|
||||
})
|
||||
})
|
||||
@@ -1,6 +1,7 @@
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { imageCatalog, generationProfile } from '../../fixtures/generation'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { AssetImage } from '@/components/ui'
|
||||
import { getOperation } from '@/features/workflows/operations'
|
||||
import GenerateImageDialog from '@/features/subject-images/components/GenerateImageDialog.vue'
|
||||
@@ -11,6 +12,8 @@ import { expandSections } from '@/testing/naive'
|
||||
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** Naive 将弹窗挂载到 body,需要从实际弹窗找到按钮。 */
|
||||
function button(label: string): HTMLButtonElement {
|
||||
@@ -18,7 +21,18 @@ function button(label: string): HTMLButtonElement {
|
||||
if (!element) throw new Error('找不到按钮:' + label)
|
||||
return element
|
||||
}
|
||||
/** 每次生成用例只返回无副作用的预览夹具。 */
|
||||
beforeEach(() =>
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>().mockImplementation(async url => {
|
||||
const formId = String(url).match(/subject-forms\/([^/]+)/)?.[1] ?? 'form-db-1'
|
||||
return new Response(JSON.stringify({ data: imagePreviewFixture(formId) }))
|
||||
})
|
||||
)
|
||||
)
|
||||
afterEach(() => {
|
||||
submitGeneration.mockClear()
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
@@ -70,10 +84,17 @@ describe('形态图片选择与操作', () => {
|
||||
form.subject.module = module
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
form,
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
profile: creativeProfile
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('母版')
|
||||
expect(document.body.textContent).toContain('质量审核')
|
||||
expect(document.body.textContent).not.toContain('道具形态生图暂不自动引用')
|
||||
})
|
||||
it('按需预览正式形态的实际参考图和 Provider Prompt,不触发生图事件', async () => {
|
||||
@@ -81,6 +102,7 @@ describe('形态图片选择与操作', () => {
|
||||
new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
...imagePreviewFixture(),
|
||||
subjectFormId: 'form-db-1',
|
||||
provider: 'seedream',
|
||||
model: 'image-model',
|
||||
@@ -101,7 +123,14 @@ describe('形态图片选择与操作', () => {
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
form: formFixture(),
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
profile: creativeProfile
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
button('预览实际生成输入').click()
|
||||
@@ -142,30 +171,56 @@ describe('形态图片选择与操作', () => {
|
||||
it('生图确认发送正式形态 ID 和项目模型参数,默认不替换已有主图', async () => {
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
form: formFixture(),
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
profile: creativeProfile
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
expect(button('确认生成图片').disabled).toBe(true)
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
expect(submitGeneration.mock.calls).toEqual([
|
||||
[
|
||||
'form-db-1',
|
||||
{
|
||||
setPrimary: false,
|
||||
expectedPreviewFingerprint: 'a'.repeat(64),
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' }
|
||||
}
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
it('新形态默认设主图并继承目录尺寸,切换形态清空提示词和费用确认', async () => {
|
||||
it('新形态默认保留候选并继承目录尺寸,切换形态清空提示词和确认', async () => {
|
||||
const form = formFixture()
|
||||
form.images = []
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
form,
|
||||
disabled: false,
|
||||
catalog: imageCatalog,
|
||||
profile: creativeProfile
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
const prompt = document.querySelector<HTMLTextAreaElement>('#image-prompt')!
|
||||
prompt.value = '上一形态自定义提示词'
|
||||
prompt.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
expect(button('确认生成图片').disabled).toBe(false)
|
||||
@@ -176,12 +231,22 @@ describe('形态图片选择与操作', () => {
|
||||
expect(document.querySelector('#image-width')).toBeNull()
|
||||
expect(document.querySelector('#image-height')).toBeNull()
|
||||
expect(document.querySelector('#confirm-image-cost')!.getAttribute('aria-checked')).toBe('false')
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-2', { setPrimary: true, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
expect(submitGeneration.mock.calls).toEqual([
|
||||
[
|
||||
'form-db-2',
|
||||
{
|
||||
setPrimary: false,
|
||||
expectedPreviewFingerprint: 'a'.repeat(64),
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' }
|
||||
}
|
||||
]
|
||||
])
|
||||
})
|
||||
|
||||
@@ -223,7 +288,7 @@ describe('形态图片选择与操作', () => {
|
||||
button('设为主参考图').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls).toHaveLength(1)
|
||||
button('确认切换主图').click()
|
||||
button('确认费用并设为主图').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.find(([, init]) => init?.method === 'PUT')?.[0]).toBe(
|
||||
'/api/subject-forms/form-db-1/images/image-db-1/primary'
|
||||
|
||||
@@ -13,6 +13,8 @@ import GenerateImageDialog from '@/features/subject-images/components/GenerateIm
|
||||
|
||||
/** 当前测试使用真实目录契约构造项目模型配置。 */
|
||||
const creativeProfile = generationProfile('gallery-test')
|
||||
/** 生成提交由测试替身接收,绝不调用真实模型。 */
|
||||
const submitGeneration = vi.fn<() => Promise<{ accepted: boolean }>>(async () => ({ accepted: true }))
|
||||
let wrapper: VueWrapper | undefined
|
||||
const projectId = 'capability-test'
|
||||
/** 从实际挂载的确认弹窗查找操作按钮。 */
|
||||
@@ -20,6 +22,7 @@ function find(label: string) {
|
||||
return [...document.querySelectorAll('button')].find(item => item.textContent?.trim() === label)!
|
||||
}
|
||||
afterEach(() => {
|
||||
submitGeneration.mockClear()
|
||||
wrapper?.unmount()
|
||||
wrapper = undefined
|
||||
document.body.innerHTML = ''
|
||||
@@ -180,13 +183,20 @@ describe('形态正式提示词与批量配置', () => {
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([['form-db-1', false]])
|
||||
})
|
||||
it('缺少正式和原始提示词仍可确认生图,由后端补齐而非前端编造', async () => {
|
||||
it('未取得有效预览时不允许直接生图,不代为补齐资料', async () => {
|
||||
const form = formFixture()
|
||||
form.appearancePrompt = null
|
||||
form.generationPrompt = null
|
||||
wrapper = mount(GenerateImageDialog, {
|
||||
attachTo: document.body,
|
||||
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
|
||||
props: {
|
||||
submitGeneration,
|
||||
open: true,
|
||||
disabled: false,
|
||||
form,
|
||||
catalog: imageCatalog,
|
||||
profile: creativeProfile
|
||||
}
|
||||
})
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLElement>('#confirm-image-cost')!.click()
|
||||
@@ -194,11 +204,9 @@ describe('形态正式提示词与批量配置', () => {
|
||||
const submit = [...document.querySelectorAll('button')].find(
|
||||
item => item.textContent?.trim() === '确认生成图片'
|
||||
)!
|
||||
expect(submit.disabled).toBe(false)
|
||||
expect(submit.disabled).toBe(true)
|
||||
submit.click()
|
||||
await flushPromises()
|
||||
expect(wrapper.emitted('generate')).toEqual([
|
||||
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
|
||||
])
|
||||
expect(submitGeneration).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,160 @@
|
||||
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'
|
||||
import { getOperation } from '@/features/workflows/operations'
|
||||
import { formFixture, imageFixture } from '@/features/subject-images/testing/fixtures'
|
||||
import { subjectImagesApi } from '@/features/subject-images/api'
|
||||
|
||||
/** 当前测试挂载的图库。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
/** 清理测试请求、活动锁和弹层。 */
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
document.body.innerHTML = ''
|
||||
vi.unstubAllGlobals()
|
||||
Object.assign(getOperation('quality-flow'), { pending: false, cause: null, error: '', notice: '' })
|
||||
})
|
||||
/**
|
||||
* 根据中文名称选择真实确认按钮。
|
||||
* @param label 完整按钮文本
|
||||
* @returns 原生按钮
|
||||
*/
|
||||
function button(label: string) {
|
||||
const value = [...document.querySelectorAll('button')].find(item => item.textContent?.trim() === label)
|
||||
if (!value) throw new Error(`缺少按钮 ${label}`)
|
||||
return value
|
||||
}
|
||||
|
||||
describe('候选质量与主图门禁', () => {
|
||||
it('completed 但质量失败的候选保留,GET 不切主图,审核不自动采纳', async () => {
|
||||
const original = imageFixture({ id: 'old' })
|
||||
const candidate = imageFixture({
|
||||
id: 'candidate',
|
||||
isPrimary: false,
|
||||
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]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: 'quality-flow', form: formFixture(), disabled: false, open: true }
|
||||
})
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLButtonElement>('[aria-label="查看图片 candidate"]')!.click()
|
||||
await flushPromises()
|
||||
expect(button('设为主参考图').disabled).toBe(true)
|
||||
expect(document.body.textContent).toContain('质量未通过')
|
||||
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
|
||||
button('审核此图片').click()
|
||||
await flushPromises()
|
||||
expect(fetcher).toHaveBeenCalledOnce()
|
||||
button('确认费用并审核').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')).toHaveLength(1)
|
||||
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'PUT')).toBe(false)
|
||||
expect(original.isPrimary).toBe(true)
|
||||
expect(document.body.textContent).toContain('需核对数量')
|
||||
})
|
||||
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]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: 'quality-flow', form: formFixture(), disabled: false, open: true }
|
||||
})
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLButtonElement>('[aria-label="查看图片 candidate"]')!.click()
|
||||
await flushPromises()
|
||||
button('设为主参考图').click()
|
||||
await flushPromises()
|
||||
button('确认费用并设为主图').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.filter(([, init]) => init?.method === 'PUT')).toHaveLength(1)
|
||||
expect(document.body.textContent).toContain('审核证据已过期')
|
||||
expect(wrapper.emitted('changed')).toBeUndefined()
|
||||
expect(original.isPrimary).toBe(true)
|
||||
})
|
||||
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]
|
||||
})
|
||||
)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
wrapper = mount(ImageGalleryDialog, {
|
||||
attachTo: document.body,
|
||||
props: { projectId: 'quality-flow', form: formFixture(), disabled: false, open: true }
|
||||
})
|
||||
await flushPromises()
|
||||
button('审核与修复').click()
|
||||
await flushPromises()
|
||||
expect(fetcher.mock.calls.some(([, init]) => init?.method === 'POST')).toBe(false)
|
||||
expect(document.querySelector<HTMLInputElement>('#quality-repair-budget')?.value).toBe('0')
|
||||
button('确认费用并执行').click()
|
||||
await flushPromises()
|
||||
const calls = fetcher.mock.calls.filter(([, init]) => init?.method === 'POST')
|
||||
expect(calls).toHaveLength(1)
|
||||
expect(JSON.parse(calls[0]![1]!.body as string)).toEqual({
|
||||
imageId: image.id,
|
||||
provider: image.provider,
|
||||
maxRepairAttempts: 0
|
||||
})
|
||||
expect(document.body.textContent).toContain('主图未切换')
|
||||
})
|
||||
it('预览携带尺寸与负面描述,结构准备只调用正式文字入口', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: {} })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const input = { width: 1024, height: 1024, negativePrompt: '不要额外配件', prompt: '原始要求' }
|
||||
await subjectImagesApi.preview('form/1', input)
|
||||
await subjectImagesApi.prepareStructure('form/1')
|
||||
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string)).toEqual(input)
|
||||
expect(fetcher.mock.calls[1]![0]).toBe('/api/subject-forms/form%2F1/prop-structure-spec/generate')
|
||||
expect(fetcher).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,70 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import {
|
||||
imageValidationPassed,
|
||||
sourceRequirementRows,
|
||||
type ImageValidationResult
|
||||
} from '@/features/subject-images/validation'
|
||||
|
||||
/**
|
||||
* 原始定义与实际计数使用不同题材的确定性样例。
|
||||
* @returns 当前主体审核记录
|
||||
*/
|
||||
function result(): ImageValidationResult {
|
||||
return {
|
||||
subjectId: 'subject',
|
||||
imageId: 'image',
|
||||
passed: true,
|
||||
summary: '审核结束',
|
||||
issues: [],
|
||||
sourceRequirementsPassed: true,
|
||||
sourceVisualRequirements: [
|
||||
{
|
||||
id: 'requirement',
|
||||
subjectId: 'subject',
|
||||
subjectName: '控制台',
|
||||
sourceQuote: '控制台上有三个圆形按键',
|
||||
quantities: [{ id: 'quantity', sourcePhrase: '三个圆形按键', expectedCount: 3 }]
|
||||
}
|
||||
],
|
||||
sourceVisualRequirementResults: [
|
||||
{
|
||||
requirementId: 'requirement',
|
||||
status: 'passed',
|
||||
evidence: '图中可辨认三个按键',
|
||||
quantities: [{ quantityId: 'quantity', observedCount: 3 }]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
describe('原始定义与数量审核', () => {
|
||||
it('只有原文、唯一审核结果与数量全部一致才显示通过', () => {
|
||||
expect(imageValidationPassed(result())).toBe(true)
|
||||
expect(sourceRequirementRows(result())[0]).toMatchObject({
|
||||
sourceQuote: '控制台上有三个圆形按键',
|
||||
label: '通过'
|
||||
})
|
||||
})
|
||||
it.each(['missing', 'duplicate', 'unobservable', 'count', 'missing_quantity', 'duplicate_quantity'] as const)(
|
||||
'%s 证据不完整时不信任顶层 passed',
|
||||
kind => {
|
||||
const value = result()
|
||||
const item = value.sourceVisualRequirementResults![0]!
|
||||
if (kind === 'missing') value.sourceVisualRequirementResults = []
|
||||
if (kind === 'duplicate') value.sourceVisualRequirementResults!.push({ ...item })
|
||||
if (kind === 'unobservable') item.status = 'unobservable'
|
||||
if (kind === 'count') item.quantities![0]!.observedCount = 2
|
||||
if (kind === 'missing_quantity') item.quantities = []
|
||||
if (kind === 'duplicate_quantity') item.quantities!.push({ ...item.quantities![0]! })
|
||||
expect(imageValidationPassed(value)).toBe(false)
|
||||
}
|
||||
)
|
||||
it('无原始数量要求时不编造数量;旧审核缺少证据不标通过', () => {
|
||||
const value = result()
|
||||
value.sourceVisualRequirements = []
|
||||
value.sourceVisualRequirementResults = []
|
||||
expect(imageValidationPassed(value)).toBe(true)
|
||||
delete value.sourceRequirementsPassed
|
||||
expect(imageValidationPassed(value)).toBe(false)
|
||||
})
|
||||
})
|
||||
@@ -32,6 +32,37 @@ afterEach(() => {
|
||||
})
|
||||
|
||||
describe('WorkflowExecution 前端契约', () => {
|
||||
it.each(['failed', 'completed'] as const)('派生任务 %s 保留部分结果,不用绿色表示全部完成', status => {
|
||||
const wrapper = mount(WorkflowExecutionPanel, {
|
||||
props: {
|
||||
loading: false,
|
||||
error: '',
|
||||
execution: execution({
|
||||
workflowName: 'storyboard-visual-state',
|
||||
status,
|
||||
current: 2,
|
||||
total: 2,
|
||||
result: {
|
||||
episodeCount: 2,
|
||||
completedEpisodes: 1,
|
||||
skippedEpisodes: 0,
|
||||
failedEpisodes: 1,
|
||||
manualReviewRequired: true,
|
||||
episodes: [
|
||||
{ episodeNo: 1, status: 'completed' },
|
||||
{ episodeNo: 2, status: 'failed', error: '来源发生变化' }
|
||||
]
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
expect(wrapper.text()).toContain('已保存 1 集')
|
||||
expect(wrapper.text()).toContain('第 2 集 · 失败')
|
||||
expect(wrapper.text()).toContain('来源发生变化')
|
||||
expect(wrapper.findAllComponents(NTag).some(tag => tag.props('type') === 'success')).toBe(false)
|
||||
expect(wrapper.findAllComponents(ContextNotice).some(notice => notice.props('type') === 'success')).toBe(false)
|
||||
wrapper.unmount()
|
||||
})
|
||||
it.each([
|
||||
{ projectStatus: 'need_review', type: 'warning', role: 'alert' },
|
||||
{ projectStatus: 'completed', type: 'success', role: undefined },
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { imagePreviewFixture } from '../../fixtures/image-preview'
|
||||
import { preparationFixture } from '../storyboard-preparation/fixtures'
|
||||
import { generationProfile, imageCatalog } from '../../fixtures/generation'
|
||||
import { routerLinkStubs } from '../../fixtures/router'
|
||||
@@ -228,6 +229,7 @@ function context(): ReturnType<typeof useProjectData> {
|
||||
projectId: fixture.id,
|
||||
script: { ready: true, reason: null },
|
||||
breakdown: { ready: true, reason: null },
|
||||
preparation: { ready: true, reason: null },
|
||||
visualStyle: { ready: true, reason: null },
|
||||
identity: { ready: true, reason: null },
|
||||
subjectAssets: { ready: true, reason: null },
|
||||
@@ -452,8 +454,8 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(openSettings).toHaveBeenCalledExactlyOnceWith('generation')
|
||||
}
|
||||
)
|
||||
it('当前主体已确认但其它角色未完成时,隐藏形态入口;保存后按新阶段状态开放', async () => {
|
||||
/** 当前主体已锁定,其它角色仍未确认,用真实项目准入规则约束页面入口。 */
|
||||
it('其它角色未完成不阻断当前主体形态准备,刷新后来源失效仍锁定入口', async () => {
|
||||
/** 已锁定主体可先准备自身素材;整体身份不齐不代替正式来源门禁。 */
|
||||
const saved = identityFixture({ isLocked: true })
|
||||
vi.spyOn(subjectIdentityApi, 'get').mockResolvedValue(saved)
|
||||
vi.spyOn(subjectIdentityApi, 'save').mockImplementation(async (_id, input) => ({ ...saved, ...input }))
|
||||
@@ -478,21 +480,21 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
const provided = await mountAssets('identity')
|
||||
provided.data.value!.stageReadiness.identity = { ready: false, reason: '还有角色身份需要确认' }
|
||||
await flushPromises()
|
||||
expect(wrapper!.get('.identity-next-action').text()).toContain('还有角色身份需要确认')
|
||||
expect(wrapper!.get('.identity-next-action').find('button').exists()).toBe(false)
|
||||
expect(wrapper!.get('.identity-subject-forms').text()).not.toContain('查看此主体形态图片')
|
||||
expect(wrapper!.find('a[href*="/subject-images"]').exists()).toBe(false)
|
||||
expect(wrapper!.get('.identity-next-action').text()).toContain('可以继续生成此主体的形态图片')
|
||||
expect(button('查看形态图片').disabled).toBe(false)
|
||||
expect(wrapper!.get('.identity-subject-forms').text()).toContain('查看此主体形态图片')
|
||||
expect(wrapper!.find('a[href*="/subject-images"]').exists()).toBe(true)
|
||||
vi.mocked(provided.refreshStageReadiness).mockImplementation(async () => {
|
||||
provided.data.value!.stageReadiness.identity = { ready: true, reason: null }
|
||||
provided.data.value!.stageReadiness.preparation = { ready: false, reason: '正式分镜来源已变化' }
|
||||
})
|
||||
await wrapper!.get('#identity-description').setValue('保存后仍保留已确认母版')
|
||||
button('保存主体身份').click()
|
||||
await flushPromises()
|
||||
expect(provided.refreshStageReadiness).toHaveBeenCalledOnce()
|
||||
expect(button('查看形态图片').disabled).toBe(false)
|
||||
expect(wrapper!.get('.identity-detail a[href*="/subject-images"]').attributes('href')).toContain(
|
||||
'subjectRef=@CH0001'
|
||||
)
|
||||
expect(wrapper!.get('.identity-next-action').text()).toContain('正式分镜来源已变化')
|
||||
expect(wrapper!.get('.identity-next-action').find('button').exists()).toBe(false)
|
||||
expect(wrapper!.find('.identity-detail a[href*="/subject-images"]').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('生成进度只在图库显示,失败详情按需查看,切换后不串主体状态', async () => {
|
||||
@@ -690,7 +692,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
button('重试读取').click()
|
||||
await flushPromises()
|
||||
expect(wrapper!.find('#style-prompt').exists()).toBe(true)
|
||||
expect(wrapper!.get('.visual-style-rules').text()).toContain('中国人物选角基线')
|
||||
expect(wrapper!.get('.visual-style-rules').text()).toContain('未明确时保持地域与族裔中性')
|
||||
expect(wrapper!.find('.n-collapse').exists()).toBe(false)
|
||||
expect(wrapper!.findAll('.style-category-fields textarea')).toHaveLength(3)
|
||||
})
|
||||
@@ -973,7 +975,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
await mountAssets('style')
|
||||
expect(wrapper!.text()).toContain('尚未创建')
|
||||
await expandSections()
|
||||
expect(wrapper!.text()).toContain('默认采用中国人物选角基线')
|
||||
expect(wrapper!.text()).toContain('未明确时保持地域与族裔中性')
|
||||
expect(wrapper!.text()).toContain('人物风格与选角背景')
|
||||
await wrapper!.get('#style-constraints').setValue('真人写实')
|
||||
await wrapper!.get('#style-lock').trigger('click')
|
||||
@@ -1149,7 +1151,7 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
})
|
||||
|
||||
it.each([true, false])(
|
||||
'身份图片校验按真实 passed=%s 反馈,等待时显示目标按钮加载,结果不驻留页面',
|
||||
'身份图片校验按真实 passed=%s 反馈,等待时显示目标按钮加载,结果按图片展示',
|
||||
async passed => {
|
||||
/** 延迟校验回执以覆盖请求期间的真实按钮状态。 */
|
||||
let finish!: (response: Response) => void
|
||||
@@ -1177,6 +1179,8 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
subjectId: 'subject-db-1',
|
||||
imageId: 'identity-image-1',
|
||||
passed,
|
||||
sourceRequirementsPassed: true,
|
||||
sourceVisualRequirements: [],
|
||||
summary: '本次视觉检查结果',
|
||||
issues: []
|
||||
})
|
||||
@@ -1185,10 +1189,10 @@ describe('视觉风格与主体身份工作区', () => {
|
||||
expect(getOperation(fixture.id)).toMatchObject({
|
||||
pending: false,
|
||||
noticeType: passed ? 'success' : 'warning',
|
||||
notice: `林知夏 的身份图片校验${passed ? '通过' : '未通过'}:本次视觉检查结果`
|
||||
notice: `林知夏 的身份图片校验${passed ? '通过' : '未通过或待复核'}:本次视觉检查结果`
|
||||
})
|
||||
expect(gallery.props('pendingOperation')).toBeNull()
|
||||
expect(wrapper!.text()).not.toContain('本次视觉检查结果')
|
||||
expect(wrapper!.text()).toContain('本次视觉检查结果')
|
||||
}
|
||||
)
|
||||
|
||||
@@ -1531,6 +1535,7 @@ describe('工作台页面交互', () => {
|
||||
it('形态单图确认后发送正式 ID 并刷新候选图,不会调用 production/start', async () => {
|
||||
const form = formFixture()
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, init) => {
|
||||
if (String(_url).endsWith('/preview')) return jsonResponse(imagePreviewFixture())
|
||||
if (init?.method === 'POST') {
|
||||
const candidate = imageFixture({
|
||||
id: 'new-candidate',
|
||||
@@ -1547,14 +1552,19 @@ describe('工作台页面交互', () => {
|
||||
await mountSubjectImages()
|
||||
button('再生成一张').click()
|
||||
await flushPromises()
|
||||
button('预览实际生成输入').click()
|
||||
await flushPromises()
|
||||
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
|
||||
await flushPromises()
|
||||
button('确认生成图片').click()
|
||||
await flushPromises()
|
||||
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
|
||||
const post = fetcher.mock.calls.find(
|
||||
([url, init]) => init?.method === 'POST' && String(url).endsWith('/images')
|
||||
)!
|
||||
expect(post[0]).toBe('/api/subject-forms/form-db-1/images')
|
||||
expect(JSON.parse(post[1]!.body as string)).toEqual({
|
||||
setPrimary: false,
|
||||
expectedPreviewFingerprint: 'a'.repeat(64),
|
||||
provider: 'qwen-image',
|
||||
generationOptions: { size: '2048*2048' }
|
||||
})
|
||||
@@ -1619,7 +1629,7 @@ describe('工作台页面交互', () => {
|
||||
await flushPromises()
|
||||
expect(document.body.textContent).toContain('数据库异常')
|
||||
expect(wrapper!.find('.form-image-card img').exists()).toBe(true)
|
||||
await new DOMWrapper(button('刷新图片').closest('.app-dialog')!).get('.n-card-header__close').trigger('click')
|
||||
await new DOMWrapper(button('刷新图片').closest('.app-drawer')!).get('.n-drawer-header__close').trigger('click')
|
||||
await flushPromises()
|
||||
expect(button('补齐项目主参考图').disabled).toBe(true)
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user