d3ro-voice/apps/desktop/tests/shared/errors.test.ts
Yun Chan 983c60cda2 feat(bootstrap): Whisper large-v3-turbo 기본 전환 + 온보딩 2단계 다운로드 진행률
- 기본 STT 모델 base → large-v3-turbo (6배 빠름, 1.6GB)
- 사이드카: /download, /download/status, /download/cancel + --models-dir
- LocalSTTService: downloadModel/cancelDownload + download-progress 이벤트
- IPC: 설계서 02의 stt:downloadModel/cancelDownload/downloadProgress 구현
- OnboardingModal: LLM(gemma4:e4b) → STT(turbo) 2단계 순차 다운로드 UI
- SettingsModal turbo 선택지 + settings.model.largeTurbo 12 locale
- 테스트: 모노레포 잔재 import 수정 (src/shared → @d3ro/core), 41/41 통과
2026-07-21 11:59:49 +09:00

75 lines
2.4 KiB
TypeScript

// tests/shared/errors.test.ts
// D3ROError + IPCResult 헬퍼 테스트
import { describe, it, expect } from 'vitest'
import { D3ROError, ErrorCode, ipcSuccess, ipcError } from '@d3ro/core/errors'
describe('D3ROError', () => {
it('code, message, details를 올바르게 설정한다', () => {
const err = new D3ROError(ErrorCode.STTModelNotFound, 'Model not found', { modelId: 'large' })
expect(err.code).toBe(ErrorCode.STTModelNotFound)
expect(err.message).toBe('Model not found')
expect(err.details).toEqual({ modelId: 'large' })
expect(err.name).toBe('D3ROError')
expect(err instanceof Error).toBe(true)
})
it('toJSON으로 직렬화할 수 있다', () => {
const err = new D3ROError(ErrorCode.LLMServerUnreachable, 'Server down')
const json = err.toJSON()
expect(json.code).toBe(300)
expect(json.message).toBe('Server down')
expect(json.details).toBeUndefined()
})
it('fromJSON으로 역직렬화할 수 있다', () => {
const json = { code: ErrorCode.AudioDeviceNotFound, message: 'No mic' }
const err = D3ROError.fromJSON(json)
expect(err).toBeInstanceOf(D3ROError)
expect(err.code).toBe(ErrorCode.AudioDeviceNotFound)
expect(err.message).toBe('No mic')
})
})
describe('IPCResult helpers', () => {
it('ipcSuccess는 success: true + data를 반환한다', () => {
const result = ipcSuccess({ value: 42 })
expect(result.success).toBe(true)
if (result.success) {
expect(result.data).toEqual({ value: 42 })
}
})
it('ipcError는 success: false + error를 반환한다', () => {
const result = ipcError(ErrorCode.DBQueryFailed, 'Query failed', { table: 'history' })
expect(result.success).toBe(false)
if (!result.success) {
expect(result.error.code).toBe(ErrorCode.DBQueryFailed)
expect(result.error.message).toBe('Query failed')
expect(result.error.details).toEqual({ table: 'history' })
}
})
})
describe('ErrorCode', () => {
it('에러 코드 범위가 올바르다', () => {
// STT: 100-199
expect(ErrorCode.STTEngineNotInstalled).toBe(100)
expect(ErrorCode.STTGPUNotAvailable).toBe(140)
// LLM: 300-399
expect(ErrorCode.LLMServerUnreachable).toBe(300)
expect(ErrorCode.LLMPromptTooLong).toBe(331)
// Audio: 400-499
expect(ErrorCode.AudioDeviceNotFound).toBe(400)
// System: 900-999
expect(ErrorCode.UnknownError).toBe(999)
})
})