fix(short-drama-agent-front): 修复代码格式检查问题

This commit is contained in:
GJ committed 2026-10-21 17:04:02 +08:00
1 parent 81d6a85260
commit 48fce3975f
87 files changed
+5714 -1436

No files matched your search

+83 -11
View File
@@ -1,7 +1,12 @@
import { afterEach, describe, expect, it, vi } from 'vitest'
import { effectScope, ref } from 'vue'
import { flushPromises } from '@vue/test-utils'
import { assertCandidateReview, breakdownQuality, normalizeBreakdownState, selectBreakdownSource } from '@/features/breakdown/quality'
import {
assertCandidateReview,
breakdownQuality,
normalizeBreakdownState,
selectBreakdownSource
} from '@/features/breakdown/quality'
import { useBreakdownQuality } from '@/features/breakdown/useBreakdownQuality'
import { breakdownApi } from '@/features/breakdown/api'
import { candidateCheckpoint, candidateReview, candidateState } from '../../fixtures/breakdown-candidate'
@@ -9,7 +14,11 @@ import type { CandidateRevalidation } from '@/features/breakdown/candidate.types
/** 测试后释放自动版本观察,避免跨用例请求。 */
let scope: ReturnType<typeof effectScope> | undefined
afterEach(() => { scope?.stop(); scope = undefined; vi.restoreAllMocks() })
afterEach(() => {
scope?.stop()
scope = undefined
vi.restoreAllMocks()
})
describe('拆解当前质量与来源隔离', () => {
it('新版候选缺少顶层成果时不借用完整的旧嵌套成果充数', () => {
@@ -29,7 +38,9 @@ describe('拆解当前质量与来源隔离', () => {
})
it('最新候选通过时不显示历史五个错误,也不把候选当作正式结果', () => {
const old = Array.from({ length: 5 }, (_, index) => ({ episodeNo: 1, message: `历史错误 ${index}` }))
const record = candidateCheckpoint(candidateState({ breakdownResult: { storyboardShotValidation: { valid: false, issues: old } } }))
const record = candidateCheckpoint(
candidateState({ breakdownResult: { storyboardShotValidation: { valid: false, issues: old } } })
)
const source = selectBreakdownSource([record])
const quality = breakdownQuality(source, candidateReview({ previousIssues: old }))
expect(source.kind).toBe('candidate')
@@ -40,8 +51,42 @@ describe('拆解当前质量与来源隔离', () => {
expect(quality.canRequestCommitPreview).toBe(true)
})
it('真实结构问题与动作阻断分别统计,正常道具检查不会变成错误', () => {
const block = { episodeNo: 1, beatNo: 1, shotNo: 2, status: 'blocked' as const, blockingCodes: ['state_used_as_action_phase'], warningCodes: [], isPendingEpisode: true }
const quality = breakdownQuality(selectBreakdownSource([candidateCheckpoint()]), candidateReview({ currentIssues: [{ episodeNo: 1, beatNo: 1, shotNo: 1, message: '主体引用缺失' }], actionQualityBlocks: [block], pendingQualityEpisodeNos: [1], candidateValidation: { valid: false, issues: ['Storyboard 质量审核未通过', '仍存在待处理的分镜质量问题'] }, propReferenceDiagnostics: [{ episodeNo: 1, beatNo: 1, shotNo: 1, subjectRef: '@PR0001', shotTitle: '', shotDescription: '', beatAllowsSubject: true, shotHasSubject: true, shotHasBinding: true, subjectName: '铜铃', availableForms: [] }] }))
const block = {
episodeNo: 1,
beatNo: 1,
shotNo: 2,
status: 'blocked' as const,
blockingCodes: ['state_used_as_action_phase'],
warningCodes: [],
isPendingEpisode: true
}
const quality = breakdownQuality(
selectBreakdownSource([candidateCheckpoint()]),
candidateReview({
currentIssues: [{ episodeNo: 1, beatNo: 1, shotNo: 1, message: '主体引用缺失' }],
actionQualityBlocks: [block],
pendingQualityEpisodeNos: [1],
candidateValidation: {
valid: false,
issues: ['Storyboard 质量审核未通过', '仍存在待处理的分镜质量问题']
},
propReferenceDiagnostics: [
{
episodeNo: 1,
beatNo: 1,
shotNo: 1,
subjectRef: '@PR0001',
shotTitle: '',
shotDescription: '',
beatAllowsSubject: true,
shotHasSubject: true,
shotHasBinding: true,
subjectName: '铜铃',
availableForms: []
}
]
})
)
expect(quality.structuralIssues).toHaveLength(1)
expect(quality.actionBlocks).toHaveLength(1)
expect(quality.issueCount).toBe(2)
@@ -52,24 +97,43 @@ describe('拆解当前质量与来源隔离', () => {
expect(breakdownQuality(source, candidateReview(), true).structureValid).toBeNull()
expect(breakdownQuality(source, null, false, '读取失败').canRequestCommitPreview).toBe(false)
expect(breakdownQuality(source, candidateReview({ checkpointId: 'old' })).needsRefresh).toBe(true)
expect(() => assertCandidateReview(candidateReview({ checkpointId: 'old' }), 'candidate-project', 'candidate-current')).toThrow('过期')
expect(() =>
assertCandidateReview(candidateReview({ checkpointId: 'old' }), 'candidate-project', 'candidate-current')
).toThrow('过期')
})
it('完整性审核中的 Form 绑定异常计入结构问题,不能标记结构通过', () => {
const quality = breakdownQuality(selectBreakdownSource([candidateCheckpoint()]), candidateReview({ candidateValidation: { valid: false, issues: ['剧集 1 Shot 2 主体 @CH0001 形态绑定无效'] } }))
const quality = breakdownQuality(
selectBreakdownSource([candidateCheckpoint()]),
candidateReview({
candidateValidation: { valid: false, issues: ['剧集 1 Shot 2 主体 @CH0001 形态绑定无效'] }
})
)
expect(quality.structuralCount).toBe(1)
expect(quality.structureValid).toBe(false)
expect(quality.problems[0]?.type).toBe('binding')
expect(quality.canRequestCommitPreview).toBe(false)
})
it('正式提交的持久化标记优先,不继承嵌套旧错误;新候选不覆盖已有正式结果', () => {
const formal = candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true, breakdownResult: { storyboardShotValidation: { valid: false, issues: [{ episodeNo: 1, message: '旧错误' }] } } }), 'formal')
const formal = candidateCheckpoint(
candidateState({
storyboardPersisted: true,
candidateCommitted: true,
breakdownResult: {
storyboardShotValidation: { valid: false, issues: [{ episodeNo: 1, message: '旧错误' }] }
}
}),
'formal'
)
const source = selectBreakdownSource([formal])
expect(breakdownQuality(source, null).source).toBe('formal')
expect(breakdownQuality(source, null).issueCount).toBe(0)
expect(selectBreakdownSource([formal, candidateCheckpoint()]).formal?.checkpointId).toBe('formal')
})
it('只有错误的最新记录可以回看成果,但不能继承候选提交资格或旧错误', () => {
const source = selectBreakdownSource([candidateCheckpoint(), { ...candidateCheckpoint({}, 'failed'), createdAt: '2026-10-17T10:00:00Z' }])
const source = selectBreakdownSource([
candidateCheckpoint(),
{ ...candidateCheckpoint({}, 'failed'), createdAt: '2026-10-17T10:00:00Z' }
])
const quality = breakdownQuality(source, null)
expect(source.kind).toBe('history')
expect(quality.isCandidate).toBe(false)
@@ -81,7 +145,10 @@ describe('拆解当前质量与来源隔离', () => {
const signals: AbortSignal[] = []
const read = vi.spyOn(breakdownApi, 'revalidateCandidate').mockImplementation(async (_id, signal) => {
signals.push(signal!)
if (signals.length === 1) return new Promise(resolve => { resolveOld = resolve })
if (signals.length === 1)
return new Promise(resolve => {
resolveOld = resolve
})
return candidateReview({ checkpointId: 'new' })
})
const records = ref([candidateCheckpoint()])
@@ -114,7 +181,12 @@ describe('拆解当前质量与来源隔离', () => {
it('正式提交后刷新或重新进入,不重新请求候选接口', async () => {
const read = vi.spyOn(breakdownApi, 'revalidateCandidate')
scope = effectScope()
const state = scope.run(() => useBreakdownQuality(ref('candidate-project'), ref([candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true }))])))!
const state = scope.run(() =>
useBreakdownQuality(
ref('candidate-project'),
ref([candidateCheckpoint(candidateState({ storyboardPersisted: true, candidateCommitted: true }))])
)
)!
await state.refresh()
expect(read).not.toHaveBeenCalled()
expect(state.quality.value.committed).toBe(true)