2026-07-25 09:47:20 +08:00
|
|
|
import { describe, it, expect, beforeAll, afterAll, vi } from 'vitest'
|
|
|
|
|
import { prisma } from '@shumai/db'
|
|
|
|
|
import { setupTestDbHooks } from '@shumai/db/test'
|
|
|
|
|
import { workflowService, TaskQueueTranscode } from '@shumai/workflow-core'
|
|
|
|
|
import { initTranscodeWorkflows } from '@shumai/transcode'
|
|
|
|
|
import { s3Service } from '@shumai/core/src/s3/s3'
|
|
|
|
|
import { fileURLToPath } from 'url'
|
|
|
|
|
import * as path from 'path'
|
|
|
|
|
import * as fs from 'fs'
|
|
|
|
|
|
|
|
|
|
const currentDir = path.dirname(fileURLToPath(import.meta.url))
|
|
|
|
|
const fixturesDir = path.resolve(currentDir, '../fixtures')
|
|
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
describe('Workflow E2E - overlayImageAnnotationWorkflow', () => {
|
|
|
|
|
setupTestDbHooks()
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
beforeAll(async () => {
|
|
|
|
|
process.env.S3_BUCKET = 'shumai-e2e-test-bucket-transcode'
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
initTranscodeWorkflows()
|
|
|
|
|
await workflowService.startWorkers(TaskQueueTranscode)
|
|
|
|
|
})
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
afterAll(async () => {
|
|
|
|
|
await workflowService.shutdownWorkers()
|
|
|
|
|
workflowService.close()
|
|
|
|
|
vi.restoreAllMocks()
|
|
|
|
|
try {
|
|
|
|
|
console.log('Cleaning up local E2E storage files...')
|
|
|
|
|
await s3Service.deletePrefix('shumai-e2e-test-bucket-transcode', '')
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Failed to clean up E2E storage folder:', err)
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
it('should run transcodeMedia image annotation overlay successfully', async () => {
|
|
|
|
|
// 1. Seed Database
|
|
|
|
|
const team = await prisma.team.create({
|
|
|
|
|
data: { name: 'E2E Image Annotation Team' },
|
2026-07-25 09:47:20 +08:00
|
|
|
})
|
|
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
const project = await prisma.project.create({
|
|
|
|
|
data: { name: 'E2E Image Annotation Project', teamId: team.id },
|
2026-07-25 09:47:20 +08:00
|
|
|
})
|
|
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
const storageKey = await prisma.storageKey.create({
|
|
|
|
|
data: {
|
|
|
|
|
key: 'projects/e2e/image-ann.png',
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
const asset = await prisma.asset.create({
|
|
|
|
|
data: {
|
|
|
|
|
name: 'image-ann.png',
|
|
|
|
|
type: 'file',
|
|
|
|
|
status: 'uploaded',
|
|
|
|
|
mediaType: 'image/png',
|
|
|
|
|
projectId: project.id,
|
|
|
|
|
storageKeyId: storageKey.id,
|
|
|
|
|
},
|
|
|
|
|
})
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
// 2. Seed S3 Storage from Fixture
|
|
|
|
|
const pngPath = path.join(fixturesDir, 'small.png')
|
|
|
|
|
const pngBuffer = fs.readFileSync(pngPath)
|
|
|
|
|
await s3Service.putObject(
|
|
|
|
|
'shumai-e2e-test-bucket-transcode',
|
|
|
|
|
'projects/e2e/image-ann.png',
|
|
|
|
|
pngBuffer,
|
|
|
|
|
pngBuffer.length,
|
|
|
|
|
'image/png',
|
|
|
|
|
)
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
// 3. Create Workflow Task
|
|
|
|
|
const task = await prisma.workflowTask.create({
|
|
|
|
|
data: {
|
|
|
|
|
type: 'transcode_image_annotation',
|
|
|
|
|
status: 'pending',
|
|
|
|
|
assetId: asset.id,
|
|
|
|
|
projectId: project.id,
|
|
|
|
|
teamId: team.id,
|
|
|
|
|
payload: {
|
2026-07-25 09:47:20 +08:00
|
|
|
projectId: project.id,
|
2026-10-19 15:35:08 +08:00
|
|
|
imageAnnotation: {
|
|
|
|
|
annotations: [
|
|
|
|
|
{
|
|
|
|
|
type: 'box',
|
|
|
|
|
color: '#ff0000',
|
|
|
|
|
points: [
|
|
|
|
|
[0.1, 0.1],
|
|
|
|
|
[0.9, 0.9],
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
],
|
2026-07-25 09:47:20 +08:00
|
|
|
},
|
|
|
|
|
},
|
2026-10-19 15:35:08 +08:00
|
|
|
},
|
|
|
|
|
})
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
// 4. Wait for workflow to complete
|
|
|
|
|
console.log(
|
|
|
|
|
`Submitted E2E Image Annotation Workflow Task. ID: ${task.id}. Awaiting completion...`,
|
|
|
|
|
)
|
|
|
|
|
const completedTask = await workflowService.executeWait(task, 45000)
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
// 5. Verification
|
|
|
|
|
expect(completedTask.status).toBe('completed')
|
2026-07-25 09:47:20 +08:00
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
// Verify task output contains overlay image key
|
|
|
|
|
const output = completedTask.output as unknown as { key: string }
|
|
|
|
|
expect(output).toBeDefined()
|
|
|
|
|
expect(output.key).toContain('annotations/')
|
|
|
|
|
}, 50000)
|
|
|
|
|
})
|