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>
117 lines
4.2 KiB
TypeScript
117 lines
4.2 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { useSessionStore } from '../../../../src/renderer/src/stores/useSessionStore'
|
|
|
|
const get = 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, 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 send a typed message via text-turn and clear the loading state on success', async () => {
|
|
sendTextTurn.mockResolvedValueOnce({ ok: true })
|
|
|
|
await useSessionStore.getState().sendTextTurn('Je veux apprendre la facturation')
|
|
|
|
expect(sendTextTurn).toHaveBeenCalledWith('Je veux apprendre la facturation')
|
|
const state = useSessionStore.getState()
|
|
expect(state.loading).toBe(false)
|
|
expect(state.error).toBeNull()
|
|
})
|
|
|
|
it('should set an error when the backend reports a failure', async () => {
|
|
sendTextTurn.mockResolvedValueOnce({ ok: false, 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 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 () => {
|
|
useSessionStore
|
|
.getState()
|
|
.applyObjectiveReady(1, { subject: 's', professionalGoal: 'g', duration: '1 semaine' })
|
|
|
|
confirmObjective.mockResolvedValueOnce({})
|
|
get.mockResolvedValueOnce({ id: 1, status: 'objective_validated' })
|
|
|
|
await useSessionStore
|
|
.getState()
|
|
.confirmObjective({ subject: 's', professionalGoal: 'g', duration: '1 semaine' })
|
|
|
|
expect(confirmObjective).toHaveBeenCalledWith(1)
|
|
const state = useSessionStore.getState()
|
|
expect(state.status).toBe('objective_validated')
|
|
})
|
|
|
|
it('should error out when confirming without an active session', async () => {
|
|
await useSessionStore
|
|
.getState()
|
|
.confirmObjective({ subject: 's', professionalGoal: 'g', duration: '1 semaine' })
|
|
|
|
expect(confirmObjective).not.toHaveBeenCalled()
|
|
expect(useSessionStore.getState().error).toBe('Aucune session en cours')
|
|
})
|
|
|
|
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()
|
|
|
|
expect(notifySessionEnded).toHaveBeenCalledOnce()
|
|
const state = useSessionStore.getState()
|
|
expect(state.sessionId).toBeNull()
|
|
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)', () => {
|
|
useSessionStore.getState().setStatus('objective_validated')
|
|
expect(useSessionStore.getState().status).toBe('objective_validated')
|
|
})
|
|
})
|