import { describe, expect, it } from 'vitest' import { ApiError, errorMessage } from '@/lib/http' import { getOperation, operationErrorText, runOperation } from '@/features/workflows/operations' describe('面向普通用户的系统提示', () => { 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('新的操作原因') }) })