From 42a1fa1d3a22ef0f8d116ea06e128f0745cb5c08 Mon Sep 17 00:00:00 2001 From: claude code agent 227 Date: Tue, 30 Jun 2026 10:01:49 +0300 Subject: [PATCH] test(#244): cover the out-of-order failure branch of the dictation emitter (F1) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The reviewer noted the in-order emitter's else branch (a NOT-next-to-emit segment failing → buffer an empty placeholder so the drain can skip it, use-streaming-dictation.ts:215-218) was the one reachable ordering branch left uncovered. Add a non-vacuous case: with 3 segments, reject seq 1 (out of order) → one notification, nothing emitted; resolve seq 0 → "alpha"; resolve seq 2 → "gamma". The seq-2 flush proves the empty placeholder let the emitter advance PAST the failed seq 1 — without the else branch the drain would stall at the missing seq 1 and "gamma" would never emit. Co-Authored-By: Claude Opus 4.8 (1M context) --- .../hooks/use-streaming-dictation.test.tsx | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/client/src/features/dictation/hooks/use-streaming-dictation.test.tsx b/apps/client/src/features/dictation/hooks/use-streaming-dictation.test.tsx index 50dfde5f..48f7fb25 100644 --- a/apps/client/src/features/dictation/hooks/use-streaming-dictation.test.tsx +++ b/apps/client/src/features/dictation/hooks/use-streaming-dictation.test.tsx @@ -156,6 +156,36 @@ describe("useStreamingDictation — in-order segment emitter", () => { expect(emitted).toEqual(["survivor"]); }); + it("an OUT-OF-ORDER failed segment is buffered as empty and skipped without stalling later text", async () => { + const emitted: string[] = []; + await startRecording((t) => emitted.push(t)); + await emitSegments(3); + + // seq 1 (NOT next-to-emit) fails first: it takes the else branch — an empty + // placeholder is buffered (resultsRef.set(seq, "")) so the emitter can later + // skip it. One notification, nothing emitted yet (seq 0 still gates). + await act(async () => { + h.pending[1].reject({ message: "boom" }); + }); + expect(notifyShow).toHaveBeenCalledTimes(1); + expect(emitted).toEqual([]); + + // seq 0 flushes; the drain then reaches the buffered empty seq 1 and SKIPS + // past it to seq 2. + await act(async () => { + h.pending[0].resolve("alpha"); + }); + expect(emitted).toEqual(["alpha"]); + + // seq 2 emits — proving the empty placeholder let the emitter advance past + // the failed seq 1. Without the else branch's placeholder the drain would + // stall at the missing seq 1 and "gamma" would never flush. + await act(async () => { + h.pending[2].resolve("gamma"); + }); + expect(emitted).toEqual(["alpha", "gamma"]); + }); + it("ignores a transcription that resolves AFTER cancel() (stale epoch — no emit)", async () => { const emitted: string[] = []; const hook = await startRecording((t) => emitted.push(t));