Files

61 lines
3.0 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest'
import { ApiError, errorMessage } from '@/lib/http'
import { getOperation, operationErrorText, runOperation } from '@/features/workflows/operations'
describe('面向普通用户的系统提示', () => {
it('规则版本冲突显示操作指引,保留原始错误码供流程恢复', () => {
const cause = new ApiError(
'QUALITY_POLICY_VERSION_CONFLICT: 质量规则已更新',
409,
undefined,
'QUALITY_POLICY_VERSION_CONFLICT'
)
expect(errorMessage(cause)).not.toContain('QUALITY_POLICY_VERSION_CONFLICT')
expect(cause.code).toBe('QUALITY_POLICY_VERSION_CONFLICT')
})
it('错误展示使用中文说明,不把技术字段和调试对象直接输出给用户', () => {
const details = {
issues: [{ message: 'Shot 主体引用缺失:@CH0001' }],
debug: { executionId: 'internal-id', sql: 'SELECT secret' }
}
const error = new ApiError('后端 Storyboard 校验失败', 400, details)
const text = errorMessage(error)
expect(text).toContain('分镜')
expect(text).toContain('主体引用缺失:@CH0001')
expect(text).not.toMatch(/后端|前端|Storyboard|\bShot\b|executionId|SELECT|"issues"/)
expect(error.details).toBe(details)
})
it('连接失败给出可操作说明,保留任务可能仍在执行的提醒', () => {
const text = errorMessage(new Error('无法连接后端。已提交的任务可能仍在运行。'))
expect(text).not.toContain('后端')
expect(text).toContain('已提交的任务可能仍在运行')
})
it('中文展示不改变恢复流程读取的原始错误,手动更新后的提示也不会沿用旧原因', async () => {
const original = new ApiError('Shot 缺少 Primary Keyframe', 400)
await runOperation('copy-recovery-test', '生成视频描述', async () => {
throw original
})
const operation = getOperation('copy-recovery-test')
expect(operation.error).toContain('首帧')
expect(operation.error).not.toContain('Primary Keyframe')
expect(operationErrorText(operation)).toBe('Shot 缺少 Primary Keyframe')
operation.error = '新的操作原因'
expect(operationErrorText(operation)).toBe('新的操作原因')
})
})
it.each([
'CANVAS_CHANGE_REQUIRES_REVALIDATION',
'CREATIVE_PROFILE_ACTIVE_WORKFLOW',
'GENERATION_CONFIG_CHANGE_REQUIRES_REVALIDATION'
])('配置冲突 %s 从真实 details.code 或顶层 code 转成中文原因', code => {
for (const cause of [
new ApiError('请求失败(409)', 409, { code }),
new ApiError('服务器内部错误', 409, undefined, code)
]) {
expect(errorMessage(cause)).not.toMatch(/请求失败|服务器内部错误|REQUIRES|WORKFLOW/)
expect(errorMessage(cause)).toMatch(/画幅|任务|模型/)
expect(cause.status).toBe(409)
}
})