feat(short-drama-agent-front): 完善镜头定位与项目配置

This commit is contained in:
GJ committed 2026-10-08 19:45:26 +08:00
1 parent 470b52e26d
commit 5b134207b8
66 files changed
+2042 -984

No files matched your search

@@ -9,10 +9,53 @@ import { referenceLocation, referenceTargets } from '@/features/production/asset
import StaleKeyframeNotice from '@/features/production/components/StaleKeyframeNotice.vue'
import SubjectImagesPage from '@/features/subject-images/SubjectImagesPage.vue'
import ProductionPage from '@/features/production/ProductionPage.vue'
import ImageGalleryDialog from '@/features/subject-images/components/ImageGalleryDialog.vue'
import type { CreativeProfile, GenerationModelCatalog } from '@/features/generation-config/types'
import { directionsResult, storyboardCheckpoint } from '@/features/storyboard/testing/fixtures'
import type { ProductionIssue } from '@/features/production/types'
import type { ShotReferences } from '@/features/storyboard/types'
/** 使用后端模型目录结构,避免空数组被误当成可用模型。 */
const imageCatalog: GenerationModelCatalog = {
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
images: [
{
type: 'image',
provider: 'qwen-image',
providerLabel: 'Qwen',
model: 'qwen-image-3.0-pro',
modelLabel: 'Qwen Image',
supported: true,
enabled: true,
isDefault: true,
capabilities: {},
generationOptions: [
{
key: 'size',
label: '图片尺寸',
type: 'size',
required: true,
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }]
}
],
defaults: { size: '2048*2048' },
projectConstraints: []
}
],
videos: []
}
/** 模拟当前项目持久化的创作配置。 */
const creativeProfile: CreativeProfile = {
projectId: 'capability-test',
aspectRatio: '1:1',
imageProvider: 'qwen-image',
imageModel: 'qwen-image-3.0-pro',
imageOptions: { size: '2048*2048' },
videoProvider: 'seedance',
videoModel: 'seedance',
videoOptions: {}
}
let wrapper: VueWrapper | undefined
afterEach(() => {
wrapper?.unmount()
@@ -98,29 +141,40 @@ function fixture() {
}
const fetcher = vi.fn<typeof fetch>().mockImplementation(async url => {
const path = String(url)
const data = path.endsWith('/subject-forms')
? [first, second, other]
: path.includes('/keyframes/readiness')
? keyframes
: path.includes('/videos/readiness')
? videos
: path.endsWith('/references')
? references
: []
const data = path.endsWith('/generation-models')
? imageCatalog
: path.endsWith('/creative-profile')
? creativeProfile
: path.endsWith('/subject-forms')
? [first, second, other]
: path.includes('/keyframes/readiness')
? keyframes
: path.includes('/videos/readiness')
? videos
: path.endsWith('/references')
? references
: []
return new Response(JSON.stringify({ data }))
})
vi.stubGlobal('fetch', fetcher)
return { first, second, other, references, issues, keyframes, videos, fetcher }
}
/** 在真实内存路由中验证跨页 URL,不替换 RouterLink 行为。 */
async function gallery(query = '') {
/**
* 在真实内存路由中验证跨页 URL,并在首次请求前设置服务端状态。
* @param query 初始素材定位参数
* @param prepare 挂载前准备当前项目的接口响应
* @returns 当前接口数据与真实内存路由
*/
async function gallery(query = '', prepare?: (data: ReturnType<typeof fixture>) => void) {
const data = fixture()
prepare?.(data)
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/projects/:projectId/subject-images', component: SubjectImagesPage },
{ path: '/projects/:projectId/production', component: { template: '<div />' } }
{ path: '/projects/:projectId/production', component: { template: '<div />' } },
{ path: '/projects/:projectId/storyboard', component: { template: '<div />' } }
]
})
await router.push('/projects/capability-test/subject-images' + query)
@@ -132,14 +186,24 @@ async function gallery(query = '') {
return { ...data, router }
}
/**
* 模拟图片记录中的主图变更完成通知,验证父页重读图库及影响状态。
* @returns 全部资产查询完成
*/
async function assetsChanged() {
wrapper!.findComponent(ImageGalleryDialog).vm.$emit('changed')
await flushPromises()
}
describe('过期首帧到具体素材定位', () => {
it('没有图片的形态卡片标记为方形占位', async () => {
const { first } = await gallery()
first.images = []
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
const { first } = await gallery('', data => {
data.first.images = []
})
const card = wrapper!.findAll('.form-image-card').find(item => item.attributes('data-form-id') === first.id)!
expect(card.get('.asset-image').classes()).toContain('form-image-empty')
expect(card.get('.asset-image').classes()).not.toContain('form-image-has-source')
expect(card.get('.asset-image-empty').text()).toContain('尚未生成主参考图')
expect(card.find('img').exists()).toBe(false)
})
it('网格与瀑布流切换保留卡片、滚动容器和筛选,不发起额外请求', async () => {
@@ -159,7 +223,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')
@@ -182,7 +246,7 @@ describe('过期首帧到具体素材定位', () => {
expect(fetcher).toHaveBeenCalledTimes(requestCount)
})
it('图库与关联检查不定时刷新,手动刷新仍能更新数据', async () => {
it('图库与关联检查不定时刷新,图片记录变更后更新数据', async () => {
vi.useFakeTimers()
const { fetcher } = await gallery('?sourceShotId=shot-target')
const count = fetcher.mock.calls.length
@@ -191,13 +255,12 @@ describe('过期首帧到具体素材定位', () => {
await flushPromises()
expect(fetcher).toHaveBeenCalledTimes(count)
expect(wrapper!.get('.form-image-grid').element).toBe(grid)
const refresh = wrapper!.get('[aria-label="刷新图库"]')
await refresh.trigger('click')
await flushPromises()
await assetsChanged()
expect(fetcher.mock.calls.length).toBeGreaterThan(count)
const refreshed = fetcher.mock.calls.length
await vi.advanceTimersByTimeAsync(30_000)
expect(fetcher).toHaveBeenCalledTimes(refreshed)
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
})
it('切换镜头时筛选、关联说明和图片共用稳定纵向容器,长关联列表单独横向滚动', async () => {
@@ -224,8 +287,7 @@ describe('过期首帧到具体素材定位', () => {
})
: original(url, init)
)
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
await assetsChanged()
wrapper!
.findAllComponents(NSelect)
.find(item => item.attributes('aria-label') === '选择关联镜头')!
@@ -428,8 +490,7 @@ describe('过期首帧到具体素材定位', () => {
it('精简图库没有历史母版字段时,不误报形态过期或破坏定位', async () => {
const { first, router } = await gallery('?subjectFormId=form-other')
first.subject.identity = { id: 'identity-1', isLocked: true, anchorImageId: 'anchor-new' }
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
await assetsChanged()
expect(wrapper!.text()).not.toContain('形态主图需要更新')
expect(router.currentRoute.value.query.subjectFormId).toBe('form-other')
expect(wrapper!.findAll('button').some(item => item.text() === '重新生成过期形态')).toBe(false)
@@ -437,8 +498,7 @@ describe('过期首帧到具体素材定位', () => {
it('仅视频接口报告过期时也显示警告,并明确两种检查不一致', async () => {
const { keyframes } = await gallery('?sourceShotId=shot-target&subjectFormId=form-special')
keyframes.items[0]!.primaryKeyframeStale = false
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
await assetsChanged()
expect(wrapper!.get('[data-keyframe-impact]').text()).toContain('检查结果不一致')
expect(wrapper!.get('.form-image-card').text()).toContain('不要据此重复生图')
})
@@ -446,8 +506,7 @@ describe('过期首帧到具体素材定位', () => {
const { keyframes, videos } = await gallery('?sourceShotId=shot-target&subjectFormId=form-special')
keyframes.items[0]!.primaryKeyframeStale = false
videos.items[0]!.issues = []
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
await assetsChanged()
expect(wrapper!.find('[data-keyframe-impact]').exists()).toBe(false)
expect(wrapper!.text()).toContain('未被标记为过期')
})
@@ -466,8 +525,7 @@ describe('过期首帧到具体素材定位', () => {
? Promise.resolve(new Response('{}', { status: 500 }))
: original(url, init)
)
await wrapper!.get('[aria-label="刷新图库"]').trigger('click')
await flushPromises()
await assetsChanged()
expect(wrapper!.text()).toContain('暂时无法确认有无过期首帧')
expect(wrapper!.findAll('.form-image-card')).toHaveLength(3)
})
@@ -480,11 +538,15 @@ describe('过期首帧到具体素材定位', () => {
const path = String(url)
return new Response(
JSON.stringify({
data: path.includes('/storyboard-directions')
? data
: path.includes('/readiness') || path.endsWith('/videos/status')
? { total: 0, items: [] }
: []
data: path.endsWith('/generation-models')
? imageCatalog
: path.endsWith('/creative-profile')
? creativeProfile
: path.includes('/storyboard-directions')
? data
: path.includes('/readiness') || path.endsWith('/videos/status')
? { total: 0, items: [] }
: []
})
)
})
+27 -27
View File
@@ -1,3 +1,4 @@
import { imageCatalog, generationProfile } from '../../fixtures/generation'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { AssetImage } from '@/components/ui'
@@ -8,22 +9,8 @@ import { coverImage, hasRunningImages, primaryImage, validImageSize } from '@/fe
import { formFixture, imageFixture } from '@/features/subject-images/testing/fixtures'
import { expandSections } from '@/testing/naive'
const imageCatalog = {
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
images: [{
type: 'image' as const, provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro',
modelLabel: 'Qwen Image', supported: true as const, enabled: true, isDefault: true, capabilities: {},
generationOptions: [{ key: 'size', label: '图片尺寸', type: 'size' as const, required: true,
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] }],
defaults: { size: '2048*2048' }, projectConstraints: []
}],
videos: []
}
const creativeProfile = {
projectId: 'gallery-test', aspectRatio: '1:1' as const, imageProvider: 'qwen-image',
imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '2048*2048' },
videoProvider: 'seedance', videoModel: 'seedance', videoOptions: {}
}
/** 当前测试使用真实目录契约构造项目模型配置。 */
const creativeProfile = generationProfile('gallery-test')
let wrapper: VueWrapper | undefined
/** Naive 将弹窗挂载到 body,需要从实际弹窗找到按钮。 */
function button(label: string): HTMLButtonElement {
@@ -81,7 +68,10 @@ describe('形态图片选择与操作', () => {
it.each(['character', 'scene', 'prop'])('按后端最新 %s 模块展示母版继承范围', async module => {
const form = formFixture()
form.subject.module = module
wrapper = mount(GenerateImageDialog, { attachTo: document.body, props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile } })
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
})
await flushPromises()
expect(document.body.textContent).toContain('母版')
expect(document.body.textContent).not.toContain('道具形态生图暂不自动引用')
@@ -149,7 +139,7 @@ describe('形态图片选择与操作', () => {
expect(validImageSize(width, height)).toBe(false)
})
it('生图确认发送正式形态 ID,不覆盖后端模型,默认不替换已有主图', async () => {
it('生图确认发送正式形态 ID 和项目模型参数,默认不替换已有主图', async () => {
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form: formFixture(), disabled: false, catalog: imageCatalog, profile: creativeProfile }
@@ -160,29 +150,39 @@ describe('形态图片选择与操作', () => {
await flushPromises()
button('确认生成图片').click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([['form-db-1', { setPrimary: false }]])
expect(wrapper.emitted('generate')).toEqual([
['form-db-1', { setPrimary: false, 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 } })
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, form, disabled: false, catalog: imageCatalog, profile: creativeProfile }
})
await flushPromises()
const width = document.querySelector<HTMLInputElement>('#image-width')!
width.value = '2048'
width.dispatchEvent(new Event('input', { bubbles: true }))
const prompt = document.querySelector<HTMLTextAreaElement>('#image-prompt')!
prompt.value = '上一形态自定义提示词'
prompt.dispatchEvent(new Event('input', { bubbles: true }))
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
await flushPromises()
expect(button('确认生成图片').disabled).toBe(true)
expect(button('确认生成图片').disabled).toBe(false)
expect(wrapper.emitted('generate')).toBeUndefined()
await wrapper.setProps({ form: { ...form, id: 'form-db-2' } })
await flushPromises()
expect(width.value).toBe('')
expect(prompt.value).toBe('')
expect(document.querySelector('#image-width')).toBeNull()
expect(document.querySelector('#image-height')).toBeNull()
expect(document.querySelector('#confirm-image-cost')!.getAttribute('aria-checked')).toBe('false')
document.querySelector<HTMLInputElement>('#confirm-image-cost')!.click()
await flushPromises()
button('确认生成图片').click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([['form-db-2', { setPrimary: true }]])
expect(wrapper.emitted('generate')).toEqual([
['form-db-2', { setPrimary: true, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
])
})
it('图库不自动生图,主图切换经确认后 PUT,失败图片不能设主图', async () => {
+15 -20
View File
@@ -1,3 +1,4 @@
import { imageCatalog, generationProfile } from '../../fixtures/generation'
import { defineComponent } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
@@ -10,22 +11,8 @@ import { useSubjectImages } from '@/features/subject-images/useSubjectImages'
import FormPromptDialog from '@/features/subject-images/components/FormPromptDialog.vue'
import GenerateImageDialog from '@/features/subject-images/components/GenerateImageDialog.vue'
const imageCatalog = {
defaults: { imageProvider: 'qwen-image', videoProvider: 'seedance' },
images: [{
type: 'image' as const, provider: 'qwen-image', providerLabel: 'Qwen', model: 'qwen-image-3.0-pro',
modelLabel: 'Qwen Image', supported: true as const, enabled: true, isDefault: true, capabilities: {},
generationOptions: [{ key: 'size', label: '图片尺寸', type: 'size' as const, required: true,
options: [{ label: '1:1 · 2048×2048', value: '2048*2048' }] }],
defaults: { size: '2048*2048' }, projectConstraints: []
}],
videos: []
}
const creativeProfile = {
projectId: 'gallery-test', aspectRatio: '1:1' as const, imageProvider: 'qwen-image',
imageModel: 'qwen-image-3.0-pro', imageOptions: { size: '2048*2048' },
videoProvider: 'seedance', videoModel: 'seedance', videoOptions: {}
}
/** 当前测试使用真实目录契约构造项目模型配置。 */
const creativeProfile = generationProfile('gallery-test')
let wrapper: VueWrapper | undefined
const projectId = 'capability-test'
/** 从实际挂载的确认弹窗查找操作按钮。 */
@@ -115,7 +102,7 @@ describe('形态正式提示词与批量配置', () => {
new Response(JSON.stringify({ data: { id: 'form-db-1', subjectId: 'subject-db-1', generationPrompt: '' } }))
)
await service.generatePrompt('form-db-1', false)
expect(getOperation(projectId).error).toContain('未确认正式提示词已保存')
expect(getOperation(projectId).error).toContain('提示词保存结果未确认')
})
it('批量提示词保留部分失败回执,不覆盖图片回执且不传图片上限', async () => {
const { service, posts } = await setup()
@@ -178,7 +165,10 @@ describe('形态正式提示词与批量配置', () => {
})
it('正式提示词确认必须勾选,未确认不发送事件', async () => {
const form = formFixture()
wrapper = mount(FormPromptDialog, { attachTo: document.body, props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile } })
wrapper = mount(FormPromptDialog, {
attachTo: document.body,
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
})
await flushPromises()
find('生成正式提示词').click()
await flushPromises()
@@ -194,7 +184,10 @@ describe('形态正式提示词与批量配置', () => {
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 } })
wrapper = mount(GenerateImageDialog, {
attachTo: document.body,
props: { open: true, disabled: false, form, catalog: imageCatalog, profile: creativeProfile }
})
await flushPromises()
document.querySelector<HTMLElement>('#confirm-image-cost')!.click()
await flushPromises()
@@ -204,6 +197,8 @@ describe('形态正式提示词与批量配置', () => {
expect(submit.disabled).toBe(false)
submit.click()
await flushPromises()
expect(wrapper.emitted('generate')).toEqual([['form-db-1', { setPrimary: false }]])
expect(wrapper.emitted('generate')).toEqual([
['form-db-1', { setPrimary: false, provider: 'qwen-image', generationOptions: { size: '2048*2048' } }]
])
})
})