feat(short-drama-agent-front): 接入人工动作修订与视频版本权限

This commit is contained in:
GJ committed 2026-10-14 13:44:02 +08:00
1 parent 7a60db3ced
commit fa76165960
38 files changed
+2003 -158

No files matched your search

@@ -62,7 +62,7 @@ const record = (workflowName: string, day: number, status: 'running' | 'complete
})
describe('精简公开资产回归', () => {
it('无内部字段的视频可播放,未知质量不得直接晋升;真实校验结果按项目隔离', async () => {
it('无内部字段的视频可播放,晋升使用后端权限,会话通过不能授权', async () => {
const projectId = 'public-video-contract'
const video = videoFixture({ isPrimary: false })
expect(video).not.toHaveProperty('rawJson')
@@ -104,7 +104,7 @@ describe('精简公开资产回归', () => {
await flushPromises()
expect(
[...document.querySelectorAll('button')].some(button => button.textContent?.trim() === '设为主视频')
).toBe(true)
).toBe(false)
expect(sessionVideoValidation('other-project', shot.shotId, video.id)).toBeNull()
session.videoValidation = { ...validation, passed: false }
await flushPromises()
+19 -1
View File
@@ -1,3 +1,4 @@
import { ApiError } from '@/lib/http'
import { defineComponent, reactive, ref } from 'vue'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { afterEach, describe, expect, it, vi } from 'vitest'
@@ -542,11 +543,27 @@ describe('质量面板渐进展示', () => {
})
describe('视频修复候选与复检晋升', () => {
it('只允许校验未通过的视频创建一个候选,不自动再次校验', async () => {
it('视频修复遇到同步版本冲突后撤销本会话旧资格并刷新', async () => {
const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
data.video.canRepair = true
data.validation.passed = false
await data.service.run('validate', input())
expect(sessionVideoValidation(data.projectId, 'shot-1', 'video-1')?.passed).toBe(false)
vi.spyOn(qualityApi, 'repairVideo').mockRejectedValueOnce(
new ApiError('动作版本已过期', 409, { currentMotionPlanRevisionId: 'r2' }, 'MOTION_PLAN_STALE')
)
await data.service.run('repair', input({ maxRepairAttempts: 2 }))
expect(sessionVideoValidation(data.projectId, 'shot-1', 'video-1')).toBeNull()
expect(data.service.session.value.error).toContain('动作版本已过期')
expect(qualityApi.repairVideo).toHaveBeenCalledTimes(1)
})
it('只允许后端授予修复权限的视频创建候选,不自动再次校验', async () => {
const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
await data.service.run('repair', input({ maxRepairAttempts: 2 }))
expect(data.posts()).toHaveLength(0)
data.validation.passed = false
data.video.canRepair = true
await data.service.run('validate', input())
data.fetcher.mockClear()
await data.service.run('repair', input({ maxRepairAttempts: 2 }))
@@ -562,6 +579,7 @@ describe('视频修复候选与复检晋升', () => {
it('修复不接受零次上限,后端次数限制错误原样保留且不重试', async () => {
const data = setup({ kind: 'video', shotId: 'shot-1', assetId: 'video-1', title: '视频' })
data.validation.passed = false
data.video.canRepair = true
await data.service.run('validate', input())
data.fetcher.mockClear()
await data.service.run('repair', input({ maxRepairAttempts: 0 }))
@@ -0,0 +1,22 @@
import { describe, expect, it } from 'vitest'
import { videoOperationAllowed } from '@/features/production/video-permissions'
import { videoFixture } from '@/features/production/testing/fixtures'
describe('视频候选操作权限', () => {
it('每个候选独立使用后端权限,两个空版本不自行视为过期', () => {
const first = videoFixture({ canValidate: false, canRepair: true, canSetPrimary: false })
const second = videoFixture({ canValidate: true, canRepair: false, canSetPrimary: true })
expect(videoOperationAllowed(first, 'validate')).toBe(false)
expect(videoOperationAllowed(first, 'repair')).toBe(true)
expect(videoOperationAllowed(second, 'repair')).toBe(false)
expect(videoOperationAllowed(second, 'primary')).toBe(true)
})
it.each(['validate', 'repair', 'primary'] as const)('过期或已终止候选不能执行 %s,即使曾经通过', action => {
const permissions = { canValidate: true, canRepair: true, canSetPrimary: true }
expect(videoOperationAllowed(videoFixture({ ...permissions, motionPlanStale: true }), action)).toBe(false)
expect(
videoOperationAllowed(videoFixture({ ...permissions, qualityTerminalStatus: 'stale_motion_plan' }), action)
).toBe(false)
})
it('缺失权限不能当作允许操作', () => expect(videoOperationAllowed({}, 'validate')).toBe(false))
})
@@ -15,6 +15,14 @@ const qualityStatus: ShotVideoQualityStatus = {
chain: [
{
videoId: 'video-failed',
motionPlanRevisionId: null,
currentMotionPlanRevisionId: null,
motionPlanStale: false,
qualityTerminalStatus: null,
staleReason: null,
canValidate: true,
canRepair: false,
canSetPrimary: false,
providerStatus: 'completed',
isPrimary: false,
repairAttempt: 0,
@@ -25,6 +33,14 @@ const qualityStatus: ShotVideoQualityStatus = {
},
{
videoId: 'video-passed',
motionPlanRevisionId: null,
currentMotionPlanRevisionId: null,
motionPlanStale: false,
qualityTerminalStatus: null,
staleReason: null,
canValidate: true,
canRepair: false,
canSetPrimary: false,
providerStatus: 'completed',
isPrimary: true,
repairAttempt: 1,
@@ -0,0 +1,115 @@
import { describe, expect, it, vi, afterEach } from 'vitest'
import { motionEvidenceCurrent, type MotionRevision } from '@/features/storyboard/motion-revision'
import { motionApi } from '@/features/storyboard/motion-api'
import { keyframeFixture } from '@/features/production/testing/fixtures'
import type { WorkflowExecution } from '@/features/workflows/execution.types'
/** 完整的不可变修订,供证据绑定验证。 */
const revision: MotionRevision = {
revisionId: 'r1',
shotId: 'shot-1',
source: 'manual',
parentRevisionId: null,
reason: '调整动作',
fingerprint: 'fp1',
createdAt: '2026-10-14T00:00:00Z',
isActive: false,
durationSeconds: 4,
motionPlan: {
beats: [
{
startSecond: 0,
endSecond: 4,
action: '人物缓慢行走',
cameraMotion: '保持静止',
physicalContinuity: '动作连贯自然',
subjectRefs: ['@CH0001'],
closingState: '停在画面中央'
}
],
globalMotionConstraints: ['保持动作连续']
}
}
/** 真正完成并通过的后台证据,指针为空表示历史 AI 生效状态。 */
const primary = keyframeFixture()
const execution: WorkflowExecution = {
id: 'e1',
projectId: 'p1',
workflowName: 'motion-plan-start-state-validation',
status: 'completed',
stage: 'completed',
current: 1,
total: 1,
currentResourceId: null,
metadata: { shotId: 'shot-1' },
error: null,
startedAt: null,
completedAt: null,
createdAt: '',
updatedAt: '',
result: {
shotId: 'shot-1',
revisionId: 'r1',
fingerprint: 'fp1',
primaryKeyframeId: primary.id,
primaryKeyframeImageUrl: primary.imageUrl,
expectedRevisionId: null,
passed: true,
stale: false,
validation: { passed: true }
}
}
afterEach(() => vi.unstubAllGlobals())
describe('动作修订激活证据', () => {
it('仅接受完成且通过的对应修订与首帧', () =>
expect(motionEvidenceCurrent(execution, revision, primary, null)).toBe(true))
it.each([
{ passed: false },
{ stale: true },
{ revisionId: 'r2' },
{ fingerprint: 'other' },
{ shotId: 'shot-2' },
{ validation: { passed: false } }
])('拒绝失败、失效或不属于当前目标的证据 %j', patch => {
expect(
motionEvidenceCurrent({ ...execution, result: { ...execution.result, ...patch } }, revision, primary, null)
).toBe(false)
})
it('任务结束不等于通过,活动任务也不能激活', () => {
expect(motionEvidenceCurrent({ ...execution, status: 'running' }, revision, primary, null)).toBe(false)
expect(motionEvidenceCurrent({ ...execution, status: 'failed' }, revision, primary, null)).toBe(false)
})
it('同 ID 首帧换图和生效指针变化都撤销证据', () => {
expect(motionEvidenceCurrent(execution, revision, { ...primary, imageUrl: '/new.png' }, null)).toBe(false)
expect(motionEvidenceCurrent(execution, revision, primary, 'r2')).toBe(false)
})
it('保存显式发送空父版本,视觉校验发送当前生效指针,激活发送真实任务 ID', async () => {
const fetcher = vi.fn<typeof fetch>().mockImplementation(async () => new Response('{"data":{}}'))
vi.stubGlobal('fetch', fetcher)
await motionApi.previewRevision('s/1', revision.motionPlan)
await motionApi.saveRevision('s/1', { motionPlan: revision.motionPlan, parentRevisionId: null, reason: null })
await motionApi.validateRevision('s/1', 'r/1', { primaryKeyframeId: primary.id, expectedRevisionId: null })
await motionApi.activateRevision('s/1', 'r/1', { expectedRevisionId: null, validationExecutionId: 'e1' })
const calls = fetcher.mock.calls
expect(calls.map(([url]) => url)).toEqual([
'/api/storyboard-shots/s%2F1/motion-plan/revisions/preview',
'/api/storyboard-shots/s%2F1/motion-plan/revisions',
'/api/storyboard-shots/s%2F1/motion-plan/revisions/r%2F1/start-state-validation/start',
'/api/storyboard-shots/s%2F1/motion-plan/revisions/r%2F1/active'
])
expect(JSON.parse(String(calls[1]?.[1]?.body))).toEqual({
motionPlan: revision.motionPlan,
parentRevisionId: null,
reason: null
})
expect(JSON.parse(String(calls[2]?.[1]?.body))).toEqual({
primaryKeyframeId: primary.id,
expectedRevisionId: null
})
expect(JSON.parse(String(calls[3]?.[1]?.body))).toEqual({
expectedRevisionId: null,
validationExecutionId: 'e1'
})
})
})