@firstpick/pi-package-webui 0.5.9 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { spawn, spawnSync } from "node:child_process";
3
+ import { createServer } from "node:http";
3
4
  import { chmod, mkdir, mkdtemp, readFile, rm, stat, writeFile } from "node:fs/promises";
4
5
  import { networkInterfaces, tmpdir } from "node:os";
5
6
  import path from "node:path";
@@ -72,6 +73,28 @@ const cwd = await mkdtemp(path.join(tmpdir(), "pi-webui-http-harness-"));
72
73
  const settingsFile = path.join(cwd, "webui-settings.json");
73
74
  await chmod(fakePi, 0o755);
74
75
 
76
+ const voiceProviderRequests = [];
77
+ const voiceProvider = createServer(async (req, res) => {
78
+ const chunks = [];
79
+ for await (const chunk of req) chunks.push(chunk);
80
+ const body = Buffer.concat(chunks);
81
+ voiceProviderRequests.push({ method: req.method, url: req.url, contentType: req.headers["content-type"], bodyLength: body.length });
82
+ if (req.url === "/stt") {
83
+ res.writeHead(200, { "content-type": "application/json" });
84
+ res.end(JSON.stringify({ text: "fake transcript from local stt" }));
85
+ return;
86
+ }
87
+ if (req.url === "/tts") {
88
+ res.writeHead(200, { "content-type": "audio/mpeg" });
89
+ res.end(Buffer.from("fake mp3 bytes"));
90
+ return;
91
+ }
92
+ res.writeHead(404, { "content-type": "application/json" });
93
+ res.end(JSON.stringify({ error: "not found" }));
94
+ });
95
+ await new Promise((resolve) => voiceProvider.listen(0, "127.0.0.1", resolve));
96
+ const voiceProviderPort = voiceProvider.address().port;
97
+
75
98
  const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.0.0.0", "--port", String(port), "--pi", fakePi], {
76
99
  stdio: ["ignore", "pipe", "pipe"],
77
100
  env: {
@@ -81,6 +104,8 @@ const child = spawn(process.execPath, [serverScript, "--cwd", cwd, "--host", "0.
81
104
  GIT_COMMITTER_NAME: "Pi WebUI Test",
82
105
  GIT_COMMITTER_EMAIL: "pi-webui-test@example.invalid",
83
106
  PI_WEBUI_SETTINGS_FILE: settingsFile,
107
+ PI_VOICE_STT_URL: `http://127.0.0.1:${voiceProviderPort}/stt`,
108
+ PI_VOICE_TTS_URL: `http://127.0.0.1:${voiceProviderPort}/tts`,
84
109
  },
85
110
  });
86
111
  let serverOutput = "";
