feat(short-drama-agent-front): 接入摄影审核与首帧制作
This commit is contained in:
1 parent
3503926d62
commit
751106985e
32 files changed
+1970
-153
No files matched your search
@@ -0,0 +1,144 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { derivedReviewApi } from '@/features/storyboard/derived-review-api'
|
||||
import { draftFromFormal } from '@/features/storyboard/derived-review'
|
||||
import { subjectImagesApi } from '@/features/subject-images/api'
|
||||
import type { DesignedShot } from '@/features/storyboard/types'
|
||||
import type { KeyframeSpec } from '@/features/production/types'
|
||||
|
||||
/** 已保存的正式镜头样本,保留空间、动作和形态值。 */
|
||||
const shot: DesignedShot = {
|
||||
shotId: 'shot/1',
|
||||
beatNo: 1,
|
||||
shotNo: 1,
|
||||
title: '开门',
|
||||
description: '角色站在门边',
|
||||
visualFocus: '手',
|
||||
direction: {
|
||||
shotSize: 'wide',
|
||||
cameraAngle: 'eye_level',
|
||||
cameraMovement: 'static',
|
||||
composition: '门在右侧',
|
||||
cameraPosition: '室内',
|
||||
lensIntent: 'wide',
|
||||
depthOfField: 'deep',
|
||||
visualIntent: '空间关系'
|
||||
},
|
||||
visualState: {
|
||||
timeOfDay: '午后',
|
||||
weather: '',
|
||||
atmosphere: '',
|
||||
environmentTransientState: '日光',
|
||||
continuityNote: '保持视角',
|
||||
subjects: [
|
||||
{
|
||||
subjectId: 'scene',
|
||||
subjectRef: '@SC0001',
|
||||
subjectFormId: 'scene-form',
|
||||
formName: '客厅',
|
||||
expression: '',
|
||||
pose: '',
|
||||
gaze: '',
|
||||
position: '画面右侧',
|
||||
transientState: ''
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
/** 正式来源及已确认的场景几何。 */
|
||||
const keyframe: KeyframeSpec = {
|
||||
formalSourceFingerprint: 'a'.repeat(64),
|
||||
projectId: 'p/1',
|
||||
shotId: shot.shotId,
|
||||
episodeNo: 1,
|
||||
beatNo: 1,
|
||||
shotNo: 1,
|
||||
prompt: '正式描述',
|
||||
references: [
|
||||
{
|
||||
subjectId: 'scene',
|
||||
subjectRef: '@SC0001',
|
||||
module: 'scene',
|
||||
role: 'layout-master',
|
||||
imageId: 'master-1',
|
||||
imageUrl: '/storage/master.png',
|
||||
spatialLayoutVersion: 'geometry-1'
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
describe('摄影草案与规格复用的正式契约', () => {
|
||||
it('受控修订只变更摄影字段,采用原预览和正式来源', async () => {
|
||||
const fingerprint = 'b'.repeat(64)
|
||||
const draft = draftFromFormal(shot, keyframe, fingerprint)
|
||||
const original = structuredClone(draft)
|
||||
draft.direction.composition = '保留原场景并移动构图'
|
||||
draft.direction.cameraPosition = '室内右侧'
|
||||
expect(draft.visualState).toEqual(original.visualState)
|
||||
expect(draft.sceneSources).toEqual([
|
||||
{ subjectRef: '@SC0001', imageId: 'master-1', spatialLayoutVersion: 'geometry-1' }
|
||||
])
|
||||
const mock = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValueOnce(
|
||||
new Response(
|
||||
JSON.stringify({ data: { draftFingerprint: 'draft-fingerprint', productionReady: false } })
|
||||
)
|
||||
)
|
||||
.mockResolvedValueOnce(new Response(JSON.stringify({ data: { shots: [{ shotId: shot.shotId }] } })))
|
||||
vi.stubGlobal('fetch', mock)
|
||||
const params = { provider: 'seedream', generationOptions: { size: '2048x2048' } }
|
||||
const preview = await derivedReviewApi.preview(shot.shotId, draft, params)
|
||||
expect(preview.productionReady).toBe(false)
|
||||
expect(mock).toHaveBeenCalledTimes(1)
|
||||
await derivedReviewApi.confirm('p/1', '人工', [
|
||||
{
|
||||
...params,
|
||||
shotId: shot.shotId,
|
||||
draft,
|
||||
expectedDraftFingerprint: preview.draftFingerprint,
|
||||
expectedCurrentFormalSourceFingerprint: keyframe.formalSourceFingerprint
|
||||
}
|
||||
])
|
||||
expect(mock.mock.calls.map(([url]) => url)).toEqual([
|
||||
'/api/storyboard-shots/shot%2F1/keyframe/preview',
|
||||
'/api/projects/p%2F1/storyboard-derived-reviews/confirm'
|
||||
])
|
||||
expect(JSON.parse(String(mock.mock.calls[1]![1]?.body)).shots[0]).toMatchObject({
|
||||
...params,
|
||||
draft,
|
||||
expectedCurrentFormalSourceFingerprint: keyframe.formalSourceFingerprint,
|
||||
expectedDraftFingerprint: 'draft-fingerprint'
|
||||
})
|
||||
})
|
||||
|
||||
it('场景沿用保留其它状态,只将选定的正式前镜证据交给免费预览', async () => {
|
||||
const draft = draftFromFormal(shot, keyframe, 'b'.repeat(64))
|
||||
draft.sceneStateCarryForward = { previousShotId: 'previous', subjectRef: '@SC0001' }
|
||||
draft.visualState.subjects[0]!.transientState = '门半开'
|
||||
const mock = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response(JSON.stringify({ data: { productionReady: false } })))
|
||||
vi.stubGlobal('fetch', mock)
|
||||
await derivedReviewApi.preview(shot.shotId, draft, {})
|
||||
expect(JSON.parse(String(mock.mock.calls[0]![1]?.body)).draft).toMatchObject({
|
||||
sceneStateCarryForward: draft.sceneStateCarryForward,
|
||||
visualState: {
|
||||
subjects: [{ formId: 'scene-form', transientState: '门半开' }],
|
||||
environment: { transientState: '日光' }
|
||||
}
|
||||
})
|
||||
expect(shot.visualState?.subjects[0]?.transientState).toBe('')
|
||||
expect(mock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('道具复用冲突只发送一次 reuseOnly,不回退文字模型', async () => {
|
||||
const mock = vi
|
||||
.fn<typeof fetch>()
|
||||
.mockResolvedValue(new Response(JSON.stringify({ message: '没有等价规格' }), { status: 409 }))
|
||||
vi.stubGlobal('fetch', mock)
|
||||
await expect(subjectImagesApi.prepareStructure('form/1', true)).rejects.toMatchObject({ status: 409 })
|
||||
expect(mock).toHaveBeenCalledTimes(1)
|
||||
expect(mock.mock.calls[0]![0]).toBe('/api/subject-forms/form%2F1/prop-structure-spec/generate')
|
||||
expect(JSON.parse(String(mock.mock.calls[0]![1]?.body))).toEqual({ reuseOnly: true })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user