diff --git a/src/helpers/recordingValidation.js b/src/helpers/recordingValidation.js index 503f01366..504e4d6e5 100644 --- a/src/helpers/recordingValidation.js +++ b/src/helpers/recordingValidation.js @@ -3,7 +3,9 @@ import { isEmptyRecording } from "./recordingGuard.js"; // Decide whether a finished MediaRecorder session carries real audio before we // hand it to the transcription backend. A fast tap can flush only the container // header, or deliver no chunks at all, which crashes FFmpeg. See issue #871. -export function evaluateFinishedRecording({ blobSize, receivedAudioData } = {}) { +export function evaluateFinishedRecording(params = {}) { + const { blobSize, receivedAudioData } = + params && typeof params === "object" ? params : {}; if (!receivedAudioData) { return { usable: false, reason: "no-audio-data" }; } diff --git a/test/helpers/recordingValidation.test.js b/test/helpers/recordingValidation.test.js index 3fc919f86..795db4073 100644 --- a/test/helpers/recordingValidation.test.js +++ b/test/helpers/recordingValidation.test.js @@ -43,10 +43,14 @@ test("rejects 255 bytes (just under the threshold)", async () => { }); }); -test("treats missing / undefined args as unusable (defensive, does not throw)", async () => { +test("treats missing / undefined / null args as unusable (defensive, does not throw)", async () => { const { evaluateFinishedRecording } = await load(); assert.deepEqual(evaluateFinishedRecording(), { usable: false, reason: "no-audio-data" }); + assert.deepEqual(evaluateFinishedRecording(null), { usable: false, reason: "no-audio-data" }); + assert.deepEqual(evaluateFinishedRecording(undefined), { usable: false, reason: "no-audio-data" }); assert.deepEqual(evaluateFinishedRecording({}), { usable: false, reason: "no-audio-data" }); + assert.deepEqual(evaluateFinishedRecording("invalid"), { usable: false, reason: "no-audio-data" }); + assert.deepEqual(evaluateFinishedRecording(123), { usable: false, reason: "no-audio-data" }); assert.deepEqual(evaluateFinishedRecording({ receivedAudioData: true }), { usable: false, reason: "empty-container",