diff --git a/mobile/src/dictation/mobile-dictation-setup.test.ts b/mobile/src/dictation/mobile-dictation-setup.test.ts index 7fa1ca221..375f989f1 100644 --- a/mobile/src/dictation/mobile-dictation-setup.test.ts +++ b/mobile/src/dictation/mobile-dictation-setup.test.ts @@ -18,6 +18,10 @@ function ok(result: unknown): RpcSuccess { function fail(message: string): RpcFailure { return { id: 'r', ok: false, error: { code: 'x', message }, _meta: { runtimeId: 'rt' } } } +function malformedFailure(error: { code?: string; message?: string }): RpcResponse { + return { id: 'r', ok: false, error, _meta: { runtimeId: 'rt' } } as unknown as RpcResponse +} + function clientWith(responses: RpcResponse[]): Pick & { calls: Array<{ method: string; params: unknown }> } { @@ -84,6 +88,56 @@ describe('rpc wrappers', () => { const client = clientWith([fail('disconnected')]) await expect(fetchDictationSetup(client)).rejects.toThrow('disconnected') }) + + it('maps legacy desktop denials to update guidance', async () => { + const client = clientWith([ + { + id: 'r', + ok: false, + error: { + code: 'forbidden', + message: "Method 'speech.models.list' is not available to mobile clients" + }, + _meta: { runtimeId: 'rt' } + } + ]) + + await expect(fetchDictationSetup(client)).rejects.toThrow( + 'Update the paired desktop Orca app to use mobile voice settings.' + ) + }) + + it('maps legacy desktop method-not-found failures to update guidance', async () => { + const client = clientWith([ + malformedFailure({ + code: 'method_not_found', + message: 'Unknown method: speech.models.list' + }) + ]) + + await expect(fetchDictationSetup(client)).rejects.toThrow( + 'Update the paired desktop Orca app to use mobile voice settings.' + ) + }) + + it('keeps unrelated speech model failures specific', async () => { + const client = clientWith([ + malformedFailure({ + code: 'internal_error', + message: 'speech.models.list failed unexpectedly' + }) + ]) + + await expect(fetchDictationSetup(client)).rejects.toThrow( + 'speech.models.list failed unexpectedly' + ) + }) + + it('falls back when runtime failures omit a message', async () => { + const client = clientWith([malformedFailure({ code: 'internal_error' })]) + + await expect(fetchDictationSetup(client)).rejects.toThrow('Failed to load dictation models') + }) }) describe('state helpers', () => { diff --git a/mobile/src/dictation/mobile-dictation-setup.ts b/mobile/src/dictation/mobile-dictation-setup.ts index 9c822922b..489465710 100644 --- a/mobile/src/dictation/mobile-dictation-setup.ts +++ b/mobile/src/dictation/mobile-dictation-setup.ts @@ -9,6 +9,20 @@ export type MobileSpeechModel = RuntimeSpeechSetupState['models'][number] // configured. Mapping them lets the mic entry point open the setup sheet // instead of dead-ending on a toast. const SETUP_REQUIRED_CODES = new Set(['voice_dictation_disabled', 'voice_model_not_selected']) +const LEGACY_DESKTOP_SPEECH_SETUP_MESSAGE = + 'Update the paired desktop Orca app to use mobile voice settings.' + +// Why: mobile can pair with older desktop runtimes that predate speech.models.list; +// show upgrade guidance instead of leaking the raw denial or not-found error. +function isLegacyDesktopSpeechSetupError( + error: { code?: string; message?: string } | undefined +): boolean { + const message = error?.message ?? '' + return ( + message.includes('speech.models.list') && + (error?.code === 'method_not_found' || message.includes('not available to mobile clients')) + ) +} export function isDictationSetupRequiredError(message: string): boolean { return SETUP_REQUIRED_CODES.has(message) || message.startsWith('voice_model_not_ready:') @@ -19,6 +33,9 @@ export async function fetchDictationSetup( ): Promise { const response = await client.sendRequest('speech.models.list', null) if (!response.ok) { + if (isLegacyDesktopSpeechSetupError(response.error)) { + throw new Error(LEGACY_DESKTOP_SPEECH_SETUP_MESSAGE) + } throw new Error(response.error?.message || 'Failed to load dictation models') } return (response as RpcSuccess).result as MobileSpeechSetup