fix(web): stop voice backend detection from raising the error banner (#1164)

This commit is contained in:
Haoqing Wang
2026-07-26 15:04:59 +08:00
committed by GitHub
parent 31ad7a6616
commit 51c2b4b3f5
2 changed files with 66 additions and 2 deletions
@@ -0,0 +1,62 @@
import { cleanup, render, waitFor } from '@testing-library/react'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { VoiceBackendSession } from '@/realtime/VoiceBackendSession'
import type { ApiClient } from '@/api/client'
const fetchVoiceBackendMock = vi.fn()
vi.mock('@/api/voice', () => ({
fetchVoiceBackend: (api: ApiClient) => fetchVoiceBackendMock(api),
}))
vi.mock('@/realtime/RealtimeVoiceSession', () => ({
RealtimeVoiceSession: () => null,
}))
vi.mock('@/realtime/GeminiLiveVoiceSession', () => ({
GeminiLiveVoiceSession: () => null,
}))
vi.mock('@/realtime/QwenVoiceSession', () => ({
QwenVoiceSession: () => null,
}))
const api = {} as ApiClient
describe('VoiceBackendSession', () => {
beforeEach(() => {
vi.clearAllMocks()
})
afterEach(() => {
cleanup()
})
it('does not report a voice error when backend detection fails', async () => {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => {})
const detectionError = new Error('HTTP 404 : 404 Not Found')
fetchVoiceBackendMock.mockRejectedValue(detectionError)
const onStatusChange = vi.fn()
render(<VoiceBackendSession api={api} micMuted={false} onStatusChange={onStatusChange} />)
await waitFor(() => {
expect(consoleError).toHaveBeenCalledWith(expect.any(String), detectionError)
})
expect(onStatusChange).not.toHaveBeenCalled()
consoleError.mockRestore()
})
it('reports the detected backend as ready', async () => {
fetchVoiceBackendMock.mockResolvedValue({ backend: 'elevenlabs', backends: ['elevenlabs'] })
const onStatusChange = vi.fn()
render(<VoiceBackendSession api={api} micMuted={false} onStatusChange={onStatusChange} />)
await waitFor(() => {
expect(fetchVoiceBackendMock).toHaveBeenCalledWith(api)
})
expect(onStatusChange).not.toHaveBeenCalled()
})
})
+4 -2
View File
@@ -36,8 +36,10 @@ export function VoiceBackendSession(props: VoiceBackendSessionProps) {
}
}).catch((err: unknown) => {
if (!cancelled) {
const msg = err instanceof Error ? err.message : 'Could not detect voice backend'
props.onStatusChange?.('error', msg)
// Detection runs on mount for every session, not in response to a user action,
// so it must not raise the global voice error banner. Leaving `backend` null
// keeps `onReadyChange` false, which disables the voice button.
console.error('Could not detect voice backend:', err)
}
})
return () => {