@firstpick/pi-package-webui 0.5.8 → 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.
- package/README.md +12 -0
- package/bin/pi-webui.mjs +857 -12
- package/lib/git-worktrees.mjs +5 -1
- package/package.json +2 -2
- package/public/app.js +1090 -45
- package/public/index.html +20 -4
- package/public/service-worker.js +2 -1
- package/public/styles.css +368 -5
- package/public/voice-conversation.mjs +466 -0
- package/tests/compaction-resume-harness.test.mjs +114 -0
- package/tests/compaction-static.test.mjs +25 -0
- package/tests/fixtures/compacting-pi.mjs +115 -0
- package/tests/fixtures/fake-pi.mjs +220 -2
- package/tests/http-endpoints-harness.test.mjs +194 -2
- package/tests/mobile-static.test.mjs +82 -8
- package/tests/voice-conversation.test.mjs +361 -0
|
@@ -154,6 +154,24 @@ assert.ok(
|
|
|
154
154
|
Math.min(optionsReloadIndex, optionsNameIndex) < optionsRemoteIndex && optionsRemoteIndex < Math.max(optionsReloadIndex, optionsNameIndex),
|
|
155
155
|
"Open Remote should render between Reload Pi and Name Session",
|
|
156
156
|
);
|
|
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
|
+
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
|
+
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)");
|
|
157
175
|
assert.match(html, /id="appRunnerMenuPanel"[^>]*aria-label="Detected app runners"/, "app-runner dropdown should render detected runner choices only from JS data");
|
|
158
176
|
assert.match(html, /id="appRunnerInfoDialog"[\s\S]*id="appRunnerInfoBody"/, "app-runner explanation popup should have a dynamic details body");
|
|
159
177
|
assert.match(app, /\.pi-webui-runners\.json/, "app-runner popup should explain the project-local custom runner config file");
|
|
@@ -295,7 +313,7 @@ assert.match(css, /\.composer-publish-menu:hover > \.composer-publish-button\[da
|
|
|
295
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");
|
|
296
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");
|
|
297
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");
|
|
298
|
-
assert.match(css, /\.composer-options-menu-panel \{[\s\S]*?max-height:\s*min\(calc\(var\(--visual-viewport-height, 100dvh\) - 2rem\),
|
|
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");
|
|
299
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");
|
|
300
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");
|
|
301
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");
|
|
@@ -400,6 +418,9 @@ assert.match(css, /(?:^|\n)\s*\.side-panel\s*\{[\s\S]*?position:\s*fixed/, "mobi
|
|
|
400
418
|
assert.match(css, /\.extension-dialog[\s\S]*?max-height:\s*calc\(var\(--visual-viewport-height/, "dialogs should fit the visual viewport on mobile");
|
|
401
419
|
assert.match(css, /\.extension-dialog[\s\S]*?inset:\s*auto 0 0 0/, "mobile dialogs should behave like bottom sheets");
|
|
402
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");
|
|
403
424
|
assert.match(css, /\.native-command-dialog \{[\s\S]*?width:\s*min\(56rem/, "native slash selector dialog should have roomy desktop layout");
|
|
404
425
|
assert.match(css, /\.extension-dialog\.remote-qr-dialog \{[\s\S]*?width:\s*min\(34rem/, "remote QR popup should have a bounded modal layout");
|
|
405
426
|
assert.match(css, /\.remote-qr-loading \{[\s\S]*?display:\s*flex/, "remote QR popup should style its loading placeholder");
|
|
@@ -695,7 +716,42 @@ assert.match(app, /id: "safetyGuard"[\s\S]*?@firstpick\/pi-extension-safety-guar
|
|
|
695
716
|
assert.match(app, /id: "tuiSkillsCommand"[\s\S]*?@firstpick\/pi-extension-setup-skills/, "optional features should include the TUI skills command companion");
|
|
696
717
|
assert.match(app, /id: "tuiToolsCommand"[\s\S]*?@firstpick\/pi-extension-tools/, "optional features should include the TUI tools command companion");
|
|
697
718
|
assert.match(app, /id: "remoteWebui"[\s\S]*?@firstpick\/pi-package-remote-webui/, "optional features should include the Remote WebUI companion");
|
|
698
|
-
assert.match(app, /
|
|
719
|
+
assert.match(app, /id: "naturalConversation"[\s\S]*?@firstpick\/pi-package-natural-conversation[\s\S]*?capabilityLabel: "\/talk, \/voice, or \/conversation"/, "optional features should include the capability-detected Natural Conversation shell");
|
|
720
|
+
assert.match(app, /NATURAL_CONVERSATION_COMMAND_NAMES = \["talk", "voice", "conversation"\]/, "frontend should detect Natural Conversation only from RPC-visible command aliases");
|
|
721
|
+
assert.match(app, /const conversationModeByTab = new Map\(\)/, "frontend should track Natural Conversation state per terminal tab");
|
|
722
|
+
assert.match(app, /function defaultConversationModeState[\s\S]*allowedTools: \["read", "grep", "find", "ls"\]/, "frontend Natural Conversation defaults should mirror the read-only tool allowlist");
|
|
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");
|
|
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");
|
|
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");
|
|
699
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");
|
|
700
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");
|
|
701
757
|
assert.match(app, /if \(featureId === "remoteWebui"\) syncRemoteWebuiControlVisibility\(false\)/, "Disabling Remote WebUI should immediately hide browser network controls before broader rerendering");
|
|
@@ -745,14 +801,19 @@ assert.match(app, /addGitWorkflowAction\("Push and Create PR", \(\) => pushAndCr
|
|
|
745
801
|
assert.match(app, /async function runGitPrPrompt\(tabId = gitWorkflowActionTabId\(\), \{ prefixOutput = "" \} = \{\}\)[\s\S]*body: \{ message: "\/pr" \}/, "guided git workflow should generate PR descriptions with /pr");
|
|
746
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");
|
|
747
803
|
assert.match(server, /case "\/api\/git-workflow\/branch":[\s\S]*createGitWorkflowBranchWorktree\(tab, body\)/, "server should route guided PR branch creation through worktree tabs");
|
|
748
|
-
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");
|
|
749
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");
|
|
750
806
|
assert.doesNotMatch(app, /gitWorkflowVisibleTabId|Workflow belongs to/, "guided git workflow should not pin or show workflows outside their owning terminal tab");
|
|
751
807
|
assert.match(app, /function renderReleaseNpmOutputWidget\(\)/, "release-npm live output should use a specialized Web UI renderer");
|
|
752
808
|
assert.match(app, /async function refreshAppRunners\(tabContext = activeTabContext\(\)\)/, "frontend should load detected app runners for the active tab cwd");
|
|
753
809
|
assert.match(app, /function renderAppRunnerWidget\(\)/, "frontend should render app runner output in the shared top widget area");
|
|
754
810
|
assert.match(app, /function tabAppRunnerRunningRun\(tab\)[\s\S]*appRunnerIsRunning\(run\)/, "frontend should derive running app-runner state for terminal tab indicators");
|
|
755
|
-
assert.match(app, /function appendTerminalTabContent\(button, \{ title, indicator, meta, count = null, appRunnerRun = null \}\)[\s\S]*terminal-tab-app-runner-indicator/, "terminal tab content should render a visible app-runner badge");
|
|
811
|
+
assert.match(app, /function appendTerminalTabContent\(button, \{ title, indicator, meta, count = null, appRunnerRun = null, conversationModeActive = false \}\)[\s\S]*terminal-tab-app-runner-indicator/, "terminal tab content should render a visible app-runner badge");
|
|
812
|
+
assert.match(app, /function appendTerminalTabContent\(button,[\s\S]*terminal-tab-conversation-indicator/, "terminal tab content should render a visible Natural Conversation badge");
|
|
813
|
+
assert.match(app, /function renderTerminalTab\(tab\)[\s\S]*conversation-mode-running/, "terminal tabs should indicate active Natural Conversation mode per tab");
|
|
814
|
+
assert.match(css, /\.composer-conversation-mode-chip[\s\S]*\.composer-conversation-end-button/, "Natural Conversation composer controls should have dedicated styles");
|
|
815
|
+
assert.match(css, /\.composer\.conversation-mode-active[\s\S]*body\.conversation-mode-active \.composer::before/, "active Natural Conversation mode should visibly glow around the composer");
|
|
816
|
+
assert.match(css, /\.terminal-tab\.conversation-mode-running[\s\S]*\.terminal-tab-conversation-indicator/, "Natural Conversation tabs should have active-tab and badge styles");
|
|
756
817
|
assert.match(app, /function renderTerminalTabGroup\(group[\s\S]*tabGroupAppRunnerRunningRun\(groupTabs\)[\s\S]*app-runner-running/, "terminal tab groups should indicate when any child tab has a running app runner");
|
|
757
818
|
assert.match(server, /function tabMeta\(tab\)[\s\S]*appRunner: publicAppRunnerState\(tab\.appRunner\)/, "server should expose app-runner state in tab metadata for inactive tab indicators");
|
|
758
819
|
assert.match(app, /function renderAppRunnerInputForm\(run\)[\s\S]*app-runner-stdin-input[\s\S]*Send stdin/, "frontend should let running app runners receive line-oriented stdin");
|
|
@@ -956,8 +1017,8 @@ assert.match(app, /sendPromptFromModeButton\("follow-up", elements\.followUpButt
|
|
|
956
1017
|
assert.match(app, /async function sendBtwQuestion\(question,[\s\S]*?`\/btw \$\{cleanQuestion\}`[\s\S]*?await sendPrompt\("prompt", message, \{ targetTabId, throwOnError: true \}\)/, "/btw helper should send text as an ephemeral slash command");
|
|
957
1018
|
assert.match(app, /async function sendBtwPromptFromButton\(\)[\s\S]*?if \(!question\) \{\n\s+openBtwComposerWidget\(\);/, "empty /btw button should open the side-question widget input");
|
|
958
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");
|
|
959
|
-
assert.match(app, /function makeBtwTransferIcon\(\)[\s\S]*?class", "btw-transfer-icon"[\s\S]*?function transferBtwContextToMain\(button\)[\s\S]*?`\/btw-transfer \$\{encoded\}`[\s\S]*?streamingBehavior:
|
|
960
|
-
assert.match(app, /async function sendPrompt\(kind = "prompt", explicitMessage, \{ targetTabId = activeTabId, throwOnError = false, streamingBehavior \} = \{\}\)[\s\S]*?if \(
|
|
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");
|
|
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");
|
|
961
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");
|
|
962
1023
|
assert.match(app, /async function runNativeCommandMenu\(command\)[\s\S]*?await handleNativeSlashSelectorCommand\(command\)/, "skills/tools command menu should open native selector dialogs directly");
|
|
963
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");
|
|
@@ -1143,7 +1204,7 @@ assert.ok(mochaBackground.length > 8000, "Catppuccin Mocha background image shou
|
|
|
1143
1204
|
|
|
1144
1205
|
assert.match(server, /AuthStorage, SessionManager/, "server should import AuthStorage for safe OAuth token refresh");
|
|
1145
1206
|
assert.match(server, /DefaultPackageManager/, "server should use Pi's package resolver when controlling Web UI tab extension loading");
|
|
1146
|
-
assert.match(server, /WEBUI_CONTROLLED_PACKAGES = new Set\(\[WEBUI_PACKAGE
|
|
1207
|
+
assert.match(server, /WEBUI_CONTROLLED_PACKAGES = new Set\(\[[\s\S]*WEBUI_PACKAGE[\s\S]*filter\(\(\[featureId\]\) => featureId !== NATURAL_CONVERSATION_FEATURE_ID\)/, "server should identify Web UI-controlled packages for de-duplicated feature loading while leaving Natural Conversation independently owned");
|
|
1147
1208
|
assert.match(server, /const args = \["--mode", "rpc", "--no-extensions", "--no-skills", "--no-prompt-templates", "--no-themes"\]/, "Web UI tabs should disable implicit resource loading before adding curated resource paths");
|
|
1148
1209
|
assert.match(server, /normalPiResourcePathsForTab[\s\S]*WEBUI_CONTROLLED_PACKAGES\.has\(packageName\)[\s\S]*continue/, "Web UI tab resource resolution should exclude separately installed Web UI feature packages");
|
|
1149
1210
|
assert.match(server, /startedWebuiResourcePaths\(resourceType\)/, "Web UI tabs should load feature resources from the started Web UI package");
|
|
@@ -1270,7 +1331,17 @@ assert.match(server, /\["btwCommand", "@firstpick\/pi-extension-btw"\]/, "server
|
|
|
1270
1331
|
assert.match(server, /\["safetyGuard", "@firstpick\/pi-extension-safety-guard"\]/, "server should allow installing the safety guard optional feature");
|
|
1271
1332
|
assert.match(server, /\["tuiSkillsCommand", "@firstpick\/pi-extension-setup-skills"\]/, "server should allow installing the TUI skills optional feature");
|
|
1272
1333
|
assert.match(server, /\["tuiToolsCommand", "@firstpick\/pi-extension-tools"\]/, "server should allow installing the TUI tools optional feature");
|
|
1273
|
-
assert.match(server,
|
|
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");
|
|
1335
|
+
assert.match(server, /const NATURAL_CONVERSATION_COMMAND_NAMES = \["talk", "voice", "conversation"\]/, "server should detect Natural Conversation from RPC-visible command aliases");
|
|
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");
|
|
1337
|
+
assert.match(server, /url\.pathname === "\/api\/features\/natural-conversation" && req\.method === "GET"[\s\S]*naturalConversationFeatureData\(tab\)/, "server should expose Natural Conversation feature metadata");
|
|
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");
|
|
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");
|
|
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");
|
|
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");
|
|
1344
|
+
assert.match(server, /function optionalFeaturePackageStatus\(featureId\)/, "server should report optional feature package install\/update status");
|
|
1274
1345
|
assert.match(server, /function installOptionalFeaturePackage\(featureId\)/, "server should provide optional feature package installation helper");
|
|
1275
1346
|
assert.match(server, /PI_WEBUI_OPTIONAL_FEATURE_INSTALL_ROOT/, "optional feature installs should support an explicit package-manager root override");
|
|
1276
1347
|
assert.match(server, /function configuredAgentNpmRoot\(\)/, "global Web UI launches should consider Pi's agent npm root for optional packages");
|
|
@@ -1317,6 +1388,7 @@ assert.match(readme, /avoiding duplicate loads while keeping global `pi-webui` l
|
|
|
1317
1388
|
assert.match(readme, /checks loaded Pi capabilities directly through RPC-visible commands and live widget events/, "README should document capability-based startup checks");
|
|
1318
1389
|
assert.match(readme, /side panel shows each optional feature as enabled, disabled, installed-but-not-loaded, update-available, or install-needed/, "README should document optional feature side-panel controls");
|
|
1319
1390
|
assert.match(readme, /Installing or updating a feature is an explicit, warned action with running\/failure feedback/, "README should document optional feature install and update warning behavior");
|
|
1391
|
+
assert.match(readme, /Natural Conversation Mode shell[\s\S]*\/talk[\s\S]*read-only/, "README should document the optional Natural Conversation WebUI shell");
|
|
1320
1392
|
assert.match(readme, /\.\/dev\/scripts\/start-webui\.sh --dev --cwd \/path\/to\/project/, "README should document the dev helper launcher");
|
|
1321
1393
|
assert.match(readme, /sync-pi-package-symlinks\.sh[\s\S]*only one copy is loaded/, "README should document dev companion symlink setup");
|
|
1322
1394
|
assert.match(startScript, /--dev\)/, "start-webui.sh should accept a --dev flag");
|
|
@@ -1335,6 +1407,8 @@ for (const [name, range] of Object.entries(companionDependencies)) {
|
|
|
1335
1407
|
assert.equal(pkg.dependencies?.[name], undefined, `webui package should not require optional companion ${name}`);
|
|
1336
1408
|
}
|
|
1337
1409
|
assert.equal(pkg.bundledDependencies, undefined, "webui optional companion packages should not be bundled into the tarball");
|
|
1410
|
+
assert.equal(pkg.optionalDependencies?.["@firstpick/pi-package-natural-conversation"], undefined, "webui package should not optionally depend on the standalone Natural Conversation package");
|
|
1411
|
+
assert.ok(!pkg.pi?.extensions?.some((entry) => String(entry).includes("pi-package-natural-conversation")), "webui Pi manifest should not load Natural Conversation directly; /talk must come from the standalone package");
|
|
1338
1412
|
assert.ok(pkg.pi?.extensions?.includes("./index.ts"), "webui Pi manifest should load its own extension");
|
|
1339
1413
|
for (const extensionPath of [
|
|
1340
1414
|
"node_modules/@firstpick/pi-extension-git-footer-status/index.ts",
|
|
@@ -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");
|