140 lines
6.9 KiB
TypeScript
140 lines
6.9 KiB
TypeScript
import { describe, expect, it, vi, afterEach } from 'vitest'
|
|
import { candidateCommitIssue, candidatePreviewReady } from '@/features/breakdown/candidate'
|
|
import { commitPreview } from '../../fixtures/breakdown-candidate'
|
|
import { breakdownApi } from '@/features/breakdown/api'
|
|
import type { BreakdownState } from '@/features/breakdown/types'
|
|
|
|
/** 构造已完成审核但尚未入库的候选快照。 */
|
|
function readyCandidate(): BreakdownState {
|
|
return {
|
|
candidateOnly: true,
|
|
storyboardPersisted: false,
|
|
expectedEpisodeFingerprints: { 1: 'fingerprint' },
|
|
runConfig: { groupSize: 3, modules: ['character'], episodeGroups: [], sourceEpisodes: [{ episodeNo: 1 }] },
|
|
subjectCandidates: [
|
|
{
|
|
profileId: 'person',
|
|
name: '人物',
|
|
ref: '@人物',
|
|
description: '',
|
|
module: 'character',
|
|
appearance_prompt: ''
|
|
}
|
|
],
|
|
subjectForms: [],
|
|
storyboardEpisodeShots: [
|
|
{
|
|
episodeNo: 1,
|
|
episodePlan: { episodeNo: 1 } as never,
|
|
beatShots: [
|
|
{
|
|
beatNo: 1,
|
|
shots: [
|
|
{
|
|
shotNo: 1,
|
|
title: '镜头',
|
|
description: '',
|
|
visualFocus: '',
|
|
subjectRefs: [],
|
|
durationSeconds: 5
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
],
|
|
storyboardShotValidation: { valid: true, issues: [] },
|
|
storyboardPendingQualityEpisodeNos: []
|
|
}
|
|
}
|
|
|
|
afterEach(() => vi.unstubAllGlobals())
|
|
|
|
describe('候选提交资格', () => {
|
|
it('关系来源检查缺失或失败时,即使 ready=true 也不能确认提交', () => {
|
|
const preview = commitPreview()
|
|
expect(candidatePreviewReady(preview, 'candidate-project', 'candidate-current')).toBe(true)
|
|
delete (preview.checks as Partial<typeof preview.checks>).relationEvidenceValid
|
|
expect(candidatePreviewReady(preview, 'candidate-project', 'candidate-current')).toBe(false)
|
|
preview.checks.relationEvidenceValid = false
|
|
expect(candidatePreviewReady(preview, 'candidate-project', 'candidate-current')).toBe(false)
|
|
})
|
|
|
|
it('关系修复只发送最新版本和所选关系原始定位,不扩展成主体删除', async () => {
|
|
const fetcher = vi.fn<typeof fetch>().mockImplementation(async () => new Response(JSON.stringify({ data: {} })))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
await breakdownApi.repairCandidateRelation('p/id', {
|
|
confirmed: true,
|
|
expectedCheckpointId: 'cp-latest',
|
|
subjectRef: '@SC0002',
|
|
relation: '位于',
|
|
target: '测试空地',
|
|
evidence: ' 原始证据,保留空格 '
|
|
})
|
|
expect(fetcher.mock.calls[0]![0]).toBe('/api/projects/p%2Fid/breakdown/candidate-relation-repair')
|
|
expect(fetcher.mock.calls[0]![1]?.method).toBe('POST')
|
|
expect(JSON.parse(fetcher.mock.calls[0]![1]?.body as string)).toEqual({
|
|
confirmed: true,
|
|
expectedCheckpointId: 'cp-latest',
|
|
subjectRef: '@SC0002',
|
|
relation: '位于',
|
|
target: '测试空地',
|
|
evidence: ' 原始证据,保留空格 '
|
|
})
|
|
})
|
|
it('只允许完整、未提交、审核通过的候选快照进入确认', () => {
|
|
expect(candidateCommitIssue(readyCandidate())).toBe('')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), candidateOnly: false })).toContain('候选')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), storyboardPersisted: true })).toContain('提交')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), storyboardPendingQualityEpisodeNos: [1] })).toContain('审核')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), storyboardShotValidation: undefined })).toContain('校验')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), expectedEpisodeFingerprints: undefined })).toContain('版本')
|
|
expect(candidateCommitIssue({ ...readyCandidate(), storyboardEpisodeShots: [] })).toContain('完整')
|
|
})
|
|
|
|
it('启动明确发送候选模式,提交不发送客户端资产', async () => {
|
|
const fetcher = vi
|
|
.fn<typeof fetch>()
|
|
.mockImplementation(async () => new Response(JSON.stringify({ data: { projectId: 'p/id' } })))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
await breakdownApi.run('p/id', 'start', { groupSize: 3, modules: ['character'], candidateOnly: true })
|
|
expect(JSON.parse(fetcher.mock.calls[0]![1]!.body as string).candidateOnly).toBe(true)
|
|
await breakdownApi.commitCandidate('p/id')
|
|
expect(fetcher.mock.calls[1]![0]).toContain('/projects/p%2Fid/breakdown/commit-candidate')
|
|
expect(JSON.parse(fetcher.mock.calls[1]![1]!.body as string)).toEqual({ confirmed: true })
|
|
})
|
|
it('候选新接口使用真实端点并携带版本,不把人工草稿扩展成正式资产请求', async () => {
|
|
const fetcher = vi.fn<typeof fetch>().mockResolvedValue(new Response(JSON.stringify({ data: {} })))
|
|
// 每次返回独立响应,模拟四个实际端点,不运行任何模型或真实写入。
|
|
fetcher.mockImplementation(async () => new Response(JSON.stringify({ data: {} })))
|
|
vi.stubGlobal('fetch', fetcher)
|
|
await breakdownApi.revalidateCandidate('p/id')
|
|
await breakdownApi.candidateCommitPreview('p/id')
|
|
await breakdownApi.repairCandidateSubject('p/id', {
|
|
expectedCheckpointId: 'current',
|
|
episodeNo: 1,
|
|
beatNo: 2,
|
|
shotNo: 3,
|
|
subjectRef: '@PR0001',
|
|
formId: 'existing-form'
|
|
})
|
|
await breakdownApi.repairCandidateActions('p/id', {
|
|
expectedCheckpointId: 'current',
|
|
repairs: [{ episodeNo: 1, beatNo: 2, shotNo: 3, actionId: 'action-1', description: '人物伸手拿起铜铃' }]
|
|
})
|
|
expect(fetcher.mock.calls.map(call => call[0])).toEqual([
|
|
'/api/projects/p%2Fid/breakdown/candidate-revalidation',
|
|
'/api/projects/p%2Fid/breakdown/candidate-commit-preview',
|
|
'/api/projects/p%2Fid/breakdown/candidate-subject-repair',
|
|
'/api/projects/p%2Fid/breakdown/candidate-action-batch-repair'
|
|
])
|
|
expect(fetcher.mock.calls.map(call => call[1]?.method)).toEqual(['GET', 'GET', 'POST', 'POST'])
|
|
const body = fetcher.mock.calls[3]?.[1]?.body
|
|
if (typeof body !== 'string') throw new Error('请求缺少 JSON 正文')
|
|
expect(JSON.parse(body)).toEqual({
|
|
expectedCheckpointId: 'current',
|
|
repairs: [{ episodeNo: 1, beatNo: 2, shotNo: 3, actionId: 'action-1', description: '人物伸手拿起铜铃' }]
|
|
})
|
|
})
|
|
})
|