feat: 同步动作与首帧编辑能力并统一工作区反馈

接入动作时间轴、密度审计、人工视线目标和后台首帧编辑;独立读取已保存提示词,并在首帧晋升前重新核对持久化质量状态。
统一 NMessage 结果反馈、局部 loading 和业务说明间距,保留真实长任务进度与部分失败语义。
验证:pnpm check(49 个文件、393 项测试)、pnpm build;当前环境无法完成 localhost 浏览器验收及真实后端联调。
This commit is contained in:
GouJ committed 2026-10-12 20:05:03 +08:00
1 parent 83482a70c5
commit 7a60db3ced
76 files changed
+2485 -457

No files matched your search

@@ -0,0 +1,139 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { NCheckbox } from 'naive-ui'
import KeyframeEditDialog from '@/features/production/components/KeyframeEditDialog.vue'
import { keyframeEditApi } from '@/features/production/keyframe-edit-api'
import { generationConfigApi } from '@/features/generation-config/api'
import { spatialApi } from '@/features/storyboard/spatial-api'
import { productionApi } from '@/features/production/api'
import { workflowExecutionApi } from '@/features/workflows/execution-api'
import { getOperation } from '@/features/workflows/operations'
import { keyframeFixture } from '@/features/production/testing/fixtures'
import { imageCatalog, generationProfile } from '../../fixtures/generation'
/** 编辑回归只模拟 API,验证确认、过期预览和费用范围,不调用真实模型。 */
let wrapper: VueWrapper | undefined
let sequence = 0
afterEach(() => {
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
localStorage.clear()
vi.restoreAllMocks()
})
/**
* 通过实际按钮操作弹窗,保留表单的公开事件与禁用守卫。
* @param text 当前按钮文案
* @returns 按钮元素
*/
function button(text: string) {
const element = [...document.querySelectorAll<HTMLButtonElement>('button')].find(
item => item.textContent?.trim() === text
)
if (!element) throw new Error(`找不到按钮:${text}`)
return element
}
/** 创建独立项目避免后台句柄影响其他测试。 */
async function openEditor() {
const projectId = `edit-regression-${sequence++}`
const source = keyframeFixture({ isPrimary: false })
vi.spyOn(generationConfigApi, 'catalog').mockResolvedValue(imageCatalog)
vi.spyOn(generationConfigApi, 'profile').mockResolvedValue(generationProfile(projectId))
vi.spyOn(spatialApi, 'bindings').mockResolvedValue([])
const preview = vi.spyOn(keyframeEditApi, 'preview').mockImplementation(async (shotId, sourceId, input) => ({
shotId,
sourceKeyframeId: sourceId,
provider: 'qwen-image',
model: 'test',
editInstruction: input.editInstruction,
editMode: input.editMode,
sourceImageSlots: 1,
maxInputImages: 4,
selected: [],
omitted: []
}))
const start = vi.spyOn(keyframeEditApi, 'start').mockResolvedValue({
executionId: `exec-${projectId}`,
projectId,
shotId: source.shotId,
sourceKeyframeId: source.id,
status: 'running'
})
vi.spyOn(productionApi, 'listKeyframes').mockResolvedValue([source])
vi.spyOn(workflowExecutionApi, 'get').mockResolvedValue({
id: `exec-${projectId}`,
projectId,
workflowName: 'keyframe-quality',
status: 'completed',
stage: 'editKeyframe',
current: 1,
total: 1,
currentResourceId: source.shotId,
metadata: { action: 'edit-keyframe' },
result: { validationSkipped: true, passed: false, primaryChanged: false },
error: null,
startedAt: null,
completedAt: null,
createdAt: '',
updatedAt: ''
})
wrapper = mount(KeyframeEditDialog, {
attachTo: document.body,
props: { projectId, shotId: source.shotId, source, disabled: false, open: true }
})
await flushPromises()
const textarea = document.querySelector<HTMLTextAreaElement>('textarea')!
textarea.value = '人物上半身自然转向右侧树桩,双眼保持协调'
textarea.dispatchEvent(new Event('input', { bubbles: true }))
await flushPromises()
return { projectId, source, preview, start, textarea }
}
describe('首帧编辑的费用与来源隔离', () => {
it('只预览不启动模型;修改指令会撤销旧预览和确认', async () => {
const { start, textarea } = await openEditor()
button('预览编辑输入').click()
await flushPromises()
expect(start).not.toHaveBeenCalled()
wrapper!.getComponent(NCheckbox).vm.$emit('update:checked', true)
await flushPromises()
expect(button('确认编辑').disabled).toBe(false)
textarea.value = '修改后的要求'
textarea.dispatchEvent(new Event('input', { bubbles: true }))
await flushPromises()
expect(button('确认编辑').disabled).toBe(true)
expect(wrapper!.getComponent(NCheckbox).props('checked')).toBe(false)
expect(start).not.toHaveBeenCalled()
})
it('源图变为主图时阻止以旧候选费用范围提交', async () => {
const { source, start, projectId } = await openEditor()
button('预览编辑输入').click()
await flushPromises()
wrapper!.getComponent(NCheckbox).vm.$emit('update:checked', true)
await flushPromises()
vi.mocked(productionApi.listKeyframes).mockResolvedValue([{ ...source, isPrimary: true }])
button('确认编辑').click()
await flushPromises()
expect(start).not.toHaveBeenCalled()
expect(getOperation(projectId).error).toContain('主首帧状态已变化')
})
it('候选编辑提交可序列化参数,202 句柄落库观察后释放真实终态锁', async () => {
const { source, start, projectId } = await openEditor()
button('预览编辑输入').click()
await flushPromises()
wrapper!.getComponent(NCheckbox).vm.$emit('update:checked', true)
await flushPromises()
button('确认编辑').click()
await flushPromises()
expect(start).toHaveBeenCalledTimes(1)
expect(start.mock.calls[0]?.slice(0, 2)).toEqual([source.shotId, source.id])
expect(start.mock.calls[0]?.[2].editInstruction).toContain('上半身')
expect(localStorage.getItem(`short-drama:workflow-execution:${projectId}:keyframe-quality`)).toBe(
`exec-${projectId}`
)
expect(getOperation(projectId).pending).toBe(false)
expect(wrapper!.emitted('started')?.[0]).toEqual([`exec-${projectId}`])
})
})
@@ -1,3 +1,4 @@
import FeedbackMessage from '@/components/ui/FeedbackMessage.vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, expect, it, vi } from 'vitest'
import ProviderInputInspector from '@/features/production/components/ProviderInputInspector.vue'
@@ -70,6 +71,7 @@ it('模型切换使晚到的旧响应失效,错误归属不发布结果', asyn
fetcher.mockResolvedValue(new Response(JSON.stringify({ data: inputSpec('wrong-shot') })))
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('不匹配')
expect(wrapper.getComponent(FeedbackMessage).props('message')).toContain('不匹配')
expect(wrapper.text()).not.toContain('不匹配')
expect(wrapper.text()).not.toContain('asset-1')
})
+2 -2
View File
@@ -106,7 +106,7 @@ async function openProject(initialPath: string) {
}
describe('剧本完成前的下游访问限制', () => {
it('身份请求加载、成功和失败均使用临时消息,切换主体不遗留横幅', async () => {
it('身份请求不使用全局加载消息,完成和失败使用临时消息且不遗留横幅', async () => {
vi.useFakeTimers()
const id = 'identity-message-test'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
@@ -119,7 +119,7 @@ describe('剧本完成前的下游访问限制', () => {
Object.assign(operation, { pending: true, notice: '' })
await flushPromises()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(document.querySelector('.n-message--loading-type')!.textContent).toContain('AI 生成主体身份,请稍候')
expect(document.querySelector('.n-message--loading-type')).toBeNull()
await router.replace({ query: { subjectId: 'second-subject' } })
Object.assign(operation, {
pending: false,
+107
View File
@@ -0,0 +1,107 @@
import { afterEach, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import MotionPlanPanel from '@/features/storyboard/components/MotionPlanPanel.vue'
import MotionAuditPanel from '@/features/storyboard/components/MotionAuditPanel.vue'
import { motionApi } from '@/features/storyboard/motion-api'
import type { MotionPlanPreview } from '@/features/storyboard/motion.types'
let wrapper: VueWrapper | undefined
afterEach(() => {
wrapper?.unmount()
wrapper = undefined
vi.restoreAllMocks()
})
/**
* 构造已有动作事实,缺失历史审计不得被误报为历史通过。
* @param shotId 正式镜头标识
* @returns 只读动作详情
*/
function plan(shotId: string): MotionPlanPreview {
return {
shotId,
episodeNo: 1,
beatNo: 1,
shotNo: 1,
durationSeconds: 5,
motionPlanAvailable: true,
beats: [
{
startSecond: 0,
endSecond: 5,
action: `${shotId} 缓慢摇头`,
cameraMotion: '保持机位',
physicalContinuity: '握持农具',
subjectRefs: [],
closingState: '手停在腰侧'
}
],
globalMotionConstraints: [],
issues: [],
actionDensityIssues: [
{ code: 'slow_repeated_action', severity: 'warning', message: '当前复核线索', beatIndex: 0 }
],
actionReviewSuggestions: [
{
code: 'slow_repeated_action',
beatIndex: 0,
suggestions: ['保留自然运动节奏'],
requiresManualReview: true
}
],
savedActionDensityIssues: null,
willCallModel: false,
willModifyAssets: false
}
}
it('切镜取消旧请求,迟到动作不覆盖新镜头,缺失历史不显示通过', async () => {
let finish!: (value: MotionPlanPreview) => void
const preview = vi
.spyOn(motionApi, 'preview')
.mockImplementationOnce(
() =>
new Promise(resolve => {
finish = resolve
})
)
.mockImplementation(async shotId => plan(shotId))
wrapper = mount(MotionPlanPanel, { props: { shotId: 'old' } })
await wrapper.setProps({ shotId: 'new' })
await flushPromises()
expect(preview.mock.calls[0]?.[1]?.aborted).toBe(true)
finish(plan('old'))
await flushPromises()
expect(wrapper.text()).toContain('new 缓慢摇头')
expect(wrapper.text()).not.toContain('old 缓慢摇头')
expect(wrapper.text()).toContain('未保存生成时审计记录')
expect(wrapper.text()).toContain('需人工复核')
expect(wrapper.text()).not.toContain('质量未通过')
})
it('项目审计按需读取,时间轴和密度独立计数并用正式 ID 定位', async () => {
const item = {
...plan('saved-shot'),
issues: [{ code: 'timeline_gap', severity: 'warning' as const, message: '未覆盖时间' }]
}
const audit = vi.spyOn(motionApi, 'audit').mockResolvedValue({
projectId: 'project',
shotCount: 1,
auditedCount: 1,
missingMotionPlanCount: 0,
warningCount: 1,
actionDensityWarningCount: 1,
items: [item],
willCallModel: false,
willModifyAssets: false
})
wrapper = mount(MotionAuditPanel, { props: { projectId: 'project' } })
expect(audit).not.toHaveBeenCalled()
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('时间轴预警 1')
expect(wrapper.text()).toContain('动作密度预警 1')
const locate = wrapper.findAll('button').find(button => button.text() === '查看镜头')!
await locate.trigger('click')
expect(wrapper.emitted('locate')?.[0]?.[0]).toMatchObject({ shotId: 'saved-shot', episodeNo: 1 })
})
+16 -7
View File
@@ -1522,7 +1522,7 @@ describe('工作台页面交互', () => {
await image.trigger('click')
await flushPromises()
expect(document.querySelector('.n-image-preview')?.getAttribute('src')).toBe(image.attributes('src'))
expect(fetcher.mock.calls).toHaveLength(1)
expect(fetcher.mock.calls).toHaveLength(2)
expect(fetcher.mock.calls.every(([, init]) => !init?.method || init.method === 'GET')).toBe(true)
})
@@ -1530,6 +1530,15 @@ describe('工作台页面交互', () => {
const shot = designedShot()
const fetcher = vi
.fn<typeof fetch>()
.mockResolvedValueOnce(
jsonResponse({
shotId: shot.shotId,
videoPrompt: null,
negativePrompt: null,
status: 'missing',
updatedAt: ''
})
)
.mockResolvedValueOnce(
new Response(
JSON.stringify({
@@ -1589,7 +1598,7 @@ describe('工作台页面交互', () => {
await flushPromises()
expect(wrapper.get('pre').text()).toContain('form-db')
expect(wrapper.get('pre').text()).toContain('地面积水')
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/generation-spec')
expect(fetcher.mock.calls[2]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/generation-spec')
expect(fetcher.mock.calls.every(([, init]) => init?.method !== 'POST')).toBe(true)
})
@@ -1870,11 +1879,11 @@ describe('工作台页面交互', () => {
attachTo: document.body,
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
})
expect(fetcher).toHaveBeenCalledTimes(1)
expect(fetcher).toHaveBeenCalledTimes(2)
await flushPromises()
expect(fetcher.mock.calls[0]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/references')
expect(fetcher.mock.calls[1]?.[0]).toBe('/api/storyboard-shots/shot-db-1-1/references')
await wrapper.setProps({ shot: { ...designedShot('shot-db-1-2'), visualState: null } })
expect(fetcher.mock.calls[0]?.[1]?.signal?.aborted).toBe(true)
expect(fetcher.mock.calls[1]?.[1]?.signal?.aborted).toBe(true)
finish(
new Response(
'{"data":{"shotId":"shot-db-1-1","references":[],"missing":[{"subjectId":"x","subjectName":"旧镜头人物","reason":"缺图"}]}}'
@@ -1907,7 +1916,7 @@ describe('工作台页面交互', () => {
props: { projectId: fixture.id, shot: designedShot(), disabled: false }
})
expect(fetcher.mock.calls.every(([, init]) => init?.method === 'GET')).toBe(true)
await confirmGeneration('读取/生成提示词')
await confirmGeneration('生成提示词')
const post = fetcher.mock.calls.find(([, init]) => init?.method === 'POST')!
expect(post[0]).toBe('/api/storyboard-shots/shot-db-1-1/video-prompt')
expect(JSON.parse(post[1]!.body as string)).toEqual({ force: false })
@@ -1931,7 +1940,7 @@ describe('工作台页面交互', () => {
props: { projectId: fixture.id, episodeNo: 1, shot: designedShot(), disabled: false }
})
await confirmGeneration('读取/生成提示词')
await confirmGeneration('生成提示词')
expect(getOperation(fixture.id).recovery).toEqual({
target: 'keyframe',