Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(voice): cover testVoiceProvider directly to clear the diff-coverage gate

M3gA-Minda3cb35524082
diff --git a/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx b/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
index a9f44800e1..3de9c85c24 100644
--- a/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
+++ b/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx
@@ -859,6 +859,27 @@ describe('VoicePanel', () => {
expect(screen.getByTestId('voice-provider-key-modal')).toBeInTheDocument();
});
+ it('renders a thrown Test Key error without saving the key', async () => {
+ // A rejected RPC (transport dead, core down) takes the `catch` branch,
+ // which is a different path from a resolved `{ ok: false }` verdict.
+ vi.mocked(testVoiceProvider).mockRejectedValueOnce(new Error('core unreachable'));
+
+ renderWithProviders(<VoicePanel />, { initialEntries: ['/settings/voice'] });
+
+ await screen.findByTestId('voice-providers-section');
+ fireEvent.click(screen.getByTestId('voice-provider-chip-elevenlabs'));
+ await screen.findByTestId('voice-provider-key-modal');
+
+ fireEvent.change(screen.getByPlaceholderText(/sk/i), {
+ target: { value: 'sk-key-for-a-dead-core' },
+ });
+ fireEvent.click(screen.getByRole('button', { name: /^Test Key$/i }));
+
+ expect(await screen.findByText(/core unreachable/i)).toBeInTheDocument();
+ expect(screen.getByTestId('voice-provider-key-modal')).toBeInTheDocument();
+ expect(vi.mocked(setVoiceProviderKey)).not.toHaveBeenCalled();
+ });
+
it('discards an in-flight Test Key result when the key is edited', async () => {
// The key field stays editable during a test (it is disabled only while
// *saving*). Without the request-id guard, key A's verdict lands next to
diff --git a/app/src/services/api/__tests__/voiceSettingsApi.test.ts b/app/src/services/api/__tests__/voiceSettingsApi.test.ts
new file mode 100644
index 0000000000..3332d9d82c
--- /dev/null
+++ b/app/src/services/api/__tests__/voiceSettingsApi.test.ts
@@ -0,0 +1,77 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { testVoiceProvider } from '../voiceSettingsApi';
+
+vi.mock('../../coreRpcClient', () => ({ callCoreRpc: vi.fn() }));
+
+const okResult = { ok: true, detail: 'Provider key is valid (12ms)', latency_ms: 12 };
+
+describe('voiceSettingsApi', () => {
+ beforeEach(async () => {
+ const { callCoreRpc } = await import('../../coreRpcClient');
+ vi.mocked(callCoreRpc).mockReset();
+ });
+
+ describe('testVoiceProvider', () => {
+ it('omits api_key entirely when no candidate key is supplied', async () => {
+ const { callCoreRpc } = await import('../../coreRpcClient');
+ vi.mocked(callCoreRpc).mockResolvedValueOnce(okResult);
+
+ await testVoiceProvider('stt', 'cloud');
+
+ // `api_key` must be ABSENT, not present-and-empty: the core reads an
+ // empty candidate as "fall back to the stored credential", so sending
+ // one would change which key is being tested.
+ expect(callCoreRpc).toHaveBeenCalledWith({
+ method: 'openhuman.voice_test_provider',
+ params: { workload: 'stt', provider: 'cloud', validate_only: false },
+ timeoutMs: 30_000,
+ });
+ const params = vi.mocked(callCoreRpc).mock.calls[0][0].params as Record<string, unknown>;
+ expect('api_key' in params).toBe(false);
+ });
+
+ it('sends the candidate key for a dry run, trimmed', async () => {
+ const { callCoreRpc } = await import('../../coreRpcClient');
+ vi.mocked(callCoreRpc).mockResolvedValueOnce(okResult);
+
+ // A pasted key routinely carries a trailing newline. The guard and the
+ // payload have to agree on which string is being tested (#5896 review).
+ await testVoiceProvider('stt', 'elevenlabs', true, ' sk-candidate-key-123\n');
+
+ expect(callCoreRpc).toHaveBeenCalledWith({
+ method: 'openhuman.voice_test_provider',
+ params: {
+ workload: 'stt',
+ provider: 'elevenlabs',
+ validate_only: true,
+ api_key: 'sk-candidate-key-123',
+ },
+ timeoutMs: 30_000,
+ });
+ });
+
+ it('treats a whitespace-only candidate key as no key at all', async () => {
+ const { callCoreRpc } = await import('../../coreRpcClient');
+ vi.mocked(callCoreRpc).mockResolvedValueOnce(okResult);
+
+ await testVoiceProvider('tts', 'elevenlabs', true, ' ');
+
+ const params = vi.mocked(callCoreRpc).mock.calls[0][0].params as Record<string, unknown>;
+ expect('api_key' in params).toBe(false);
+ });
+
+ it('strips the core log prefix from the returned detail', async () => {
+ const { callCoreRpc } = await import('../../coreRpcClient');
+ vi.mocked(callCoreRpc).mockResolvedValueOnce({
+ ok: false,
+ detail: '[voice-factory] Key test failed: API returned 401',
+ });
+
+ const result = await testVoiceProvider('stt', 'elevenlabs', true, 'sk-bad');
+
+ expect(result.detail).toBe('Key test failed: API returned 401');
+ expect(result.ok).toBe(false);
+ });
+ });
+});