import { afterEach, describe, expect, it, vi } from 'vitest' import { flushPromises, mount, DOMWrapper, type VueWrapper } from '@vue/test-utils' import { NSelect } from 'naive-ui' import StoryboardDiagnosis from '@/features/breakdown/components/StoryboardDiagnosis.vue' import { projectContextKey } from '@/features/projects/context' import { testProjectContext } from '@/testing/project-context' import WorkflowExecutionPanel from '@/features/workflows/WorkflowExecutionPanel.vue' import { breakdownApi } from '@/features/breakdown/api' import type { LegacyActionDiagnosisResults } from '@/features/breakdown/types' import type { WorkflowExecution } from '@/features/workflows/execution.types' /** 页面回执同时包含修订完成、局部证据不足和 AI 待复查。 */ const shot: LegacyActionDiagnosisResults['shots'][number] = { shotId: 'shot-1', episodeNo: 1, beatNo: 1, shotNo: 1, title: '捂耳取铃', diagnosisId: 'diag-1', status: 'stale' as const, issues: [], createdAt: null, policyStatus: 'stale', shotStale: true, repairStatus: 'repaired', requiresPostRepairDiagnosis: true, handAudit: { status: 'partial_evidence', evidenceCount: 1, expectedActionCount: 2, coveredActionCount: 1, issueCount: 0, coverage: 0.5 }, bodyMotionFindings: [{ dimension: 'balance', status: 'needs_review', description: '重心需要核对', quote: '单脚站立' }] } let wrapper: VueWrapper | undefined afterEach(() => { wrapper?.unmount(); wrapper = undefined; vi.restoreAllMocks(); vi.unstubAllGlobals(); document.body.innerHTML = '' }) describe('诊断版本及复查展示', () => { it('顶部摘要优先表达正式审核通过,不因没有额外 AI 记录提示分镜尚未诊断', async () => { const current = { ...shot, status: 'not_diagnosed' as const, policyStatus: 'not_diagnosed' as const, shotStale: false, bodyMotionFindings: [] } vi.spyOn(breakdownApi, 'legacyActionDiagnosisResults').mockResolvedValue({ projectId: 'diag-update', episodeNo: 1, counts: { total: 1, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 1 }, shots: [current] }) const context = testProjectContext('diag-update') wrapper = mount(StoryboardDiagnosis, { props: { projectId: 'diag-update', episodeNo: 1, episodeNos: [1] }, global: { provide: { [projectContextKey as symbol]: context } } }) await flushPromises() expect(wrapper.text()).toContain('分镜校验与审核已通过') expect(wrapper.text()).not.toContain('尚未诊断') context.data.value!.stageReadiness.breakdown = { ready: false, reason: '审核已失效' } await flushPromises() expect(wrapper.text()).not.toContain('分镜校验与审核已通过') expect(wrapper.text()).toContain('正式分镜检查待确认') context.data.value!.stageReadiness.projectId = 'other-project' context.data.value!.stageReadiness.breakdown.ready = true await flushPromises() expect(wrapper.text()).not.toContain('分镜校验与审核已通过') }) it('有当前真实问题时摘要仍明确提示处理,不被正式审核状态盖住', async () => { const current = { ...shot, status: 'conflict_found' as const, policyStatus: 'current' as const, shotStale: false, bodyMotionFindings: [] } vi.spyOn(breakdownApi, 'legacyActionDiagnosisResults').mockResolvedValue({ projectId: 'diag-update', episodeNo: 1, counts: { total: 1, conflict: 1, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 0 }, shots: [current] }) wrapper = mount(StoryboardDiagnosis, { props: { projectId: 'diag-update', episodeNo: 1, episodeNos: [1] }, global: { provide: { [projectContextKey as symbol]: testProjectContext('diag-update') } } }) await flushPromises() expect(wrapper.text()).toContain('1 个镜头有实际问题待处理') expect(wrapper.text()).not.toContain('分镜校验与审核已通过') }) it('已修订并审核通过默认不列入需处理,可在可选复查中查看且没有修复按钮', async () => { const current = { ...shot, status: 'not_diagnosed' as const, policyStatus: 'not_diagnosed' as const, shotStale: false, bodyMotionFindings: [], handAudit: undefined, resourceAudit: { status: 'insufficient_evidence' as const, issueCount: 0, evidenceCount: 2, expectedActionCount: 0, coveredActionCount: 0, coverage: null } } vi.spyOn(breakdownApi, 'legacyActionDiagnosisResults').mockResolvedValue({ projectId: 'diag-update', episodeNo: 1, counts: { total: 1, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 0, pending: 1 }, shots: [current] }) vi.spyOn(breakdownApi, 'handOccupancyDiagnostics').mockResolvedValue({ projectId: 'diag-update', shotCount: 1, evidenceShotCount: 0, diagnostics: [] } as never) const start = vi.spyOn(breakdownApi, 'startLegacyActionDiagnosis') wrapper = mount(StoryboardDiagnosis, { attachTo: document.body, props: { projectId: 'diag-update', episodeNo: 1, episodeNos: [1] }, global: { provide: { [projectContextKey as symbol]: testProjectContext('diag-update') } } }) await flushPromises(); await wrapper.get('button').trigger('click'); await flushPromises() const dialog = new DOMWrapper(document.querySelector('[aria-label="动作诊断"]')!) expect(dialog.findAll('.diagnosis-result-item')).toHaveLength(0) expect(dialog.text()).toContain('当前正式分镜已审核通过') expect(dialog.findAll('button').some(item => item.text() === '查看可选 AI 复查')).toBe(false) wrapper!.getComponent(NSelect).vm.$emit('update:value', 'review') await flushPromises() expect(dialog.findAll('.diagnosis-result-item')).toHaveLength(1) expect(dialog.text()).toContain('已修订并审核通过') expect(dialog.text()).not.toContain('动作占用证据不足') expect(dialog.find('[aria-label="查看并修订动作"]').exists()).toBe(false) expect(start).not.toHaveBeenCalled() }) it('修订完成不显示全部通过,展示规则和镜头过期、手部覆盖及全身疑点', async () => { vi.spyOn(breakdownApi, 'legacyActionDiagnosisResults').mockResolvedValue({ projectId: 'diag-update', episodeNo: 1, counts: { total: 1, conflict: 0, clear: 0, insufficient: 0, invalid: 0, stale: 1, pending: 0 }, shots: [shot] }) vi.spyOn(breakdownApi, 'handOccupancyDiagnostics').mockResolvedValue({ projectId: 'diag-update', shotCount: 1, evidenceShotCount: 0, diagnostics: [] } as never) wrapper = mount(StoryboardDiagnosis, { attachTo: document.body, props: { projectId: 'diag-update', episodeNo: 1, episodeNos: [1] } }) await flushPromises(); await wrapper.get('button').trigger('click'); await flushPromises() const dialog = new DOMWrapper(document.querySelector('[aria-label="动作诊断"]')!) wrapper!.getComponent(NSelect).vm.$emit('update:value', 'review'); await flushPromises() expect(dialog.text()).toContain('镜头已修订,可按需进行 AI 复查。') expect(dialog.text()).toContain('镜头内容已变化') expect(dialog.text()).toContain('质量规则已变化') expect(dialog.text()).not.toContain('手部动作证据 1 / 2') expect(dialog.text()).toContain('重心需要核对') expect(dialog.text()).not.toContain('全部通过') }) it('中断诊断显示人工核查与可复用数量,不把未匹配镜头描述为未计费', () => { const execution = { id: 'task', projectId: 'p', workflowName: 'storyboard-legacy-action-diagnosis', status: 'failed', current: 1, total: 3, result: { recoveryRequired: true, retryAutomatically: false, requiresManualReview: true, resumeMode: 'manual', reusableShotCount: 1, manualReviewShotCount: 2, scopedShotCount: 3, qualityPolicyVerified: true }, metadata: null, stage: 'interrupted', currentResourceId: null, error: '诊断中断', startedAt: null, completedAt: null, createdAt: '', updatedAt: '' } satisfies WorkflowExecution wrapper = mount(WorkflowExecutionPanel, { props: { execution, loading: false, error: '' } }) expect(wrapper.text()).toContain('需要人工核查') expect(wrapper.text()).toContain('可复用 1 镜') expect(wrapper.text()).toContain('待核查 2 镜') expect(wrapper.text()).toContain('可能已产生费用') expect(wrapper.text()).not.toContain('未计费') }) })