qwen3:4b가 reasoning 모델이라 <think>...</think> 블록을 길게 생성 → stripReasoningBlocks 후 빈 문자열 → 원본 transcript fallback으로 끝나면서 LLM refine이 42초 걸리는 병목 발견. Google Gemma 4 e4b(4.5B effective params, 2026-04-02 릴리스)로 교체. non-reasoning 기본 + Ollama v0.20+ think: false 파라미터로 2중 방어. 실측 결과: 받아쓰기 한 사이클 51.4s → 5.5s (9.3배 빠름). STT 500ms + LLM 3,925ms + insert 1,092ms. refine 품질 정상 동작 확인: "테스트하는 중입니다" → "테스트하고 있습니다". - LocalLLMService: 3개 fallback 기본값 변경(generate / streamGenerate / chatStream) + Ollama 요청 body에 think: false 명시 추가. non-reasoning 모델은 무시, reasoning 모델은 thinking 토큰 차단. NO_THINK 주석을 legacy 설명으로 업데이트 — qwen3/deepseek-r1 수동 선택자를 위한 3중 방어(/no_think + think:false + stripReasoningBlocks) 명시. - OnboardingModal / OllamaGuideModal: pull 명령어 갱신 - 테스트 fixture 갱신 - 12개 i18n locale JSON: settings.ollamaHint / ollama.step2.alt 키 업데이트 (qwen3:4b → gemma4:e4b, qwen3:8b → gemma4:26b) - 10개 site i18n locale TS + HowItWorks.tsx 파이프라인 시각화 — detail 문자열 'qwen3 / llama3 / gemma3' → 'gemma4 / llama3.2 / phi4', 파이프라인 라벨 'qwen3:4b @ localhost' → 'gemma4:e4b @ localhost' - 설계서 00 LLMConfig 기본값 + CONFIG_DEFAULTS - 설계서 05: 6개 API 스키마 예시, 2개 OllamaClient 코드 예시, LLM 모델 추천 표 재정렬(gemma4:e4b 최상위, qwen3는 reasoning 경고와 함께 후순위), 권장 JSON 설정에 think:false 추가 - phase-14 meeting mode 컨텍스트 윈도우 표 갱신 - V2-5 Mac 부트스트랩 가이드 pull 커맨드 갱신 - project_status.md Part 7 전체 섹션 추가
202 lines
5.9 KiB
TypeScript
202 lines
5.9 KiB
TypeScript
// tests/main/services/VoiceModeService.test.ts
|
|
// 상태 머신 전이 + 이중 조건 플러시 + accidentalPress 테스트
|
|
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
|
import { RecognitionState, AudioState } from '../../../src/shared/types'
|
|
import { TIMING } from '../../../src/shared/constants'
|
|
|
|
// 모든 하위 서비스 모킹
|
|
vi.mock('../../../src/main/services/LoggerService', () => ({
|
|
getLogger: () => ({
|
|
info: vi.fn(),
|
|
warn: vi.fn(),
|
|
error: vi.fn(),
|
|
debug: vi.fn()
|
|
})
|
|
}))
|
|
|
|
const mockSTT = {
|
|
initialize: vi.fn(() => Promise.resolve()),
|
|
transcribe: vi.fn(() =>
|
|
Promise.resolve({ text: '테스트 전사', segments: [], language: 'ko', duration: 2, processingTime: 500 })
|
|
),
|
|
getStatus: vi.fn(() => ({ state: 'ready', modelId: 'base', uptime: 0 })),
|
|
on: vi.fn(),
|
|
off: vi.fn()
|
|
}
|
|
|
|
vi.mock('../../../src/main/services/LocalSTTService', () => ({
|
|
getLocalSTTService: () => mockSTT
|
|
}))
|
|
|
|
const mockAudio = {
|
|
start: vi.fn(() => Promise.resolve()),
|
|
stop: vi.fn(() => Promise.resolve()),
|
|
on: vi.fn(),
|
|
off: vi.fn()
|
|
}
|
|
|
|
vi.mock('../../../src/main/services/AudioCaptureService', () => ({
|
|
getAudioCaptureService: () => mockAudio
|
|
}))
|
|
|
|
const mockHotkey = {
|
|
on: vi.fn(),
|
|
off: vi.fn()
|
|
}
|
|
|
|
vi.mock('../../../src/main/services/HotkeyService', () => ({
|
|
getHotkeyService: () => mockHotkey
|
|
}))
|
|
|
|
vi.mock('../../../src/main/services/ConfigService', () => ({
|
|
configGet: vi.fn((key: string) => {
|
|
const defaults: Record<string, unknown> = {
|
|
sttModelId: 'base',
|
|
defaultLLMAction: 'refine',
|
|
ollamaServerUrl: 'http://localhost:11434',
|
|
llmModelId: 'gemma4:e4b'
|
|
}
|
|
return defaults[key]
|
|
})
|
|
}))
|
|
|
|
const mockTextInsert = {
|
|
insertText: vi.fn(() => Promise.resolve({ success: true, method: 'clipboard', textLength: 10, durationMs: 50 }))
|
|
}
|
|
|
|
vi.mock('../../../src/main/services/TextInsertService', () => ({
|
|
getTextInsertService: () => mockTextInsert
|
|
}))
|
|
|
|
const mockLLM = {
|
|
isAvailable: vi.fn(() => false),
|
|
processText: vi.fn(() => Promise.resolve('다듬어진 텍스트')),
|
|
on: vi.fn(),
|
|
off: vi.fn()
|
|
}
|
|
|
|
vi.mock('../../../src/main/services/LocalLLMService', () => ({
|
|
getLocalLLMService: () => mockLLM
|
|
}))
|
|
|
|
let getVoiceModeService: () => ReturnType<typeof import('../../../src/main/services/VoiceModeService')['getVoiceModeService']>
|
|
|
|
beforeEach(async () => {
|
|
vi.resetModules()
|
|
vi.clearAllMocks()
|
|
const mod = await import('../../../src/main/services/VoiceModeService')
|
|
getVoiceModeService = mod.getVoiceModeService
|
|
})
|
|
|
|
describe('VoiceModeService', () => {
|
|
describe('상태 머신', () => {
|
|
it('초기 상태는 IDLE이다', () => {
|
|
const svc = getVoiceModeService()
|
|
const state = svc.getState()
|
|
|
|
expect(state.recognitionState).toBe(RecognitionState.IDLE)
|
|
expect(state.audioState).toBe(AudioState.IDLE)
|
|
expect(state.sessionId).toBeNull()
|
|
})
|
|
|
|
it('startSession 호출 시 PREPARING으로 전이한다', async () => {
|
|
const svc = getVoiceModeService()
|
|
const stateChanges: RecognitionState[] = []
|
|
|
|
svc.on('recognition-state-changed', (payload: { current: RecognitionState }) => {
|
|
stateChanges.push(payload.current)
|
|
})
|
|
|
|
await svc.startSession('dictation')
|
|
|
|
// PREPARING → CONNECTING → READY 순서
|
|
expect(stateChanges[0]).toBe(RecognitionState.PREPARING)
|
|
expect(stateChanges).toContain(RecognitionState.CONNECTING)
|
|
})
|
|
|
|
it('isActive는 세션이 활성일 때 true이다', async () => {
|
|
const svc = getVoiceModeService()
|
|
expect(svc.isActive).toBe(false)
|
|
|
|
// startSession은 완전 비동기이므로 await 후 세션 활성 확인
|
|
await svc.startSession('dictation')
|
|
expect(svc.isActive).toBe(true)
|
|
})
|
|
})
|
|
|
|
describe('accidentalPress', () => {
|
|
it('700ms 미만 세션은 자동 취소된다', async () => {
|
|
const svc = getVoiceModeService()
|
|
let cancelReason: string | null = null
|
|
|
|
svc.on('session-cancelled', (payload: { reason: string }) => {
|
|
cancelReason = payload.reason
|
|
})
|
|
|
|
// 세션 시작 즉시 종료 (700ms 미만)
|
|
await svc.startSession('dictation')
|
|
await svc.stopSession()
|
|
|
|
expect(cancelReason).toBe('too-short')
|
|
})
|
|
})
|
|
|
|
describe('cancelSession', () => {
|
|
it('user 취소로 세션을 종료한다', async () => {
|
|
const svc = getVoiceModeService()
|
|
let cancelReason: string | null = null
|
|
|
|
svc.on('session-cancelled', (payload: { reason: string }) => {
|
|
cancelReason = payload.reason
|
|
})
|
|
|
|
await svc.startSession('dictation')
|
|
svc.cancelSession()
|
|
|
|
expect(cancelReason).toBe('user')
|
|
})
|
|
})
|
|
|
|
describe('getState', () => {
|
|
it('현재 상태를 VoiceState 형태로 반환한다', () => {
|
|
const svc = getVoiceModeService()
|
|
const state = svc.getState()
|
|
|
|
expect(state).toHaveProperty('recognitionState')
|
|
expect(state).toHaveProperty('audioState')
|
|
expect(state).toHaveProperty('mode')
|
|
expect(state).toHaveProperty('sessionId')
|
|
expect(state).toHaveProperty('recordingStartedAt')
|
|
})
|
|
})
|
|
|
|
describe('터미널 상태', () => {
|
|
it('cancelSession 후 _resetToIdle의 200ms 딜레이 후 IDLE로 전이한다', async () => {
|
|
vi.useFakeTimers()
|
|
const svc = getVoiceModeService()
|
|
|
|
await svc.startSession('dictation')
|
|
svc.cancelSession()
|
|
|
|
// 200ms 딜레이로 IDLE 전이 예약됨
|
|
vi.advanceTimersByTime(250)
|
|
|
|
const state = svc.getState()
|
|
expect(state.recognitionState).toBe(RecognitionState.IDLE)
|
|
|
|
vi.useRealTimers()
|
|
})
|
|
})
|
|
})
|
|
|
|
describe('TIMING 상수', () => {
|
|
it('핵심 타이밍 값이 Speakly 패턴과 일치한다', () => {
|
|
expect(TIMING.MIN_AUDIO_DURATION).toBe(700)
|
|
expect(TIMING.DOUBLE_PRESS_DURATION).toBe(300)
|
|
expect(TIMING.POST_RECORDING_WAIT).toBe(4000)
|
|
expect(TIMING.POST_RECORDING_WAIT_BUFFERED).toBe(6000)
|
|
expect(TIMING.ABSOLUTE_MAX_WAIT).toBe(120000)
|
|
expect(TIMING.AUDIO_LEVEL_INTERVAL).toBe(100)
|
|
})
|
|
})
|