2026-07-19 12:32:08 +08:00
|
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
|
import { overlayImageAnnotationWorkflow } from './overlay-image-annotation'
|
|
|
|
|
import { WorkflowTask, WorkflowTaskStatus, WorkflowTaskType } from '@shumai/db'
|
2026-10-19 15:35:08 +08:00
|
|
|
import { getAssetActivity, updateTaskStatusActivity } from '@shumai/workflow-core'
|
|
|
|
|
import { overlayAnnotationsActivity } from '../activities/transcode'
|
2026-07-19 12:32:08 +08:00
|
|
|
|
|
|
|
|
vi.mock('@shumai/workflow-core', async (importOriginal) => {
|
2026-10-19 15:35:08 +08:00
|
|
|
const actual = await importOriginal<typeof import('@shumai/workflow-core')>()
|
2026-07-19 12:32:08 +08:00
|
|
|
return {
|
|
|
|
|
...actual,
|
2026-10-19 15:35:08 +08:00
|
|
|
updateTaskStatusActivity: vi.fn(),
|
|
|
|
|
getAssetActivity: vi.fn(),
|
2026-07-19 12:32:08 +08:00
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2026-10-19 15:35:08 +08:00
|
|
|
vi.mock('../activities/transcode', () => ({
|
|
|
|
|
overlayAnnotationsActivity: vi.fn(),
|
|
|
|
|
}))
|
|
|
|
|
|
2026-07-19 12:32:08 +08:00
|
|
|
describe('overlayImageAnnotationWorkflow', () => {
|
|
|
|
|
const mockActivities = {
|
2026-10-19 15:35:08 +08:00
|
|
|
updateTaskStatusActivity: vi.mocked(updateTaskStatusActivity),
|
|
|
|
|
getAssetActivity: vi.mocked(getAssetActivity),
|
|
|
|
|
overlayAnnotationsActivity: vi.mocked(overlayAnnotationsActivity),
|
2026-07-19 12:32:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('should run image annotation overlay workflow successfully', async () => {
|
|
|
|
|
const task: WorkflowTask = {
|
|
|
|
|
id: 'task-image-ann',
|
|
|
|
|
assetId: 'asset-image',
|
|
|
|
|
type: WorkflowTaskType.transcode_image_annotation,
|
|
|
|
|
status: WorkflowTaskStatus.pending,
|
|
|
|
|
sessionId: null,
|
|
|
|
|
output: null,
|
|
|
|
|
payload: {
|
|
|
|
|
projectId: 'proj-1',
|
|
|
|
|
imageAnnotation: {
|
|
|
|
|
annotations: [{ type: 'box', color: '#ff0000', points: [] }],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
createdAt: new Date(),
|
|
|
|
|
updatedAt: new Date(),
|
|
|
|
|
heartbeat: null,
|
|
|
|
|
teamId: 'team-1',
|
|
|
|
|
projectId: 'proj-1',
|
|
|
|
|
uid: 'task-uid',
|
|
|
|
|
model: null,
|
|
|
|
|
inputTokens: 0,
|
|
|
|
|
outputTokens: 0,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mockActivities.getAssetActivity.mockResolvedValue({
|
|
|
|
|
id: 'asset-image',
|
|
|
|
|
storageKey: { key: 'image.png' },
|
|
|
|
|
mediaType: 'image/png',
|
|
|
|
|
media: {
|
|
|
|
|
imageTranscodes: [{ key: 'image-transcoded.webp' }],
|
|
|
|
|
},
|
2026-10-19 15:35:08 +08:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
|
|
|
} as any)
|
2026-07-19 12:32:08 +08:00
|
|
|
|
|
|
|
|
mockActivities.overlayAnnotationsActivity.mockResolvedValue(
|
|
|
|
|
'files/asset-image/annotations/ann1.webp',
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
await overlayImageAnnotationWorkflow(task)
|
|
|
|
|
|
|
|
|
|
expect(mockActivities.overlayAnnotationsActivity).toHaveBeenCalledWith({
|
|
|
|
|
assetKey: 'image-transcoded.webp',
|
|
|
|
|
assetId: 'asset-image',
|
|
|
|
|
annotations: [{ type: 'box', color: '#ff0000', points: [] }],
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
expect(mockActivities.updateTaskStatusActivity).toHaveBeenCalledWith({
|
|
|
|
|
taskId: 'task-image-ann',
|
|
|
|
|
status: WorkflowTaskStatus.completed,
|
|
|
|
|
output: { key: 'files/asset-image/annotations/ann1.webp' },
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|