Skip to content

Commit 50fc0ed

Browse files
author
Julius Marminge
committed
fix(client-runtime): clear voice errors on draft switches
1 parent 1b75b59 commit 50fc0ed

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎packages/client-runtime/src/voice-input/controller.test.ts‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,41 @@ describe("VoiceInputController", () => {
166166
expect(denied.recorder.record).not.toHaveBeenCalled();
167167
});
168168

169+
it.each(["permission", "transcription"] as const)(
170+
"clears %s errors when switching to another draft",
171+
async (failure) => {
172+
const harness = createHarness(
173+
failure === "permission"
174+
? { requestPermission: async () => ({ granted: false, canAskAgain: false }) }
175+
: {
176+
getTranscriber: () => ({
177+
prepare: async () =>
178+
preparedTranscription(async () => {
179+
throw new Error("Transcription failed");
180+
}),
181+
}),
182+
},
183+
);
184+
await harness.controller.start();
185+
await harness.controller.stop();
186+
expect(harness.controller.currentState).toMatchObject({
187+
phase: "error",
188+
error: expect.any(String),
189+
errorAction: failure === "permission" ? "settings" : "retry",
190+
});
191+
192+
harness.setDraft(draft({ ownerKey: "environment:other-thread" }));
193+
harness.controller.ownerChanged();
194+
195+
expect(harness.controller.currentState).toEqual({
196+
phase: "idle",
197+
error: null,
198+
errorAction: null,
199+
});
200+
expect(harness.commits).toEqual([]);
201+
},
202+
);
203+
169204
it.each(["permission", "preparation", "recording"] as const)(
170205
"keeps the selected transcriber when preferences change during %s",
171206
async (changeDuring) => {

‎packages/client-runtime/src/voice-input/controller.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ export class VoiceInputController {
330330
}
331331

332332
ownerChanged(): void {
333-
if (this.state.phase === "idle" || this.state.phase === "error") return;
333+
if (this.state.phase === "idle") return;
334334
this.cancel();
335335
}
336336

0 commit comments

Comments
 (0)