feat(short-drama-agent-front): 接入草案、首帧证据与审核继续
This commit is contained in:
1 parent
751106985e
commit
d0264c08ce
23 files changed
+990
-170
No files matched your search
@@ -0,0 +1,87 @@
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import KeyframeInputDetails from '@/features/production/components/KeyframeInputDetails.vue'
|
||||
import { historicalReferenceUrl, type HistoricalKeyframeReference } from '@/features/production/keyframe-input'
|
||||
|
||||
/** 两种职责对应同一张实际参考图。 */
|
||||
const reference: HistoricalKeyframeReference = {
|
||||
imageNumber: 1,
|
||||
sha256: 'a'.repeat(64),
|
||||
pixelFingerprint: 'b'.repeat(64),
|
||||
mimeType: 'image/png',
|
||||
width: 512,
|
||||
height: 512,
|
||||
byteLength: 100,
|
||||
bindings: [
|
||||
{ role: 'identity-anchor', subjectRef: '@CH01' },
|
||||
{ role: 'form-primary', subjectRef: '@CH02' }
|
||||
],
|
||||
availability: 'available',
|
||||
imageUrl: '/api/storyboard-shots/shot/keyframes/one/generation-input/references/1?projectId=project'
|
||||
}
|
||||
|
||||
describe('历史首帧输入', () => {
|
||||
it('只解析归属当前候选的正式原件地址', () => {
|
||||
expect(historicalReferenceUrl(reference, 'project', 'shot', 'one')).toContain('?projectId=project')
|
||||
expect(historicalReferenceUrl(reference, 'project', 'shot', 'two')).toBeNull()
|
||||
expect(historicalReferenceUrl(reference, 'wrong', 'shot', 'one')).toBeNull()
|
||||
expect(historicalReferenceUrl({ ...reference, availability: 'changed' }, 'project', 'shot', 'one')).toBeNull()
|
||||
})
|
||||
|
||||
it('展开才读取历史,切换候选不混用输入和参考', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async path => {
|
||||
const keyframeId = String(path).includes('/one/') ? 'one' : 'two'
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
data: {
|
||||
shotId: 'shot',
|
||||
keyframeId,
|
||||
inputSnapshotStatus: 'recorded',
|
||||
providerInputFingerprint: 'fingerprint',
|
||||
providerInputSnapshot: {
|
||||
provider: 'seedream',
|
||||
model: 'test',
|
||||
providerPrompt: '当次描述 ' + keyframeId,
|
||||
fingerprint: 'fingerprint',
|
||||
sourceFingerprint: 'source',
|
||||
generationOptions: { size: '2048x2048' },
|
||||
version: 1,
|
||||
references: [
|
||||
{
|
||||
...reference,
|
||||
imageUrl: null,
|
||||
availability: keyframeId === 'one' ? 'changed' : 'unavailable'
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const wrapper = mount(KeyframeInputDetails, {
|
||||
props: { projectId: 'project', shotId: 'shot', keyframeId: 'one' }
|
||||
})
|
||||
try {
|
||||
expect(fetcher).not.toHaveBeenCalled()
|
||||
await wrapper.get('.n-collapse-item__header-main').trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('当次描述 one')
|
||||
expect(wrapper.text()).toContain('原件字节已变化')
|
||||
expect(wrapper.text()).toContain('@CH01')
|
||||
expect(wrapper.text()).toContain('@CH02')
|
||||
expect(wrapper.find('img').exists()).toBe(false)
|
||||
await wrapper.setProps({ keyframeId: 'two' })
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('当次描述 two')
|
||||
expect(wrapper.text()).not.toContain('当次描述 one')
|
||||
expect(wrapper.text()).toContain('原件不可用')
|
||||
expect(fetcher.mock.calls.map(([url]) => url)).toEqual([
|
||||
'/api/storyboard-shots/shot/keyframes/one/generation-input?projectId=project',
|
||||
'/api/storyboard-shots/shot/keyframes/two/generation-input?projectId=project'
|
||||
])
|
||||
} finally {
|
||||
wrapper.unmount()
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -114,40 +114,45 @@ describe('正式首帧 Vision 的费用与恢复边界', () => {
|
||||
expect(fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('有正式可继续结论时使用原文字显式提交,保留已完成步骤', async () => {
|
||||
let accepted = 0
|
||||
const saved = history('failed', { recoveryRequired: false, resumeAvailable: true })
|
||||
it('新会话从正式历史恢复任务,只显式发送任务和指纹', async () => {
|
||||
const fingerprint = 'f'.repeat(64)
|
||||
const saved = {
|
||||
...history('failed'),
|
||||
allowedTexts: ['旧门牌'],
|
||||
requestFingerprint: fingerprint,
|
||||
recoveryRequired: false,
|
||||
resumeAvailable: true
|
||||
}
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (_url, options) => {
|
||||
if (options?.method === 'POST') {
|
||||
accepted++
|
||||
if (options?.method === 'POST')
|
||||
return response(
|
||||
{
|
||||
shotId,
|
||||
keyframeId: assetId,
|
||||
validationTaskId: taskId,
|
||||
executionId: accepted === 1 ? executionId : 'resume-execution',
|
||||
executionId: 'resume-execution',
|
||||
status: 'pending'
|
||||
},
|
||||
202
|
||||
)
|
||||
}
|
||||
return response([saved])
|
||||
})
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await submitKeyframeVision(shotId, assetId, ['旧门牌'], [])
|
||||
const vision = observe()
|
||||
await flushPromises()
|
||||
expect(vision.resumeTexts.value).toEqual(['旧门牌'])
|
||||
const resume = { resumeValidationTaskId: taskId, expectedRequestFingerprint: fingerprint }
|
||||
expect(vision.resume.value).toEqual(resume)
|
||||
expect(vision.state.value.resumable?.steps?.map(item => item.status)).toEqual(['completed', 'received'])
|
||||
await expect(submitKeyframeVision(shotId, assetId, ['新门牌'], [saved])).rejects.toThrow('原审核参数')
|
||||
expect(accepted).toBe(1)
|
||||
await submitKeyframeVision(shotId, assetId, ['旧门牌'], [saved])
|
||||
expect(accepted).toBe(2)
|
||||
expect(
|
||||
fetcher.mock.calls
|
||||
.filter(([, options]) => options?.method === 'POST')
|
||||
.map(([, options]) => JSON.parse(String(options?.body)))
|
||||
).toEqual([{ allowedTexts: ['旧门牌'] }, { allowedTexts: ['旧门牌'] }])
|
||||
await expect(submitKeyframeVision(shotId, assetId, ['新门牌'], [saved])).rejects.toThrow('继续原审核')
|
||||
await expect(
|
||||
submitKeyframeVision(shotId, assetId, { ...resume, expectedRequestFingerprint: 'a'.repeat(64) }, [saved])
|
||||
).rejects.toThrow('任务状态已变化')
|
||||
expect(fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')).toHaveLength(0)
|
||||
await submitKeyframeVision(shotId, assetId, resume, [saved], 'project/1')
|
||||
const writes = fetcher.mock.calls.filter(([, options]) => options?.method === 'POST')
|
||||
expect(writes).toHaveLength(1)
|
||||
expect(String(writes[0]?.[0])).toContain('?projectId=project%2F1')
|
||||
expect(JSON.parse(String(writes[0]?.[1]?.body))).toEqual(resume)
|
||||
})
|
||||
|
||||
it('409 活动审核只观察原编号,不能把当前表单参数当作原参数', async () => {
|
||||
@@ -168,7 +173,7 @@ describe('正式首帧 Vision 的费用与恢复边界', () => {
|
||||
const vision = observe()
|
||||
await flushPromises()
|
||||
expect(vision.execution.data.value?.id).toBe(executionId)
|
||||
expect(vision.resumeTexts.value).toBeNull()
|
||||
expect(vision.resume.value).toBeNull()
|
||||
expect(vision.blocked.value).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -114,7 +114,7 @@ function server() {
|
||||
const executionState = { status: 'completed' as 'running' | 'completed' | 'failed' }
|
||||
let batchMetadata: QualityInput | null = null
|
||||
const fetcher = vi.fn<typeof fetch>().mockImplementation(async (url, options) => {
|
||||
const path = String(url)
|
||||
const path = String(url).split('?')[0]!
|
||||
let data: unknown
|
||||
if (options?.method === 'POST') {
|
||||
if (path.endsWith('/generate-quality')) {
|
||||
@@ -235,7 +235,9 @@ describe('视觉质量契约与付费边界', () => {
|
||||
expect(data.fetcher).not.toHaveBeenCalled()
|
||||
await data.service.run('validate', input({ allowedTexts: ['记忆当铺'] }))
|
||||
expect(data.posts()).toHaveLength(1)
|
||||
expect(data.posts()[0]?.[0]).toBe('/api/storyboard-shots/shot-1/keyframes/keyframe-1/validate')
|
||||
expect(data.posts()[0]?.[0]).toBe(
|
||||
'/api/storyboard-shots/shot-1/keyframes/keyframe-1/validate?projectId=' + data.projectId
|
||||
)
|
||||
expect(JSON.parse(String(data.posts()[0]?.[1]?.body))).toEqual({ allowedTexts: ['记忆当铺'] })
|
||||
expect(data.service.session.value.receipt).toMatchObject({ kind: 'keyframe', result: { passed: true } })
|
||||
})
|
||||
|
||||
@@ -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'
|
||||
])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user