Add localhost->127.0.0.1 fallback for transcription fetch

This commit is contained in:
William Valentin
2026-02-22 20:26:38 -08:00
parent 58eee60023
commit 3d59e5ea9d
6 changed files with 111 additions and 8 deletions
+22
View File
@@ -460,6 +460,28 @@ describe('transcribeAudio', () => {
expect(global.fetch).toHaveBeenCalledTimes(2);
});
it('falls back from localhost to 127.0.0.1 on transient fetch failures', async () => {
vi.mocked(global.fetch)
.mockRejectedValueOnce(new TypeError('fetch failed'))
.mockResolvedValueOnce({
ok: true,
json: async () => ({ text: mockTranscript }),
} as Response);
const config: AudioTranscriptionConfig = {
endpoint: 'http://localhost:18801/v1/audio/transcriptions',
apiKey: 'test-key',
model: 'test-model',
};
const result = await transcribeAudio(oggAudioAttachment, config);
expect(result).toBe(mockTranscript);
expect(global.fetch).toHaveBeenCalledTimes(2);
expect(vi.mocked(global.fetch).mock.calls[0]?.[0]).toBe('http://localhost:18801/v1/audio/transcriptions');
expect(vi.mocked(global.fetch).mock.calls[1]?.[0]).toBe('http://127.0.0.1:18801/v1/audio/transcriptions');
});
// Positive: uses Whisper-1 model by default.
it('uses whisper-1 model by default', async () => {
const config: AudioTranscriptionConfig = {