diff --git a/src/helpers/transcriptionFallback.js b/src/helpers/transcriptionFallback.js index 75f3d0d23..24889e74e 100644 --- a/src/helpers/transcriptionFallback.js +++ b/src/helpers/transcriptionFallback.js @@ -1,11 +1,10 @@ // Where a streaming session's batch fallback goes. "skip" keeps a signed-out // cloud user's audio from being diverted to a leftover BYOK provider. -export function resolveStreamingFallbackTarget({ - useLocalWhisper, - cloudTranscriptionMode, - isSignedIn, -}) { - const isCloudMode = !useLocalWhisper && cloudTranscriptionMode === "openwhispr"; +export function resolveStreamingFallbackTarget(params = {}) { + const { useLocalWhisper, cloudTranscriptionMode, isSignedIn } = params || {}; + const normMode = + typeof cloudTranscriptionMode === "string" ? cloudTranscriptionMode.trim().toLowerCase() : ""; + const isCloudMode = !useLocalWhisper && normMode === "openwhispr"; if (isCloudMode) return isSignedIn ? "cloud" : "skip"; return "byok"; } diff --git a/test/helpers/transcriptionFallback.test.js b/test/helpers/transcriptionFallback.test.js index 7b1014105..77008a727 100644 --- a/test/helpers/transcriptionFallback.test.js +++ b/test/helpers/transcriptionFallback.test.js @@ -38,3 +38,26 @@ test("BYOK mode falls back to the user's own provider", async () => { "byok" ); }); + +test("handles nullish parameters and case-insensitive cloudTranscriptionMode", async () => { + const { resolveStreamingFallbackTarget } = await load(); + assert.equal(resolveStreamingFallbackTarget(), "byok"); + assert.equal(resolveStreamingFallbackTarget(null), "byok"); + assert.equal(resolveStreamingFallbackTarget(undefined), "byok"); + assert.equal( + resolveStreamingFallbackTarget({ + useLocalWhisper: false, + cloudTranscriptionMode: "OpenWhispr", + isSignedIn: true, + }), + "cloud" + ); + assert.equal( + resolveStreamingFallbackTarget({ + useLocalWhisper: false, + cloudTranscriptionMode: " OPENWHISPR ", + isSignedIn: false, + }), + "skip" + ); +});