feat(short-drama-agent-front): 新增诊断抽屉并优化项目弹窗

This commit is contained in:
GJ committed 2026-10-16 13:58:01 +08:00
1 parent 97dc784c8b
commit 49ad08a63e
21 files changed
+1479 -363

No files matched your search

+113 -47
View File
@@ -1,5 +1,5 @@
import { computed, ref } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { NSelect } from 'naive-ui'
import { readFileSync } from 'node:fs'
@@ -159,6 +159,62 @@ async function selectTab(label: string) {
await flushPromises()
}
/**
* 提供完整的空诊断记录,用于只验证分镜列表的用例隔离只读摘要请求。
* @returns 后端诊断结果响应
*/
function diagnosisResultsResponse() {
return new Response(
JSON.stringify({
data: {
projectId: 'breakdown-scroll-test',
episodeNo: 1,
counts: { total: 0, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 0 },
shots: []
}
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
}
/**
* 提供完整结构化校验响应,通过证据数量区分当前与迟到结果。
* @param evidenceShotCount 具有有效动作证据的镜头数量
* @returns 后端结构化校验响应
*/
function handDiagnosticsResponse(evidenceShotCount: number) {
return new Response(
JSON.stringify({
data: {
projectId: 'breakdown-scroll-test',
episodeCount: 1,
shotCount: 25,
validSnapshotCount: 25,
evidenceShotCount,
invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 25 - evidenceShotCount,
evidenceCoverage: evidenceShotCount / 25,
assessment: evidenceShotCount ? 'complete_evidence' : 'insufficient_evidence',
warningCount: 0,
diagnostics: [],
willCallModel: false,
willModifyAssets: false
}
}),
{ status: 200, headers: { 'Content-Type': 'application/json' } }
)
}
/**
* 从真实挂载的抽屉读取内容,不把诊断抽屉误当成拆解设置弹窗。
* @returns 当前动作诊断抽屉
*/
function qualityDrawer() {
const panel = document.querySelector<HTMLElement>('.storyboard-diagnosis-drawer')
if (!panel) throw new Error('动作诊断抽屉未打开')
return new DOMWrapper(panel)
}
describe('拆解页内容滚动', () => {
it('拆解设置保留输入标签、单行单位与模块说明,改版后仍校验模块和剧本状态', async () => {
const fetcher = vi.fn<typeof fetch>()
@@ -332,6 +388,10 @@ describe('拆解页内容滚动', () => {
})
it('分镜选择与计数、入口同排,默认显示实际剧集,切换后内容和统计同步', async () => {
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
)
const record = checkpoint()
const result = record.state.breakdownResult!
const first = result.storyboardPlans![0]!
@@ -395,6 +455,11 @@ describe('拆解页内容滚动', () => {
['分镜', '镜头 25'],
['任务明细', '任务错误 50']
])('%s 的末项始终放在独立结果滚动容器内', async (label, lastItem) => {
if (label === '分镜')
vi.stubGlobal(
'fetch',
vi.fn<typeof fetch>().mockImplementation(async () => diagnosisResultsResponse())
)
mountPage()
await selectTab(label)
expect(wrapper!.find('.workspace-scroll').exists()).toBe(false)
@@ -451,64 +516,65 @@ describe('拆解页内容滚动', () => {
expect(drawerPanel().text()).toContain('重试失败抽取')
})
it('手部质量诊断仅在点击后请求,并展示证据不足状态', async () => {
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({
data: {
projectId: 'breakdown-scroll-test', episodeCount: 1,
shotCount: 25, validSnapshotCount: 25,
evidenceShotCount: 0, invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 25, evidenceCoverage: 0,
assessment: 'insufficient_evidence', warningCount: 0,
diagnostics: [], willCallModel: false, willModifyAssets: false
}
}), { status: 200, headers: { 'Content-Type': 'application/json' } }))
it('诊断摘要与抽屉按需读取,展开结构化校验后展示证据不足', async () => {
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
const url = String(input)
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
if (url.endsWith('storyboard-hand-occupancy-diagnostics')) return handDiagnosticsResponse(0)
throw new Error(`未预期的诊断请求:${url}`)
})
vi.stubGlobal('fetch', fetcher)
mountPage()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await flushPromises()
expect(fetcher).not.toHaveBeenCalled()
const panel = drawerPanel()
const action = panel.findAll('button').find(button => button.text() === '查看诊断')
expect(action).toBeDefined()
await action!.trigger('click')
await flushPromises()
await selectTab('分镜')
expect(fetcher).toHaveBeenCalledTimes(1)
expect(String(fetcher.mock.calls[0]?.[0])).toContain('/breakdown/storyboard-hand-occupancy-diagnostics')
expect(panel.text()).toContain('有效证据 0 / 25')
expect(panel.text()).toContain('证据不足')
expect(String(fetcher.mock.calls[0]?.[0])).toContain('diagnosis-results?episodeNo=1')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
const panel = qualityDrawer()
await panel.get('.n-collapse-item__header-main').trigger('click')
await flushPromises()
expect(panel.text()).toContain('有效动作证据 0 / 25 镜')
expect(panel.text()).toContain('证据不足,暂无法判断冲突情况')
expect(
fetcher.mock.calls.filter(([input]) => String(input).endsWith('storyboard-hand-occupancy-diagnostics'))
).toHaveLength(1)
})
it('关闭弹窗后迟到的诊断响应不会污染再次打开的状态', async () => {
let resolveRequest: ((value: Response) => void) | undefined
const fetcher = vi.fn<typeof fetch>().mockImplementation(() => new Promise<Response>(resolve => {
resolveRequest = resolve
}))
it('关闭抽屉后的迟到校验响应不会污染再次打开的状态', async () => {
let resolveFirst: ((value: Response) => void) | undefined
let handRequests = 0
const fetcher = vi.fn<typeof fetch>().mockImplementation(async input => {
const url = String(input)
if (url.includes('storyboard-legacy-action-diagnosis-results')) return diagnosisResultsResponse()
if (url.endsWith('storyboard-hand-occupancy-diagnostics')) {
handRequests++
if (handRequests === 1)
return new Promise<Response>(resolve => {
resolveFirst = resolve
})
return handDiagnosticsResponse(0)
}
throw new Error(`未预期的诊断请求:${url}`)
})
vi.stubGlobal('fetch', fetcher)
mountPage()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await selectTab('分镜')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
const action = drawerPanel().findAll('button').find(button => button.text() === '查看诊断')
expect(action).toBeDefined()
await action!.trigger('click')
expect(fetcher).toHaveBeenCalledTimes(1)
await drawerPanel().get('.n-card-header__close').trigger('click')
expect(handRequests).toBe(1)
await qualityDrawer().get('.n-drawer-header__close').trigger('click')
await flushPromises()
resolveRequest!(new Response(JSON.stringify({
data: {
projectId: 'breakdown-scroll-test', episodeCount: 1,
shotCount: 25, validSnapshotCount: 25,
evidenceShotCount: 25, invalidEvidenceShotCount: 0,
missingEvidenceShotCount: 0, evidenceCoverage: 1,
assessment: 'complete_evidence', warningCount: 0,
diagnostics: [], willCallModel: false, willModifyAssets: false
}
}), { status: 200, headers: { 'Content-Type': 'application/json' } }))
resolveFirst!(handDiagnosticsResponse(25))
await flushPromises()
await wrapper!.get('[data-workspace-tools]').trigger('click')
await wrapper!.get('.storyboard-diagnosis-summary button').trigger('click')
await flushPromises()
expect(drawerPanel().text()).not.toContain('有效证据 25 / 25')
expect(drawerPanel().findAll('button').some(button => button.text() === '查看诊断')).toBe(true)
expect(fetcher).toHaveBeenCalledTimes(1)
const panel = qualityDrawer()
await panel.get('.n-collapse-item__header-main').trigger('click')
await flushPromises()
expect(panel.text()).not.toContain('有效动作证据 25 / 25')
expect(panel.text()).toContain('有效动作证据 0 / 25 镜')
expect(handRequests).toBe(2)
})
it('没有正式剧集时保留可滚动的空状态,不显示拆解设置与结果', () => {
+104
View File
@@ -0,0 +1,104 @@
import { describe, expect, it } from 'vitest'
import { diagnosisInput, scopeDiagnosisShots, summarizeDiagnosis } from '@/features/breakdown/diagnosis'
import type { LegacyActionDiagnosisResults } from '@/features/breakdown/types'
/** 同集不同节拍及跨集镜头,用于验证范围不会混入其它位置的结果。 */
const shots: LegacyActionDiagnosisResults['shots'] = [
{
shotId: 'a',
episodeNo: 1,
beatNo: 1,
shotNo: 1,
title: '镜头一',
diagnosisId: null,
status: 'not_diagnosed',
issues: [],
createdAt: null
},
{
shotId: 'b',
episodeNo: 1,
beatNo: 1,
shotNo: 2,
title: '镜头二',
diagnosisId: 'b',
status: 'conflict_found',
issues: [],
createdAt: null
},
{
shotId: 'c',
episodeNo: 1,
beatNo: 2,
shotNo: 1,
title: '镜头三',
diagnosisId: 'c',
status: 'stale',
issues: [],
createdAt: null
},
{
shotId: 'd',
episodeNo: 2,
beatNo: 1,
shotNo: 1,
title: '镜头四',
diagnosisId: 'd',
status: 'no_conflict_found',
issues: [],
createdAt: null
}
]
describe('动作诊断范围与统计', () => {
it('单镜头和节拍只保留准确位置,不能直接使用整集结果统计', () => {
expect(
scopeDiagnosisShots(shots, { kind: 'shot', episodeNo: 1, beatNo: 1, shotNo: 2 }).map(item => item.shotId)
).toEqual(['b'])
const beat = scopeDiagnosisShots(shots, { kind: 'beat', episodeNo: 1, beatNo: 1 })
expect(beat.map(item => item.shotId)).toEqual(['a', 'b'])
expect(summarizeDiagnosis(beat)).toEqual({
total: 2,
conflict: 1,
clear: 0,
insufficient: 0,
invalid: 0,
stale: 0,
pending: 1
})
})
it('单集不混入其它剧集,全项目保留全部结果', () => {
expect(scopeDiagnosisShots(shots, { kind: 'episode', episodeNo: 2 }).map(item => item.shotId)).toEqual(['d'])
expect(scopeDiagnosisShots(shots, { kind: 'project' })).toHaveLength(4)
})
it('未诊断、证据不足、证据无效和过期都不能计入未发现冲突', () => {
const results = [
shots[0]!,
shots[2]!,
{ ...shots[1]!, status: 'insufficient_evidence' as const },
{ ...shots[1]!, status: 'invalid_evidence' as const }
]
expect(summarizeDiagnosis(results)).toEqual({
total: 4,
conflict: 0,
clear: 0,
insufficient: 1,
invalid: 1,
stale: 1,
pending: 1
})
})
it('全项目启动不遗留集、节拍或镜头条件,单镜头保留全部条件', () => {
expect(diagnosisInput({ kind: 'project' }, 3)).toEqual({ confirmed: true, concurrency: 3 })
expect(diagnosisInput({ kind: 'shot', episodeNo: 2, beatNo: 4, shotNo: 1 }, 2)).toEqual({
confirmed: true,
concurrency: 2,
episodeNo: 2,
beatNo: 4,
shotNo: 1
})
})
})