186 lines
7.2 KiB
TypeScript
186 lines
7.2 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import {
|
|
FALLBACK_OLLAMA_MODELS,
|
|
RECOMMENDED_OLLAMA_MODEL,
|
|
clampMicMeterPercent,
|
|
formatModelSizeGb,
|
|
listUninstalledFallbackModels,
|
|
resolveActiveOllamaModel,
|
|
resolveOllamaStatusSummary
|
|
} from '../../src/renderer/components/settings/settings-model-helpers'
|
|
import {
|
|
applyCorrectionToContext,
|
|
buildDecisionInputSignature,
|
|
isDuplicateCandidateText,
|
|
normalizeSuggestionPolicyConfig,
|
|
rerankFilledCandidates,
|
|
resolveTerminalTypingContext,
|
|
sameCandidateText,
|
|
toSuggestionCorrectionFromPlan
|
|
} from '../../src/main/services/suggestion/suggestion-policy-helpers'
|
|
import type { TypingContext } from '../../src/main/services/InputTelemetryService'
|
|
|
|
function createTypingContext(overrides: Partial<TypingContext> = {}): TypingContext {
|
|
return {
|
|
available: true,
|
|
isEditable: true,
|
|
isPassword: false,
|
|
isComposing: false,
|
|
hasSelection: false,
|
|
editedSinceFocus: true,
|
|
typedRecently: true,
|
|
prefix: '회의 안건을 정리했습니다',
|
|
documentBefore: '회의 안건을 정리했습니다',
|
|
fullText: '회의 안건을 정리했습니다',
|
|
appName: 'Notion',
|
|
windowTitle: '주간 회의록',
|
|
windowHandle: 101,
|
|
anchor: null,
|
|
anchorKind: null,
|
|
idleMs: 700,
|
|
...overrides
|
|
}
|
|
}
|
|
|
|
describe('settings-model-helpers', () => {
|
|
it('활성모델결정_설정없을때_권장모델을반환한다', () => {
|
|
expect(resolveActiveOllamaModel(undefined)).toBe(RECOMMENDED_OLLAMA_MODEL)
|
|
expect(resolveActiveOllamaModel('qwen2.5:7b')).toBe('qwen2.5:7b')
|
|
})
|
|
|
|
it('미설치기본모델목록_설치된모델제외_나머지후보만반환한다', () => {
|
|
expect(listUninstalledFallbackModels([{ name: 'llama3.2:3b' }])).toEqual(['qwen2.5:3b'])
|
|
expect(listUninstalledFallbackModels([])).toEqual([...FALLBACK_OLLAMA_MODELS])
|
|
})
|
|
|
|
it('모델크기표시_바이트입력시_소수첫째자리기가바이트를계산한다', () => {
|
|
const twoPointFiveGb = Math.round(2.5 * 1024 * 1024 * 1024)
|
|
expect(formatModelSizeGb(twoPointFiveGb)).toBe(2.5)
|
|
expect(formatModelSizeGb(0)).toBe(0)
|
|
})
|
|
|
|
it('마이크레벨백분율_범위초과및음수_0과100사이정수로고정한다', () => {
|
|
expect(clampMicMeterPercent(-0.3)).toBe(0)
|
|
expect(clampMicMeterPercent(0.456)).toBe(46)
|
|
expect(clampMicMeterPercent(1.8)).toBe(100)
|
|
})
|
|
|
|
it('Ollama상태요약_연결상태별_적절한번역키와인자를반환한다', () => {
|
|
expect(resolveOllamaStatusSummary(null, 0)).toEqual({ kind: 'checking' })
|
|
expect(
|
|
resolveOllamaStatusSummary({ connectionState: 'disconnected', models: [] }, 0)
|
|
).toEqual({ kind: 'offline' })
|
|
expect(
|
|
resolveOllamaStatusSummary({ connectionState: 'connected', serverVersion: '0.6.2', models: [] }, 3)
|
|
).toEqual({ kind: 'connectedVersion', version: '0.6.2', count: 3 })
|
|
expect(
|
|
resolveOllamaStatusSummary({ connectionState: 'connected', models: [] }, 2)
|
|
).toEqual({ kind: 'connected', count: 2 })
|
|
})
|
|
})
|
|
|
|
describe('suggestion-policy-helpers', () => {
|
|
it('오타교정문맥적용_접두끝일치시_prefix와documentBefore끝만교체한다', () => {
|
|
const context = createTypingContext({
|
|
prefix: '오늘 회으에서',
|
|
documentBefore: '제목\n오늘 회으에서'
|
|
})
|
|
const updated = applyCorrectionToContext(context, {
|
|
from: '회으에서',
|
|
to: '회의에서',
|
|
edits: [{ start: 0, end: 2, to: '회의' }]
|
|
})
|
|
|
|
expect(updated.prefix).toBe('오늘 회의에서')
|
|
expect(updated.documentBefore).toBe('제목\n오늘 회의에서')
|
|
})
|
|
|
|
it('후보동일성및중복검사_공백문장부호정규화및접두확장_중복으로판정한다', () => {
|
|
expect(sameCandidateText('다음 주에 공유드릴게요!', '다음 주에 공유드릴게요.')).toBe(true)
|
|
expect(
|
|
isDuplicateCandidateText('다음 주에 공유드릴게요 그리고 검토 부탁드립니다', [
|
|
{ text: '다음 주에 공유드릴게요', rank: 0 }
|
|
])
|
|
).toBe(true)
|
|
expect(
|
|
isDuplicateCandidateText('내일 오전에 다시 확인하겠습니다', [
|
|
{ text: '다음 주에 공유드릴게요', rank: 0 }
|
|
])
|
|
).toBe(false)
|
|
})
|
|
|
|
it('채우기후보재정렬_개인화점수높은신규후보_개인후보유지하고모델후보앞으로배치한다', () => {
|
|
const candidates = [
|
|
{ text: '먼저', rank: 0, source: 'personal' as const },
|
|
{ text: '일반적인 안내 문장입니다.', rank: 1 },
|
|
{ text: '주간 배포 체크리스트 공유드립니다.', rank: 2 }
|
|
]
|
|
const reranked = rerankFilledCandidates(candidates, '주간 배포 체크리스트 공유드립니다.', {
|
|
prefix: '이번 스프린트 마무리하며',
|
|
continuationHints: ['주간 배포 체크리스트 공유드립니다.'],
|
|
followUpHints: ['주간 배포 체크리스트 공유드립니다.'],
|
|
relatedHints: [],
|
|
phraseHints: ['주간 배포 체크리스트']
|
|
})
|
|
|
|
expect(reranked[0]).toEqual({ text: '먼저', rank: 0, source: 'personal' })
|
|
expect(reranked[1]).toEqual({ text: '주간 배포 체크리스트 공유드립니다.', rank: 1 })
|
|
expect(reranked[2]).toEqual({ text: '일반적인 안내 문장입니다.', rank: 2 })
|
|
})
|
|
|
|
it('정책설정정규화_최소지연시간및분당최대요청상한_강제적용한다', () => {
|
|
const normalized = normalizeSuggestionPolicyConfig({
|
|
triggerDelayMs: 50,
|
|
minPrefixChars: 0,
|
|
maxRequestsPerMinute: 999,
|
|
dailyBudget: 0,
|
|
excludedApps: ['1Password.exe']
|
|
})
|
|
|
|
expect(normalized.triggerDelayMs).toBeGreaterThanOrEqual(200)
|
|
expect(normalized.maxRequestsPerMinute).toBe(30)
|
|
expect(normalized.excludedApps).toEqual(['1Password.exe'])
|
|
})
|
|
|
|
it('교정계획변환_접두끝불일치시_제외하고일치시상대오프셋으로변환한다', () => {
|
|
const mismatched = toSuggestionCorrectionFromPlan('다른 문장', {
|
|
originalText: '회으',
|
|
insertText: '회의',
|
|
corrections: [{ start: 10, end: 12, to: '회의' }]
|
|
})
|
|
expect(mismatched).toBe(undefined)
|
|
|
|
const matched = toSuggestionCorrectionFromPlan('오늘 회으 진행', {
|
|
originalText: '회으 진행',
|
|
insertText: '회의 진행',
|
|
corrections: [{ start: 3, end: 5, to: '회의' }]
|
|
})
|
|
expect(matched).toEqual({
|
|
from: '회으 진행',
|
|
to: '회의 진행',
|
|
edits: [{ start: 0, end: 2, to: '회의' }]
|
|
})
|
|
})
|
|
|
|
it('판단입력서명및터미널문맥_회색추천문구와끝타이핑_정확히구분한다', () => {
|
|
const context = createTypingContext({ anchor: { x: 10, y: 20, width: 4, height: 18 } })
|
|
expect(
|
|
buildDecisionInputSignature(context, { modelAvailable: true, enabled: true })
|
|
).toBe('true|true|false|false|A|true|true|true|true')
|
|
|
|
const emptyStep = resolveTerminalTypingContext(
|
|
createTypingContext({ appName: 'WindowsTerminal', fullText: 'PS D:\\repo> ' }),
|
|
{ lastPrompt: null, promptTyped: false }
|
|
)
|
|
expect(emptyStep.context.caretReliable).toBe(true)
|
|
|
|
const ghostSuggestionStep = resolveTerminalTypingContext(
|
|
createTypingContext({
|
|
appName: 'WindowsTerminal',
|
|
fullText: 'PS D:\\repo> run the entire verification pipeline now'
|
|
}),
|
|
emptyStep.nextState
|
|
)
|
|
expect(ghostSuggestionStep.context.caretReliable).toBe(false)
|
|
})
|
|
})
|