feat(short-drama-agent-front): 接入连续性状态签收与联合审核
This commit is contained in:
1 parent
0d58dd8c53
commit
10e008ca10
21 files changed
+1319
-25
No files matched your search
@@ -0,0 +1,157 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount, flushPromises, type VueWrapper } from '@vue/test-utils'
|
||||
import { NInput, NInputNumber, NCheckbox } from 'naive-ui'
|
||||
import Joint from '@/features/production/components/ContinuityJointReview.vue'
|
||||
import { jointApi } from '@/features/production/continuity-joint'
|
||||
import { validStateChecks, type StateCheck } from '@/features/production/continuity-state'
|
||||
import { jointPlan, jointTask, stateContexts } from '../../fixtures/continuity-joint'
|
||||
import { diagnosisFixture } from '../../fixtures/continuity'
|
||||
vi.mock('@/features/workflows/execution', () => ({
|
||||
useWorkflowExecution: () => ({
|
||||
query: { data: { value: null }, loading: { value: false }, error: { value: '' }, refresh: vi.fn<() => void>() },
|
||||
track: vi.fn<() => void>()
|
||||
})
|
||||
}))
|
||||
/** 当前隔离组件。 */
|
||||
let wrapper: VueWrapper | undefined
|
||||
afterEach(() => {
|
||||
wrapper?.unmount()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
/**
|
||||
* 挂载真实联合表单,所有服务隔离。
|
||||
* @param status 计划状态
|
||||
* @returns 组件
|
||||
*/
|
||||
async function open(status: 'ready' | 'blocked' | 'reusable' = 'ready') {
|
||||
vi.spyOn(jointApi, 'preview').mockResolvedValue({
|
||||
...jointPlan,
|
||||
status,
|
||||
executionAvailable: status === 'ready',
|
||||
reusableTaskId: status === 'reusable' ? 't' : null
|
||||
})
|
||||
vi.spyOn(jointApi, 'task').mockResolvedValue(jointTask)
|
||||
wrapper = mount(Joint, {
|
||||
props: {
|
||||
projectId: 'p',
|
||||
disabled: false,
|
||||
review: {
|
||||
reviewId: 'r',
|
||||
reviewer: '审核人',
|
||||
reviewedAt: '',
|
||||
status: 'passed',
|
||||
invalidation: null,
|
||||
diagnosis: diagnosisFixture({ shotIds: ['s1', 's2'], sceneFormId: 'f' })
|
||||
}
|
||||
}
|
||||
})
|
||||
await wrapper.find('button').trigger('click')
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
describe('联合审核单次批准和业务状态', () => {
|
||||
it.each(['ready', 'blocked', 'reusable'] as const)('%s 免费计划不自动批准执行', async status => {
|
||||
const auth = vi.spyOn(jointApi, 'authorize')
|
||||
const execute = vi.spyOn(jointApi, 'execute')
|
||||
const w = await open(status)
|
||||
expect(w.text()).toContain('未知')
|
||||
expect(w.text()).toContain('空间参考')
|
||||
expect(w.text()).toContain('s1')
|
||||
expect(w.text()).toContain('s2')
|
||||
expect(auth).not.toHaveBeenCalled()
|
||||
expect(execute).not.toHaveBeenCalled()
|
||||
expect((w.vm as unknown as { canExecute: boolean }).canExecute).toBeFalsy()
|
||||
expect(w.text()).not.toContain('联合任务:通过')
|
||||
expect(w.text().includes('联合任务:未通过')).toBe(status === 'reusable')
|
||||
})
|
||||
it('明确批准当前总指纹后仍须单独执行确认', async () => {
|
||||
const w = await open()
|
||||
const auth = vi
|
||||
.spyOn(jointApi, 'authorize')
|
||||
.mockResolvedValue({ authorizationId: 'auth', planFingerprint: jointPlan.fingerprint })
|
||||
const execute = vi
|
||||
.spyOn(jointApi, 'execute')
|
||||
.mockResolvedValue({ validationTaskId: 't', executionId: 'e', status: 'completed', reused: false })
|
||||
w.findAllComponents(NInput).forEach((input, i) =>
|
||||
input.vm.$emit('update:value', ['批准人', '操作人', 'b'.repeat(64)][i])
|
||||
)
|
||||
w.findAllComponents(NInputNumber).forEach((input, i) => input.vm.$emit('update:value', i))
|
||||
await flushPromises()
|
||||
w.findComponent(NCheckbox).vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
const vm = w.vm as unknown as {
|
||||
authorize: () => Promise<void>
|
||||
canExecute: boolean
|
||||
execute: () => Promise<void>
|
||||
}
|
||||
await vm.authorize()
|
||||
expect(auth.mock.calls[0]?.[2].plan).toEqual({
|
||||
purpose: 'continuity',
|
||||
reviewId: 'r',
|
||||
fingerprint: jointPlan.fingerprint
|
||||
})
|
||||
expect(vm.canExecute).toBe(false)
|
||||
expect(execute).not.toHaveBeenCalled()
|
||||
w.findAllComponents(NCheckbox).at(-1)!.vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
await vm.execute()
|
||||
await flushPromises()
|
||||
expect(execute).toHaveBeenCalledExactlyOnceWith('p', 'r', 'auth')
|
||||
expect(w.text()).toContain('联合任务:未通过')
|
||||
})
|
||||
})
|
||||
it('状态范围只接受相邻正式主体、原依据和完整人工意见,保留 null', () => {
|
||||
const check: StateCheck = {
|
||||
fromShotId: 's1',
|
||||
toShotId: 's2',
|
||||
subjectRef: '@CH1',
|
||||
dimension: 'gaze',
|
||||
before: null,
|
||||
after: '向前',
|
||||
verdict: 'unknown',
|
||||
sourceIds: ['s1-state'],
|
||||
evidence: '前镜视线无法辨认'
|
||||
}
|
||||
expect(validStateChecks([check], stateContexts)).toBe(true)
|
||||
expect(validStateChecks([{ ...check, verdict: null }], stateContexts)).toBe(false)
|
||||
expect(validStateChecks([{ ...check, sourceIds: ['伪造'] }], stateContexts)).toBe(false)
|
||||
expect(validStateChecks([{ ...check, subjectRef: '@CH2' }], stateContexts)).toBe(false)
|
||||
expect(validStateChecks([check, check], stateContexts)).toBe(false)
|
||||
})
|
||||
|
||||
it('恢复仅使用服务端证明的原任务和原指纹,另行确认且不新授权', async () => {
|
||||
const w = await open('reusable')
|
||||
vi.mocked(jointApi.task).mockResolvedValue({
|
||||
...jointTask,
|
||||
taskStatus: 'failed',
|
||||
workflowStatus: 'failed',
|
||||
resumeAvailable: true
|
||||
})
|
||||
const refresh = w.findAll('button').find(b => b.text() === '只读刷新原联合任务')!
|
||||
await refresh.trigger('click')
|
||||
await flushPromises()
|
||||
const auth = vi.spyOn(jointApi, 'authorize')
|
||||
const resume = vi.spyOn(jointApi, 'resume').mockResolvedValue({ validationTaskId: 't', executionId: 'e' })
|
||||
const vm = w.vm as unknown as { canResume: boolean; resume: () => Promise<void> }
|
||||
expect(vm.canResume).toBe(false)
|
||||
w.findAllComponents(NCheckbox).at(-1)!.vm.$emit('update:checked', true)
|
||||
await flushPromises()
|
||||
expect(vm.canResume).toBe(true)
|
||||
expect(w.text()).toContain('免费解析原回执')
|
||||
await vm.resume()
|
||||
expect(resume).toHaveBeenCalledExactlyOnceWith('p', 't', jointPlan.fingerprint)
|
||||
expect(auth).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('旧计划刷新失败后撤销批准,不自动重试或调用收费接口', async () => {
|
||||
const w = await open()
|
||||
const auth = vi.spyOn(jointApi, 'authorize')
|
||||
const execute = vi.spyOn(jointApi, 'execute')
|
||||
vi.mocked(jointApi.preview).mockRejectedValueOnce(new Error('CONTINUITY_VISION_PLAN_STALE: 来源变化'))
|
||||
await w.find('button').trigger('click')
|
||||
await flushPromises()
|
||||
expect(jointApi.preview).toHaveBeenLastCalledWith('p', 'r', jointPlan.fingerprint, expect.any(AbortSignal))
|
||||
expect((w.vm as unknown as { canAuthorize: boolean }).canAuthorize).toBeFalsy()
|
||||
expect(auth).not.toHaveBeenCalled()
|
||||
expect(execute).not.toHaveBeenCalled()
|
||||
})
|
||||
Reference in new issue
Block a user