diff --git a/AGENTS.md b/AGENTS.md index 032a3289..50750d5f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -442,6 +442,10 @@ In multi-replica deployments (e.g., multiple transcode or agent worker instances - In Docker/container environments, `HOSTNAME` (container ID) is automatically used. - On bare metal/multi-process hosts, `process.pid` and an instance suffix are appended to guarantee uniqueness. +### Durable Step File Exchange + +Intermediate files passed across steps must be saved to durable storage (S3) by the producing step, consuming steps must use `ensureLocalMediaFile` (or S3 fetch) rather than assuming local `/tmp` presence, and any purely temporary S3 scratch files must be cleaned up in a `finally` block. + ## Import conventions - When importing across workspace packages, always use absolute workspace imports (e.g. `import { prisma } from '@shumai/db'`, `import { teamService } from '@shumai/core/src/team/team'`). diff --git a/CHANGELOG.md b/CHANGELOG.md index 5626084b..3a29aee3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Fixed +* **transcode**: Fix an issue where PDF, 3D model, and image background transcode workflows could fail with missing temporary file errors if a worker restarted or recovered midway through processing + ### Changed * **workflow**: Migrate the background workflow engine to DBOS, unifying all-in-one and dedicated worker deployments using the existing PostgreSQL database without requiring a separate Temporal cluster diff --git a/packages/e2e/workflow/transcode-pdf.test.ts b/packages/e2e/workflow/transcode-pdf.test.ts index 22111792..3a1267ef 100644 --- a/packages/e2e/workflow/transcode-pdf.test.ts +++ b/packages/e2e/workflow/transcode-pdf.test.ts @@ -4,6 +4,7 @@ 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 { transcodeService } from '@shumai/core/src/transcode/transcode' import { fileURLToPath } from 'url' import * as path from 'path' import * as fs from 'fs' @@ -289,4 +290,137 @@ describe('Workflow E2E - transcodePdfWorkflow', () => { expect(mediaInfo.sprite?.key).toContain('sprite.webp') expect(mediaInfo.frames).toBeGreaterThan(0) }, 50000) + + it('should recover and complete workflow when intermediate local proxy is deleted before downstream steps', async () => { + // 1. Create Team, Project, Asset & StorageKey + const team = await prisma.team.create({ + data: { name: 'E2E Recovery Transcode Team' }, + }) + + const project = await prisma.project.create({ + data: { name: 'E2E Recovery Transcode Project', teamId: team.id }, + }) + + const storageKey = await prisma.storageKey.create({ + data: { + key: 'projects/e2e/recovery-doc.md', + status: 'active', + }, + }) + + const asset = await prisma.asset.create({ + data: { + name: 'recovery-doc.md', + type: 'file', + status: 'uploaded', + mediaType: 'text/markdown', + projectId: project.id, + storageKeyId: storageKey.id, + }, + }) + + // 2. Seed S3 Storage with Markdown text + const mdText = '# Recovery Test\n\nVerifying that intermediate proxy.pdf recovers from S3.' + const mdBuffer = Buffer.from(mdText, 'utf-8') + await s3Service.putObject( + 'shumai-e2e-test-bucket-transcode', + 'projects/e2e/recovery-doc.md', + mdBuffer, + mdBuffer.length, + 'text/markdown', + ) + + // 3. Spy on createTempDir and s3Service to intercept proxy.pdf upload and delete it locally + let capturedTmpDir: string | undefined + const origCreateTempDir = transcodeService.createTempDir.bind(transcodeService) + const createTempDirSpy = vi + .spyOn(transcodeService, 'createTempDir') + .mockImplementation((prefix: string) => { + const dir = origCreateTempDir(prefix) + if (prefix.startsWith('transcode-')) { + capturedTmpDir = dir + } + return dir + }) + + const origPutObject = s3Service.putObject.bind(s3Service) + const origDownloadToFile = s3Service.downloadToFile.bind(s3Service) + const downloadedKeys: string[] = [] + + const downloadSpy = vi + .spyOn(s3Service, 'downloadToFile') + .mockImplementation(async (bucket, key, localPath) => { + downloadedKeys.push(key) + return origDownloadToFile(bucket, key, localPath) + }) + + const putSpy = vi.spyOn(s3Service, 'putObject').mockImplementation(async (...args) => { + const result = await origPutObject(...args) + const key = String(args[1] || '') + if (key.endsWith('proxy.pdf') && capturedTmpDir) { + // Once proxy.pdf has been uploaded to S3 by generatePdfProxyActivity, + // delete the local file to simulate empty filesystem on a recovery/worker node. + const localProxyPath = path.join(capturedTmpDir, 'proxy.pdf') + if (fs.existsSync(localProxyPath)) { + fs.unlinkSync(localProxyPath) + } + } + return result + }) + + // 4. Create Workflow Task + const task = await prisma.workflowTask.create({ + data: { + type: 'transcode_pdf', + status: 'pending', + assetId: asset.id, + projectId: project.id, + teamId: team.id, + payload: { + projectId: project.id, + transcode: { + poster: true, + sprite: true, + }, + }, + }, + }) + + try { + console.log( + `Submitted E2E Recovery Transcode Workflow Task. ID: ${task.id}. Awaiting completion...`, + ) + const completedTask = await workflowService.executeWait(task, 45000) + + // 5. Verification + expect(completedTask.status).toBe('completed') + + const updatedAsset = await prisma.asset.findUnique({ + where: { id: asset.id }, + }) + expect(updatedAsset?.status).toBe(AssetStatus.processed) + + const mediaInfo = updatedAsset?.media as unknown as { + proxyType?: string + pdfTranscode?: { key: string } + poster?: { key: string } + sprite?: { key: string } + frames?: number + } + expect(mediaInfo).toBeDefined() + expect(mediaInfo.proxyType).toBe('pdf') + expect(mediaInfo.pdfTranscode?.key).toBe('projects/e2e/proxy.pdf') + expect(mediaInfo.poster?.key).toContain('poster.webp') + expect(mediaInfo.sprite?.key).toContain('sprite.webp') + expect(mediaInfo.frames).toBeGreaterThan(0) + + // Verify that proxy.pdf was re-downloaded from S3 via ensureLocalMediaFile + const proxyDownloadCall = downloadedKeys.find((k) => k.endsWith('proxy.pdf')) + expect(proxyDownloadCall).toBeDefined() + } finally { + createTempDirSpy.mockRestore() + downloadSpy.mockRestore() + putSpy.mockRestore() + } + }, 50000) }) diff --git a/packages/transcode/src/activities/transcode-3d.test.ts b/packages/transcode/src/activities/transcode-3d.test.ts index ad22225b..babe5d78 100644 --- a/packages/transcode/src/activities/transcode-3d.test.ts +++ b/packages/transcode/src/activities/transcode-3d.test.ts @@ -25,6 +25,7 @@ vi.mock('@shumai/core/src/turntable/turntable', () => ({ vi.mock('@shumai/core/src/s3/s3', () => ({ s3Service: { putObject: vi.fn(), + downloadToFile: vi.fn(), }, })) @@ -120,6 +121,46 @@ describe('3D Transcode Activities', () => { expect(res.modelMetadata).toEqual({ format: 'glb', vertices: 120 }) }) + it('recovers 3D model from S3 assetKey when local file is missing', async () => { + vi.mocked(turntableService.uploadFile).mockResolvedValue({ + id: 'f_input', + name: 'model.glb', + size: 1024, + }) + + vi.mocked(turntableService.startRender).mockResolvedValue({ + taskId: 'task_render_1', + status: 'queued', + poster: { + fileId: 'f_poster', + contentType: 'image/png', + width: 1080, + height: 1080, + size: 5000, + }, + metadata: { format: 'glb', vertices: 120 }, + }) + + vi.mocked(turntableService.downloadFile).mockResolvedValue(Buffer.from('poster-raw-bytes')) + + const targetPath = `/tmp/test-3d-model-${Date.now()}.glb` + await start3dRenderActivity({ + taskId: 'wf-task-1', + teamId: 'team-1', + assetId: 'asset-1', + assetKey: 'files/asset-1/model.glb', + filePath: targetPath, + filename: 'model.glb', + targetPosterKey: 'files/asset-1/poster.webp', + }) + + expect(s3Service.downloadToFile).toHaveBeenCalledWith( + 'shumai', + 'files/asset-1/model.glb', + targetPath, + ) + }) + it('throws ApplicationFailure when poster file ID is missing', async () => { vi.mocked(turntableService.uploadFile).mockResolvedValue({ id: 'f_input', @@ -326,6 +367,24 @@ describe('3D Transcode Activities', () => { ) expect(res.spriteKey).toBe('files/asset-1/sprite.webp') }) + + it('recovers turntable video from S3 videoKey when local file is missing', async () => { + const targetPath = `/tmp/test-turntable-${Date.now()}.mp4` + const res = await generate3dSpriteActivity({ + taskId: 'wf-task-3', + assetKey: 'files/asset-1/model.glb', + videoKey: 'files/asset-1/turntable.mp4', + videoFilePath: targetPath, + spriteKey: 'files/asset-1/sprite.webp', + }) + + expect(s3Service.downloadToFile).toHaveBeenCalledWith( + 'shumai', + 'files/asset-1/turntable.mp4', + targetPath, + ) + expect(res.spriteKey).toBe('files/asset-1/sprite.webp') + }) }) describe('generate3dViewsActivity', () => { @@ -351,5 +410,23 @@ describe('3D Transcode Activities', () => { ) expect(res.viewsKey).toBe('files/asset-1/views.webp') }) + + it('recovers turntable video from S3 videoKey when local file is missing', async () => { + const targetPath = `/tmp/test-turntable-views-${Date.now()}.mp4` + const res = await generate3dViewsActivity({ + taskId: 'wf-task-4', + assetKey: 'files/asset-1/model.glb', + videoKey: 'files/asset-1/turntable.mp4', + videoFilePath: targetPath, + viewsKey: 'files/asset-1/views.webp', + }) + + expect(s3Service.downloadToFile).toHaveBeenCalledWith( + 'shumai', + 'files/asset-1/turntable.mp4', + targetPath, + ) + expect(res.viewsKey).toBe('files/asset-1/views.webp') + }) }) }) diff --git a/packages/transcode/src/activities/transcode.test.ts b/packages/transcode/src/activities/transcode.test.ts index 5400f428..bb99b812 100644 --- a/packages/transcode/src/activities/transcode.test.ts +++ b/packages/transcode/src/activities/transcode.test.ts @@ -12,6 +12,7 @@ vi.mock('child_process', () => ({ execFile: vi.fn(), })) import { + ensureLocalMediaFile, getMediaInfoActivity, overlayAnnotationsActivity, renderPdfPagesActivity, @@ -107,6 +108,7 @@ describe('Transcode Activities', () => { vi.clearAllMocks() const fs = await import('fs') vi.mocked(fs.readFileSync).mockImplementation(() => Buffer.from('fake data') as never) + vi.mocked(fs.existsSync).mockReturnValue(true) }) it('should convert CSV via Gotenberg in landscape mode when maxCols > 5', async () => { @@ -941,14 +943,43 @@ describe('Transcode Activities', () => { }) describe('Non-retryable Error Handling', () => { - it('should throw non-retryable ApplicationFailure when downloadMediaToTmpActivity fails with ENOENT', async () => { + it('should throw non-retryable ApplicationFailure when downloadMediaToTmpActivity fails with ENOENT or AWS SDK NoSuchKey', async () => { vi.mocked(s3Service.downloadToFile).mockRejectedValue({ - code: 'ENOENT', - message: 'ENOENT: no such file or directory', + name: 'NoSuchKey', + message: 'The specified key does not exist.', }) - await expect(downloadMediaToTmpActivity({ assetKey: 'missing.mp4' })).rejects.toThrowError( - /Failed to download media to tmp/, + await expect(downloadMediaToTmpActivity({ assetKey: 'missing.mp4' })).rejects.toMatchObject({ + message: expect.stringMatching(/Failed to download media to tmp/), + nonRetryable: true, + }) + }) + + it('should throw non-retryable ApplicationFailure when ensureLocalMediaFile fails with ENOENT or AWS SDK NoSuchKey', async () => { + vi.mocked(fs.existsSync).mockReturnValue(false) + vi.mocked(s3Service.downloadToFile).mockRejectedValue({ + name: 'NoSuchKey', + message: 'The specified key does not exist.', + }) + + const targetPath = `/tmp/test-recovery-${Date.now()}.mp4` + await expect(ensureLocalMediaFile('missing.mp4', targetPath)).rejects.toMatchObject({ + message: expect.stringMatching(/Failed to download media to local file/), + nonRetryable: true, + }) + }) + + it('should recover missing local file from S3 via ensureLocalMediaFile', async () => { + vi.mocked(fs.existsSync).mockReturnValue(false) + vi.mocked(s3Service.downloadToFile).mockResolvedValue() + const targetPath = `/tmp/test-recovery-${Date.now()}.mp4` + + const result = await ensureLocalMediaFile('asset.mp4', targetPath) + expect(result).toBe(targetPath) + expect(s3Service.downloadToFile).toHaveBeenCalledWith( + expect.any(String), + 'asset.mp4', + targetPath, ) }) @@ -1142,6 +1173,37 @@ describe('Transcode Activities', () => { ) }) + it('generateSpriteActivity recovers local file from inputKey when provided and missing on disk', async () => { + vi.mocked(fs.existsSync).mockReturnValue(false) + vi.mocked(s3Service.headObject).mockRejectedValue(new Error('Not found')) + vi.mocked(s3Service.downloadToFile).mockResolvedValue() + vi.mocked(transcodeService.generateSprite).mockImplementation( + async (_in, spriteOut, posterOut) => { + const fs = await import('fs') + fs.writeFileSync(spriteOut, 'fake-sprite') + fs.writeFileSync(posterOut, 'fake-poster') + }, + ) + + const targetPath = `/tmp/test-sprite-${Date.now()}.pdf` + await generateSpriteActivity({ + assetKey: 'files/asset-1/doc.docx', + inputKey: 'files/asset-1/proxy.pdf', + filePath: targetPath, + mediaInfo: { + duration: 10, + } as unknown as PrismaJson.MediaInfo, + spriteSpec: { key: 'files/asset-1/sprite.webp', frames: 100, tileX: 10, tileY: 10 }, + posterSpec: { key: 'files/asset-1/poster.webp' }, + }) + + expect(s3Service.downloadToFile).toHaveBeenCalledWith( + expect.any(String), + 'files/asset-1/proxy.pdf', + targetPath, + ) + }) + it('should throw non-retryable ApplicationFailure when takeScreenshotsActivity fails with error', async () => { vi.mocked(transcodeService.takeScreenshots).mockRejectedValue(new Error('FFmpeg failed')) diff --git a/packages/transcode/src/activities/transcode.ts b/packages/transcode/src/activities/transcode.ts index 58dc1f32..3ad3b6f8 100644 --- a/packages/transcode/src/activities/transcode.ts +++ b/packages/transcode/src/activities/transcode.ts @@ -22,38 +22,19 @@ import { isMarkdownDocument, isOfficeDocument, } from '@shumai/core/src/utils/mime' -import { logger } from '@shumai/core/src/logger' -import { ApplicationFailure, defineStep, getLocalTaskAbortSignal } from '@shumai/workflow-core' - -function getActivityCancellationSignal(taskId?: string): AbortSignal | undefined { - return getLocalTaskAbortSignal(taskId) -} - -export async function ensureLocalMediaFile(assetKey: string, filePath: string): Promise { - if (fs.existsSync(filePath)) { - return filePath - } - const dir = path.dirname(filePath) - if (!fs.existsSync(dir)) { - fs.mkdirSync(dir, { recursive: true }) - } - const bucket = process.env.S3_BUCKET || 'shumai' - await s3Service.downloadToFile(bucket, assetKey, filePath) - return filePath -} import * as path from 'path' import * as fs from 'fs' import * as os from 'os' import { execFile } from 'child_process' import { promisify } from 'util' import { ulid } from 'ulid' +import { logger } from '@shumai/core/src/logger' +import { ApplicationFailure, defineStep, getLocalTaskAbortSignal } from '@shumai/workflow-core' const execFileAsync = promisify(execFile) -export interface GetMediaInfoActivityParams { - assetId: string - assetKey: string - mediaType: string +function getActivityCancellationSignal(taskId?: string): AbortSignal | undefined { + return getLocalTaskAbortSignal(taskId) } function getErrorDetails(err: unknown): { code?: string; message: string; name?: string } { @@ -75,6 +56,46 @@ function getErrorDetails(err: unknown): { code?: string; message: string; name?: } } +export async function ensureLocalMediaFile(assetKey: string, filePath: string): Promise { + if (fs.existsSync(filePath)) { + return filePath + } + const dir = path.dirname(filePath) + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }) + } + const bucket = process.env.S3_BUCKET || 'shumai' + try { + await s3Service.downloadToFile(bucket, assetKey, filePath) + } catch (err) { + const { code, message, name } = getErrorDetails(err) + const lowerMsg = message.toLowerCase() + const lowerCode = (code || '').toLowerCase() + const lowerName = (name || '').toLowerCase() + if ( + lowerCode === 'enoent' || + lowerCode === 'nosuchkey' || + lowerName === 'nosuchkey' || + lowerMsg.includes('enoent') || + lowerMsg.includes('nosuchkey') + ) { + throw ApplicationFailure.create({ + message: `Failed to download media to local file: ${message}`, + nonRetryable: true, + cause: err instanceof Error ? err : undefined, + }) + } + throw err + } + return filePath +} + +export interface GetMediaInfoActivityParams { + assetId: string + assetKey: string + mediaType: string +} + async function ensureAssetNotPurging(assetKey: string): Promise { const sk = await prisma.storageKey.findUnique({ where: { key: assetKey }, @@ -129,6 +150,8 @@ export const getMediaInfoActivity = defineStep(async function getMediaInfoActivi nonRetryable: true, }) } + } else if (params.assetKey) { + mediaSource = await ensureLocalMediaFile(params.assetKey, mediaSource) } const fileType = isVideo @@ -846,6 +869,7 @@ export const transcodeImageActivity = defineStep(async function transcodeImageAc export interface GenerateSpriteActivityParams { taskId?: string assetKey: string + inputKey?: string filePath: string mediaInfo: PrismaJson.MediaInfo spriteSpec: PrismaJson.SpriteInfo @@ -872,7 +896,7 @@ export const generateSpriteActivity = defineStep(async function generateSpriteAc // Not found } - await ensureLocalMediaFile(params.assetKey, params.filePath) + await ensureLocalMediaFile(params.inputKey || params.assetKey, params.filePath) const tmpDir = path.dirname(params.filePath) const spriteFile = path.join(tmpDir, 'sprite.webp') const posterFile = path.join(tmpDir, 'poster.webp') @@ -979,6 +1003,8 @@ export interface GeneratePdfProxyActivityParams { export const generatePdfProxyActivity = defineStep(async function generatePdfProxyActivity( params: GeneratePdfProxyActivityParams, ): Promise<{ pdfProxyKey: string; pdfFilePath: string }> { + await ensureLocalMediaFile(params.assetKey, params.filePath) + const isOffice = isOfficeDocument(params.mediaType, params.filename) const isHtml = isHtmlDocument(params.mediaType, params.filename) const isMd = isMarkdownDocument(params.mediaType, params.filename) @@ -1107,9 +1133,17 @@ export const downloadMediaToTmpActivity = defineStep( try { await s3Service.downloadToFile(bucket, params.assetKey, filePath) } catch (err) { - const { code, message } = getErrorDetails(err) + const { code, message, name } = getErrorDetails(err) const lowerMsg = message.toLowerCase() - if (code === 'ENOENT' || lowerMsg.includes('enoent') || lowerMsg.includes('nosuchkey')) { + const lowerCode = (code || '').toLowerCase() + const lowerName = (name || '').toLowerCase() + if ( + lowerCode === 'enoent' || + lowerCode === 'nosuchkey' || + lowerName === 'nosuchkey' || + lowerMsg.includes('enoent') || + lowerMsg.includes('nosuchkey') + ) { throw ApplicationFailure.create({ message: `Failed to download media to tmp: ${message}`, nonRetryable: true, @@ -1765,6 +1799,8 @@ export const start3dRenderActivity = defineStep(async function start3dRenderActi }) } + await ensureLocalMediaFile(params.assetKey, params.filePath) + const bucket = process.env.S3_BUCKET || 'shumai' const tmpDir = path.dirname(params.filePath) const posterFilePath = path.join(tmpDir, 'poster.webp') @@ -1987,6 +2023,7 @@ export const render3dModelActivity = defineStep(async function render3dModelActi export interface Generate3dSpriteActivityParams { taskId: string assetKey: string + videoKey?: string videoFilePath: string spriteKey: string } @@ -2002,6 +2039,9 @@ export const generate3dSpriteActivity = defineStep(async function generate3dSpri }) } + const downloadKey = params.videoKey || params.assetKey + await ensureLocalMediaFile(downloadKey, params.videoFilePath) + const bucket = process.env.S3_BUCKET || 'shumai' const tmpDir = path.dirname(params.videoFilePath) const spriteFilePath = path.join(tmpDir, 'sprite.webp') @@ -2035,6 +2075,7 @@ export const generate3dSpriteActivity = defineStep(async function generate3dSpri export interface Generate3dViewsActivityParams { taskId: string assetKey: string + videoKey?: string videoFilePath: string viewsKey: string } @@ -2050,6 +2091,9 @@ export const generate3dViewsActivity = defineStep(async function generate3dViews }) } + const downloadKey = params.videoKey || params.assetKey + await ensureLocalMediaFile(downloadKey, params.videoFilePath) + const bucket = process.env.S3_BUCKET || 'shumai' const tmpDir = path.dirname(params.videoFilePath) const viewsFilePath = path.join(tmpDir, 'views.webp') diff --git a/packages/transcode/src/workflows/transcode-3d.test.ts b/packages/transcode/src/workflows/transcode-3d.test.ts index 3d7d87f8..22890456 100644 --- a/packages/transcode/src/workflows/transcode-3d.test.ts +++ b/packages/transcode/src/workflows/transcode-3d.test.ts @@ -165,6 +165,7 @@ describe('transcode3dWorkflow', () => { expect(mockActivities.generate3dSpriteActivity).toHaveBeenCalledWith({ taskId: 'task-3d', assetKey: 'files/asset-3d/robot.glb', + videoKey: 'files/asset-3d/turntable.mp4', videoFilePath: '/tmp/turntable.mp4', spriteKey: 'files/asset-3d/sprite.webp', }) @@ -172,6 +173,7 @@ describe('transcode3dWorkflow', () => { expect(mockActivities.generate3dViewsActivity).toHaveBeenCalledWith({ taskId: 'task-3d', assetKey: 'files/asset-3d/robot.glb', + videoKey: 'files/asset-3d/turntable.mp4', videoFilePath: '/tmp/turntable.mp4', viewsKey: 'files/asset-3d/views.webp', }) diff --git a/packages/transcode/src/workflows/transcode-3d.ts b/packages/transcode/src/workflows/transcode-3d.ts index ced7a686..6ec7ae26 100644 --- a/packages/transcode/src/workflows/transcode-3d.ts +++ b/packages/transcode/src/workflows/transcode-3d.ts @@ -99,6 +99,7 @@ export async function transcode3dWorkflow(task: WorkflowTask): Promise { await generate3dSpriteActivity({ taskId: task.id, assetKey: key, + videoKey, videoFilePath: renderVideo.videoFilePath, spriteKey, }) @@ -113,6 +114,7 @@ export async function transcode3dWorkflow(task: WorkflowTask): Promise { await generate3dViewsActivity({ taskId: task.id, assetKey: key, + videoKey, videoFilePath: renderVideo.videoFilePath, viewsKey, }) diff --git a/packages/transcode/src/workflows/transcode-image.test.ts b/packages/transcode/src/workflows/transcode-image.test.ts index 76e83209..a8031aad 100644 --- a/packages/transcode/src/workflows/transcode-image.test.ts +++ b/packages/transcode/src/workflows/transcode-image.test.ts @@ -118,6 +118,13 @@ describe('transcodeImageWorkflow', () => { await transcodeImageWorkflow(task) + expect(mockActivities.getMediaInfoActivity).toHaveBeenCalledWith( + expect.objectContaining({ + assetKey: 'image.jpg', + filePath: '/tmp/image.jpg', + }), + ) + expect(mockActivities.updateAssetStatusActivity).toHaveBeenCalledWith({ assetId: 'asset-image', status: AssetStatus.processing, diff --git a/packages/transcode/src/workflows/transcode-image.ts b/packages/transcode/src/workflows/transcode-image.ts index 4a2087de..069a182d 100644 --- a/packages/transcode/src/workflows/transcode-image.ts +++ b/packages/transcode/src/workflows/transcode-image.ts @@ -33,6 +33,7 @@ export async function transcodeImageWorkflow(task: WorkflowTask): Promise const spec = task.payload?.transcode || {} const mediaInfo = await getMediaInfoActivity({ + assetKey: key, filePath, assetId: asset.id, proxyType: 'image', diff --git a/packages/transcode/src/workflows/transcode-pdf.test.ts b/packages/transcode/src/workflows/transcode-pdf.test.ts index 921317f5..be166be9 100644 --- a/packages/transcode/src/workflows/transcode-pdf.test.ts +++ b/packages/transcode/src/workflows/transcode-pdf.test.ts @@ -128,8 +128,17 @@ describe('transcodePdfWorkflow', () => { status: AssetStatus.processing, }) + expect(mockActivities.getMediaInfoActivity).toHaveBeenCalledWith({ + assetKey: 'document.pdf', + filePath: '/tmp/doc.pdf', + assetId: 'asset-pdf', + proxyType: 'pdf', + mediaType: 'application/pdf', + }) + expect(mockActivities.generateSpriteActivity).toHaveBeenCalledWith({ assetKey: 'document.pdf', + inputKey: 'document.pdf', filePath: '/tmp/doc.pdf', spriteSpec: expect.objectContaining({ key: 'sprite.webp' }), posterSpec: expect.objectContaining({ key: 'poster.webp' }), diff --git a/packages/transcode/src/workflows/transcode-pdf.ts b/packages/transcode/src/workflows/transcode-pdf.ts index 0931da8c..6248c1f4 100644 --- a/packages/transcode/src/workflows/transcode-pdf.ts +++ b/packages/transcode/src/workflows/transcode-pdf.ts @@ -45,6 +45,7 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise { const spec = task.payload?.transcode || {} const mediaInfo = await getMediaInfoActivity({ + assetKey: pdfProxy.pdfProxyKey, filePath: currentFilePath, assetId: asset.id, proxyType: 'pdf', @@ -76,6 +77,7 @@ export async function transcodePdfWorkflow(task: WorkflowTask): Promise { const spriteResult = await generateSpriteActivity({ assetKey: key, + inputKey: pdfProxy.pdfProxyKey, filePath: currentFilePath, spriteSpec, posterSpec,