feat(short-drama-agent-front): 接入连续性状态签收与联合审核

This commit is contained in:
GJ committed 2026-11-09 14:40:12 +08:00
1 parent 0d58dd8c53
commit 10e008ca10
21 files changed
+1319 -25

No files matched your search

+12
View File
@@ -0,0 +1,12 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>连续性审核隔离验收</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="./v02-continuity.ts"></script>
</body>
</html>
+91
View File
@@ -0,0 +1,91 @@
import { createApp, defineComponent, h, ref } from 'vue'
import { NButton, NConfigProvider, NMessageProvider, zhCN, dateZhCN } from 'naive-ui'
import Drawer from '../../src/features/production/components/ContinuityReviewDrawer.vue'
import { createContinuityMock, continuityShots, diagnosisFixture } from '../fixtures/continuity'
import { jointPlan, jointTask, stateContexts } from '../fixtures/continuity-joint'
import '../../src/styles/styles.css'
import '../../src/styles/admin.css'
/** 全部服务隔离,不向真实 API 发写请求。 */
const mock = createContinuityMock('http://localhost:4312/tests/browser/candidate.svg')
/** 当前隔离计划状态。 */
const planStatus = ref<'ready' | 'blocked' | 'reusable'>('ready')
/** 当前隔离签收。 */
const review = {
reviewId: 'mock-review',
reviewer: '隔离审核人',
reviewedAt: '',
status: 'passed',
invalidation: null,
diagnosis: diagnosisFixture(
{ shotIds: ['s1', 's2'], sceneFormId: 'scene-form' },
'http://localhost:4312/tests/browser/candidate.svg'
)
}
/**
* 只允许免费诊断和只读回读,批准、签收、执行及恢复全部拒绝。
* @param input 请求地址
* @param init 请求选项
* @returns 隔离响应
*/
window.fetch = async (input, init) => {
const path = String(input)
if (init?.method && init.method !== 'GET' && !path.endsWith('/continuity/diagnosis'))
return new Response(JSON.stringify({ message: '隔离页禁止写入与付费' }), { status: 403 })
let data: unknown
if (path.includes('/vision/preview'))
data = {
...jointPlan,
projectId: 'mock-project',
reviewId: 'mock-review',
status: planStatus.value,
executionAvailable: planStatus.value === 'ready',
reusableTaskId: planStatus.value === 'reusable' ? 't' : null
}
else if (path.includes('/vision-tasks/')) data = { ...jointTask, reviewId: 'mock-review' }
else if (path.endsWith('/reviews/mock-review')) data = review
else if (path.includes('/workflow-executions/')) data = null
else if (path.endsWith('/continuity/diagnosis')) {
const response = await mock.fetcher(input, init)
const body = await response.json()
if (JSON.parse(String(init?.body)).scope) body.data.stateContext = stateContexts
return new Response(JSON.stringify(body))
} else return mock.fetcher(input, init)
return new Response(JSON.stringify({ data }))
}
/** 可复用现有抽屉的隔离浏览器入口。 */
const Preview = defineComponent({
setup() {
/** 当前抽屉。 */ const open = ref(false)
return () =>
h('main', { style: 'padding:24px' }, [
h('h1', 'V02 连续性隔离验收:批准、执行、保存均禁止'),
...(['ready', 'blocked', 'reusable'] as const).map(value =>
h(
NButton,
{
onClick: () => {
planStatus.value = value
open.value = true
}
},
() => value
)
),
h(Drawer, {
open: open.value,
'onUpdate:open': (v: boolean) => (open.value = v),
projectId: 'mock-project',
shots: continuityShots,
disabled: false
})
])
}
})
createApp({
render: () =>
h(
NConfigProvider,
{ locale: zhCN, dateLocale: dateZhCN },
{ default: () => h(NMessageProvider, null, { default: () => h(Preview) }) }
)
}).mount('#app')
@@ -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()
})
+73
View File
@@ -0,0 +1,73 @@
import type { JointPlan, JointTask } from '../../src/features/production/continuity-joint'
import type { StateContext } from '../../src/features/production/continuity-state'
/** 联合审核隔离计划,不包含真实收费批准。 */
export const jointPlan: JointPlan = {
projectId: 'p',
reviewId: 'r',
fingerprint: 'a'.repeat(64),
model: '隔离模型',
status: 'ready',
executionAvailable: true,
requiresExplicitApproval: true,
paidCalls: 0,
proposedMaximumProviderRequests: 1,
additionalProviderRequests: 1,
feeEstimate: { currency: 'CNY', amount: null, reason: '待估算' },
capability: { verified: true, reason: '隔离核验' },
latestTask: null,
reusableTaskId: null,
imageManifest: [
{
imageNumber: 1,
label: '首帧',
pixels: { sha256: 'b'.repeat(64), width: 1024, height: 1024 },
bindings: [{ shotId: 's1', imageId: 'i1', role: 'frame' }]
},
{
imageNumber: 2,
label: '合并空间图',
pixels: { sha256: 'c'.repeat(64), width: 1024, height: 1024 },
bindings: [
{ shotId: 's1', imageId: 'layout', role: 'spatial_reference' },
{ shotId: 's2', imageId: 'layout', role: 'spatial_reference' }
]
}
],
request: { messages: [{ role: 'user', content: '正式状态与动作依据' }] }
}
/** 已完成但业务失败的原任务。 */
export const jointTask: JointTask = {
validationTaskId: 't',
executionId: 'e',
reviewId: 'r',
taskStatus: 'completed',
workflowStatus: 'completed',
status: 'failed',
current: true,
planFingerprint: jointPlan.fingerprint,
resumeAvailable: false,
requiresNewProviderRequest: false,
retryAutomatically: false,
diagnosis: { status: 'failed' },
machineObservation: { summary: '原机器观察' },
summary: '结构冲突',
feeScope: { currency: 'CNY', estimatedMin: 0, estimatedMax: 1, maxRequests: 1 },
step: { name: 'general', status: 'completed' }
}
/** 正式相邻两镜人工状态依据。 */
export const stateContexts: StateContext[] = ['s1', 's2'].map(shotId => ({
shotId,
generation: { subjects: [{ subjectRef: '@CH1', gaze: shotId === 's1' ? '向左' : '向前' }] },
requiredActions: [{ id: 'A1', description: '观察', kind: 'action', mustPerformInShot: true }],
sources: [
{
id: shotId + '-state',
shotId,
kind: 'visual_state',
subjectRef: '@CH1',
field: 'gaze',
text: '当前正式视线',
executable: false
}
]
}))