import { describe, expect, it, vi, afterEach } from 'vitest' import { candidateCommitIssue } from '@/features/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('只允许完整、未提交、审核通过的候选快照进入确认', () => { 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() .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 }) }) })