feat(short-drama-agent-front): 接入空间母版恢复与修订
This commit is contained in:
1 parent
c808a58a3f
commit
7e149a10c0
18 files changed
+2732
-12
No files matched your search
@@ -0,0 +1,230 @@
|
||||
import { effectScope, reactive } from 'vue'
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { useMasterGeneration } from '@/features/spatial-layouts/useMasterGeneration'
|
||||
import { createMasterMock, spatialLayoutFixture } from '../../fixtures/spatial-masters'
|
||||
|
||||
/** 每个测试使用独立作用域与费用标记,不连接任何 Provider。 */
|
||||
let scope = effectScope()
|
||||
afterEach(() => {
|
||||
scope.stop()
|
||||
scope = effectScope()
|
||||
sessionStorage.clear()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
describe('母版输入来源与重复付费保护', () => {
|
||||
it('明确 Draft 修订后绑定同次指纹;输入改变撤销费用勾选,成功只生成一次草稿', async () => {
|
||||
const mock = createMasterMock()
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const generated = vi.fn<() => void>()
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const form = scope.run(() => useMasterGeneration(props, generated, () => {}))!
|
||||
await flushPromises()
|
||||
expect(mock.calls.every(call => call.method === 'GET')).toBe(true)
|
||||
form.revisionMode.value = true
|
||||
form.referenceId.value = 'draft'
|
||||
form.instruction.value = '只调整转轴方向'
|
||||
await form.loadPreview()
|
||||
expect(form.preview.value?.preflight.referenceMasterId).toBe('draft')
|
||||
form.acknowledged.value = true
|
||||
form.instruction.value = '只调整门扇方向'
|
||||
await flushPromises()
|
||||
expect(form.preview.value).toBeNull()
|
||||
expect(form.acknowledged.value).toBe(false)
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await Promise.all([form.submit(), form.submit()])
|
||||
const writes = mock.calls.filter(call => call.url.endsWith('/generate'))
|
||||
expect(writes).toHaveLength(1)
|
||||
expect(writes[0]!.body).toMatchObject({
|
||||
referenceMasterId: 'draft',
|
||||
revisionInstruction: '只调整门扇方向',
|
||||
expectedPreviewFingerprint: 'f'.repeat(64),
|
||||
confirmPaidGeneration: true,
|
||||
expectedVersion: spatialLayoutFixture.version
|
||||
})
|
||||
expect(generated).toHaveBeenCalledTimes(1)
|
||||
expect(mock.calls.some(call => call.url.endsWith('/validate') || call.url.endsWith('/confirm'))).toBe(false)
|
||||
})
|
||||
it('费用前 409 且任务未创建可重新免费预检;费用后冲突存在新任务则持续阻断', async () => {
|
||||
const mock = createMasterMock()
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const form = scope.run(() =>
|
||||
useMasterGeneration(
|
||||
props,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
)!
|
||||
await flushPromises()
|
||||
form.referenceId.value = 'old'
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
mock.state.generationConflict = true
|
||||
await form.submit()
|
||||
expect(form.recoveryNotice.value).toBe('')
|
||||
expect(form.preview.value).toBeNull()
|
||||
mock.state.generationConflict = false
|
||||
mock.state.afterPaidConflict = true
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(form.recoveryNotice.value).toContain('费用待核对')
|
||||
form.instruction.value = '修改也不能绕过费用保护'
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/generate'))).toHaveLength(2)
|
||||
})
|
||||
it('付费阶段的 400 不能当成未收费,必须按新任务证据保持阻断', async () => {
|
||||
const mock = createMasterMock()
|
||||
mock.state.afterPaidConflict = true
|
||||
mock.state.generationErrorStatus = 400
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const form = scope.run(() =>
|
||||
useMasterGeneration(
|
||||
props,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
)!
|
||||
await flushPromises()
|
||||
form.referenceId.value = 'old'
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(form.recoveryNotice.value).toContain('费用待核对')
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/generate'))).toHaveLength(1)
|
||||
})
|
||||
it('200 畸形回执不当作成功,保留未知费用且不自动重发', async () => {
|
||||
const mock = createMasterMock()
|
||||
const fetcher = vi.fn<typeof fetch>(async (input, init) =>
|
||||
String(input).endsWith('/generate')
|
||||
? new Response(JSON.stringify({ data: null }))
|
||||
: mock.fetcher(input, init)
|
||||
)
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const generated = vi.fn<() => void>()
|
||||
const form = scope.run(() => useMasterGeneration(props, generated, () => {}))!
|
||||
await flushPromises()
|
||||
form.referenceId.value = 'old'
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(form.recoveryNotice.value).toContain('费用待核对')
|
||||
expect(generated).not.toHaveBeenCalled()
|
||||
await form.submit()
|
||||
expect(fetcher.mock.calls.filter(([input]) => String(input).endsWith('/generate'))).toHaveLength(1)
|
||||
})
|
||||
it('连接中断保持费用保护;关闭并刷新观察器不自动重发', async () => {
|
||||
const mock = createMasterMock()
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>(async (input, init) => {
|
||||
if (String(input).endsWith('/generate')) throw new TypeError('网络中断')
|
||||
return mock.fetcher(input, init)
|
||||
})
|
||||
)
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const form = scope.run(() =>
|
||||
useMasterGeneration(
|
||||
props,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
)!
|
||||
await flushPromises()
|
||||
form.referenceId.value = 'old'
|
||||
await form.loadPreview()
|
||||
form.acknowledged.value = true
|
||||
await form.submit()
|
||||
expect(form.recoveryNotice.value).toContain('费用待核对')
|
||||
scope.stop()
|
||||
scope = effectScope()
|
||||
const restored = scope.run(() =>
|
||||
useMasterGeneration(
|
||||
props,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
)!
|
||||
await flushPromises()
|
||||
expect(restored.recoveryNotice.value).toContain('费用待核对')
|
||||
expect(restored.canSubmit.value).toBe(false)
|
||||
})
|
||||
it('切项目和同项目切布局都清除旧参考与预检,迟到响应不回填', async () => {
|
||||
const mock = createMasterMock()
|
||||
let resolveOld!: (response: Response) => void
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn<typeof fetch>(async (input, init) =>
|
||||
String(input).endsWith('/generation-preflight')
|
||||
? new Promise(resolve => {
|
||||
resolveOld = resolve
|
||||
})
|
||||
: mock.fetcher(input, init)
|
||||
)
|
||||
)
|
||||
const props = reactive({
|
||||
projectId: 'p',
|
||||
layout: { ...spatialLayoutFixture },
|
||||
masters: mock.state.masters,
|
||||
disabled: false
|
||||
})
|
||||
const form = scope.run(() =>
|
||||
useMasterGeneration(
|
||||
props,
|
||||
() => {},
|
||||
() => {}
|
||||
)
|
||||
)!
|
||||
await flushPromises()
|
||||
form.referenceId.value = 'old'
|
||||
const loading = form.loadPreview()
|
||||
await flushPromises()
|
||||
props.projectId = 'p2'
|
||||
props.layout = { ...spatialLayoutFixture, id: 'layout2', projectId: 'p2' }
|
||||
await flushPromises()
|
||||
resolveOld(
|
||||
new Response(JSON.stringify({ data: { layoutId: 'layout', layoutVersion: spatialLayoutFixture.version } }))
|
||||
)
|
||||
await loading
|
||||
expect(form.preview.value).toBeNull()
|
||||
expect(form.referenceId.value).toBe('')
|
||||
expect(form.provider.value).toBe('mock')
|
||||
props.layout = { ...props.layout, id: 'layout3' }
|
||||
await flushPromises()
|
||||
expect(form.provider.value).toBe('mock')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,108 @@
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
import { NCheckbox, NInput, NSelect, NTabs } from 'naive-ui'
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import SceneMasterManager from '@/features/spatial-layouts/components/SceneMasterManager.vue'
|
||||
import { createMasterMock } from '../../fixtures/spatial-masters'
|
||||
|
||||
/** 固定栏与长内容在 Chrome 验收,组件层使用实际表单和正式接口 Mock。 */
|
||||
let wrapper: VueWrapper
|
||||
/**
|
||||
* 点击可见业务按钮,保留实际提交门禁。
|
||||
* @param label 完整按钮名称
|
||||
*/
|
||||
async function click(label: string) {
|
||||
const button = wrapper.findAll('button').find(item => item.text() === label)
|
||||
expect(button).toBeDefined()
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
/**
|
||||
* 创建隔离管理页,不把初始读取变成审核或生成。
|
||||
* @returns 请求 Mock 状态
|
||||
*/
|
||||
async function setup() {
|
||||
const mock = createMasterMock()
|
||||
vi.stubGlobal('fetch', mock.fetcher)
|
||||
wrapper = mount(SceneMasterManager, {
|
||||
props: { open: true, projectId: 'p', layoutId: 'layout' },
|
||||
global: { stubs: { AppDrawer: { template: '<div><slot/><slot name="footer"/></div>' }, AssetImage: true } }
|
||||
})
|
||||
await flushPromises()
|
||||
return mock
|
||||
}
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
sessionStorage.clear()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
describe('F04 空间母版管理增量流程', () => {
|
||||
it('打开不调用 Provider,确认历史不冒充当前母版,预检没有报价不伪造金额', async () => {
|
||||
const mock = await setup()
|
||||
expect(wrapper.text()).toContain('暂无当前版本已确认母版')
|
||||
expect(wrapper.text()).toContain('机器:AI 视觉审核未通过或未运行')
|
||||
expect(mock.calls.every(call => call.method === 'GET')).toBe(true)
|
||||
expect(wrapper.findAll('.n-form-item--error')).toHaveLength(0)
|
||||
wrapper.findComponent(NTabs).vm.$emit('update:value', 'generate')
|
||||
await flushPromises()
|
||||
await click('免费预检母版输入')
|
||||
expect(wrapper.text()).toContain('预检接口未提供报价')
|
||||
expect(wrapper.text()).not.toContain('¥0.60')
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/generate'))).toHaveLength(0)
|
||||
})
|
||||
it('人工逐项确认使用真实身份和版本,独立保存 Human Passed,不自动 Vision', async () => {
|
||||
const mock = await setup()
|
||||
const select = wrapper
|
||||
.findAllComponents(NSelect)
|
||||
.find(item => item.attributes('aria-label') === '第 1 项人工结论')!
|
||||
select.vm.$emit('update:value', 'passed')
|
||||
for (const input of wrapper.findAllComponents(NInput)) {
|
||||
const placeholder = input.props('placeholder')
|
||||
input.vm.$emit('update:value', placeholder === '填写真实确认人' ? 'goujun' : '清晰可见固定连接位置')
|
||||
}
|
||||
await flushPromises()
|
||||
await click('正式人工确认母版')
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/confirm'))).toHaveLength(1)
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/validate'))).toHaveLength(0)
|
||||
expect(wrapper.text()).toContain('人工:人工审核通过')
|
||||
expect(wrapper.text()).toContain('机器:AI 视觉审核未通过或未运行')
|
||||
const body = mock.calls.find(call => call.url.endsWith('/confirm'))!.body
|
||||
expect(body.confirmedBy).toBe('goujun')
|
||||
expect(body.reviewResults).toEqual([{ index: 1, result: 'passed', evidence: '清晰可见固定连接位置' }])
|
||||
})
|
||||
it('AI 通过仍为 Draft,不自动填人工通过或确认;必须独立勾选费用', async () => {
|
||||
const mock = await setup()
|
||||
const button = wrapper.findAll('button').find(item => item.text() === 'AI 视觉审核')!
|
||||
expect(button.attributes('disabled')).toBeDefined()
|
||||
wrapper
|
||||
.findAllComponents(NCheckbox)
|
||||
.find(item => item.text().includes('单独确认'))!
|
||||
.vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
await click('AI 视觉审核')
|
||||
expect(wrapper.text()).toContain('机器:AI 视觉审核通过')
|
||||
expect(wrapper.text()).toContain('资产:草稿')
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/confirm'))).toHaveLength(0)
|
||||
expect(
|
||||
wrapper
|
||||
.findAll('button')
|
||||
.find(item => item.text() === '正式人工确认母版')!
|
||||
.attributes('disabled')
|
||||
).toBeDefined()
|
||||
})
|
||||
it('按需读取来源影响,原件可读与过期独立展示,不改历史 Primary', async () => {
|
||||
const mock = await setup()
|
||||
expect(mock.calls.filter(call => call.url.endsWith('/recovery-impact'))).toHaveLength(0)
|
||||
wrapper.findComponent(NTabs).vm.$emit('update:value', 'impact')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('图片原件有效 ≠ 来源当前有效')
|
||||
expect(wrapper.text()).toContain('关联镜头8')
|
||||
const headings = wrapper.findAll('.n-collapse-item__header-main')
|
||||
await headings.find(item => item.text().includes('星港相遇'))!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('原件与原审核一致')
|
||||
expect(wrapper.text()).toContain('布局版本已变化')
|
||||
expect(wrapper.text()).toContain('历史主首帧(Primary)')
|
||||
expect(wrapper.text()).toContain('需要重新核验')
|
||||
expect(mock.calls.every(call => call.method === 'GET')).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,151 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { spatialMasterApi } from '@/features/spatial-layouts/api'
|
||||
import {
|
||||
canUseMasterReference,
|
||||
masterReviewLabels,
|
||||
toMasterPreview,
|
||||
impactVisionLabel
|
||||
} from '@/features/spatial-layouts/model'
|
||||
import { runGuardedImageRequest, imageRequestNotice } from '@/features/subject-images/image-request-guard'
|
||||
|
||||
/** 所有请求均由隔离 Mock 接收,禁止连接真实 Provider。 */
|
||||
afterEach(() => {
|
||||
sessionStorage.clear()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
describe('F04 母版正式契约与独立证据', () => {
|
||||
it('历史及草稿修订预检、生成复用同一参数与指纹', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>(async () => new Response(JSON.stringify({ data: {} })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
const input = {
|
||||
expectedVersion: 'a'.repeat(64),
|
||||
referenceMasterId: 'draft',
|
||||
revisionInstruction: '仅调整活动方向',
|
||||
providerName: 'provider',
|
||||
generationOptions: { size: '2048x2048' }
|
||||
}
|
||||
await spatialMasterApi.preflight('p/a', 'l/b', input)
|
||||
await spatialMasterApi.generate('p/a', 'l/b', {
|
||||
...input,
|
||||
expectedPreviewFingerprint: 'f'.repeat(64),
|
||||
confirmPaidGeneration: true
|
||||
})
|
||||
expect(String(fetcher.mock.calls[0]![0])).toBe(
|
||||
'/api/projects/p%2Fa/shared-spatial-layouts/l%2Fb/masters/generation-preflight'
|
||||
)
|
||||
expect(JSON.parse(String(fetcher.mock.calls[0]![1]?.body))).toEqual(input)
|
||||
expect(JSON.parse(String(fetcher.mock.calls[1]![1]?.body))).toEqual({
|
||||
...input,
|
||||
expectedPreviewFingerprint: 'f'.repeat(64),
|
||||
confirmPaidGeneration: true
|
||||
})
|
||||
})
|
||||
it('来源影响、人工清单和单独 Vision 使用正式路径及独立费用确认', async () => {
|
||||
const fetcher = vi.fn<typeof fetch>(async () => new Response(JSON.stringify({ data: {} })))
|
||||
vi.stubGlobal('fetch', fetcher)
|
||||
await spatialMasterApi.impact('p', 'l', new AbortController().signal)
|
||||
await spatialMasterApi.review('p', 'l', 'm')
|
||||
await spatialMasterApi.validate('p', 'l', 'm')
|
||||
await spatialMasterApi.confirm('p', 'l', 'm', {
|
||||
expectedVersion: 'a'.repeat(64),
|
||||
evidence: '人工依据',
|
||||
confirmedBy: '审核人',
|
||||
reviewResults: [{ index: 1, result: 'passed', evidence: '连接位置可见' }]
|
||||
})
|
||||
expect(fetcher.mock.calls.map(([url]) => String(url))).toEqual([
|
||||
'/api/projects/p/shared-spatial-layouts/l/masters/recovery-impact',
|
||||
'/api/projects/p/shared-spatial-layouts/l/masters/m/review',
|
||||
'/api/projects/p/shared-spatial-layouts/l/masters/m/validate',
|
||||
'/api/projects/p/shared-spatial-layouts/l/masters/m/confirm'
|
||||
])
|
||||
expect(JSON.parse(String(fetcher.mock.calls[2]![1]?.body))).toEqual({ confirmPaidValidation: true })
|
||||
})
|
||||
it('草稿只有明确修订且属于当前布局版本才能作参考,人工通过不冒充 Vision 通过', () => {
|
||||
expect(canUseMasterReference({ status: 'draft', spatialLayoutVersion: 'old' }, 'now', true)).toBe(false)
|
||||
expect(canUseMasterReference({ status: 'draft', spatialLayoutVersion: 'now' }, 'now', false)).toBe(false)
|
||||
expect(canUseMasterReference({ status: 'draft', spatialLayoutVersion: 'now' }, 'now', true)).toBe(true)
|
||||
expect(canUseMasterReference({ status: 'confirmed', spatialLayoutVersion: 'old' }, 'now', false)).toBe(true)
|
||||
expect(
|
||||
masterReviewLabels({
|
||||
status: 'confirmed',
|
||||
currentVersion: true,
|
||||
reviewStatus: 'human_passed',
|
||||
automatedVisionPassed: false
|
||||
})
|
||||
).toMatchObject({ human: '人工审核通过', vision: 'AI 视觉审核未通过或未运行', asset: '已确认' })
|
||||
})
|
||||
it('完成但质量待复核不能展示通过,历史分步证据缺失明确保留未知', () => {
|
||||
expect(
|
||||
impactVisionLabel({
|
||||
id: 'v',
|
||||
status: 'completed',
|
||||
passed: true,
|
||||
qualityDecision: 'needs_review',
|
||||
evidenceComplete: true,
|
||||
historical: true
|
||||
})
|
||||
).toBe('原结论待人工复核')
|
||||
expect(
|
||||
impactVisionLabel({
|
||||
id: 'v',
|
||||
status: 'running',
|
||||
passed: true,
|
||||
qualityDecision: 'passed',
|
||||
evidenceComplete: true,
|
||||
historical: false
|
||||
})
|
||||
).toBe('原审核未完成')
|
||||
})
|
||||
it('适配预检时保留原始参数和参考摘要,不虚构预计费用或正式确认', () => {
|
||||
const result = toMasterPreview({
|
||||
layoutId: 'l',
|
||||
layoutVersion: 'a'.repeat(64),
|
||||
provider: 'provider',
|
||||
model: 'model',
|
||||
generationOptions: { size: '2048x2048' },
|
||||
prompt: '最终画面描述',
|
||||
references: [
|
||||
{
|
||||
imageId: 'm',
|
||||
imageUrl: '/storage/m.png',
|
||||
providerImageUrl: 'data:image/png;base64,AA==',
|
||||
providerInputResolved: true,
|
||||
role: 'layout-master',
|
||||
sourceMasterStatus: 'draft'
|
||||
}
|
||||
],
|
||||
previewFingerprint: 'f'.repeat(64),
|
||||
referenceMasterId: 'm',
|
||||
revisionInstruction: '修订',
|
||||
referenceCount: 1,
|
||||
verifiedSceneCount: 2,
|
||||
maxReferenceImages: 10,
|
||||
generationAllowed: false,
|
||||
reason: '免费预检'
|
||||
})
|
||||
expect(result.providerPrompt).toBe('最终画面描述')
|
||||
expect(result.referenceImages).toEqual(['/storage/m.png'])
|
||||
expect(result.previewFingerprint).toBe('f'.repeat(64))
|
||||
})
|
||||
it('仅在请求确定被拒绝且只读证据证明没有创建任务时解除费用保护', async () => {
|
||||
const target = 'master-reject'
|
||||
const reject = new Error('来源过期')
|
||||
const proof = vi.fn<() => Promise<boolean>>().mockResolvedValue(true)
|
||||
await expect(
|
||||
runGuardedImageRequest(
|
||||
target,
|
||||
async () => {
|
||||
throw reject
|
||||
},
|
||||
{ confirmRejection: proof }
|
||||
)
|
||||
).rejects.toBe(reject)
|
||||
expect(imageRequestNotice(target)).toBe('')
|
||||
const calls = vi.fn<() => Promise<void>>().mockRejectedValue(new Error('连接中断'))
|
||||
await expect(runGuardedImageRequest(target, calls, { confirmRejection: async () => false })).rejects.toThrow(
|
||||
'连接中断'
|
||||
)
|
||||
await expect(runGuardedImageRequest(target, calls)).rejects.toThrow('费用待核对')
|
||||
expect(calls).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Vendored
+349
@@ -0,0 +1,349 @@
|
||||
import type {
|
||||
MasterRecoveryImpact,
|
||||
MasterReview,
|
||||
SceneMaster,
|
||||
SpatialLayout,
|
||||
MasterJob
|
||||
} from '@/features/spatial-layouts/types'
|
||||
import type { GenerationModelCatalog, CreativeProfile } from '@/features/generation-config/types'
|
||||
|
||||
/** 隔离当前几何版本,不引用真实项目。 */
|
||||
export const masterVersion = 'a'.repeat(64)
|
||||
/** 正式布局的跨题材夹具。 */
|
||||
export const spatialLayoutFixture: SpatialLayout = {
|
||||
id: 'layout',
|
||||
projectId: 'p',
|
||||
name: '星港中枢共享空间',
|
||||
version: masterVersion,
|
||||
sceneSubjectIds: ['scene']
|
||||
}
|
||||
/**
|
||||
* 构造正式草稿/确认母版,图片仅为隔离地址。
|
||||
* @param patch 当前测试差异
|
||||
* @returns 母版资产
|
||||
*/
|
||||
export function sceneMasterFixture(patch: Partial<SceneMaster> = {}): SceneMaster {
|
||||
return {
|
||||
id: 'draft',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
status: 'draft',
|
||||
subjectFormId: null,
|
||||
viewDescription: null,
|
||||
evidence: null,
|
||||
confirmedBy: null,
|
||||
confirmedAt: null,
|
||||
visionReviewedAt: null,
|
||||
createdAt: '2026-11-07T00:00:00Z',
|
||||
updatedAt: '2026-11-07T00:00:00Z',
|
||||
...patch
|
||||
}
|
||||
}
|
||||
/** 隔离项目已保存的模型配置。 */
|
||||
export const masterProfile: CreativeProfile = {
|
||||
projectId: 'p',
|
||||
aspectRatio: '1:1',
|
||||
imageProvider: 'mock',
|
||||
imageModel: 'mock-model',
|
||||
imageOptions: { size: '2048x2048' },
|
||||
videoProvider: 'mock-video',
|
||||
videoModel: 'mock-video',
|
||||
videoOptions: {}
|
||||
}
|
||||
/** 使用正式目录结构,仅暴露一个测试模型。 */
|
||||
export const masterCatalog: GenerationModelCatalog = {
|
||||
defaults: { imageProvider: 'mock', videoProvider: 'mock-video' },
|
||||
images: [
|
||||
{
|
||||
type: 'image',
|
||||
provider: 'mock',
|
||||
providerLabel: '隔离图片模型',
|
||||
model: 'mock-model',
|
||||
modelLabel: '测试模型',
|
||||
supported: true,
|
||||
enabled: true,
|
||||
isDefault: true,
|
||||
capabilities: {},
|
||||
generationOptions: [],
|
||||
defaults: { size: '2048x2048' },
|
||||
projectConstraints: []
|
||||
}
|
||||
],
|
||||
videos: []
|
||||
}
|
||||
/**
|
||||
* 独立人工与机器证据,确认不改变机器结论。
|
||||
* @param master 指定母版
|
||||
* @param visionPassed 本次正式机器证据
|
||||
* @returns 正式审核材料
|
||||
*/
|
||||
export function masterReviewFixture(master: SceneMaster, visionPassed = false): MasterReview {
|
||||
const current = master.spatialLayoutVersion === masterVersion
|
||||
return {
|
||||
masterId: master.id,
|
||||
imageUrl: master.imageUrl,
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentVersion: current,
|
||||
status: master.status,
|
||||
reviewStatus: master.status === 'confirmed' && current ? 'human_passed' : 'needs_review',
|
||||
automatedVisionPassed: visionPassed,
|
||||
automatedVisionReview: visionPassed ? { summary: '隔离机器审核通过' } : null,
|
||||
sceneSubjectIds: ['scene'],
|
||||
subjectFormId: null,
|
||||
viewDescription: null,
|
||||
checklist: [
|
||||
{
|
||||
index: 1,
|
||||
kind: 'structural-connection',
|
||||
subjectId: 'scene',
|
||||
referenceSubjectId: null,
|
||||
requirement: '观察面内固定连接位置正确',
|
||||
acceptance: '连接处可见',
|
||||
result: 'needs_review'
|
||||
}
|
||||
],
|
||||
canConfirm: current && master.status === 'draft',
|
||||
humanReviewEvidence:
|
||||
master.status === 'confirmed' && current
|
||||
? {
|
||||
summary: master.evidence || '人工证据',
|
||||
compositionReviews: [{ index: 1, result: 'passed', evidence: '连接可见' }]
|
||||
}
|
||||
: null,
|
||||
note: '人工与AI证据独立'
|
||||
}
|
||||
}
|
||||
/** 真实影响结构:原件有效但来源过期,不能认定损坏或自动重生。 */
|
||||
export const masterImpactFixture: MasterRecoveryImpact = {
|
||||
projectId: 'p',
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentMaster: null,
|
||||
summary: {
|
||||
affectedShots: 8,
|
||||
primaryShots: 1,
|
||||
shotsWithVision: 1,
|
||||
shotsWithoutAssets: 7,
|
||||
candidateCount: 1,
|
||||
primaryRevalidationShots: 1
|
||||
},
|
||||
generationAllowed: false,
|
||||
limitation: '不改变主图',
|
||||
assets: [
|
||||
{
|
||||
subjectId: 'scene',
|
||||
ref: '@SC001',
|
||||
name: '星港中枢',
|
||||
anchors: [{ id: 'anchor', imageUrl: '/storage/anchor.png', fileStatus: 'readable', action: 'revalidate' }],
|
||||
forms: [
|
||||
{
|
||||
id: 'form',
|
||||
name: '基础形态',
|
||||
primaryImages: [
|
||||
{
|
||||
id: 'form-image',
|
||||
imageUrl: '/storage/form.png',
|
||||
fileStatus: 'readable',
|
||||
currentness: { current: false, reason: '母版来源已变化' }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
shots: [
|
||||
{
|
||||
shotId: 'shot',
|
||||
episodeNo: 1,
|
||||
beatNo: 1,
|
||||
shotNo: 1,
|
||||
title: '星港相遇',
|
||||
primaryCount: 1,
|
||||
visionTaskCount: 1,
|
||||
primary: null,
|
||||
candidates: [
|
||||
{
|
||||
id: 'primary',
|
||||
isPrimary: true,
|
||||
status: 'completed',
|
||||
imageUrl: '/storage/primary.png',
|
||||
width: 2048,
|
||||
height: 2048,
|
||||
imageIntegrity: 'matches_review',
|
||||
sourceStatus: 'layout_version_changed',
|
||||
sourceReason: '布局版本已变化',
|
||||
action: 'revalidate',
|
||||
providerInputFingerprint: 'f'.repeat(64),
|
||||
referenceEvidence: [],
|
||||
latestVision: {
|
||||
id: 'old-vision',
|
||||
status: 'completed',
|
||||
passed: true,
|
||||
qualityDecision: 'passed',
|
||||
evidenceComplete: true,
|
||||
historical: true
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
/**
|
||||
* 所有正式路由均隔离模拟;未匹配请求返回 404,不连接真实服务。
|
||||
* @returns Mock 请求、调用记录及可调整状态
|
||||
*/
|
||||
export function createMasterMock() {
|
||||
const calls: Array<{ url: string; method: string; body: Record<string, unknown> }> = []
|
||||
const state = {
|
||||
masters: [
|
||||
sceneMasterFixture(),
|
||||
sceneMasterFixture({ id: 'old', status: 'confirmed', spatialLayoutVersion: 'b'.repeat(64) })
|
||||
],
|
||||
jobs: [] as MasterJob[],
|
||||
visionPassed: false,
|
||||
visionMasterId: '',
|
||||
generationConflict: false,
|
||||
afterPaidConflict: false,
|
||||
generationErrorStatus: 409 as 400 | 409
|
||||
}
|
||||
/**
|
||||
* 隔离正式路由,不调用 Provider。
|
||||
* @param input 请求地址
|
||||
* @param init HTTP 参数
|
||||
* @returns Mock 响应
|
||||
*/
|
||||
const fetcher: typeof fetch = async (input, init) => {
|
||||
const url = new URL(String(input), 'http://localhost')
|
||||
const path = url.pathname
|
||||
const method = init?.method || 'GET'
|
||||
const body = JSON.parse(String(init?.body || '{}')) as Record<string, unknown>
|
||||
calls.push({ url: String(input), method, body })
|
||||
let data: unknown
|
||||
if (path === '/api/generation-models') data = masterCatalog
|
||||
else if (path.endsWith('/creative-profile')) data = { ...masterProfile, projectId: path.split('/')[3] }
|
||||
else if (path.endsWith('/shared-spatial-layouts')) data = [spatialLayoutFixture]
|
||||
else if (path.endsWith('/generation-jobs')) data = state.jobs
|
||||
else if (path.endsWith('/recovery-impact'))
|
||||
data = {
|
||||
...masterImpactFixture,
|
||||
currentMaster:
|
||||
state.masters.find(
|
||||
item => item.status === 'confirmed' && item.spatialLayoutVersion === masterVersion
|
||||
) ?? null
|
||||
}
|
||||
else if (path.endsWith('/confirmed'))
|
||||
data =
|
||||
state.masters.find(
|
||||
item => item.status === 'confirmed' && item.spatialLayoutVersion === masterVersion
|
||||
) ?? null
|
||||
else if (path.endsWith('/generation-preflight'))
|
||||
data = {
|
||||
layoutId: 'layout',
|
||||
layoutVersion: body.expectedVersion,
|
||||
provider: body.providerName,
|
||||
model: 'mock-model',
|
||||
generationOptions: body.generationOptions,
|
||||
prompt: '本次仅修订活动方向,保留星港结构。',
|
||||
references: body.referenceMasterId
|
||||
? [
|
||||
{
|
||||
imageId: body.referenceMasterId,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
providerImageUrl: 'data:image/png;base64,AA==',
|
||||
providerInputResolved: true,
|
||||
role: 'layout-master',
|
||||
sourceLayoutVersion: state.masters.find(item => item.id === body.referenceMasterId)
|
||||
?.spatialLayoutVersion,
|
||||
sha256: 'd'.repeat(64),
|
||||
pixelFingerprint: 'e'.repeat(64),
|
||||
width: 800,
|
||||
height: 800,
|
||||
sourceMasterStatus: state.masters.find(item => item.id === body.referenceMasterId)?.status
|
||||
}
|
||||
]
|
||||
: [],
|
||||
referenceCount: body.referenceMasterId ? 1 : 0,
|
||||
verifiedSceneCount: 2,
|
||||
maxReferenceImages: 10,
|
||||
referenceMasterId: body.referenceMasterId ?? null,
|
||||
revisionInstruction: body.revisionInstruction ?? null,
|
||||
previewFingerprint: 'f'.repeat(64),
|
||||
generationAllowed: false,
|
||||
reason: '免费预检'
|
||||
}
|
||||
else if (path.endsWith('/generate')) {
|
||||
if (state.afterPaidConflict)
|
||||
state.jobs.push({
|
||||
id: 'interrupted-job',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
status: 'interrupted',
|
||||
referenceSnapshot: [],
|
||||
provider: 'mock',
|
||||
model: 'mock-model',
|
||||
prompt: '已提交的原输入',
|
||||
generationOptions: {},
|
||||
imageUrl: null,
|
||||
errorMessage: '保存失败',
|
||||
createdAt: '2026-11-07',
|
||||
updatedAt: '2026-11-07'
|
||||
})
|
||||
if (state.generationConflict || state.afterPaidConflict)
|
||||
return new Response(JSON.stringify({ message: '空间布局版本已变化,请重新预检' }), {
|
||||
status: state.generationErrorStatus
|
||||
})
|
||||
state.masters.unshift(sceneMasterFixture({ id: 'generated' }))
|
||||
state.jobs.push({
|
||||
id: 'job',
|
||||
projectId: 'p',
|
||||
spatialLayoutId: 'layout',
|
||||
spatialLayoutVersion: masterVersion,
|
||||
status: 'completed',
|
||||
referenceSnapshot: [],
|
||||
provider: 'mock',
|
||||
model: 'mock-model',
|
||||
prompt: '本次仅修订活动方向,保留星港结构。',
|
||||
generationOptions: masterProfile.imageOptions,
|
||||
imageUrl: '/storage/mock-master.png',
|
||||
errorMessage: null,
|
||||
createdAt: '2026-11-07',
|
||||
updatedAt: '2026-11-07'
|
||||
})
|
||||
data = { jobId: 'job', masterId: 'generated', imageUrl: '/storage/mock-master.png', status: 'completed' }
|
||||
} else if (path.endsWith('/review'))
|
||||
data = masterReviewFixture(
|
||||
state.masters.find(item => item.id === path.split('/').at(-2))!,
|
||||
state.visionPassed && state.visionMasterId === path.split('/').at(-2)
|
||||
)
|
||||
else if (path.endsWith('/validate')) {
|
||||
state.visionPassed = true
|
||||
state.visionMasterId = path.split('/').at(-2)!
|
||||
data = {
|
||||
masterId: path.split('/').at(-2),
|
||||
layoutId: 'layout',
|
||||
layoutVersion: masterVersion,
|
||||
currentVersion: true,
|
||||
persisted: true,
|
||||
automatedVisionPassed: true,
|
||||
reviewStatus: 'passed',
|
||||
summary: '隔离视觉审核通过'
|
||||
}
|
||||
} else if (path.endsWith('/confirm')) {
|
||||
const master = state.masters.find(item => item.id === path.split('/').at(-2))!
|
||||
Object.assign(master, {
|
||||
status: 'confirmed',
|
||||
evidence: body.evidence,
|
||||
confirmedBy: body.confirmedBy,
|
||||
confirmedAt: '2026-11-07T01:00:00Z'
|
||||
})
|
||||
data = master
|
||||
} else if (path.endsWith('/masters')) data = state.masters
|
||||
else return new Response(JSON.stringify({ message: '隔离测试未匹配请求' }), { status: 404 })
|
||||
return new Response(JSON.stringify({ data }))
|
||||
}
|
||||
return { calls, state, fetcher }
|
||||
}
|
||||
Reference in new issue
Block a user