d3ro-voice/apps/desktop/tests/red/meeting-llm.usecase.test.ts
Yun Chan e2d17601a4 feat(meeting): ground AI transcript correction in learned vocabulary
AI polishing of a recorded or pasted transcript was a generic rewrite: it
cleaned fillers but left names and in-house terms mangled even when the app
already knew them. Polishing now corrects dictionary pronunciations and
typed identifiers deterministically before and after the model, and hands
the model the learned term list plus the user's own expressions with
explicit rules: rewrite a misheard name, product or in-house term to the
learned spelling, and never swap an ordinary noun or ending on similarity
alone. Dictation output is re-checked the same way after the model runs.
2026-11-06 17:22:54 +09:00

106 lines
4 KiB
TypeScript

import { describe, it, expect, vi } from 'vitest'
import { ErrorCode } from '@d3ro/core/errors'
import { getMeetingModeService } from '../../src/main/services/MeetingModeService'
import { getDatabase } from '../../src/main/db'
import { meetingSessions } from '../../src/main/db/schema'
import { configSet } from '../../src/main/services/ConfigService'
import { getDictionaryService } from '../../src/main/services/DictionaryService'
import { useRedHarness } from './harness'
import { FX, USER_TEXT } from './fixtures'
const localGenerate = vi.fn(async () => ({ text: FX.LLM_OK, model: 'fx-local-model' }))
const premiumGenerate = vi.fn(async () => {
throw new Error('fx.premium.should-not-run-on-local-backend')
})
vi.mock('../../src/main/services/LocalLLMService', () => ({
getLocalLLMService: () => ({
isAvailable: () => true,
generate: (...args: unknown[]) => localGenerate(...args),
chatStream: async function* () {
yield FX.LLM_OK
return FX.LLM_OK
},
}),
resetLocalLLMServiceForTests: () => undefined,
startLocalLLMAvailability: vi.fn(),
}))
vi.mock('../../src/main/services/PremiumLLMService', () => ({
getPremiumLLMService: () => ({
isAvailable: () => false,
generate: (...args: unknown[]) => premiumGenerate(...args),
chatStream: async function* () {
throw new Error('fx.premium.chat.should-not-run')
},
}),
resetPremiumLLMServiceForTests: () => undefined,
}))
useRedHarness()
function insertSession(id: string): void {
const now = Date.now()
getDatabase()
.insert(meetingSessions)
.values({
id,
title: 'llm-session',
status: 'completed',
startedAt: now,
createdAt: now,
updatedAt: now,
rawTranscript: USER_TEXT.KO,
})
.run()
}
describe('유스케이스: 회의 문서/폴리시가 로컬 LLM 을 탄다', () => {
it('llmBackend=local 이면 polish 가 LocalLLM generate 를 쓰고 Premium 을 부르지 않는다', async () => {
configSet('llmBackend', 'local')
insertSession('meet-local-polish')
localGenerate.mockClear()
premiumGenerate.mockClear()
const polished = await getMeetingModeService().polishTranscript('meet-local-polish')
expect(polished).toBe(FX.LLM_OK)
expect(localGenerate).toHaveBeenCalled()
expect(premiumGenerate).not.toHaveBeenCalled()
expect(getMeetingModeService().getSession('meet-local-polish').editedTranscript).toBe(FX.LLM_OK)
})
it('llmBackend=local 이면 generateDocument 도 LocalLLM 을 탄다', async () => {
configSet('llmBackend', 'local')
insertSession('meet-local-doc')
localGenerate.mockClear()
premiumGenerate.mockClear()
const doc = await getMeetingModeService().generateDocument({
sessionId: 'meet-local-doc',
templateId: 'builtin-minutes',
})
expect(doc.content).toBe(FX.LLM_OK)
expect(localGenerate).toHaveBeenCalled()
expect(premiumGenerate).not.toHaveBeenCalled()
})
it('polish 는 모델이 되돌린 사전 표기를 학습 표기로 다시 강제한다', async () => {
configSet('llmBackend', 'local')
getDictionaryService().add({ word: 'D3RO', pronunciation: '디에로' })
insertSession('meet-polish-dict')
localGenerate.mockClear()
// 모델이 사전 표기를 무시하고 발음 그대로 돌려준 상황
localGenerate.mockResolvedValueOnce({ text: '[00:01] 디에로 보이스 설정 확인해 주세요', model: 'fx-local-model' })
const polished = await getMeetingModeService().polishTranscript('meet-polish-dict')
expect(polished).toBe('[00:01] D3RO 보이스 설정 확인해 주세요')
const systemPrompt = String(localGenerate.mock.calls.at(-1)?.[1]?.systemPrompt ?? '')
expect(systemPrompt).toContain('[사용자 용어')
expect(systemPrompt).toContain('D3RO')
})
it('없는 세션 polish 는 MeetingSessionNotFound 다', async () => {
configSet('llmBackend', 'local')
await expect(getMeetingModeService().polishTranscript('missing')).rejects.toMatchObject({
code: ErrorCode.MeetingSessionNotFound,
})
})
})