gongxiangp2/lib/__tests__/task-upload-init-source-preservation.test.ts
chenpei 7326e273e1 fix: harden media upload and release safety
Protect upload cleanup and atomic completion paths, add durable media worker leases and brand asset validation, and introduce verified migration/bootstrap/deployment gates.
2026-08-12 18:04:08 +08:00

41 lines
1.5 KiB
TypeScript
Raw 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.

/** @jest-environment node */
import { readFileSync } from 'fs'
import path from 'path'
const INIT_ROUTES = [
'app/api/materials/upload/3d-original/init/route.ts',
'app/api/materials/upload/ai-original/init/route.ts',
'app/api/materials/upload/real-photo/init/route.ts',
'app/api/materials/upload/video-screenshot/init/route.ts',
'app/api/materials/upload/task-page/init/route.ts',
'app/api/materials/upload/product-package/init/route.ts',
]
describe('任务素材 init 不永久清理旧数据', () => {
test.each(INIT_ROUTES)('%s 只能校验并创建 uploading,不得调用旧素材 purge', (relativePath) => {
const source = readFileSync(path.join(process.cwd(), relativePath), 'utf8')
expect(source).not.toContain('purgeDeletedMaterialsByTaskNo')
expect(source).not.toContain('deleteFiles(')
expect(source).not.toContain('prisma.material.delete')
})
test('通用上传失败清理必须先条件回滚数据库,再删除派生文件', () => {
const source = readFileSync(
path.join(process.cwd(), 'app/api/materials/upload/route.ts'),
'utf8',
)
const conditionalDatabaseDelete = source.indexOf(
'const deleteResult = await prisma.material.deleteMany',
)
const derivedFileDelete = source.indexOf(
'const cleanupResult = await deleteFiles(filesToDelete)',
conditionalDatabaseDelete,
)
expect(conditionalDatabaseDelete).toBeGreaterThan(-1)
expect(derivedFileDelete).toBeGreaterThan(conditionalDatabaseDelete)
})
})