refactor(pipeline): the text bar is not a chat, Max always replies by voice
Two pieces of direct user feedback, addressed together since they touch the same files: 1. ObjectiveValidationCard now lives in its own dedicated, movable window (objectiveWindow.ts / ObjectiveWindowRoot.tsx), independent of the text input window. Confirming an objective must never depend on opening that window, including when the whole exchange happens by voice. Both sendTextTurn and voice-turn open/feed this window through the same shared handleRouteMessageResult code path, so text and voice behave identically - no more special-casing one channel. 2. The "chat window" was never meant to be a chat: it's an alternate text entry point for the exact same voice pipeline. Removed the message history/ChatBubble display and the old sessions:route-message + voice-turn-synced plumbing that existed to sync a conversation transcript across windows. Replaced with a new text-turn IPC handler mirroring voice-turn (routeMessage -> handleRouteMessageResult -> synthesizeSpeech) minus the STT step; the reply is relayed to the avatar window via the existing proactive-speech channel and spoken aloud, never displayed. The input window shrinks accordingly (560px -> 100px tall) and no longer auto-opens when a session starts, since there is nothing to show there anymore - it only opens on explicit user request. useProactiveSpeech now accepts an onStateChange callback so the avatar status indicator correctly flips back to idle once a text-turn reply finishes playing (it previously only ever got set to 'speaking', never reset - a latent gap this reuse surfaced). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
4b45c4a644
commit
85da9fcad0
@@ -234,13 +234,13 @@ describe('<App />', () => {
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should open the chat window automatically if a session starts without it (safety net)', async () => {
|
||||
it('should NOT open the text input window automatically when a session starts (not a chat - only explicit user request opens it)', async () => {
|
||||
getAuthStatus.mockResolvedValue({ loggedIn: true, email: 'william@example.com' })
|
||||
render(<App />)
|
||||
await waitFor(() => expect(getAuthStatus).toHaveBeenCalled())
|
||||
|
||||
act(() => useSessionStore.setState({ sessionId: 1, status: 'objective_discovery' }))
|
||||
|
||||
expect(toggleChatWindow).toHaveBeenCalledOnce()
|
||||
expect(toggleChatWindow).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,90 +1,47 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'
|
||||
import { render, screen, fireEvent } from '@testing-library/react'
|
||||
import ChatPanel from '../../../src/renderer/src/components/ChatPanel'
|
||||
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
|
||||
|
||||
const get = vi.fn()
|
||||
const routeMessage = vi.fn()
|
||||
const confirmObjective = vi.fn()
|
||||
const sendTextTurn = vi.fn()
|
||||
const notifySessionEnded = vi.fn()
|
||||
const onVoiceTurnSynced = vi.fn(() => () => {})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
sessions: { get, routeMessage, confirmObjective },
|
||||
notifySessionEnded,
|
||||
onVoiceTurnSynced
|
||||
sendTextTurn,
|
||||
notifySessionEnded
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
|
||||
/**
|
||||
* Ce n'est PAS un chat (retour utilisateur direct) : juste une barre de saisie alternative au
|
||||
* micro. Le texte tape suit le meme pipeline qu'une phrase prononcee et Max repond toujours a
|
||||
* voix haute - aucune bulle, aucun historique de conversation affiche ici.
|
||||
*/
|
||||
describe('<ChatPanel />', () => {
|
||||
it('should show an input bar and no pipeline steps before any session exists', () => {
|
||||
it('should show only the message input, no conversation history', () => {
|
||||
render(<ChatPanel />)
|
||||
expect(screen.getByLabelText('Message')).toBeInTheDocument()
|
||||
expect(screen.queryByText('Objectif')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should send the first message, creating a session, and render the conversation', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Quel est ton sujet ?',
|
||||
ready: false
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
|
||||
render(<ChatPanel />)
|
||||
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'Je veux apprendre' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
|
||||
|
||||
expect(await screen.findByText('Je veux apprendre')).toBeInTheDocument()
|
||||
expect(await screen.findByText('Quel est ton sujet ?')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the ObjectiveValidationCard instead of the input bar once the agent is ready', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Voici le recap',
|
||||
ready: true,
|
||||
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
|
||||
render(<ChatPanel />)
|
||||
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Ton objectif de formation')).toBeInTheDocument())
|
||||
expect(screen.queryByLabelText('Message')).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the ObjectiveValidationCard from a voice-originated turn, not just a typed message', async () => {
|
||||
let voiceTurnCallback: ((result: unknown) => void) | undefined
|
||||
onVoiceTurnSynced.mockImplementationOnce((callback: (result: unknown) => void) => {
|
||||
voiceTurnCallback = callback
|
||||
return () => {}
|
||||
})
|
||||
|
||||
render(<ChatPanel />)
|
||||
expect(screen.queryByText('Ton objectif de formation')).not.toBeInTheDocument()
|
||||
|
||||
voiceTurnCallback?.({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Voici le recap (dit a voix haute)',
|
||||
ready: true,
|
||||
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
|
||||
})
|
||||
|
||||
await waitFor(() => expect(screen.getByText('Ton objectif de formation')).toBeInTheDocument())
|
||||
expect(screen.getByText('Voici le recap (dit a voix haute)')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the store error message when a call fails', async () => {
|
||||
routeMessage.mockRejectedValueOnce(new Error('Max API injoignable'))
|
||||
it('should submit the typed text via text-turn and clear the field', async () => {
|
||||
sendTextTurn.mockResolvedValueOnce({ ok: true })
|
||||
|
||||
render(<ChatPanel />)
|
||||
fireEvent.change(screen.getByLabelText('Message'), {
|
||||
target: { value: 'Je veux apprendre la facturation' }
|
||||
})
|
||||
fireEvent.click(screen.getByRole('button', { name: 'Envoyer le message' }))
|
||||
|
||||
expect(sendTextTurn).toHaveBeenCalledWith('Je veux apprendre la facturation')
|
||||
expect(await screen.findByDisplayValue('')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should show the store error message when the backend reports a failure', async () => {
|
||||
sendTextTurn.mockResolvedValueOnce({ ok: false, error: 'Max API injoignable' })
|
||||
|
||||
render(<ChatPanel />)
|
||||
fireEvent.change(screen.getByLabelText('Message'), { target: { value: 'message' } })
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react'
|
||||
import ObjectiveWindowRoot from '../../../src/renderer/src/components/ObjectiveWindowRoot'
|
||||
import { useSessionStore } from '../../../src/renderer/src/stores/useSessionStore'
|
||||
|
||||
const confirmObjective = vi.fn()
|
||||
const notifySessionEnded = vi.fn()
|
||||
let objectiveReadyCallback: ((sessionId: number, draft: unknown) => void) | undefined
|
||||
const onObjectiveReady = vi.fn((callback: (sessionId: number, draft: unknown) => void) => {
|
||||
objectiveReadyCallback = callback
|
||||
return () => {}
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
objectiveReadyCallback = undefined
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
sessions: { confirmObjective, get: vi.fn() },
|
||||
notifySessionEnded,
|
||||
onObjectiveReady
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
|
||||
/**
|
||||
* Fenetre independante du chat texte (retour utilisateur direct : la confirmation de l'objectif
|
||||
* ne doit jamais dependre d'ouvrir la conversation, y compris quand tout l'echange se fait au
|
||||
* vocal). Son etat vient exclusivement du relais "objective-ready" du main process.
|
||||
*/
|
||||
describe('<ObjectiveWindowRoot />', () => {
|
||||
it('should render nothing before the main process relays a ready objective', () => {
|
||||
const { container } = render(<ObjectiveWindowRoot />)
|
||||
expect(container).toBeEmptyDOMElement()
|
||||
})
|
||||
|
||||
it('should show the card once the main process relays a ready objective (text or voice, same path)', () => {
|
||||
render(<ObjectiveWindowRoot />)
|
||||
|
||||
act(() =>
|
||||
objectiveReadyCallback?.(1, {
|
||||
subject: 'Facturation freelance',
|
||||
professionalGoal: 'Facturer sans erreur',
|
||||
duration: '2 semaines'
|
||||
})
|
||||
)
|
||||
|
||||
expect(screen.getByText('Ton objectif de formation')).toBeInTheDocument()
|
||||
expect(screen.getByText('Facturation freelance')).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('should confirm the objective via the store, independently of any chat window', async () => {
|
||||
confirmObjective.mockResolvedValueOnce({})
|
||||
;(window as unknown as { api: { sessions: Record<string, unknown> } }).api.sessions.get = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ id: 1, status: 'objective_validated' })
|
||||
|
||||
render(<ObjectiveWindowRoot />)
|
||||
act(() =>
|
||||
objectiveReadyCallback?.(1, {
|
||||
subject: 'Facturation freelance',
|
||||
professionalGoal: 'Facturer sans erreur',
|
||||
duration: '2 semaines'
|
||||
})
|
||||
)
|
||||
|
||||
fireEvent.click(
|
||||
screen.getByRole('button', { name: "C'est exactement ca, confirmer l'objectif" })
|
||||
)
|
||||
|
||||
await waitFor(() => expect(confirmObjective).toHaveBeenCalledWith(1))
|
||||
expect(await screen.findByText(/Objectif enregistre/)).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -2,116 +2,76 @@ import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
import { useSessionStore } from '../../../../src/renderer/src/stores/useSessionStore'
|
||||
|
||||
const get = vi.fn()
|
||||
const routeMessage = vi.fn()
|
||||
const sendTextTurn = vi.fn()
|
||||
const confirmObjective = vi.fn()
|
||||
const notifySessionEnded = vi.fn()
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
;(window as unknown as { api: Record<string, unknown> }).api = {
|
||||
sessions: { get, routeMessage, confirmObjective },
|
||||
sessions: { get, confirmObjective },
|
||||
sendTextTurn,
|
||||
notifySessionEnded
|
||||
}
|
||||
useSessionStore.getState().restart()
|
||||
})
|
||||
|
||||
/**
|
||||
* La barre de saisie texte n'est PAS un chat (retour utilisateur direct) : elle ne garde aucun
|
||||
* historique de conversation, et Max repond toujours a voix haute (voir text-turn dans
|
||||
* src/main/index.ts). Le store ne fait donc que suivre le succes/l'echec de l'envoi, rien de plus.
|
||||
*/
|
||||
describe('useSessionStore', () => {
|
||||
it('should not create a session when the backend classifies the message as chat', async () => {
|
||||
routeMessage.mockResolvedValueOnce({ type: 'chat', reply: 'Salut, comment puis-je aider ?' })
|
||||
it('should send a typed message via text-turn and clear the loading state on success', async () => {
|
||||
sendTextTurn.mockResolvedValueOnce({ ok: true })
|
||||
|
||||
await useSessionStore.getState().sendMessage('Salut ça va ?')
|
||||
await useSessionStore.getState().sendTextTurn('Je veux apprendre la facturation')
|
||||
|
||||
expect(routeMessage).toHaveBeenCalledWith('Salut ça va ?')
|
||||
expect(get).not.toHaveBeenCalled()
|
||||
expect(sendTextTurn).toHaveBeenCalledWith('Je veux apprendre la facturation')
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.sessionId).toBeNull()
|
||||
expect(state.messages.map((m) => m.role)).toEqual(['user', 'max'])
|
||||
expect(state.loading).toBe(false)
|
||||
expect(state.error).toBeNull()
|
||||
})
|
||||
|
||||
it('should set the session id and fetch the fresh status when the backend starts a training session', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Quel est ton sujet ?',
|
||||
ready: false
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
it('should set an error when the backend reports a failure', async () => {
|
||||
sendTextTurn.mockResolvedValueOnce({ ok: false, error: 'Max API injoignable' })
|
||||
|
||||
await useSessionStore.getState().sendMessage('Je veux apprendre la facturation')
|
||||
|
||||
expect(get).toHaveBeenCalledWith(1)
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.sessionId).toBe(1)
|
||||
expect(state.status).toBe('objective_discovery')
|
||||
expect(state.messages.map((m) => m.role)).toEqual(['user', 'max'])
|
||||
})
|
||||
|
||||
it('should reuse the same session id on subsequent messages of an ongoing training', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Quel est ton sujet ?',
|
||||
ready: false
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
await useSessionStore.getState().sendMessage('premier message')
|
||||
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Et ton but professionnel ?',
|
||||
ready: false
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
await useSessionStore.getState().sendMessage('second message')
|
||||
|
||||
expect(routeMessage).toHaveBeenCalledTimes(2)
|
||||
expect(useSessionStore.getState().sessionId).toBe(1)
|
||||
})
|
||||
|
||||
it('should store the draft and ready flag once the agent is ready to confirm', async () => {
|
||||
const draft = {
|
||||
subject: 'Facturation freelance',
|
||||
professionalGoal: 'Facturer sans erreur',
|
||||
duration: '2 semaines'
|
||||
}
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Voici le recap',
|
||||
ready: true,
|
||||
draft
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
|
||||
await useSessionStore.getState().sendMessage('message')
|
||||
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.objectiveReady).toBe(true)
|
||||
expect(state.objectiveDraft).toEqual(draft)
|
||||
})
|
||||
|
||||
it('should set an error and stop loading when sending a message fails', async () => {
|
||||
routeMessage.mockRejectedValueOnce(new Error('Max API injoignable'))
|
||||
|
||||
await useSessionStore.getState().sendMessage('message')
|
||||
await useSessionStore.getState().sendTextTurn('message')
|
||||
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.error).toBe('Max API injoignable')
|
||||
expect(state.loading).toBe(false)
|
||||
})
|
||||
|
||||
it('should set an error and stop loading when sending a message throws', async () => {
|
||||
sendTextTurn.mockRejectedValueOnce(new Error('Max API injoignable'))
|
||||
|
||||
await useSessionStore.getState().sendTextTurn('message')
|
||||
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.error).toBe('Max API injoignable')
|
||||
expect(state.loading).toBe(false)
|
||||
})
|
||||
|
||||
it('should apply an objective-ready broadcast from the main process (used by the dedicated objective window)', () => {
|
||||
const draft = {
|
||||
subject: 'Facturation freelance',
|
||||
professionalGoal: 'Facturer sans erreur',
|
||||
duration: '2 semaines'
|
||||
}
|
||||
|
||||
useSessionStore.getState().applyObjectiveReady(1, draft)
|
||||
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.sessionId).toBe(1)
|
||||
expect(state.objectiveReady).toBe(true)
|
||||
expect(state.objectiveDraft).toEqual(draft)
|
||||
})
|
||||
|
||||
it('should confirm the objective and refresh the session status', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'Recap',
|
||||
ready: true,
|
||||
draft: { subject: 's', professionalGoal: 'g', duration: '1 semaine' }
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
await useSessionStore.getState().sendMessage('message')
|
||||
useSessionStore
|
||||
.getState()
|
||||
.applyObjectiveReady(1, { subject: 's', professionalGoal: 'g', duration: '1 semaine' })
|
||||
|
||||
confirmObjective.mockResolvedValueOnce({})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_validated' })
|
||||
@@ -122,7 +82,6 @@ describe('useSessionStore', () => {
|
||||
|
||||
expect(confirmObjective).toHaveBeenCalledWith(1)
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.objectiveConfirmed).toBe(true)
|
||||
expect(state.status).toBe('objective_validated')
|
||||
})
|
||||
|
||||
@@ -135,15 +94,10 @@ describe('useSessionStore', () => {
|
||||
expect(useSessionStore.getState().error).toBe('Aucune session en cours')
|
||||
})
|
||||
|
||||
it('should reset all state on restart and notify the main process', async () => {
|
||||
routeMessage.mockResolvedValueOnce({
|
||||
type: 'learn',
|
||||
sessionId: 1,
|
||||
reply: 'ok',
|
||||
ready: false
|
||||
})
|
||||
get.mockResolvedValueOnce({ id: 1, status: 'objective_discovery' })
|
||||
await useSessionStore.getState().sendMessage('message')
|
||||
it('should reset all state on restart and notify the main process', () => {
|
||||
useSessionStore
|
||||
.getState()
|
||||
.applyObjectiveReady(1, { subject: 's', professionalGoal: 'g', duration: '1 semaine' })
|
||||
|
||||
notifySessionEnded.mockClear()
|
||||
useSessionStore.getState().restart()
|
||||
@@ -151,7 +105,8 @@ describe('useSessionStore', () => {
|
||||
expect(notifySessionEnded).toHaveBeenCalledOnce()
|
||||
const state = useSessionStore.getState()
|
||||
expect(state.sessionId).toBeNull()
|
||||
expect(state.messages).toEqual([])
|
||||
expect(state.objectiveReady).toBe(false)
|
||||
expect(state.objectiveDraft).toBeNull()
|
||||
})
|
||||
|
||||
it('should set the status directly (used by the stepper window to sync with the main process)', () => {
|
||||
|
||||
@@ -31,4 +31,16 @@ describe('useProactiveSpeech()', () => {
|
||||
onProactiveSpeechCallback?.(audio)
|
||||
expect(enqueueSpeech).toHaveBeenCalledWith(audio)
|
||||
})
|
||||
|
||||
it('should report speaking then idle around playback (used by the avatar status indicator for text-turn replies)', async () => {
|
||||
const onStateChange = vi.fn()
|
||||
renderHook(() => useProactiveSpeech({ current: null }, onStateChange))
|
||||
|
||||
onProactiveSpeechCallback?.(new ArrayBuffer(4))
|
||||
expect(onStateChange).toHaveBeenCalledWith('speaking')
|
||||
|
||||
await Promise.resolve()
|
||||
await Promise.resolve()
|
||||
expect(onStateChange).toHaveBeenCalledWith('idle')
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user