The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(voice): cover testVoiceProvider directly to clear the diff-coverage gate\n\n`PR CI Gate` failed at 0% diff coverage. The cause was not a missing\nassertion but a missing *executor*: `VoicePanel.test.tsx` mocks the whole\n`voiceSettingsApi` module, so `testVoiceProvider`'s body — including the\nnew `api_key` handling — was never run by any test. diff-cover measured\nexactly two lines, both inside that function, both uncovered.\n\nAdded `app/src/services/api/__tests__/voiceSettingsApi.test.ts`, mocking\nonly `callCoreRpc` (the idiom `voiceInstallApi.test.ts` already uses), so\nthe function itself executes:\n\n* `api_key` is ABSENT, not present-and-empty, when no candidate is given —\n the core reads an empty candidate as "fall back to the stored\n credential", so sending one would silently change which key is tested.\n* a candidate key is sent trimmed.\n* a whitespace-only candidate is treated as no key.\n* the `[voice-factory]` log prefix is stripped from `detail`.\n\nAlso covered the modal's `catch` branch. Coverage showed lines 210-211\nunhit: every existing test resolves `{ ok: false }`, which is the verdict\npath, never the *thrown* path (transport dead, core down). Those are lines\nthis PR added, so they counted against the gate — and the branch had no\ntest regardless of the gate.\n\nVerification, all local through the fleet CI semaphore:\n\n* `vitest run voiceSettingsApi.test.ts VoicePanel.test.tsx` — 48 passed.\n* Coverage re-measured from `coverage/lcov.info`: the two previously\n missing lines in `voiceSettingsApi.ts` now show 4 hits each, and no line\n this PR changed in `VoicePanelKeyModal.tsx` is uncovered. The remaining\n unhit lines there (25-56, 146-147, 246) are pre-existing Piper\n install-status branches this PR does not touch.\n* Revert-proofs, each failing on its own assertion, then restored:\n - drop the `.trim()` on the payload → "sends the candidate key for a dry\n run, trimmed" fails at `:42`, diffing `" sk-candidate-key-123\n"`.\n - always send `api_key: apiKey ?? ''` → the two omission tests fail at\n `:25` and `:61`, and the trim test at `:42`; the log-prefix test stays\n green, which is correct — it does not test that behaviour.\n - neuter `stripLogPrefix` → only the prefix test fails, at `:73`.\n - genericise the catch detail to `'Test failed'` → the thrown-error test\n fails at `:878`.\n
M3gA-Mind37be8e6fedae
diff --git a/app/src/components/settings/panels/__tests__/VoicePanel.test.tsx b/app/src/components/settings/panels/__tests__/VoicePanel.test.tsxindex 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 todiff --git a/app/src/services/api/__tests__/voiceSettingsApi.test.ts b/app/src/services/api/__tests__/voiceSettingsApi.test.tsnew file mode 100644index 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);+ });+ });+});