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('没有正式剧集时保留可滚动的空状态,不显示拆解设置与结果', () => {