Skip to content

Commit fc9a2bb

Browse files
fix(voice): close model setup when dictation is cancelled
1 parent 9c34fc4 commit fc9a2bb

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

‎apps/web/src/speech/useEnvironmentSpeechInput.browser.test.tsx‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { useLayoutEffect } from "react";
22
import { expect, it, vi } from "vite-plus/test";
33
import { page, userEvent } from "vite-plus/test/browser";
4+
import * as Deferred from "effect/Deferred";
45
import * as Effect from "effect/Effect";
56
import * as Option from "effect/Option";
67
import type { PreparedConnection } from "@t3tools/client-runtime/connection";
8+
import { getEnvironmentSpeechModels } from "@t3tools/client-runtime/voice-input";
79
import {
810
DEFAULT_CLIENT_SETTINGS,
911
DEFAULT_SERVER_SETTINGS,
@@ -129,11 +131,12 @@ vi.mock("@t3tools/client-runtime/voice-input", async (importOriginal) => ({
129131
if (mocks.selectionFails) throw new Error("selection failed");
130132
return { models: mocks.models };
131133
}),
132-
getEnvironmentSpeechModels: () =>
134+
getEnvironmentSpeechModels: vi.fn(() =>
133135
Effect.sync(() => {
134136
if (mocks.catalogOffline) throw new Error("Catalog offline");
135137
return { models: mocks.models };
136138
}),
139+
),
137140
postProcessEnvironmentTranscript: (
138141
prepared: PreparedConnection,
139142
transcript: string,
@@ -445,6 +448,29 @@ it.each([
445448
},
446449
);
447450

451+
it("closes setup when dictation is cancelled during a catalog read", async () => {
452+
setup({ destination: "env-a" });
453+
mocks.modelState = "missing-model";
454+
mocks.settings = { speechLanguage: "en" };
455+
mocks.models = [catalogModel("current", ["en"], true)];
456+
const response = Deferred.makeUnsafe<{ models: EnvironmentSpeechModel[] }>();
457+
vi.mocked(getEnvironmentSpeechModels).mockReturnValueOnce(Deferred.await(response));
458+
await using _screen = await render(<Probe showWizard />);
459+
let firstStart!: Promise<void>;
460+
await act(() => {
461+
firstStart = mocks.voice.start();
462+
});
463+
await expect.element(page.getByText("Loading transcription models…")).toBeVisible();
464+
await act(() => mocks.voice.cancel());
465+
expect(mocks.voice.setup.open).toBe(false);
466+
467+
await act(() => mocks.voice.start());
468+
Deferred.doneUnsafe(response, Effect.succeed({ models: [catalogModel("stale", ["en"], true)] }));
469+
await act(() => firstStart);
470+
await expect.element(page.getByRole("heading", { name: "current" })).toBeVisible();
471+
expect(mocks.microphoneRequests).toEqual([]);
472+
});
473+
448474
it.each([true, false])(
449475
"never downloads the English default when no German recommendation is available (catalog offline: %s)",
450476
async (offline) => {

‎apps/web/src/speech/useEnvironmentSpeechInput.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,7 @@ export function useEnvironmentSpeechInput(input: HookInput) {
594594
pendingSubmissionRef.current = null;
595595
startRequestRef.current += 1;
596596
setQueuedStart(null);
597+
setSetup(INITIAL_SETUP);
597598
controllerRef.current?.cancel();
598599
}),
599600
skipPostProcessing: useStableCallback(() => controllerRef.current?.skipPostProcessing()),

0 commit comments

Comments
 (0)