Files

264 lines
13 KiB
TypeScript

import { flushPromises, mount } from '@vue/test-utils'
import { describe, expect, it, vi } from 'vitest'
import ModelCapabilities from '@/features/production/components/ModelCapabilities.vue'
import KeyframePreviewChecks from '@/features/production/components/KeyframePreviewChecks.vue'
import KeyframeCard from '@/features/production/components/KeyframeCard.vue'
import KeyframeValidationHistory from '@/features/production/components/KeyframeValidationHistory.vue'
import { additionalImageFixture } from '../../fixtures/image-additional'
import { AssetImage } from '@/components/ui'
import { keyframeFixture } from '@/features/production/testing/fixtures'
import { keyframeDisplayNames } from '@/features/production/model'
import { imagePreviewFixture } from '../../fixtures/image-preview'
describe('V8-10免费输入与独立门禁', () => {
it('图片名称按原创建时间编号,倒序与主图切换仍使用相同名称', () => {
const old = keyframeFixture({ id: 'old', createdAt: '2026-11-01T00:00:00Z', isPrimary: false }),
recent = keyframeFixture({ id: 'recent', createdAt: '2026-11-02T00:00:00Z', isPrimary: true })
const names = keyframeDisplayNames([recent, old], '午后收整工具', 1)
expect(names.get('old')).toBe('午后收整工具 · 图片 01')
expect(names.get('recent')).toBe('午后收整工具 · 图片 02')
expect(
keyframeDisplayNames(
[
{ ...old, isPrimary: true },
{ ...recent, isPrimary: false }
],
'午后收整工具',
1
)
).toEqual(names)
})
it('旧图片按需查看原费用与来源,切换项目/候选后不混入其它记录或未执行计划', async () => {
const fetcher = vi.fn<typeof fetch>(async url => {
const path = String(url)
if (path.endsWith('/image-authorizations')) {
const projectId = path.includes('/second-project/') ? 'second-project' : 'original-project',
list = additionalImageFixture(projectId)
list.requests[0]!.input.targetId = 'history-shot'
list.requests[0]!.input.model = '原图片实际型号'
list.requests[0]!.input.candidateId = projectId === 'second-project' ? 'second-image' : 'old-image'
list.requests.push({
...structuredClone(list.requests[0]!),
id: 'another-candidate-request',
input: { ...list.requests[0]!.input, candidateId: 'unrelated-image', model: '其它图片的型号' }
})
return Response.json({ data: list })
}
return Response.json({
data: path.includes('/quality-review')
? {
shotId: 'history-shot',
keyframeId: 'old-image',
qualityDecision: 'failed',
effectiveQualityStatus: 'stale',
validationTaskId: null,
historicalGazePreview: [],
manualReview: null,
manualReviewAvailable: false
}
: []
})
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(KeyframeValidationHistory, {
props: {
projectId: 'original-project',
shotId: 'history-shot',
keyframeId: 'old-image',
initialOpen: true,
disabled: true
}
})
try {
await flushPromises()
expect(fetcher.mock.calls.some(([url]) => String(url).endsWith('/image-authorizations'))).toBe(false)
await wrapper
.findAll('.n-collapse-item__header-main')
.find(row => row.text() === '原图片生成来源与费用')!
.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('原预留 USD 0.5')
expect(wrapper.text()).toContain('原图片实际型号')
expect(wrapper.text()).not.toContain('其它图片的型号')
expect(wrapper.findAll('[aria-label="原图片生成记录"]')).toHaveLength(1)
expect(wrapper.text()).toContain('实际账单 未知')
expect(wrapper.text()).toContain('历史审核未通过,当前来源已变化')
expect(wrapper.text()).not.toContain('another-candidate-request')
await wrapper.setProps({ projectId: 'second-project', keyframeId: 'second-image' })
await flushPromises()
expect(wrapper.text()).not.toContain('原预留 USD 0.5')
await wrapper
.findAll('.n-collapse-item__header-main')
.find(row => row.text() === '原图片生成来源与费用')!
.trigger('click')
await flushPromises()
expect(
fetcher.mock.calls.some(([url]) => String(url) === '/api/projects/second-project/image-authorizations')
).toBe(true)
expect(fetcher.mock.calls.every(([, init]) => !init?.method || init.method === 'GET')).toBe(true)
} finally {
wrapper.unmount()
}
})
it.each(['failed', 'passed'] as const)(
'保留原机器%s、当前stale及已有Primary图,不允许旧通过晋升',
async machine => {
const fetcher = vi.fn<typeof fetch>(async url =>
Response.json({
data: String(url).includes('/quality-review')
? {
shotId: 'quality-shot',
keyframeId: 'old-image',
qualityDecision: machine,
effectiveQualityStatus: 'stale',
validationTaskId: 'original-machine-task',
manualReviewAvailable: false,
historicalGazePreview: [],
manualReview: null
}
: []
})
)
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(KeyframeCard, {
props: {
item: keyframeFixture({
id: 'old-image',
shotId: 'quality-shot',
isPrimary: true,
imageUrl: '/mock.png',
model: '仅供详情核对的原型号',
error: '这份很长的历史错误只应在详情中展示'
}),
projectId: 'quality-project',
shotId: 'quality-shot',
shotNo: 1,
stale: false,
blocked: true,
validationPassed: true,
confirming: false,
readonly: true,
displayName: '午后收整工具 · 图片 01'
},
global: { stubs: { teleport: true } }
})
try {
await flushPromises()
expect(wrapper.get('.keyframe-card-name').text()).toBe('午后收整工具 · 图片 01')
expect(wrapper.text()).not.toContain('这份很长的历史错误')
expect(wrapper.text()).not.toContain('仅供详情核对的原型号')
expect(wrapper.text()).toContain('审核来源过期')
await wrapper.get('button[aria-label="查看首帧详情"]').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('这份很长的历史错误只应在详情中展示')
expect(wrapper.text()).toContain('仅供详情核对的原型号')
expect(wrapper.text()).toContain(
machine === 'failed' ? '历史审核未通过,当前来源已变化' : '历史审核通过,当前来源已变化'
)
expect(wrapper.text()).toContain('主首帧')
expect(wrapper.getComponent(AssetImage).props('src')).toBe('/mock.png')
expect(wrapper.text()).not.toContain('质量通过')
expect(wrapper.text()).not.toContain('设为主首帧')
expect(wrapper.findAll('button').some(row => row.attributes('aria-label') === '质量检查')).toBe(false)
expect(fetcher.mock.calls.every(([, input]) => !input?.method || input.method === 'GET')).toBe(true)
} finally {
wrapper.unmount()
}
}
)
it('同一Provider再次检查容量409时清除旧成功记录,保留实际阻断与模型限制', async () => {
let blocked = false
const fetcher = vi.fn<typeof fetch>(async url => {
if (String(url).endsWith('/image-providers/capabilities'))
return Response.json({
data: [
{
provider: 'test-provider',
active: true,
capabilities: { references: { supported: true, maxReferenceImages: 3 } }
}
]
})
return blocked
? Response.json(
{
code: 'IMAGE_REFERENCE_CAPACITY_EXCEEDED',
message: '必需参考实际需要6张,当前Provider限制3张',
details: { code: 'IMAGE_REFERENCE_CAPACITY_EXCEEDED' }
},
{ status: 409 }
)
: Response.json({
data: {
provider: 'test-provider',
valid: true,
referenceCount: 7,
maxReferenceImages: 3,
plannedReferenceCount: 3,
omittedReferenceCount: 4,
requiresPlanning: true,
strategy: 'all'
}
})
})
vi.stubGlobal('fetch', fetcher)
const wrapper = mount(ModelCapabilities, { props: { shotId: 'capacity-shot', provider: 'test-provider' } })
try {
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('本次计划输入 3 张')
blocked = true
await wrapper.get('button').trigger('click')
await flushPromises()
expect(wrapper.text()).toContain('必需参考实际需要6张')
expect(wrapper.text()).toContain('最多 3 张参考图')
expect(wrapper.text()).not.toContain('本次计划输入 3 张')
expect(wrapper.get('button').attributes('disabled')).toBeUndefined()
expect(fetcher.mock.calls.every(([, input]) => !input?.method || input.method === 'GET')).toBe(true)
} finally {
wrapper.unmount()
}
})
it('已确认规划只解释场景衔接,真实视频末态仍未验证且其它阻断继续展示', () => {
const base = imagePreviewFixture()
const wrapper = mount(KeyframePreviewChecks, {
props: {
preview: {
...base,
generationConfig: { options: {} },
continuity: {
previousShotId: 'previous',
sameScene: true,
previousClosingState: null,
subjects: [],
reviewIssues: [{ code: 'character_form_transition_unconfirmed', subjectRef: '@CH0001' }],
sceneTransition: {
previousShotId: 'previous',
subjectRef: '@SC0001',
subjectFormId: 'form',
basis: 'confirmed_plan',
fingerprint: 'a'.repeat(64),
requestFingerprint: 'b'.repeat(64),
verifiedVideoEndState: false
}
},
specConsistencySummary: {
blocking: true,
warningCount: 0,
hasWarnings: false,
requiresManualReview: true
}
}
}
})
try {
expect(wrapper.text()).toContain('人工规划衔接已确认,视频末态尚未验证')
expect(wrapper.text()).toContain('暂不能生成')
expect(wrapper.text()).toContain('角色形态变化待确认')
expect(wrapper.text()).not.toContain('质量通过')
} finally {
wrapper.unmount()
}
})
})