Files
opencode-manager/frontend/src/components/message/VoiceConversationBar.test.tsx
T
ioplex 4ec62cd4e7 fix: address findings from the full Docker evaluation of main
Critical and high:
- repos: unlinking a local repo removes only the Manager reference and alias,
  never the repository files; confirm button reads "Unlink"
- auth: rate-limit by the socket address; trust proxy headers only when
  AUTH_TRUSTED_PROXY_HEADERS is set (documented and forwarded in compose)
- composer: per-session in-memory drafts (text, bash mode, attachments);
  Escape no longer clears the prompt
- url params: compose same-tick updates so schedule dialogs stay closed after
  create/delete; delete dialog names the job

Medium:
- tool rows show failures (non-zero shell exit, failed exploration members)
- voice conversation shows the specific error and a starting state
- settings: Escape in dropdowns and the shortcut recorder no longer closes
  the dialog; mobile deep links open the requested section; one content tree
  per platform
- closing pushed sheets, settings, tool panels and schedule dialogs goes back
  in history
- login returns to the requested page; signed-out pages make no
  authenticated requests
- action terminals keep their output (Manager-side output capture and replay)
- unpushed-commit detection, commit message kept on failure
- binary files with unknown extensions are detected and not editable
- tool panel resizes when docked and floats as a dismissible sheet when the
  page is too narrow
- Docker image runs tini as PID 1

Low: not-found states, add-repo and branch validation errors (4xx),
search-aware empty states, mobile repo sort/filter/select cues, sidebar
resize affordance and collapse shortcut, mobile unread badge, preview port
filtering, terminal close handling, walkthrough empty state and helper
session filtering, placeholder contrast, permission labels and focus,
TTS task-list sanitizing, git identity email validation, quieter git
logging, hermetic worktree tests, and accessible names for icon-only
controls.
2026-10-23 11:42:37 -04:00

218 lines
7.6 KiB
TypeScript

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { describe, expect, it, vi } from 'vitest'
import { VoiceConversationBar } from './VoiceConversationBar'
import type { VoiceConversationController } from '@/hooks/useVoiceConversation'
const buildController = (
overrides: Partial<VoiceConversationController> = {},
): VoiceConversationController => ({
isActive: true,
phase: 'listening',
label: 'Listening',
hint: 'Speak what you want the agent to do',
orbLabel: 'Send now',
liveTranscript: '',
canEditInTextBox: false,
canStopAgent: false,
hasHeldReading: false,
isEndpointing: false,
notice: null,
start: vi.fn(),
exit: vi.fn(),
editInTextBox: vi.fn(),
tapOrb: vi.fn(),
pause: vi.fn(),
resume: vi.fn(),
stopAgent: vi.fn(),
...overrides,
})
const renderBar = (
controller: VoiceConversationController,
props: { hasPendingApproval?: boolean; onViewApproval?: () => void } = {},
) =>
render(
<VoiceConversationBar
controller={controller}
hasPendingApproval={props.hasPendingApproval ?? false}
onViewApproval={props.onViewApproval ?? vi.fn()}
/>,
)
describe('VoiceConversationBar', () => {
it('shows the status, the hint and the live transcript', () => {
renderBar(
buildController({
label: 'Listening',
hint: 'Speak what you want the agent to do',
liveTranscript: 'add a retry to the upload call',
}),
)
expect(screen.getByText('Listening')).toBeInTheDocument()
expect(screen.getByText('Speak what you want the agent to do')).toBeInTheDocument()
expect(screen.getByText('add a retry to the upload call')).toBeInTheDocument()
})
it('hides the transcript when it is empty', () => {
const { container } = renderBar(buildController({ liveTranscript: '' }))
const status = screen.getByRole('status')
expect(status).toHaveTextContent('Listening')
expect(container.querySelector('[dir="rtl"]')).toBeNull()
})
it('announces status changes through a polite live region', () => {
renderBar(buildController({ label: 'Working' }))
const status = screen.getByRole('status')
expect(status).toHaveAttribute('aria-live', 'polite')
expect(status).toHaveTextContent('Working')
})
it('exits the conversation from the close control', async () => {
const user = userEvent.setup()
const controller = buildController()
renderBar(controller)
await user.click(screen.getByRole('button', { name: 'Exit voice conversation' }))
expect(controller.exit).toHaveBeenCalledTimes(1)
expect(controller.editInTextBox).not.toHaveBeenCalled()
})
it('swaps the close control for the edit control when the transcript can be kept', async () => {
const user = userEvent.setup()
const controller = buildController({
canEditInTextBox: true,
liveTranscript: 'half a sentence',
})
renderBar(controller)
expect(screen.queryByRole('button', { name: 'Exit voice conversation' })).toBeNull()
await user.click(screen.getByRole('button', { name: 'Edit in text box' }))
expect(controller.editInTextBox).toHaveBeenCalledTimes(1)
expect(controller.exit).not.toHaveBeenCalled()
})
it('shows the stop control only while the agent can be stopped', async () => {
const user = userEvent.setup()
const { unmount } = renderBar(buildController({ canStopAgent: false }))
expect(screen.queryByRole('button', { name: 'Stop the agent' })).toBeNull()
unmount()
const controller = buildController({ canStopAgent: true })
renderBar(controller)
await user.click(screen.getByRole('button', { name: 'Stop the agent' }))
expect(controller.stopAgent).toHaveBeenCalledTimes(1)
})
it('shows the approval control instead of pause while the session waits for approval', async () => {
const user = userEvent.setup()
const onViewApproval = vi.fn()
const controller = buildController({ phase: 'working', canStopAgent: true })
renderBar(controller, { hasPendingApproval: true, onViewApproval })
expect(screen.queryByRole('button', { name: 'Pause voice conversation' })).toBeNull()
await user.click(screen.getByRole('button', { name: 'View pending permission' }))
expect(onViewApproval).toHaveBeenCalledTimes(1)
expect(controller.pause).not.toHaveBeenCalled()
})
it('pauses the conversation outside the paused phase', async () => {
const user = userEvent.setup()
const controller = buildController({ phase: 'listening' })
renderBar(controller)
await user.click(screen.getByRole('button', { name: 'Pause voice conversation' }))
expect(controller.pause).toHaveBeenCalledTimes(1)
expect(controller.resume).not.toHaveBeenCalled()
})
it('resumes the conversation while paused', async () => {
const user = userEvent.setup()
const controller = buildController({ phase: 'paused', orbLabel: 'Resume voice conversation' })
renderBar(controller)
expect(screen.queryByRole('button', { name: 'Pause voice conversation' })).toBeNull()
await user.click(screen.getByRole('button', { name: 'Resume' }))
expect(controller.resume).toHaveBeenCalledTimes(1)
})
it('continues a held reading while paused mid-reply', () => {
renderBar(buildController({ phase: 'paused', hasHeldReading: true }))
expect(screen.getByRole('button', { name: 'Continue reading' })).toBeInTheDocument()
expect(screen.queryByRole('button', { name: 'Resume' })).toBeNull()
})
it('sends the orb action for the current phase when the orb is pressed', async () => {
const user = userEvent.setup()
const controller = buildController({ phase: 'working', orbLabel: 'Add a message' })
renderBar(controller)
await user.click(screen.getByRole('button', { name: 'Add a message' }))
expect(controller.tapOrb).toHaveBeenCalledTimes(1)
})
it('names the orb action for every phase', () => {
const phases = [
{ phase: 'listening', orbLabel: 'Send now' },
{ phase: 'sending', orbLabel: 'Sending' },
{ phase: 'working', orbLabel: 'Add a message' },
{ phase: 'speaking', orbLabel: 'Skip reply' },
{ phase: 'recording', orbLabel: 'Send to queue' },
{ phase: 'paused', orbLabel: 'Resume voice conversation' },
{ phase: 'off', orbLabel: 'Voice conversation' },
] as const
for (const { phase, orbLabel } of phases) {
const { unmount } = renderBar(buildController({ phase, orbLabel }))
expect(screen.getByRole('button', { name: orbLabel })).toBeInTheDocument()
unmount()
}
})
it('marks the orb busy while a turn is sent', () => {
renderBar(buildController({ phase: 'sending', orbLabel: 'Sending' }))
expect(screen.getByRole('button', { name: 'Sending' })).toHaveAttribute('aria-busy', 'true')
})
it('shows the failure reason and its fix instead of a bare retry', () => {
renderBar(
buildController({
phase: 'paused',
label: 'Microphone access denied. Please allow microphone permissions.',
hint: 'Allow microphone access, then tap to retry',
orbLabel: 'Resume voice conversation',
}),
)
expect(
screen.getByText('Microphone access denied. Please allow microphone permissions.'),
).toBeInTheDocument()
expect(screen.getByText('Allow microphone access, then tap to retry')).toBeInTheDocument()
})
it('shows the notice when there is one and keeps the reserved hint line empty', () => {
renderBar(
buildController({
hint: '',
notice: 'Turn on speech-to-text in Voice settings',
}),
)
expect(screen.getByText('Turn on speech-to-text in Voice settings')).toBeInTheDocument()
})
})