d3ro-voice/apps/desktop/tests/main/services/personal-graph-context.test.ts

103 lines
4.9 KiB
TypeScript

// tests/main/services/personal-graph-context.test.ts
// 개인 그래프 문맥 조회 (실제 SQLite) — 직전 문장 follows · 조사 무관 용어 매칭 · 짧은 꼬리 물러나기.
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createTestDb } from '../../helpers/createTestDb'
const holder = vi.hoisted(() => ({ db: null as unknown }))
vi.mock('../../../src/main/db', async (importOriginal) => ({
...(await importOriginal<typeof import('../../../src/main/db')>()),
getDatabase: () => holder.db
}))
vi.mock('../../../src/main/services/LoggerService', () => ({
getLogger: () => ({ debug: vi.fn(), info: vi.fn(), warn: vi.fn(), error: vi.fn() })
}))
import {
getPersonalGraphService,
resetPersonalGraphServiceForTests
} from '../../../src/main/services/PersonalGraphService'
let testDb: ReturnType<typeof createTestDb>
beforeEach(() => {
testDb = createTestDb()
holder.db = testDb.db
resetPersonalGraphServiceForTests()
})
afterEach(() => {
testDb.close()
})
describe('PersonalGraphService.retrieveContext', () => {
it('직전 문장 뒤에 사용자가 실제로 이어 쓴 문장을 followUps 로 준다', () => {
const graph = getPersonalGraphService()
graph.indexText('배포 끝났습니다. 모니터링 대시보드 확인 부탁드립니다.', { source: 'typed' })
graph.indexText('배포 끝났습니다. 모니터링 대시보드 확인 부탁드립니다.', { source: 'typed' })
const context = graph.retrieveContext('오전 작업 공유드립니다. 배포 끝났습니다. ')
expect(context.followUps).toEqual(['모니터링 대시보드 확인 부탁드립니다'])
})
it('직전 문장이 조금 달라도 용어가 거의 같으면 그 노드의 follows 를 쓴다', () => {
const graph = getPersonalGraphService()
graph.indexText('주간 보고서 초안 작성했습니다. 피드백은 금요일까지 부탁드려요.', { source: 'typed' })
const context = graph.retrieveContext('주간 보고서 초안을 작성했습니다! ')
expect(context.followUps).toEqual(['피드백은 금요일까지 부탁드려요'])
})
it('조사가 달라도 같은 주제의 문장을 관련 문장으로 끌어온다', () => {
const graph = getPersonalGraphService()
graph.indexText('금요일 배포를 위해 회귀 테스트를 끝내야 합니다', { source: 'typed' })
graph.indexText('점심은 김치찌개 어때요', { source: 'typed' })
const context = graph.retrieveContext('이번 배포는 회귀 테스트가')
expect(context.related).toContain('금요일 배포를 위해 회귀 테스트를 끝내야 합니다')
expect(context.related).not.toContain('점심은 김치찌개 어때요')
})
it('긴 꼬리가 맞지 않으면 짧은 어절 꼬리로 물러나 이어쓰기를 찾는다', () => {
const graph = getPersonalGraphService()
graph.indexText('회의록은 내일 오전까지 공유드리겠습니다', { source: 'typed' })
const context = graph.retrieveContext('지난번 논의한 안건의 회의록은')
expect(context.continuations).toEqual(['내일 오전까지 공유드리겠습니다'])
})
it('이미 접두에 쓴 문장은 다시 주지 않는다', () => {
const graph = getPersonalGraphService()
graph.indexText('배포 끝났습니다. 배포 로그 확인했습니다.', { source: 'typed' })
const context = graph.retrieveContext('배포 끝났습니다. 배포 로그 확인했습니다. ')
expect(context.related).not.toContain('배포 로그 확인했습니다')
expect(context.followUps).not.toContain('배포 로그 확인했습니다')
})
it('같은 앱에서 단문 메시지를 연속으로 보내도 세션 follows 사슬을 잇고 recentWrites 로 복원한다', () => {
const graph = getPersonalGraphService()
const now = Date.now()
graph.indexText('배포 모두 끝났습니다', { source: 'typed', appName: 'Slack.exe', at: now })
graph.indexText('모니터링 대시보드 확인 부탁드립니다', {
source: 'typed',
appName: 'Slack.exe',
at: now + 15_000
})
// 채팅창에서 엔터로 전송해 입력칸이 비워진 뒤 다음 메시지를 치기 시작한 상태
const context = graph.retrieveContext('지금 ', 4, {
appName: 'Slack.exe',
recentWrites: ['배포 모두 끝났습니다']
})
expect(context.followUps).toContain('모니터링 대시보드 확인 부탁드립니다')
})
it('조사가 달라 정확한 부분 문자열이 어긋나도 어간(stem) 연속 일치로 이어쓰기를 찾는다', () => {
const graph = getPersonalGraphService()
graph.indexText('회의록 정리해서 내일 오전까지 공유드리겠습니다', { source: 'typed' })
const context = graph.retrieveContext('오늘 회의록을 정리해서')
expect(context.continuations).toEqual(['내일 오전까지 공유드리겠습니다'])
})
})