feat(desktop): built-in Han/Eng layout auto-switching, terminal/Vim support, and Unicode input
This commit is contained in:
parent
1da04b9e46
commit
a3ac44da2b
109 changed files with 8234 additions and 242 deletions
|
|
@ -0,0 +1,165 @@
|
|||
// 후보 없이 끝났을 때 말없이 닫지 않고 "제안 사항 없음" 을 1초 보여 준다.
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const config = vi.hoisted(() => ({
|
||||
suggestionEnabled: true as boolean,
|
||||
suggestionModelId: 'gemma4:e4b' as string | null,
|
||||
llmModelId: 'gemma4:e4b' as string | null,
|
||||
inputExcludedApps: [] as string[],
|
||||
suggestionTriggerDelayMs: 600,
|
||||
suggestionMinPrefixChars: 4,
|
||||
suggestionMaxRequestsPerMinute: 20,
|
||||
suggestionDailyBudget: 500,
|
||||
suggestionRequestTimeoutMs: 8000,
|
||||
inputLearnTypedText: false,
|
||||
inputTelemetryEnabled: false,
|
||||
suggestionOverlayInteractive: true,
|
||||
insertMethod: 'clipboard'
|
||||
}))
|
||||
const harness = vi.hoisted(() => ({
|
||||
streamGenerate: vi.fn(),
|
||||
insertText: vi.fn(async (text: string) => ({ success: true, method: 'clipboard', textLength: text.length })),
|
||||
replaceBeforeCaret: vi.fn(async (_count: number, text: string) => ({
|
||||
success: true,
|
||||
method: 'clipboard',
|
||||
textLength: text.length
|
||||
}))
|
||||
}))
|
||||
|
||||
vi.mock('../../../src/main/services/ConfigService', () => ({
|
||||
configGet: vi.fn((key: keyof typeof config) => config[key]),
|
||||
configSet: vi.fn()
|
||||
}))
|
||||
vi.mock('../../../src/main/services/LoggerService', () => ({
|
||||
getLogger: () => ({ info: vi.fn(), warn: vi.fn(), error: vi.fn(), debug: vi.fn() })
|
||||
}))
|
||||
vi.mock('../../../src/main/services/LocalLLMService', () => ({
|
||||
getLocalLLMService: () => ({ isAvailable: () => true, streamGenerate: harness.streamGenerate })
|
||||
}))
|
||||
vi.mock('../../../src/main/services/InputTelemetryService', () => ({
|
||||
getInputTelemetryService: () => ({ listPhrases: () => [], listRecentWrites: () => [] })
|
||||
}))
|
||||
vi.mock('../../../src/main/services/PersonalGraphService', () => ({
|
||||
getPersonalGraphService: () => ({ retrieveContext: () => ({ continuations: [], related: [] }) })
|
||||
}))
|
||||
vi.mock('../../../src/main/services/TextInsertService', () => ({
|
||||
getTextInsertService: () => ({ insertText: harness.insertText, replaceBeforeCaret: harness.replaceBeforeCaret })
|
||||
}))
|
||||
vi.mock('../../../src/main/services/modifier-state', () => ({ prepareModifiersForPaste: async () => 'released' }))
|
||||
vi.mock('../../../src/main/utils/win32-foreground', () => ({ getForegroundWindowInfo: () => null }))
|
||||
vi.mock('../../../src/main/db', () => ({ getDatabase: vi.fn() }))
|
||||
vi.mock('../../../src/main/db/schema', () => ({ suggestions: {} }))
|
||||
|
||||
import {
|
||||
SuggestionService,
|
||||
type SuggestionServiceDeps
|
||||
} from '../../../src/main/services/SuggestionService'
|
||||
import { SuggestionBudget } from '../../../src/main/services/suggestion/SuggestionBudget'
|
||||
import { ModelWarmTracker } from '../../../src/main/services/suggestion/ModelWarmTracker'
|
||||
import type { TypingContext } from '../../../src/main/services/InputTelemetryService'
|
||||
|
||||
const PREFIX = '지금 테스트 해보는데 잠시 쉬면'
|
||||
|
||||
function typingContext(overrides: Partial<TypingContext> = {}): TypingContext {
|
||||
const prefix = overrides.prefix ?? PREFIX
|
||||
return {
|
||||
prefix,
|
||||
fullText: prefix,
|
||||
caretOffset: prefix.length,
|
||||
documentBefore: prefix,
|
||||
anchor: { x: 10, y: 10, width: 2, height: 16 },
|
||||
anchorKind: 'caret',
|
||||
isPassword: false,
|
||||
isEditable: true,
|
||||
isComposing: false,
|
||||
hasSelection: false,
|
||||
available: true,
|
||||
appName: 'notepad.exe',
|
||||
windowTitle: 'notes',
|
||||
windowHandle: null,
|
||||
idleMs: 2000,
|
||||
capturedAt: Date.now(),
|
||||
editedSinceFocus: true,
|
||||
typedRecently: true,
|
||||
...overrides
|
||||
}
|
||||
}
|
||||
|
||||
function deps(): SuggestionServiceDeps {
|
||||
const warmth = new ModelWarmTracker()
|
||||
warmth.noteWarm('gemma4:e4b', Date.now() + 600_000)
|
||||
return {
|
||||
repository: { record: vi.fn(), markAccepted: vi.fn(), list: vi.fn(() => []) },
|
||||
budget: new SuggestionBudget(),
|
||||
warmth,
|
||||
foreground: { currentWindowHandle: () => null },
|
||||
learning: { expectProgrammaticInsert: vi.fn(() => vi.fn()), recordAccepted: vi.fn() }
|
||||
}
|
||||
}
|
||||
|
||||
interface Internal {
|
||||
_generate(prefix: string, context: TypingContext, maxCandidates: number, maxChars: number): Promise<void>
|
||||
_lastContext: TypingContext | null
|
||||
_lastRequestAt: number
|
||||
}
|
||||
|
||||
let services: SuggestionService[] = []
|
||||
function create(): SuggestionService {
|
||||
const service = new SuggestionService(deps())
|
||||
services.push(service)
|
||||
return service
|
||||
}
|
||||
|
||||
import { shouldPresentSuggestion } from '../../../src/main/windows/suggestion-overlay-presenter'
|
||||
import { suggestionPanelHeight } from '../../../src/main/windows/suggestion-overlay-geometry'
|
||||
|
||||
beforeEach(() => {
|
||||
harness.streamGenerate.mockReset()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
for (const service of services) service.dispose()
|
||||
services = []
|
||||
vi.useRealTimers()
|
||||
})
|
||||
|
||||
describe('"제안 사항 없음" 알림 (2026-10-25 사용자 요청)', () => {
|
||||
it('생성 중이 보이다 후보 없이 끝나면 알림을 1초 보여 주고 닫는다', async () => {
|
||||
harness.streamGenerate.mockImplementation(async function* () {
|
||||
yield ''
|
||||
})
|
||||
const service = create()
|
||||
const cleared: string[] = []
|
||||
service.on('cleared', ({ reason }) => cleared.push(reason))
|
||||
;(service as unknown as Internal)._lastContext = typingContext()
|
||||
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
|
||||
await (service as unknown as Internal)._generate(PREFIX, typingContext(), 3, 160)
|
||||
|
||||
expect(service.getState()).toMatchObject({ notice: 'no-suggestion', candidates: [], generating: false })
|
||||
expect(shouldPresentSuggestion(service.getState())).toBe(true)
|
||||
expect(cleared).toEqual([])
|
||||
|
||||
vi.advanceTimersByTime(1000)
|
||||
expect(service.getState().notice).toBeNull()
|
||||
expect(cleared).toEqual(['generation-failed'])
|
||||
})
|
||||
|
||||
it('사용자가 닫거나 새로 생성하면 알림은 바로 사라진다', async () => {
|
||||
harness.streamGenerate.mockImplementation(async function* () {
|
||||
yield ''
|
||||
})
|
||||
const service = create()
|
||||
;(service as unknown as Internal)._lastContext = typingContext()
|
||||
await (service as unknown as Internal)._generate(PREFIX, typingContext(), 3, 160)
|
||||
expect(service.getState().notice).toBe('no-suggestion')
|
||||
|
||||
service.dismiss('dismissed')
|
||||
expect(service.getState().notice).toBeNull()
|
||||
})
|
||||
|
||||
it('알림 줄은 상태 줄 자리를 쓴다 (창 높이)', () => {
|
||||
const base = { candidateCount: 0, activeIndex: 0, generating: false, warmingUp: false, hasPartialText: false }
|
||||
expect(suggestionPanelHeight({ ...base, hasNotice: true })).toBe(suggestionPanelHeight({ ...base, generating: true }))
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue