feat(V2-1a): Monorepo 구조 전환 — apps/desktop으로 V1 이동
- npm workspaces 루트 (apps/*, packages/*) 세팅 - V1 전체를 apps/desktop/으로 git mv (src, resources, tests, sidecar, scripts, electron.vite.config.ts, electron-builder.yml, vitest.config.ts, tsconfig.node.json, tsconfig.web.json) - apps/desktop/package.json 신규 (name=@d3ro/desktop) - productName: 'd3ro-voice' 명시 — app.getName()을 고정하여 userData 경로 %APPDATA%\d3ro-voice\ 그대로 유지 (기존 DB/설정 연속성 보장) - 루트 package.json을 workspace 루트로 재구성, 공통 devDep만 유지 (typescript, eslint, prettier) - turbo.json, tsconfig.base.json 추가 (Turborepo 자체 설치는 별도 sub-phase) - memory/project_status.md 생성 (규칙 13) 검증: - npm run typecheck 통과 - npm run build 통과 (electron-vite main+preload+renderer) - npm run dev 실제 실행 → DB/핫키/Ollama 자동 실행 모두 정상
This commit is contained in:
parent
3a160b9032
commit
45a580878a
178 changed files with 214 additions and 0 deletions
|
|
@ -0,0 +1,190 @@
|
|||
// tests/main/services/CustomInstructionService.test.ts
|
||||
// CRUD + 프리셋 보호 + 순서 변경 테스트
|
||||
|
||||
import { describe, it, expect, beforeEach, vi } from 'vitest'
|
||||
|
||||
// ConfigService 모킹
|
||||
const mockStore: Record<string, unknown> = {}
|
||||
|
||||
vi.mock('../../../src/main/services/ConfigService', () => ({
|
||||
configGet: vi.fn((key: string) => mockStore[key]),
|
||||
configSet: vi.fn((key: string, value: unknown) => {
|
||||
mockStore[key] = value
|
||||
})
|
||||
}))
|
||||
|
||||
vi.mock('../../../src/main/services/LoggerService', () => ({
|
||||
getLogger: () => ({
|
||||
info: vi.fn(),
|
||||
warn: vi.fn(),
|
||||
error: vi.fn(),
|
||||
debug: vi.fn()
|
||||
})
|
||||
}))
|
||||
|
||||
let getCustomInstructionService: () => ReturnType<typeof import('../../../src/main/services/CustomInstructionService')['getCustomInstructionService']>
|
||||
|
||||
beforeEach(async () => {
|
||||
// 매번 모듈과 스토어 초기화
|
||||
for (const key of Object.keys(mockStore)) {
|
||||
delete mockStore[key]
|
||||
}
|
||||
vi.resetModules()
|
||||
const mod = await import('../../../src/main/services/CustomInstructionService')
|
||||
getCustomInstructionService = mod.getCustomInstructionService
|
||||
})
|
||||
|
||||
describe('CustomInstructionService', () => {
|
||||
describe('initialize + getAll', () => {
|
||||
it('첫 실행 시 5개 프리셋이 생성된다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const all = svc.getAll()
|
||||
expect(all.length).toBe(5)
|
||||
expect(all.every((i) => i.isBuiltin)).toBe(true)
|
||||
})
|
||||
|
||||
it('order 순으로 정렬하여 반환한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const all = svc.getAll()
|
||||
for (let i = 1; i < all.length; i++) {
|
||||
expect(all[i].order).toBeGreaterThanOrEqual(all[i - 1].order)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
describe('getById', () => {
|
||||
it('존재하는 ID로 명령어를 반환한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const inst = svc.getById('builtin-translate')
|
||||
expect(inst).not.toBeNull()
|
||||
expect(inst!.name).toBe('번역')
|
||||
})
|
||||
|
||||
it('없는 ID에 대해 null을 반환한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
expect(svc.getById('nonexistent')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('create', () => {
|
||||
it('사용자 정의 명령어를 추가한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const created = svc.create({
|
||||
name: 'My Custom',
|
||||
description: 'Test custom instruction',
|
||||
prompt: 'Custom prompt: {{text}}',
|
||||
icon: 'Star'
|
||||
})
|
||||
|
||||
expect(created.isBuiltin).toBe(false)
|
||||
expect(created.name).toBe('My Custom')
|
||||
expect(svc.getAll().length).toBe(6)
|
||||
})
|
||||
})
|
||||
|
||||
describe('update', () => {
|
||||
it('사용자 정의 명령어의 모든 필드를 수정할 수 있다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const created = svc.create({
|
||||
name: 'Original',
|
||||
description: 'Desc',
|
||||
prompt: 'Prompt',
|
||||
icon: 'Star'
|
||||
})
|
||||
|
||||
const updated = svc.update(created.id, { name: 'Updated', prompt: 'New prompt' })
|
||||
expect(updated).not.toBeNull()
|
||||
expect(updated!.name).toBe('Updated')
|
||||
expect(updated!.prompt).toBe('New prompt')
|
||||
})
|
||||
|
||||
it('프리셋은 프롬프트만 수정 가능하다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const updated = svc.update('builtin-translate', { name: 'Changed Name', prompt: 'New prompt' })
|
||||
expect(updated).not.toBeNull()
|
||||
expect(updated!.name).toBe('번역') // 이름은 변경 안 됨
|
||||
expect(updated!.prompt).toBe('New prompt') // 프롬프트는 변경됨
|
||||
})
|
||||
})
|
||||
|
||||
describe('delete', () => {
|
||||
it('프리셋은 삭제할 수 없다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
expect(svc.delete('builtin-translate')).toBe(false)
|
||||
expect(svc.getAll().length).toBe(5)
|
||||
})
|
||||
|
||||
it('사용자 정의 명령어는 삭제할 수 있다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const created = svc.create({
|
||||
name: 'To Delete',
|
||||
description: '',
|
||||
prompt: '',
|
||||
icon: ''
|
||||
})
|
||||
|
||||
expect(svc.delete(created.id)).toBe(true)
|
||||
expect(svc.getAll().length).toBe(5)
|
||||
})
|
||||
|
||||
it('없는 ID 삭제 시 false를 반환한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
expect(svc.delete('nonexistent')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('reorder', () => {
|
||||
it('지정된 순서대로 order를 재설정한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
const all = svc.getAll()
|
||||
const reversed = [...all].reverse().map((i) => i.id)
|
||||
svc.reorder(reversed)
|
||||
|
||||
const reordered = svc.getAll()
|
||||
expect(reordered[0].id).toBe(reversed[0])
|
||||
expect(reordered[4].id).toBe(reversed[4])
|
||||
})
|
||||
})
|
||||
|
||||
describe('resetBuiltins', () => {
|
||||
it('프리셋을 초기값으로 복원하고 사용자 명령어는 유지한다', () => {
|
||||
const svc = getCustomInstructionService()
|
||||
svc.initialize()
|
||||
|
||||
// 프롬프트 수정
|
||||
svc.update('builtin-translate', { prompt: 'modified prompt' })
|
||||
|
||||
// 사용자 명령어 추가
|
||||
svc.create({ name: 'User', description: '', prompt: '', icon: '' })
|
||||
|
||||
svc.resetBuiltins()
|
||||
|
||||
const all = svc.getAll()
|
||||
const translate = all.find((i) => i.id === 'builtin-translate')
|
||||
expect(translate!.prompt).toContain('{{targetLanguage}}') // 원래 프롬프트
|
||||
expect(all.length).toBe(6) // 프리셋 5 + 사용자 1
|
||||
})
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue