feat(short-drama-agent-front): 接入草案、首帧证据与审核继续

This commit is contained in:
GJ committed 2026-11-06 18:21:31 +08:00
1 parent 751106985e
commit d0264c08ce
23 files changed
+990 -170

No files matched your search

@@ -142,3 +142,55 @@ describe('摄影草案与规格复用的正式契约', () => {
expect(JSON.parse(String(mock.mock.calls[0]![1]?.body))).toEqual({ reuseOnly: true })
})
})
/** 草案 API 的隔离保存记录,只模拟正式修订规则。 */
describe('待审摄影草案的保存与回读', () => {
it('按项目和镜头区分草案;首次保存、回读和 409 不触发预览', async () => {
const rows = new Map<string, { revision: number; draft: unknown }>()
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (path, options) => {
const url = new URL(String(path), 'http://localhost')
const key = url.pathname
const previous = rows.get(key)
if (options?.method !== 'PUT') return new Response(JSON.stringify({ data: previous ?? null }))
const body = JSON.parse(String(options.body)) as { expectedRevision: number | null; draft: unknown }
if (body.expectedRevision !== (previous?.revision ?? null))
return new Response(
JSON.stringify({
message: '草案修订已变化',
details: {
code: 'KEYFRAME_REVIEW_DRAFT_REVISION_CONFLICT',
currentRevision: previous?.revision ?? null
}
}),
{ status: 409 }
)
const data = { revision: (previous?.revision ?? 0) + 1, draft: body.draft }
rows.set(key, data)
return new Response(JSON.stringify({ data }))
})
vi.stubGlobal('fetch', fetcher)
const first = draftFromFormal(shot, keyframe, 'b'.repeat(64))
const second = { ...first, direction: { ...first.direction, composition: '另一镜构图' } }
expect(await derivedReviewApi.draft('p/1', 'one')).toBeNull()
await derivedReviewApi.saveDraft('p/1', 'one', { expectedRevision: null, draft: first })
await derivedReviewApi.saveDraft('p/1', 'two', { expectedRevision: null, draft: second })
expect((await derivedReviewApi.draft('p/1', 'one'))?.draft.direction.composition).toBe(
first.direction.composition
)
expect((await derivedReviewApi.draft('p/1', 'two'))?.draft.direction.composition).toBe('另一镜构图')
await expect(
derivedReviewApi.saveDraft('p/1', 'one', { expectedRevision: null, draft: second })
).rejects.toMatchObject({
status: 409,
details: { currentRevision: 1 }
})
expect(fetcher.mock.calls.map(([url]) => String(url))).toEqual([
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
'/api/storyboard-shots/two/keyframe-review-draft?projectId=p%2F1',
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1',
'/api/storyboard-shots/two/keyframe-review-draft?projectId=p%2F1',
'/api/storyboard-shots/one/keyframe-review-draft?projectId=p%2F1'
])
})
})