Harden audio transcription fetch path with retries and timeout
This commit is contained in:
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user