Harden audio transcription fetch path with retries and timeout

This commit is contained in:
William Valentin
2026-02-22 19:54:58 -08:00
parent abaa9be3f1
commit 487f26e36d
6 changed files with 175 additions and 4 deletions
+20
View File
@@ -440,6 +440,26 @@ describe('transcribeAudio', () => {
expect(result).toBe('[Audio message transcription failed]');
});
it('retries transient fetch failure and succeeds on a later attempt', async () => {
vi.mocked(global.fetch)
.mockRejectedValueOnce(new TypeError('fetch failed'))
.mockResolvedValueOnce({
ok: true,
json: async () => ({ text: mockTranscript }),
} as Response);
const config: AudioTranscriptionConfig = {
endpoint: 'https://api.example.com/v1/audio/transcriptions',
apiKey: 'test-key',
model: 'test-model',
};
const result = await transcribeAudio(oggAudioAttachment, config);
expect(result).toBe(mockTranscript);
expect(global.fetch).toHaveBeenCalledTimes(2);
});
// Positive: uses Whisper-1 model by default.
it('uses whisper-1 model by default', async () => {
const config: AudioTranscriptionConfig = {