@@ -140,6 +165,17 @@ try {
140
165
  assert.equal(gzipResponse.headers.get("content-encoding"), "gzip", "styles.css should fall back to gzip");
141
166
  await gzipResponse.arrayBuffer();
142
167
 
168
+ // The browser voice loop is dynamically imported by app.js; a missing static
169
+ // allowlist entry would 404 the module and silently disable voice mode.
170
+ const voiceModuleResponse = await fetch(`http://127.0.0.1:${port}/voice-conversation.mjs`, {
171
+ signal: AbortSignal.timeout(5_000),
172
+ });
173
+ assert.equal(voiceModuleResponse.status, 200, "voice-conversation.mjs must be served for the Natural Conversation browser voice loop");
174
+ assert.match(voiceModuleResponse.headers.get("content-type") || "", /text\/javascript/, "voice-conversation.mjs should use a JavaScript MIME type");
175
+ const voiceModuleBody = await voiceModuleResponse.arrayBuffer();
176
+ const rawVoiceModuleSize = (await stat(join(root, "public", "voice-conversation.mjs"))).size;
177
+ assert.equal(voiceModuleBody.byteLength, rawVoiceModuleSize, "served voice-conversation.mjs should match the raw file byte-for-byte in size");
178
+
143
179
  const mermaidModuleResponse = await fetch(`http://127.0.0.1:${port}/vendor/mermaid/mermaid.esm.min.mjs`, {
144
180
  signal: AbortSignal.timeout(5_000),
145
181
  });
@@ -665,6 +701,19 @@ try {
665
701
  assert.ok(conversationFeature.body?.data?.commands?.includes("talk"), "Natural Conversation feature data should expose loaded /talk commands");
666
702
  assert.equal(conversationFeature.body?.data?.mode?.enabled, false, "Natural Conversation should start disabled per tab");
667
703
 
704
+ const conversationVoices = await request("127.0.0.1", `/api/conversation-voices?tab=${encodeURIComponent(tabId)}`);
705
+ assert.equal(conversationVoices.status, 200);
706
+ assert.ok(Array.isArray(conversationVoices.body?.data?.voices), "conversation-voices should return a voices array");
707
+ assert.ok(
708
+ conversationVoices.body.data.voices.some((voice) => voice.id === "de_DE-thorsten-medium"),
709
+ "conversation-voices should include the mirrored Piper catalog",
710
+ );
711
+ const badVoice = await request("127.0.0.1", "/api/conversation-voice", {
712
+ method: "POST",
713
+ body: { voice: "../etc/passwd; rm -rf", tab: tabId },
714
+ });
715
+ assert.equal(badVoice.status, 400, "conversation-voice must reject ids that are not plain voice names");
716
+
668
717
  const conversationOn = await request("127.0.0.1", "/api/conversation-mode", {
669
718
  method: "POST",
670
719
  body: { enabled: true, tab: tabId },
@@ -692,9 +741,18 @@ try {
692
741
  const allowedConversationPrompt = await request("127.0.0.1", "/api/prompt", { method: "POST", body: { message: "Explain the current repo briefly", tab: tabId } });
693
742
  assert.equal(allowedConversationPrompt.status, 200, "ordinary prompts remain allowed while Natural Conversation is active");
694
743
 
695
- const sttPlaceholder = await request("127.0.0.1", "/api/stt/transcribe", { method: "POST", body: { tab: tabId } });
696
- assert.equal(sttPlaceholder.status, 501, "hosted/local STT placeholder route should be explicit and non-operational");
697
- assert.match(String(sttPlaceholder.body?.error || ""), /STT\/TTS fallbacks are not implemented/);
744
+ const localStt = await request("127.0.0.1", "/api/stt/transcribe", { method: "POST", body: { tab: tabId, provider: "local", mimeType: "audio/webm", audioBase64: Buffer.from("fake audio").toString("base64") } });
745
+ assert.equal(localStt.status, 200, `local STT fallback should transcribe through the configured endpoint: ${localStt.body?.error || ""}`);
746
+ assert.equal(localStt.body?.data?.provider, "local");
747
+ assert.equal(localStt.body?.data?.text, "fake transcript from local stt");
748
+ assert.ok(voiceProviderRequests.some((item) => item.url === "/stt" && /multipart\/form-data/.test(String(item.contentType || ""))), "local STT should receive a multipart audio upload");
749
+
750
+ const localTts = await request("127.0.0.1", "/api/tts/speech", { method: "POST", body: { tab: tabId, provider: "local", text: "Say this aloud" } });
751
+ assert.equal(localTts.status, 200, `local TTS fallback should synthesize through the configured endpoint: ${localTts.body?.error || ""}`);
752
+ assert.equal(localTts.body?.data?.provider, "local");
753
+ assert.equal(localTts.body?.data?.contentType, "audio/mpeg");
754
+ assert.equal(Buffer.from(localTts.body?.data?.audioBase64 || "", "base64").toString("utf8"), "fake mp3 bytes");
755
+ assert.ok(voiceProviderRequests.some((item) => item.url === "/tts" && /application\/json/.test(String(item.contentType || ""))), "local TTS should receive a JSON text synthesis request");
698
756
 
699
757
  const conversationOff = await request("127.0.0.1", "/api/conversation-mode", {
700
758
  method: "POST",
@@ -738,6 +796,20 @@ try {
738
796
  const remoteHealthBeforeAuth = await request(lan, "/api/health");
739
797
  assert.equal(remoteHealthBeforeAuth.status, 200, "LAN clients should connect without a PIN while auth is off");
740
798
 
799
+ const remoteSttWithoutConsent = await request(lan, "/api/stt/transcribe", {
800
+ method: "POST",
801
+ body: { tab: tabId, provider: "local", mimeType: "audio/webm", audioBase64: Buffer.from("fake remote audio").toString("base64") },
802
+ });
803
+ assert.equal(remoteSttWithoutConsent.status, 403, "remote STT uploads must require explicit microphone streaming consent");
804
+ assert.match(String(remoteSttWithoutConsent.body?.error || ""), /explicit.*remote microphone streaming consent/i);
805
+
806
+ const remoteSttWithConsent = await request(lan, "/api/stt/transcribe", {
807
+ method: "POST",
808
+ body: { tab: tabId, provider: "local", mimeType: "audio/webm", audioBase64: Buffer.from("fake remote audio").toString("base64"), remoteMicStreamingConsentAccepted: true },
809
+ });
810
+ assert.equal(remoteSttWithConsent.status, 200, "remote STT uploads should proceed after explicit per-request consent");
811
+ assert.equal(remoteSttWithConsent.body?.data?.text, "fake transcript from local stt");
812
+
741
813
  const remoteDelete = await request(lan, "/api/session-delete", {
742
814
  method: "POST",
743
815
  body: { sessionPath: path.join(cwd, "outside.jsonl"), confirmed: true, tab: tabId },
@@ -829,6 +901,7 @@ try {
829
901
  child.kill("SIGKILL");
830
902
  await new Promise((resolve) => child.once("exit", resolve));
831
903
  }
904
+ await new Promise((resolve) => voiceProvider.close(() => resolve()));
832
905
  await rmWithRetry(cwd);
833
906
  }
834
907
 
@@ -157,6 +157,21 @@ assert.ok(
157
157
  assert.match(html, /id="optionsConversationModeButton"[^>]*data-command="\/talk"[^>]*hidden[\s\S]*?<span>Start Conversation<\/span>/, "Options menu should include the feature-gated Natural Conversation toggle");
158
158
  assert.match(html, /id="conversationModeChip" class="composer-conversation-mode-chip"[\s\S]*hidden>Voice: off<\/button>/, "composer should expose a hidden-until-active conversation status chip");
159
159
  assert.match(html, /id="conversationModeEndButton" class="composer-conversation-end-button"[\s\S]*hidden>End conversation<\/button>/, "composer should expose a persistent End conversation button while active");
160
+ assert.match(html, /id="conversationVoiceMenu" class="composer-publish-menu composer-conversation-voice-menu" hidden>[\s\S]*id="conversationVoiceButton"[\s\S]*id="conversationVoiceMenuPanel" class="composer-publish-menu-panel[\s\S]*id="conversationModeEndButton"/, "composer should expose the conversation voice menu (publish-menu pattern) next to the End conversation button");
161
+ assert.match(app, /conversationVoiceMenuPanel: \$\("#conversationVoiceMenuPanel"\)/, "frontend should register the conversation voice menu panel");
162
+ assert.match(app, /\/api\/conversation-voices/, "frontend should load the Piper voice list from the server");
163
+ assert.match(app, /\/api\/conversation-voice"/, "frontend should switch voices through the conversation-voice endpoint");
164
+ assert.match(app, /void switchConversationVoice\(voice\.id\);/, "voice menu item clicks should trigger the voice switch");
165
+ assert.match(app, /elements\.conversationVoiceButton\?\.addEventListener\("click", \(\) => \{\n\s*setConversationVoiceMenuOpen\(!conversationVoiceMenuOpen\);/, "voice menu must open on click like the Common-Pi-options menu (touch devices have no hover)");
166
+ assert.match(app, /\{ menu: elements\.conversationVoiceMenu, button: elements\.conversationVoiceButton, panel: elements\.conversationVoiceMenuPanel \}/, "voice menu should participate in mobile dropdown height bounding");
167
+ assert.match(app, /function conversationVoiceLanguageLabel\(voiceId\)/, "voice labels should include a compact DE/EN language indicator");
168
+ assert.match(app, /function conversationVoiceGenderLabel\(voiceId\)/, "voice labels should include a compact M/F gender indicator");
169
+ assert.match(app, /\$\{label\} ↓\$\{conversationVoiceDownloadSizeText\(voice\)\}/, "voices that are not downloaded yet should use compact labels with a download marker and size");
170
+ assert.match(app, /showConversationVoiceFeedback/, "voice selection and download should surface explicit user feedback");
171
+ assert.match(app, /event\.stopPropagation\(\);\n\s*void switchConversationVoice\(voice\.id\);/, "voice menu item clicks should not be swallowed by surrounding dropdown handlers");
172
+ assert.match(app, /downloading\|testing/, "voice-switch progress from the package status text should surface on the conversation chip");
173
+ assert.match(app, /function nativeConversationAudioEngaged\(\)[\s\S]*widgets\.has\("natural-conversation-audio"\)/, "frontend should detect the package's native audio loop via its widget");
174
+ assert.match(app, /mode\.enabled === true && !!activeTabId && !nativeConversationAudioEngaged\(\)/, "browser Web Speech loop must stand down while native audio is armed (no double voices)");
160
175
  assert.match(html, /id="appRunnerMenuPanel"[^>]*aria-label="Detected app runners"/, "app-runner dropdown should render detected runner choices only from JS data");
161
176
  assert.match(html, /id="appRunnerInfoDialog"[\s\S]*id="appRunnerInfoBody"/, "app-runner explanation popup should have a dynamic details body");
162
177
  assert.match(app, /\.pi-webui-runners\.json/, "app-runner popup should explain the project-local custom runner config file");
@@ -298,7 +313,7 @@ assert.match(css, /\.composer-publish-menu:hover > \.composer-publish-button\[da
298
313
  assert.match(css, /\.composer-publish-menu-panel \{[\s\S]*?display:\s*none;[\s\S]*?flex-direction:\s*column/, "Publish workflow menu should hide when closed and expand like grouped tabs");
299
314
  assert.match(css, /\.composer-publish-menu:hover \.composer-publish-menu-panel,[\s\S]*?\.composer-publish-menu:focus-within \.composer-publish-menu-panel,[\s\S]*?\.composer-publish-menu\.open \.composer-publish-menu-panel \{\n\s+display:\s*flex;/, "Publish workflow menu should open on hover, focus, or explicit open state");
300
315
  assert.match(css, /\.composer-native-command-button \{[\s\S]*?color:\s*var\(--ctp-mauve\)/, "skills/tools command menu should have a distinct slash-command button style");
301
- assert.match(css, /\.composer-options-menu-panel \{[\s\S]*?max-height:\s*min\(calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\), 44rem\)/, "Options menu should be tall enough for common commands without scrolling on normal viewports");
316
+ assert.match(css, /\.composer-options-menu-panel \{[\s\S]*?max-height:\s*min\(calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\), 48rem\)/, "Options menu should be tall enough for common commands without scrolling on normal viewports");
302
317
  assert.match(css, /\.composer-publish-menu-panel \{[\s\S]*?overscroll-behavior:\s*contain;[\s\S]*?-webkit-overflow-scrolling:\s*touch/, "dropdown panels should use contained momentum scrolling when their options overflow");
303
318
  assert.match(css, /\.composer-actions-panel > \.composer-publish-menu \.composer-publish-menu-panel \{[\s\S]*?max-height:\s*min\(var\(--mobile-dropdown-max-height, 34dvh\), calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\)\)/, "mobile composer dropdowns should clamp to an in-viewport scroll height");
304
319
  assert.match(css, /\.composer-actions-panel > \.composer-options-menu \.composer-publish-menu-panel,\n\s+\.composer-actions-panel > \.composer-app-runner-menu \.composer-publish-menu-panel \{\n\s+inset-inline:\s*auto 0;/, "mobile Options and app-runner dropdowns should share the clamped scrollable popover placement");
@@ -403,6 +418,9 @@ assert.match(css, /(?:^|\n)\s*\.side-panel\s*\{[\s\S]*?position:\s*fixed/, "mobi
403
418
  assert.match(css, /\.extension-dialog[\s\S]*?max-height:\s*calc\(var\(--visual-viewport-height/, "dialogs should fit the visual viewport on mobile");
404
419
  assert.match(css, /\.extension-dialog[\s\S]*?inset:\s*auto 0 0 0/, "mobile dialogs should behave like bottom sheets");
405
420
  assert.match(css, /#dialogMessage \{[\s\S]*?white-space:\s*pre-wrap/, "extension dialog messages should preserve multiline prompts");
421
+ assert.match(css, /\.edit-retry-dialog \{[\s\S]*?width:\s*min\(44rem, calc\(100vw - 2rem\)\);[\s\S]*?max-height:\s*calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\);[\s\S]*?overflow:\s*hidden/, "edit/retry dialog should stay bounded by the viewport instead of bleeding off-screen");
422
+ assert.match(css, /\.edit-retry-dialog form \{[\s\S]*?display:\s*grid;[\s\S]*?grid-template-rows:\s*auto auto minmax\(0, 1fr\) auto auto;[\s\S]*?max-height:\s*calc\(var\(--visual-viewport-height, 100dvh\) - 4rem\);[\s\S]*?min-height:\s*0/, "edit/retry dialog form should let the editor row shrink inside the modal");
423
+ assert.match(css, /\.edit-retry-text \{[\s\S]*?min-width:\s*0;[\s\S]*?max-height:\s*min\(32rem, 48vh\);[\s\S]*?overflow-x:\s*hidden;[\s\S]*?overflow-y:\s*auto;[\s\S]*?overflow-wrap:\s*anywhere;[\s\S]*?white-space:\s*pre-wrap/, "edit/retry editor should wrap long prompts and scroll vertically without expanding the modal");
406
424
  assert.match(css, /\.native-command-dialog \{[\s\S]*?width:\s*min\(56rem/, "native slash selector dialog should have roomy desktop layout");
407
425
  assert.match(css, /\.extension-dialog\.remote-qr-dialog \{[\s\S]*?width:\s*min\(34rem/, "remote QR popup should have a bounded modal layout");
408
426
  assert.match(css, /\.remote-qr-loading \{[\s\S]*?display:\s*flex/, "remote QR popup should style its loading placeholder");
@@ -704,6 +722,35 @@ assert.match(app, /const conversationModeByTab = new Map\(\)/, "frontend should
704
722
  assert.match(app, /function defaultConversationModeState[\s\S]*allowedTools: \["read", "grep", "find", "ls"\]/, "frontend Natural Conversation defaults should mirror the read-only tool allowlist");
705
723
  assert.match(app, /function renderConversationModeControls\(\)[\s\S]*document\.body\.classList\.toggle\("conversation-mode-active", active\)[\s\S]*optionsConversationModeButton[\s\S]*conversationModeChip[\s\S]*conversationModeEndButton/, "frontend should render active Natural Conversation controls and page\/composer state");
706
724
  assert.match(app, /async function setNaturalConversationModeEnabled\(enabled\)[\s\S]*api\("\/api\/conversation-mode", \{ method: "POST"/, "frontend Natural Conversation toggle should use the WebUI shell endpoint");
725
+ // Phase 3: browser voice loop (Web Speech STT/TTS) wiring.
726
+ const voiceModule = await readFile(join(root, "public", "voice-conversation.mjs"), "utf8");
727
+ assert.match(voiceModule, /export function createVoiceConversationController\(options = \{\}\)/, "voice loop should live in a dependency-injected module for Node tests");
728
+ assert.match(voiceModule, /if \(state\.assistantStreaming && state\.toolRunning\) \{[\s\S]*queuedInterrupt/, "voice transcripts during tool phases must be queued, not injected");
729
+ assert.match(voiceModule, /if \(!bargeInEnabled\) stopRecognition\(\{ forSpeech: true \}\)/, "microphone must pause during TTS unless barge-in is enabled");
730
+ assert.match(voiceModule, /function pause\(\{ reason = "manual" \} = \{\}\)[\s\S]*stopRecognition\(\{ forSpeech: true \}\)[\s\S]*setUiState\("paused"/, "voice loop should support manual pause without disabling safe mode");
731
+ assert.match(voiceModule, /function resume\(\)[\s\S]*state\.userPaused = false[\s\S]*resumeListeningAfterTurn\(\)/, "voice loop should support manual resume back to listening");
732
+ assert.match(voiceModule, /togglePaused/, "voice controller should expose a pause/resume toggle");
733
+ assert.match(voiceModule, /if \(!transcript \|\| !state\.active \|\| state\.userPaused\) return/, "paused voice loop should drop speech transcripts");
734
+ assert.match(voiceModule, /if \(state\.userPaused\) return snapshot\(\)/, "paused voice loop should not speak a completed assistant turn");
735
+ assert.match(voiceModule, /export function voiceSilenceEventMessage/, "silence events should use a shared structured message");
736
+ assert.match(app, /import\("\.\/voice-conversation\.mjs\?v=\d+"\)/, "app.js should lazy-load the voice module with a cache-busted dynamic import");
737
+ assert.match(app, /function syncVoiceConversationLoop\(\)[\s\S]*stopVoiceConversationLoop\(\)[\s\S]*startVoiceConversationLoop\(activeTabId\)/, "voice loop should follow per-tab conversation mode state");
738
+ assert.match(app, /function toggleVoiceConversationPaused\(\)[\s\S]*togglePaused\?\.\(\)[\s\S]*Browser voice loop paused/, "composer voice chip should be wired to pause or resume browser listening");
739
+ assert.match(app, /function conversationModeDisplayText\(mode = activeConversationMode\(\)\)[\s\S]*voiceConversationVisibleProviderLabel\(\)[\s\S]*browser STT\/TTS/, "conversation status chip should show the active browser voice provider state");
740
+ assert.match(app, /conversationModeChip\?\.addEventListener\("click", \(\) => toggleVoiceConversationPaused\(\)\)/, "conversation chip should pause/resume the browser voice loop instead of ending safe mode");
741
+ assert.match(app, /async function startVoiceConversationLoop\(tabId = activeTabId\)[\s\S]*remoteMicConsentGranted\(tabId\)/, "voice loop must gate remote sessions behind explicit microphone consent");
742
+ assert.match(app, /function isLocalhostWebui\(\)[\s\S]*127\.0\.0\.1/, "remote-consent detection should treat localhost as implicitly consented");
743
+ assert.match(app, /function latestAssistantSpokenText\(\)[\s\S]*assistantDisplayMessages\(message\)\.find\(\(item\) => item\?\.title === "final output"\)/, "spoken text must come from final output only, never thinking or tool payloads");
744
+ assert.match(app, /function speakableTextFromMarkdown\(text\)[\s\S]*Code block omitted/, "spoken text should strip code blocks and markdown syntax");
745
+ assert.match(app, /case "agent_end":[\s\S]*handleVoiceConversationTurnEnd\(tabContext\)/, "agent_end should hand the finished turn to the voice loop");
746
+ assert.match(app, /case "tool_execution_start":[\s\S]*setAssistantActivity\(\{ toolRunning: true \}\)/, "tool execution start should mark the voice loop tool phase");
747
+ assert.match(app, /case "tool_execution_end":[\s\S]*setAssistantActivity\(\{ toolRunning: false \}\)/, "tool execution end should clear the voice loop tool phase");
748
+ assert.match(html, /id="remoteMicStreamingConsentButton"[^>]*disabled>Allow remote microphone streaming</, "remote mic consent button should exist, start disabled, and use action-specific copy");
749
+ assert.match(html, /id="remoteMicStreamingConsent" class="composer-remote-mic-consent" role="alert" hidden/, "remote mic consent disclosure container should exist and start hidden");
750
+ assert.match(css, /\.composer-remote-mic-consent[\s\S]*\.composer-remote-mic-consent-button/, "remote mic consent banner should have dedicated styles");
751
+ assert.match(css, /\.composer-conversation-mode-chip\[data-voice-state="speaking"\]/, "conversation chip should style voice states");
752
+ assert.match(serviceWorker.toString(), /\/voice-conversation\.mjs/, "service worker app shell should include the voice module");
753
+ assert.ok(pkg.scripts.check.includes("node --check public/voice-conversation.mjs"), "npm run check should parse the voice module");
707
754
  assert.match(app, /function updateOptionalFeatureAvailability\(\)[\s\S]*hasAvailableCommand\("git-staged-msg"\)[\s\S]*hasAvailableCommand\("release-npm"\)[\s\S]*hasAvailableCommand\("release-aur"\)[\s\S]*hasAvailableCommand\("safety-guard"\)[\s\S]*hasLoadedRpcCommand\("skills"\)[\s\S]*hasAvailableCommand\("todo-progress-status"\)[\s\S]*hasLoadedRpcCommand\("tools"\)[\s\S]*hasAvailableCommand\("remote"\)[\s\S]*NATURAL_CONVERSATION_COMMAND_NAMES\.some\(\(name\) => hasAvailableCommand\(name\)\)/, "optional feature detection should call RPC-visible commands directly and distinguish native resource selectors from TUI companions");
708
755
  assert.match(app, /hasRemoteWebuiCommand = isOptionalFeatureEnabled\("remoteWebui"\) && hasAvailableCommand\("remote"\)[\s\S]*optionsRemoteButton\.hidden = !hasRemoteWebuiCommand[\s\S]*syncRemoteWebuiControlVisibility\(hasRemoteWebuiCommand\)/, "Options menu should track /remote availability and delegate network card visibility");
709
756
  assert.match(app, /function syncRemoteWebuiControlVisibility[\s\S]*networkControlField\.hidden = !hasRemoteWebuiCommand/, "Remote WebUI network card should render whenever the optional feature and /remote command are enabled");
@@ -754,7 +801,7 @@ assert.match(app, /addGitWorkflowAction\("Push and Create PR", \(\) => pushAndCr
754
801
  assert.match(app, /async function runGitPrPrompt\(tabId = gitWorkflowActionTabId\(\), \{ prefixOutput = "" \} = \{\}\)[\s\S]*body: \{ message: "\/pr" \}/, "guided git workflow should generate PR descriptions with /pr");
755
802
  assert.match(server, /case "\/api\/git-workflow\/branch-name":[\s\S]*readGitWorkflowBranchName\(cwd\)/, "server should expose generated branch-name file loading for the guided PR workflow");
756
803
  assert.match(server, /case "\/api\/git-workflow\/branch":[\s\S]*createGitWorkflowBranchWorktree\(tab, body\)/, "server should route guided PR branch creation through worktree tabs");
757
- assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*snapshotGitWorkflowBranchState\(root\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should copy staged state before opening the worktree tab");
804
+ assert.match(server, /async function createGitWorkflowBranchWorktree\(tab, body = \{\}\)[\s\S]*snapshotGitWorkflowBranchState\(root, tab\.cwd\)[\s\S]*applyGitWorkflowBranchStateToWorktree\(snapshot, worktreePath\)[\s\S]*openWorktreeResultForTab\(tab, createdResult/, "guided PR worktree creation should copy staged state before opening the worktree tab");
758
805
  assert.match(server, /case "\/api\/git-workflow\/create-pr":[\s\S]*runGitHubWorkflowCommand\(\["pr", "create"/, "server should create PRs with the GitHub CLI after confirmation");
759
806
  assert.doesNotMatch(app, /gitWorkflowVisibleTabId|Workflow belongs to/, "guided git workflow should not pin or show workflows outside their owning terminal tab");
760
807
  assert.match(app, /function renderReleaseNpmOutputWidget\(\)/, "release-npm live output should use a specialized Web UI renderer");
@@ -971,7 +1018,7 @@ assert.match(app, /async function sendBtwQuestion\(question,[\s\S]*?`\/btw \$\{c
971
1018
  assert.match(app, /async function sendBtwPromptFromButton\(\)[\s\S]*?if \(!question\) \{\n\s+openBtwComposerWidget\(\);/, "empty /btw button should open the side-question widget input");
972
1019
  assert.match(app, /function renderBtwComposerForm\(\)[\s\S]*?form\.requestSubmit\(\)[\s\S]*?sendBtwQuestion\(question\)/, "/btw widget input should submit each message as a /btw trigger");
973
1020
  assert.match(app, /function makeBtwTransferIcon\(\)[\s\S]*?class", "btw-transfer-icon"[\s\S]*?function transferBtwContextToMain\(button, \{ transferMode = "full" \} = \{\}\)[\s\S]*?`\/btw-transfer \$\{encoded\}`[\s\S]*?streamingBehavior: "steer"[\s\S]*?Summarize & Steer/, "/btw widget should expose full-context and summary transfer actions that send steering context during active runs");
974
- assert.match(app, /async function sendPrompt\(kind = "prompt", explicitMessage, \{ targetTabId = activeTabId, throwOnError = false, streamingBehavior \} = \{\}\)[\s\S]*?if \(targetWasStreaming\) body\.streamingBehavior = streamingBehavior \|\| busyBehavior/, "prompt sending should support a per-call streaming behavior override");
1021
+ assert.match(app, /async function sendPrompt\(kind = "prompt", explicitMessage, \{ targetTabId = activeTabId, throwOnError = false, streamingBehavior \} = \{\}\)[\s\S]*?if \(targetWasBusy\) body\.streamingBehavior = streamingBehavior \|\| busyBehavior/, "prompt sending should support a per-call streaming behavior override");
975
1022
  assert.match(app, /function runPublishWorkflow\(command\)[\s\S]*?sendPrompt\("prompt", `\/\$\{resolvedCommandName\}\$\{commandRest\}`\)/, "Publish workflows should send resolved slash commands directly without replacing the draft");
976
1023
  assert.match(app, /async function runNativeCommandMenu\(command\)[\s\S]*?await handleNativeSlashSelectorCommand\(command\)/, "skills/tools command menu should open native selector dialogs directly");
977
1024
  assert.match(app, /async function runNativeCommandMenu\(command\)[\s\S]*?sendPrompt\("prompt", command\)/, "generic native command menu should fall back to slash-command prompt execution");
@@ -1286,10 +1333,12 @@ assert.match(server, /\["tuiSkillsCommand", "@firstpick\/pi-extension-setup-skil
1286
1333
  assert.match(server, /\["tuiToolsCommand", "@firstpick\/pi-extension-tools"\]/, "server should allow installing the TUI tools optional feature");
1287
1334
  assert.match(server, /\["naturalConversation", "@firstpick\/pi-package-natural-conversation"\]/, "server should know the standalone Natural Conversation package for status\/install guidance without making it WebUI-owned");
1288
1335
  assert.match(server, /const NATURAL_CONVERSATION_COMMAND_NAMES = \["talk", "voice", "conversation"\]/, "server should detect Natural Conversation from RPC-visible command aliases");
1289
- assert.match(server, /function naturalConversationFeatureData\(tab[\s\S]*getCommandData\(tab\)[\s\S]*available[\s\S]*mode/, "server should expose a capability-based Natural Conversation feature snapshot");
1336
+ assert.match(server, /function naturalConversationFeatureData\(tab[\s\S]*getCommandData\(tab, \{ annotateSkills: false \}\)[\s\S]*available[\s\S]*mode/, "server should expose a capability-based Natural Conversation feature snapshot");
1290
1337
  assert.match(server, /url\.pathname === "\/api\/features\/natural-conversation" && req\.method === "GET"[\s\S]*naturalConversationFeatureData\(tab\)/, "server should expose Natural Conversation feature metadata");
1291
1338
  assert.match(server, /url\.pathname === "\/api\/conversation-mode" && req\.method === "POST"[\s\S]*setNaturalConversationMode\(tab, body\)/, "server should toggle Natural Conversation through the package-owned slash command");
1292
- assert.match(server, /url\.pathname === "\/api\/stt\/transcribe" \|\| url\.pathname === "\/api\/tts\/speech"[\s\S]*501[\s\S]*hosted\/local STT\/TTS fallbacks are not implemented/, "server STT\/TTS routes should be explicit later-phase placeholders");
1339
+ assert.match(server, /url\.pathname === "\/api\/stt\/transcribe"[\s\S]*handleNaturalConversationSttTranscribe[\s\S]*url\.pathname === "\/api\/tts\/speech"[\s\S]*handleNaturalConversationTtsSpeech/, "server should expose opt-in Natural Conversation STT/TTS fallback routes");
1340
+ assert.match(server, /PI_VOICE_STT_URL[\s\S]*PI_VOICE_TTS_URL[\s\S]*GROQ_API_KEY[\s\S]*OPENAI_API_KEY[\s\S]*CLOUDFLARE_API_TOKEN/, "server voice fallbacks should be gated by server-side provider environment variables");
1341
+ assert.match(server, /function requireRemoteMicConsentForStt\(req, body = \{\}\)[\s\S]*remoteMicStreamingConsentAccepted/, "server STT fallback should require explicit remote microphone streaming consent for remote clients");
1293
1342
  assert.match(server, /function ensureNaturalConversationPromptSafety\(tab, command\)[\s\S]*setThinkingLevelForTab\(tab, "off"/, "server should force thinking off before WebUI prompts while conversation mode is active");
1294
1343
  assert.match(server, /function enforceNaturalConversationCommandAllowed\(tab, command\)[\s\S]*thinking is forced off[\s\S]*slash commands are blocked from the Web UI shell/, "server should block unsafe direct RPC\/WebUI commands while conversation mode is active");
1295
1344
  assert.match(server, /function optionalFeaturePackageStatus\(featureId\)/, "server should report optional feature package install\/update status");
@@ -0,0 +1,361 @@
1
+ import assert from "node:assert/strict";
2
+ import {
3
+ createVoiceConversationController,
4
+ voiceSilenceEventMessage,
5
+ VOICE_UI_STATES,
6
+ } from "../public/voice-conversation.mjs";
7
+
8
+ // Voice-loop unit tests: drive the dependency-injected controller with fake
9
+ // speech recognition, fake speech synthesis, and fake timers so the whole
10
+ // listen -> prompt -> speak -> listen contract runs deterministically in Node.
11
+
12
+ class FakeRecognition {
13
+ constructor(log) {
14
+ this.log = log;
15
+ this.started = false;
16
+ this.onresult = null;
17
+ this.onerror = null;
18
+ this.onend = null;
19
+ }
20
+ start() {
21
+ if (this.started) throw new Error("InvalidStateError: already started");
22
+ this.started = true;
23
+ this.log.push("recognition:start");
24
+ }
25
+ stop() {
26
+ this.started = false;
27
+ this.log.push("recognition:stop");
28
+ this.onend?.();
29
+ }
30
+ abort() {
31
+ this.started = false;
32
+ this.log.push("recognition:abort");
33
+ this.onend?.();
34
+ }
35
+ emitFinal(text) {
36
+ this.onresult?.({ resultIndex: 0, results: [Object.assign([{ transcript: text }], { isFinal: true })] });
37
+ }
38
+ emitInterim(text) {
39
+ this.onresult?.({ resultIndex: 0, results: [Object.assign([{ transcript: text }], { isFinal: false })] });
40
+ }
41
+ emitError(code) {
42
+ this.onerror?.({ error: code });
43
+ }
44
+ }
45
+
46
+ class FakeSynthesis {
47
+ constructor(log) {
48
+ this.log = log;
49
+ this.utterances = [];
50
+ this.cancelled = 0;
51
+ }
52
+ speak(utterance) {
53
+ this.utterances.push(utterance);
54
+ this.log.push(`synthesis:speak:${utterance.text}`);
55
+ }
56
+ cancel() {
57
+ this.cancelled += 1;
58
+ this.log.push("synthesis:cancel");
59
+ }
60
+ lastUtterance() {
61
+ return this.utterances[this.utterances.length - 1];
62
+ }
63
+ }
64
+
65
+ function createFakeTimers() {
66
+ let nextId = 1;
67
+ const timers = new Map();
68
+ return {
69
+ setTimeoutFn: (handler, delayMs) => {
70
+ const id = nextId++;
71
+ timers.set(id, { handler, delayMs });
72
+ return id;
73
+ },
74
+ clearTimeoutFn: (id) => timers.delete(id),
75
+ fireAll: () => {
76
+ for (const [id, timer] of [...timers]) {
77
+ timers.delete(id);
78
+ timer.handler();
79
+ }
80
+ },
81
+ count: () => timers.size,
82
+ };
83
+ }
84
+
85
+ async function tick(rounds = 4) {
86
+ for (let index = 0; index < rounds; index += 1) await Promise.resolve();
87
+ }
88
+
89
+ function createHarness({ bargeInEnabled = false, silenceTimeoutMs = 8000, tts = true, stt = true, failTranscript = false } = {}) {
90
+ const log = [];
91
+ const recognition = new FakeRecognition(log);
92
+ const synthesis = tts ? new FakeSynthesis(log) : null;
93
+ const transcripts = [];
94
+ const silenceEvents = [];
95
+ const partialTranscripts = [];
96
+ const states = [];
97
+ const events = [];
98
+ const timers = createFakeTimers();
99
+ const controller = createVoiceConversationController({
100
+ recognitionFactory: stt ? () => recognition : () => null,
101
+ synthesis,
102
+ utteranceFactory: tts ? (text) => ({ text, onend: null, onerror: null }) : null,
103
+ sendTranscript: async (text, { reason } = {}) => {
104
+ if (failTranscript) throw new Error("send failed");
105
+ transcripts.push({ text, reason });
106
+ },
107
+ sendSilenceEvent: async (info) => {
108
+ silenceEvents.push(info);
109
+ },
110
+ onPartialTranscript: (text) => partialTranscripts.push(text),
111
+ onStateChange: (uiState) => states.push(uiState),
112
+ onEvent: (message, level) => events.push({ message, level }),
113
+ bargeInEnabled,
114
+ silenceTimeoutMs,
115
+ setTimeoutFn: timers.setTimeoutFn,
116
+ clearTimeoutFn: timers.clearTimeoutFn,
117
+ });
118
+ return { controller, recognition, synthesis, transcripts, silenceEvents, partialTranscripts, states, events, timers, log };
119
+ }
120
+
121
+ // Exported state vocabulary matches the plan's visible states.
122
+ for (const expected of ["off", "listening", "transcribing", "answering", "speaking", "interrupting", "silence", "paused", "error"]) {
123
+ assert.ok(VOICE_UI_STATES.includes(expected), `VOICE_UI_STATES should include ${expected}`);
124
+ }
125
+ assert.match(voiceSilenceEventMessage(8), /stayed silent for 8s/, "silence event message should carry the silent duration");
126
+ assert.match(voiceSilenceEventMessage(8), /Do not invent intent/, "silence event message should instruct conservative interpretation");
127
+
128
+ // 1. start(): recognition begins and state is listening.
129
+ {
130
+ const h = createHarness();
131
+ h.controller.start();
132
+ assert.equal(h.controller.getState().uiState, "listening", "start should enter listening");
133
+ assert.equal(h.recognition.started, true, "start should start recognition");
134
+ assert.equal(h.controller.isActive(), true);
135
+ }
136
+
137
+ // 2. Final transcript while idle is sent as a normal prompt.
138
+ {
139
+ const h = createHarness();
140
+ h.controller.start();
141
+ h.recognition.emitInterim("what is");
142
+ assert.equal(h.controller.getState().uiState, "transcribing", "interim results should show transcribing");
143
+ assert.equal(h.controller.getState().partialTranscript, "what is", "interim results should be exposed as a partial transcript");
144
+ assert.deepEqual(h.partialTranscripts, ["what is"], "partial transcript listeners should receive interim text");
145
+ h.recognition.emitFinal("what is this repo about");
146
+ await tick();
147
+ assert.deepEqual(h.transcripts, [{ text: "what is this repo about", reason: "prompt" }]);
148
+ assert.equal(h.controller.getState().partialTranscript, "", "final transcripts should clear the partial preview");
149
+ assert.deepEqual(h.partialTranscripts, ["what is", ""], "partial transcript listeners should be cleared on final text");
150
+ assert.equal(h.controller.getState().uiState, "answering", "sent transcript should show answering");
151
+ }
152
+
153
+ // 3. Turn end speaks the final answer, pauses the mic, then resumes listening.
154
+ {
155
+ const h = createHarness();
156
+ h.controller.start();
157
+ h.controller.setAssistantActivity({ streaming: true });
158
+ h.controller.handleAssistantTurnEnd("The tests all pass.", { askedQuestion: false });
159
+ assert.equal(h.controller.getState().uiState, "speaking", "final text should be spoken");
160
+ assert.equal(h.synthesis.lastUtterance().text, "The tests all pass.");
161
+ assert.equal(h.recognition.started, false, "mic should be paused while speaking without barge-in");
162
+ h.synthesis.lastUtterance().onend();
163
+ assert.equal(h.controller.getState().uiState, "listening", "TTS end should resume listening");
164
+ assert.equal(h.recognition.started, true, "recognition should restart after speaking");
165
+ assert.equal(h.timers.count(), 0, "no silence timer without a question");
166
+ }
167
+
168
+ // 4. Barge-in enabled: speech during TTS cancels it and interrupts.
169
+ {
170
+ const h = createHarness({ bargeInEnabled: true });
171
+ h.controller.start();
172
+ h.controller.handleAssistantTurnEnd("Long answer being spoken aloud.", { askedQuestion: false });
173
+ assert.equal(h.controller.getState().uiState, "speaking");
174
+ assert.equal(h.recognition.started, true, "barge-in keeps the mic open while speaking");
175
+ const cancelledBefore = h.synthesis.cancelled;
176
+ h.recognition.emitFinal("stop and try something else");
177
+ await tick();
178
+ assert.ok(h.synthesis.cancelled > cancelledBefore, "barge-in should cancel active TTS");
179
+ assert.deepEqual(h.transcripts, [{ text: "stop and try something else", reason: "interrupt" }]);
180
+ assert.equal(h.controller.getState().uiState, "answering");
181
+ }
182
+
183
+ // 5. Speech during assistant final-output streaming is an interruption.
184
+ {
185
+ const h = createHarness();
186
+ h.controller.start();
187
+ h.controller.setAssistantActivity({ streaming: true });
188
+ h.recognition.emitFinal("actually use the other file");
189
+ await tick();
190
+ assert.deepEqual(h.transcripts, [{ text: "actually use the other file", reason: "interrupt" }]);
191
+ }
192
+
193
+ // 6. Speech during a tool phase is queued, then flushed after the tool ends.
194
+ {
195
+ const h = createHarness();
196
+ h.controller.start();
197
+ h.controller.setAssistantActivity({ streaming: true, toolRunning: true });
198
+ h.recognition.emitFinal("wait, stop reading files");
199
+ await tick();
200
+ assert.deepEqual(h.transcripts, [], "transcripts must not be injected during a tool phase");
201
+ assert.equal(h.controller.getState().uiState, "interrupting");
202
+ assert.equal(h.controller.getState().queuedInterrupt, "wait, stop reading files");
203
+ h.controller.setAssistantActivity({ toolRunning: false });
204
+ await tick();
205
+ assert.deepEqual(h.transcripts, [{ text: "wait, stop reading files", reason: "interrupt" }], "queued interrupt should flush after the tool phase");
206
+ }
207
+
208
+ // 7. A queued interrupt still pending at turn end becomes the next prompt and
209
+ // suppresses speaking the interrupted answer.
210
+ {
211
+ const h = createHarness();
212
+ h.controller.start();
213
+ h.controller.setAssistantActivity({ streaming: true, toolRunning: true });
214
+ h.recognition.emitFinal("never mind, different question");
215
+ await tick();
216
+ h.controller.handleAssistantTurnEnd("Here is the answer you interrupted.", { askedQuestion: false });
217
+ await tick();
218
+ assert.deepEqual(h.transcripts, [{ text: "never mind, different question", reason: "prompt" }], "queued interrupt should be delivered as the next turn");
219
+ assert.equal(h.synthesis.utterances.length, 0, "the interrupted answer must not be spoken");
220
+ }
221
+
222
+ // 8. Questions arm the silence timer; timeout emits one structured event.
223
+ {
224
+ const h = createHarness();
225
+ h.controller.start();
226
+ h.controller.handleAssistantTurnEnd("Should I continue with the refactor?", { askedQuestion: true });
227
+ h.synthesis.lastUtterance().onend();
228
+ assert.equal(h.timers.count(), 1, "a question should arm the silence timer");
229
+ h.timers.fireAll();
230
+ await tick();
231
+ assert.equal(h.silenceEvents.length, 1, "silence timeout should emit one event");
232
+ assert.equal(h.silenceEvents[0].silentSeconds, 8);
233
+ assert.equal(h.controller.getState().uiState, "answering", "silence event hands the turn back to the assistant");
234
+ }
235
+
236
+ // 9. User speech cancels a pending silence timer.
237
+ {
238
+ const h = createHarness();
239
+ h.controller.start();
240
+ h.controller.handleAssistantTurnEnd("Which branch should I use?", { askedQuestion: true });
241
+ h.synthesis.lastUtterance().onend();
242
+ assert.equal(h.timers.count(), 1);
243
+ h.recognition.emitFinal("use the main branch");
244
+ await tick();
245
+ assert.equal(h.timers.count(), 0, "answering the question should cancel the silence timer");
246
+ assert.deepEqual(h.transcripts, [{ text: "use the main branch", reason: "prompt" }]);
247
+ assert.equal(h.silenceEvents.length, 0);
248
+ }
249
+
250
+ // 10. Manual composer activity cancels the silence timer too.
251
+ {
252
+ const h = createHarness();
253
+ h.controller.start();
254
+ h.controller.handleAssistantTurnEnd("Anything else?", { askedQuestion: true });
255
+ h.synthesis.lastUtterance().onend();
256
+ assert.equal(h.timers.count(), 1);
257
+ h.controller.handleUserActivity();
258
+ assert.equal(h.timers.count(), 0, "typed prompts should cancel the silence timer");
259
+ }
260
+
261
+ // 11. STT unavailable: paused state, but answers are still spoken.
262
+ {
263
+ const h = createHarness({ stt: false });
264
+ h.controller.start();
265
+ assert.equal(h.controller.getState().uiState, "paused", "missing STT should pause listening, not error");
266
+ h.controller.handleAssistantTurnEnd("Spoken without a microphone.", { askedQuestion: false });
267
+ assert.equal(h.synthesis.lastUtterance().text, "Spoken without a microphone.");
268
+ h.synthesis.lastUtterance().onend();
269
+ assert.equal(h.controller.getState().uiState, "paused", "loop stays paused when STT is unavailable");
270
+ }
271
+
272
+ // 12. Neither STT nor TTS: explicit error state.
273
+ {
274
+ const h = createHarness({ stt: false, tts: false });
275
+ h.controller.start();
276
+ assert.equal(h.controller.getState().uiState, "error");
277
+ }
278
+
279
+ // 13. Microphone permission denial surfaces as an error and stops listening.
280
+ {
281
+ const h = createHarness();
282
+ h.controller.start();
283
+ h.recognition.emitError("not-allowed");
284
+ assert.equal(h.controller.getState().uiState, "error");
285
+ assert.equal(h.recognition.started, false, "denied permission should stop recognition");
286
+ assert.ok(h.events.some((event) => event.level === "error" && /Microphone access was denied/.test(event.message)));
287
+ }
288
+
289
+ // 14. Benign recognition end restarts listening automatically.
290
+ {
291
+ const h = createHarness();
292
+ h.controller.start();
293
+ h.recognition.started = false;
294
+ h.recognition.onend();
295
+ assert.equal(h.recognition.started, true, "spontaneous recognition end should restart the mic");
296
+ }
297
+
298
+ // 15. Manual pause stops listening without disabling the safe conversation mode;
299
+ // resume restarts the microphone and accepts transcripts again.
300
+ {
301
+ const h = createHarness();
302
+ h.controller.start();
303
+ h.controller.pause();
304
+ assert.equal(h.controller.isActive(), true, "pause must keep the controller active");
305
+ assert.equal(h.controller.getState().uiState, "paused");
306
+ assert.equal(h.controller.getState().userPaused, true);
307
+ assert.equal(h.recognition.started, false, "pause should stop recognition");
308
+ h.recognition.onend();
309
+ assert.equal(h.recognition.started, false, "paused recognition must not auto-restart on onend");
310
+ h.recognition.emitFinal("ignored while paused");
311
+ await tick();
312
+ assert.deepEqual(h.transcripts, [], "paused transcripts should be dropped");
313
+ h.controller.resume();
314
+ assert.equal(h.controller.getState().userPaused, false);
315
+ assert.equal(h.controller.getState().uiState, "listening");
316
+ assert.equal(h.recognition.started, true, "resume should restart recognition");
317
+ h.recognition.emitFinal("resume listening");
318
+ await tick();
319
+ assert.deepEqual(h.transcripts, [{ text: "resume listening", reason: "prompt" }]);
320
+ }
321
+
322
+ // 16. Pause clears pending silence timers and suppresses speaking the completed turn.
323
+ {
324
+ const h = createHarness();
325
+ h.controller.start();
326
+ h.controller.handleAssistantTurnEnd("Should I wait?", { askedQuestion: true });
327
+ h.synthesis.lastUtterance().onend();
328
+ assert.equal(h.timers.count(), 1, "question should arm silence timer before pause");
329
+ h.controller.pause();
330
+ assert.equal(h.timers.count(), 0, "pause should clear pending silence timers");
331
+ h.controller.setAssistantActivity({ streaming: true });
332
+ h.controller.handleAssistantTurnEnd("This should not be spoken while paused.", { askedQuestion: false });
333
+ assert.equal(h.synthesis.utterances.length, 1, "paused turn end should not enqueue new TTS");
334
+ }
335
+
336
+ // 17. stop() tears everything down.
337
+ {
338
+ const h = createHarness();
339
+ h.controller.start();
340
+ h.controller.handleAssistantTurnEnd("Do you want more detail?", { askedQuestion: true });
341
+ h.controller.stop();
342
+ assert.equal(h.controller.getState().uiState, "off");
343
+ assert.equal(h.controller.isActive(), false);
344
+ assert.equal(h.recognition.started, false, "stop should stop recognition");
345
+ assert.equal(h.timers.count(), 0, "stop should clear pending silence timers");
346
+ h.recognition.emitFinal("this should be ignored");
347
+ await tick();
348
+ assert.deepEqual(h.transcripts, [], "transcripts after stop are dropped");
349
+ }
350
+
351
+ // 18. Failed transcript delivery returns the loop to listening.
352
+ {
353
+ const h = createHarness({ failTranscript: true });
354
+ h.controller.start();
355
+ h.recognition.emitFinal("this will fail to send");
356
+ await tick();
357
+ assert.equal(h.controller.getState().uiState, "listening", "send failures should fall back to listening");
358
+ assert.ok(h.events.some((event) => event.level === "error" && /Failed to send voice transcript/.test(event.message)));
359
+ }
360
+
361
+ console.log("voice-conversation controller checks passed");