mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-26 01:19:24 +00:00
fix(transcode): ensure durable file exchange and crash recovery across workflow steps (#484)
* fix(transcode): ensure durable file exchange and crash recovery across workflow steps * fix(transcode): recognize AWS SDK NoSuchKey by name and add workflow E2E recovery test
This commit is contained in:
@@ -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'))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user