Files
short-drama-agent-front/tests/features/projects/access.test.ts
T

614 lines
32 KiB
TypeScript

import { preparationApi } from '@/features/storyboard-preparation/api'
import { preparationFixture } from '../storyboard-preparation/fixtures'
import { h } from 'vue'
import { createMemoryHistory, createRouter } from 'vue-router'
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { readFileSync } from 'node:fs'
import App from '@/App.vue'
import ProjectLayout from '@/features/projects/ProjectLayout.vue'
import { isProjectComplete } from '@/features/projects/access'
import { useProjectContext } from '@/features/projects/context'
import { projectsApi } from '@/features/projects/api'
import { workflowExecutionApi } from '@/features/workflows/execution-api'
import { getOperation } from '@/features/workflows/operations'
import type { ProjectDetail, ProjectStageReadiness, ProjectStatus } from '@/features/projects/types'
import { readAllStyles } from '@/testing/styles'
const downstream = ['breakdown', 'visual-style', 'subject-identity', 'subject-images', 'storyboard', 'production']
/**
* 构造服务端完整阶段状态,允许测试单独模拟各步骤的就绪变化。
* @param id 项目编号
* @param ready 所有制作阶段是否就绪
* @returns 项目阶段响应
*/
function readiness(id: string, ready = true): ProjectStageReadiness {
/** 每个阶段独立创建,避免修改某一步时污染其它前置状态。 */
const stage = () => ({ ready, reason: ready ? null : '请先完成剧本创作' })
return {
projectId: id,
script: stage(),
breakdown: stage(),
preparation: stage(),
visualStyle: stage(),
identity: stage(),
subjectAssets: stage(),
storyboard: stage()
}
}
beforeEach(() => {
vi.spyOn(preparationApi, 'approval').mockImplementation(async id => preparationFixture(id).approval)
vi.spyOn(workflowExecutionApi, 'latest').mockResolvedValue(null)
vi.spyOn(projectsApi, 'stageReadiness').mockImplementation(async id => readiness(id))
})
let wrapper: VueWrapper | undefined
afterEach(() => {
wrapper?.unmount()
wrapper = undefined
document.body.innerHTML = ''
localStorage.clear()
vi.useRealTimers()
vi.restoreAllMocks()
})
/**
* 用已有剧集模拟中途生成的项目,完成与否必须取 status 而非数组长度。
* @param id 项目编号
* @param status 项目状态
* @returns 含部分剧集的项目详情
*/
function project(id: string, status: ProjectStatus): ProjectDetail {
return {
id,
status,
durationMode: 'auto',
episodeCount: 1,
targetDurationSeconds: null,
episodeMinSeconds: null,
episodeMaxSeconds: null,
title: '访问限制测试',
topic: '',
style: null,
createdAt: '',
updatedAt: '',
episodes: [{ episode: 1, targetDurationSeconds: null, title: '部分剧集', content: '已经写入的内容' }],
characters: [],
world: null
}
}
/**
* 真实项目布局与侧栏,子工作区以挂载探针代替,防止测试发起实际生成请求。
* @param initialPath 首次访问的项目地址
* @returns 真实路由与工作区挂载记录
*/
async function openProject(initialPath: string) {
const mounted = vi.fn<(path: string) => void>()
const router = createRouter({
history: createMemoryHistory(),
routes: [
{ path: '/assets', component: { render: () => h('div', '资产库') } },
{ path: '/projects', component: { render: () => h('div', '项目列表') } },
{
path: '/projects/:projectId',
component: ProjectLayout,
children: ['create-drama', ...downstream, 'assets', 'unknown-step'].map(path => ({
path,
component: {
setup() {
mounted(path)
/** 测试探针只执行手动项目读取,不发起制作任务。 */
const context = useProjectContext()
return () => [
h('div', { class: 'workspace-probe' }, path),
h('button', { class: 'probe-refresh', onClick: context.refresh }, '手动刷新')
]
}
}
}))
}
]
})
await router.push(initialPath)
wrapper = mount(App, { attachTo: document.body, global: { plugins: [router] } })
await flushPromises()
return { router, mounted }
}
describe('剧本完成前的下游访问限制', () => {
it('正式分镜存在时可读查看,完整生产与素材入口仍保留原门禁', async () => {
const id = 'formal-read-only'
const state = readiness(id, false)
state.script.ready = true
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const fixture = preparationFixture(id)
vi.mocked(preparationApi.approval).mockResolvedValue({
...fixture.approval,
valid: true,
confirmation: fixture.record
})
const { mounted } = await openProject(`/projects/${id}/storyboard`)
expect(mounted).toHaveBeenCalledWith('storyboard')
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
})
it('已知项目资产入口不受制作阶段拦截,未知工作区仍默认锁定', async () => {
const id = 'independent-project-assets'
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(readiness(id, false))
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'generating'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router, mounted } = await openProject(`/projects/${id}/assets`)
expect(mounted).toHaveBeenCalledExactlyOnceWith('assets')
expect(wrapper!.find('.project-access-gate').exists()).toBe(false)
await router.push(`/projects/${id}/unknown-step`)
await flushPromises()
expect(mounted).not.toHaveBeenCalledWith('unknown-step')
expect(wrapper!.find('.project-access-gate').exists()).toBe(true)
})
it('导航使用当前阶段结果,旧待审标记不盖过已审核状态,下游素材仍独立限制', async () => {
const id = 'current-review-navigation'
const state = readiness(id, false)
state.script = { ready: true, reason: null }
state.breakdown = { ready: true, reason: null }
state.preparation = { ready: true, reason: null }
state.storyboard = { ready: true, reason: null }
vi.mocked(projectsApi.stageReadiness).mockImplementation(async () => structuredClone(state))
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([
{
checkpointId: 'old-pending-review',
workflowName: 'breakdown',
createdAt: '2026-10-01T00:00:00Z',
updatedAt: '2026-10-01T00:00:00Z',
state: {}
}
])
const { mounted } = await openProject(`/projects/${id}/visual-style`)
expect(mounted).toHaveBeenCalledExactlyOnceWith('visual-style')
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/visual-style"]`).exists()).toBe(true)
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/subject-identity"]`).exists()).toBe(false)
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
state.breakdown = { ready: false, reason: '当前分镜来源已变化,请重新核对。' }
state.preparation = { ready: false, reason: '当前分镜来源已变化,请重新核对。' }
await wrapper!.get('.probe-refresh').trigger('click')
await flushPromises()
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('当前分镜来源已变化')
})
it('身份请求不使用全局加载消息,完成和失败使用临时消息且不遗留横幅', async () => {
vi.useFakeTimers()
const id = 'identity-message-test'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const operation = getOperation(id)
Object.assign(operation, { pending: false, label: 'AI 生成主体身份', error: '', notice: '旧成功提示' })
const { router } = await openProject(`/projects/${id}/subject-identity`)
expect(wrapper!.text()).not.toContain('旧成功提示')
expect(document.querySelector('.n-message')).toBeNull()
Object.assign(operation, { pending: true, notice: '' })
await flushPromises()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(document.querySelector('.n-message--loading-type')).toBeNull()
await router.replace({ query: { subjectId: 'second-subject' } })
Object.assign(operation, {
pending: false,
notice: '请求已返回,正在重新读取后端状态;最终结果以下方记录为准。'
})
await flushPromises()
expect(document.querySelector('.n-message--success-type')!.textContent).toContain('身份文本已生成并保存')
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(operation.notice).toBe('')
await vi.advanceTimersByTimeAsync(4000)
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
await router.replace({ query: { subjectId: 'third-subject' } })
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
operation.error = '模型不可用,请稍后重试'
await flushPromises()
expect(wrapper!.find('.operation-guide').exists()).toBe(false)
expect(document.querySelector('.n-message--error-type')!.textContent).toContain('模型不可用')
Object.assign(operation, { error: '', notice: '', pending: false })
})
it('图片校验未通过显示警告而非成功,关闭消息后不遗留校验结果块', async () => {
vi.useFakeTimers()
const id = 'identity-warning-test'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
await openProject(`/projects/${id}/subject-identity`)
const operation = getOperation(id)
Object.assign(operation, {
label: '校验林夏身份图片',
noticeType: 'warning',
notice: '林夏的身份图片校验未通过:面部模糊'
})
await flushPromises()
expect(document.querySelector('.n-message--warning-type')!.textContent).toContain('校验未通过:面部模糊')
expect(document.querySelector('.n-message--success-type')).toBeNull()
expect(wrapper!.find('.project-notices').exists()).toBe(false)
expect(operation).toMatchObject({ notice: '', noticeType: null })
await vi.advanceTimersByTimeAsync(9000)
await flushPromises()
expect(document.querySelector('.n-message')).toBeNull()
})
it.each(['breakdown', 'visual-style', 'subject-identity'] as const)(
'%s 首次读取显示骨架,刷新保留已有内容,切换项目完成后仍遵守访问限制',
async section => {
/** 延迟真实查询入口,覆盖初次读取、后台刷新和跨项目读取三个阶段。 */
let resolveDetail!: (value: ProjectDetail) => void
let pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
vi.spyOn(projectsApi, 'detail').mockImplementation(() => pending)
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, id === 'skeleton-first'))
const { router, mounted } = await openProject(`/projects/skeleton-first/${section}`)
const skeleton =
section === 'subject-identity'
? '.subject-identity-skeleton'
: section === 'breakdown'
? '.breakdown-skeleton'
: '.visual-style-skeleton'
expect(wrapper!.get(skeleton).attributes('aria-busy')).toBe('true')
expect(wrapper!.find('.workspace-loading').exists()).toBe(false)
expect(wrapper!.get('.project-title').text()).toBe('')
expect(wrapper!.findAll('.project-header-action-placeholder')).toHaveLength(1)
expect(wrapper!.find('.project-header .n-button').exists()).toBe(false)
expect(mounted).not.toHaveBeenCalled()
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.find('.project-header-action-placeholder').exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe(section)
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await wrapper!.get('.probe-refresh').trigger('click')
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.get('.workspace-probe').text()).toBe(section)
resolveDetail(project('skeleton-first', 'completed'))
await flushPromises()
pending = new Promise<ProjectDetail>(resolve => {
resolveDetail = resolve
})
await router.push(`/projects/skeleton-second/${section}`)
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(true)
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
resolveDetail(project('skeleton-second', 'draft'))
await flushPromises()
expect(wrapper!.find(skeleton).exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
expect(mounted).toHaveBeenCalledExactlyOnceWith(section)
}
)
it('切换图库与其他工作区不自动重复读取项目状态', async () => {
vi.useFakeTimers()
const detail = vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('manual-gallery', 'completed'))
const checkpoints = vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router } = await openProject('/projects/manual-gallery/production')
await router.push('/projects/manual-gallery/subject-images')
await flushPromises()
await vi.advanceTimersByTimeAsync(30_000)
expect(detail).toHaveBeenCalledTimes(1)
expect(checkpoints).toHaveBeenCalledTimes(1)
await router.push('/projects/manual-gallery/production')
await flushPromises()
await vi.advanceTimersByTimeAsync(6000)
expect(detail).toHaveBeenCalledTimes(1)
expect(checkpoints).toHaveBeenCalledTimes(1)
expect(projectsApi.stageReadiness).toHaveBeenCalledTimes(1)
})
it('图库直接链接只读取一次项目,未完成时可手动刷新解锁', async () => {
vi.useFakeTimers()
let status: ProjectStatus = 'generating'
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, status === 'completed'))
const detail = vi.spyOn(projectsApi, 'detail').mockImplementation(async id => project(id, status))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
await openProject('/projects/manual-gate/subject-images')
await vi.advanceTimersByTimeAsync(30_000)
expect(detail).toHaveBeenCalledTimes(1)
expect(wrapper!.get('.project-access-gate').text()).not.toContain('状态会自动更新')
status = 'completed'
const refresh = wrapper!.findAll('button').find(button => button.text() === '刷新项目状态')!
await refresh.trigger('click')
await flushPromises()
expect(detail).toHaveBeenCalledTimes(2)
expect(wrapper!.get('.workspace-probe').text()).toBe('subject-images')
})
it.each(['draft', 'generating', 'need_review', 'failed'] as const)(
'%s 不解锁导航,也不挂载直接链接对应的工作区',
async status => {
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(readiness('unfinished', false))
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('unfinished', status))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router, mounted } = await openProject('/projects/unfinished/production')
for (const path of downstream) {
await router.push(`/projects/unfinished/${path}`)
await flushPromises()
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(wrapper!.find(`.n-menu a[href="/projects/unfinished/${path}"]`).exists()).toBe(false)
}
expect(mounted).not.toHaveBeenCalled()
expect(wrapper!.findAll('.n-menu [aria-disabled="true"]')).toHaveLength(6)
await wrapper!.get('.project-access-gate button').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe('/projects/unfinished/breakdown')
expect(mounted).not.toHaveBeenCalled()
await wrapper!.get('.project-access-gate button').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe('/projects/unfinished/create-drama')
expect(wrapper!.get('.workspace-probe').text()).toBe('create-drama')
expect(mounted).toHaveBeenCalledExactlyOnceWith('create-drama')
}
)
it('手动刷新就绪状态解锁;服务端撤销就绪后撤下下游面板', async () => {
vi.useFakeTimers()
let ready = false
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('manual-refresh', 'completed'))
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, ready))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router, mounted } = await openProject('/projects/manual-refresh/subject-images')
expect(mounted).not.toHaveBeenCalled()
ready = true
await vi.advanceTimersByTimeAsync(30_000)
expect(mounted).not.toHaveBeenCalled()
const refresh = wrapper!.findAll('button').find(button => button.text() === '刷新项目状态')!
await refresh.trigger('click')
await flushPromises()
expect(wrapper!.get('.workspace-probe').text()).toBe('subject-images')
expect(wrapper!.findAll('.n-menu a')).toHaveLength(9)
await router.push('/projects/manual-refresh/production')
await flushPromises()
ready = false
await wrapper!.get('.probe-refresh').trigger('click')
await flushPromises()
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本创作')
expect(wrapper!.findAll('.n-menu a')).toHaveLength(3)
expect(mounted.mock.calls.map(([path]) => path)).toEqual(['subject-images', 'production'])
})
it('切换项目与首次读取期间不能沿用上一个已完成项目的权限', async () => {
let resolveSecond!: (value: ProjectDetail) => void
const pending = new Promise<ProjectDetail>(resolve => {
resolveSecond = resolve
})
vi.spyOn(projectsApi, 'detail').mockImplementation(async id =>
id === 'first' ? project(id, 'completed') : pending
)
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
vi.mocked(projectsApi.stageReadiness).mockImplementation(async id => readiness(id, id === 'first'))
const { router, mounted } = await openProject('/projects/first/production')
expect(wrapper!.findAll('.n-menu a')).toHaveLength(9)
await router.push('/projects/second/production')
await flushPromises()
expect(wrapper!.findAll('.n-menu a')).toHaveLength(3)
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
resolveSecond(project('second', 'draft'))
await flushPromises()
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(mounted).toHaveBeenCalledExactlyOnceWith('production')
await router.push('/projects')
await flushPromises()
expect(wrapper!.findAll('.n-menu a')).toHaveLength(2)
})
it('读取失败时禁用项目操作;重试成功后恢复入口和正文', async () => {
const detail = vi
.spyOn(projectsApi, 'detail')
.mockRejectedValueOnce(new Error('项目读取失败'))
.mockResolvedValue(project('retry', 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { mounted } = await openProject('/projects/retry/storyboard')
expect(mounted).not.toHaveBeenCalled()
expect(wrapper!.findAll('.n-menu a')).toHaveLength(3)
const menu = wrapper!.get('.project-header button[aria-label="项目操作"]')
expect(menu.attributes('disabled')).toBeDefined()
expect(wrapper!.find('.project-header .n-tag').exists()).toBe(false)
await wrapper!.get('.project-notices button').trigger('click')
await flushPromises()
expect(detail).toHaveBeenCalledTimes(2)
expect(wrapper!.get('.project-header button[aria-label="项目操作"]').attributes('disabled')).toBeUndefined()
expect(mounted).toHaveBeenCalledExactlyOnceWith('storyboard')
})
it('自动检查已就绪但整体审核待完成时可先进入风格准备,镜头制作仍保持限制', async () => {
const id = 'prepare-before-approval'
const state = {
...readiness(id),
preparation: { ready: true, reason: null },
breakdown: { ready: false, reason: '整体审核待完成' }
}
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { mounted } = await openProject(`/projects/${id}/visual-style`)
expect(mounted).toHaveBeenCalledExactlyOnceWith('visual-style')
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/visual-style"]`).exists()).toBe(true)
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
})
it('采用正式分镜后,导航与直达路由使用当前项目的素材准入,仍保留制作门禁', async () => {
const id = 'adopted-preparation'
const state = readiness(id)
state.breakdown = { ready: false, reason: '正式分镜尚未完成人工审核' }
state.subjectAssets = { ready: false, reason: '主体图片仍需准备' }
vi.mocked(projectsApi.stageReadiness).mockImplementation(async projectId =>
projectId === id ? state : readiness(id)
)
vi.spyOn(projectsApi, 'detail').mockImplementation(async projectId => project(projectId, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([
{
checkpointId: 'adopted',
workflowName: 'breakdown',
createdAt: '2026-10-01T10:00:00Z',
updatedAt: '2026-10-01T10:00:00Z',
state: { workflowExecution: { status: 'failed' } }
}
])
const { router, mounted } = await openProject(`/projects/${id}/breakdown`)
for (const section of ['visual-style', 'subject-identity', 'subject-images']) {
await wrapper!.get(`.n-menu a[href="/projects/${id}/${section}"]`).trigger('click')
await flushPromises()
expect(wrapper!.get('.workspace-probe').text()).toBe(section)
}
await router.push(`/projects/${id}/production`)
await flushPromises()
expect(wrapper!.get('.project-access-gate').text()).toContain('正式分镜尚未完成人工审核')
const disabledMenu = wrapper!.get(
'.n-menu [aria-disabled="true"][aria-label="镜头生产,正式分镜尚未完成人工审核"]'
)
expect(disabledMenu.text()).toBe('镜头生产')
await router.push('/projects/other-project/subject-identity')
await flushPromises()
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(wrapper!.find('.n-menu a[href="/projects/other-project/subject-identity"]').exists()).toBe(false)
expect(mounted.mock.calls.flat()).toEqual(['breakdown', 'visual-style', 'subject-identity', 'subject-images'])
})
it('候选未采用时,不以镜头存在推定素材准备通过', async () => {
const id = 'candidate-without-adoption'
const state = readiness(id)
state.preparation = { ready: false, reason: '请先采用当前候选分镜' }
state.breakdown = { ready: false, reason: '尚无正式分镜' }
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([
{
checkpointId: 'unadopted',
workflowName: 'breakdown',
createdAt: '2026-10-01T10:00:00Z',
updatedAt: '2026-10-01T10:00:00Z',
state: {}
}
])
const { mounted } = await openProject(`/projects/${id}/subject-identity`)
expect(mounted).not.toHaveBeenCalled()
expect(wrapper!.get('.project-access-gate').text()).toContain('请先采用当前候选分镜')
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/subject-identity"]`).exists()).toBe(false)
})
it('部分身份未齐备时允许核对已准备分镜,项目制作仍受限', async () => {
const id = 'partial-asset-preparation'
const state = readiness(id)
state.identity = { ready: false, reason: '还有角色尚未确认选角' }
state.subjectAssets = { ready: false, reason: '素材尚未准备完整' }
state.breakdown = { ready: false, reason: '整体审核待完成' }
vi.mocked(projectsApi.stageReadiness).mockResolvedValue(state)
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(id, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { mounted } = await openProject(`/projects/${id}/subject-images`)
expect(mounted).toHaveBeenCalledExactlyOnceWith('subject-images')
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/subject-images"]`).exists()).toBe(true)
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/storyboard"]`).exists()).toBe(true)
expect(wrapper!.find(`.n-menu a[href="/projects/${id}/production"]`).exists()).toBe(false)
})
it('剧本完成仍按服务端前置步骤逐步解锁,不能直接进入生产', async () => {
const state = readiness('staged', false)
state.script = { ready: true, reason: null }
state.breakdown.reason = '请先完成剧本拆解'
vi.mocked(projectsApi.stageReadiness).mockImplementation(async () => structuredClone(state))
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project('staged', 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router, mounted } = await openProject('/projects/staged/production')
expect(mounted).not.toHaveBeenCalled()
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成剧本拆解')
expect(wrapper!.find('.n-menu a[href="/projects/staged/breakdown"]').exists()).toBe(true)
expect(wrapper!.find('.n-menu a[href="/projects/staged/visual-style"]').exists()).toBe(false)
await wrapper!.get('.project-access-gate button').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe('/projects/staged/breakdown')
state.breakdown = { ready: true, reason: null }
state.preparation = { ready: true, reason: null }
state.subjectAssets = { ready: true, reason: null }
state.storyboard = { ready: false, reason: '请先完成分镜设计' }
await wrapper!.get('.probe-refresh').trigger('click')
await flushPromises()
await router.push('/projects/staged/production')
await flushPromises()
expect(wrapper!.find('.workspace-probe').exists()).toBe(false)
expect(wrapper!.get('.project-access-gate').text()).toContain('请先完成分镜设计')
await wrapper!.get('.project-access-gate button').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe('/projects/staged/storyboard')
expect(wrapper!.get('.workspace-probe').text()).toBe('storyboard')
})
it('不存在、未知状态或项目 ID 不匹配时默认锁定', () => {
expect(isProjectComplete(null, 'p')).toBe(false)
expect(isProjectComplete({ id: 'other', status: 'completed' }, 'p')).toBe(false)
expect(isProjectComplete({ id: 'p', status: 'unknown' as ProjectStatus }, 'p')).toBe(false)
expect(isProjectComplete({ id: 'p', status: 'completed' }, 'p')).toBe(true)
})
it('镜头提示词缺少主首帧时给出下一步,并定位到对应镜头的首帧生成', async () => {
const projectId = 'guided-keyframe'
vi.spyOn(projectsApi, 'detail').mockResolvedValue(project(projectId, 'completed'))
vi.spyOn(projectsApi, 'checkpointSummaries').mockResolvedValue([])
const { router } = await openProject(`/projects/${projectId}/storyboard`)
Object.assign(getOperation(projectId), {
pending: false,
label: '读取/生成镜头 3 提示词',
error: '服务器内部错误 Shot 缺少可用于视频 0 秒起点校验的 Primary Keyframe: shot-db-2-3',
notice: '',
recovery: { target: 'keyframe', shotId: 'shot-db-2-3', episodeNo: 2 }
})
await flushPromises()
/** 操作失败改为临时消息,但保留直接定位首帧生成的恢复入口。 */
const message = new DOMWrapper(document.querySelector('.n-message')!)
expect(wrapper!.find('.operation-guide').exists()).toBe(false)
expect(message.text()).toContain('还没有可用首帧,请先生成并确认首帧。')
expect(message.get('button').text()).toBe('先生成主首帧')
await message.get('button').trigger('click')
await flushPromises()
expect(router.currentRoute.value.path).toBe(`/projects/${projectId}/production`)
expect(router.currentRoute.value.query).toEqual({
episodeNo: '2',
shotId: 'shot-db-2-3',
action: 'keyframe'
})
})
it('配置复选框居中对齐,输入表面随面板背景分层而非增加边框', () => {
// 保护布局契约;实际像素对齐仍需浏览器视觉验收。
const css = readAllStyles()
expect(css).toMatch(
/\.n-checkbox\.control-row-checkbox\s*\{[^}]*align-items:\s*center;[^}]*min-height:\s*34px;[^}]*padding-block:\s*0/
)
expect(css).toMatch(/\.app-dialog\s*\{[^}]*--app-field:\s*var\(--app-control\)/)
expect(readFileSync('src/styles/styles.css', 'utf8')).toMatch(
/\.panel\s*\{[^}]*--app-field:\s*var\(--app-control\)/
)
for (const path of [
'production/ProductionPage.vue',
'storyboard/StoryboardPage.vue',
'subject-identity/SubjectIdentityPage.vue',
'subject-images/SubjectImagesPage.vue'
]) {
const source = readFileSync(`src/features/${path}`, 'utf8')
expect(source).toContain('control-row-checkbox')
expect(source).not.toMatch(/<NCheckbox\b[^>]*class="[^"]*pb-[23]/)
}
})
})