fix(voice-action): route plans through the LLM gateway and validate what reaches the shell
The feature is not wired to the UI yet but is reachable over IPC:
- planning called the premium proxy directly, sending speech to the cloud
even with the local backend selected and failing in local mode
- LLM-provided app names and key combos were spliced into cmd/PowerShell
strings; they are now validated, and combos map named keys (alt+tab no
longer types Alt+T, a, b)
- presets matched substrings and bare nouns ("commute" toggled mute,
"크롬 캐시 지워줘" opened Chrome); they now match whole words only
- a plan without safe=true is treated as unsafe and unsafe shell commands
are not run; URLs go through openExternalSafe
This commit is contained in:
parent
9cf3fd7317
commit
29d22504ae
3 changed files with 158 additions and 27 deletions
62
apps/desktop/tests/main/services/voice-action-policy.test.ts
Normal file
62
apps/desktop/tests/main/services/voice-action-policy.test.ts
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
// tests/main/services/voice-action-policy.test.ts
|
||||
// 음성 액션 순수 판정: 프리셋은 단어로만 맞추고, 셸에 넘길 앱 이름·키 조합은 검증·변환한다.
|
||||
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { VoiceActionPreset } from '@d3ro/core/types'
|
||||
import { isSafeAppName, matchVoiceActionPreset, toSendKeys } from '../../../src/main/services/voice-action-policy'
|
||||
|
||||
const PRESETS: VoiceActionPreset[] = [
|
||||
{
|
||||
keywords: ['크롬 열어', 'open chrome'],
|
||||
action: { action: 'open_app', target: 'chrome', description: 'Open Chrome', safe: true },
|
||||
},
|
||||
{
|
||||
keywords: ['음소거', 'mute sound'],
|
||||
action: { action: 'keyboard_shortcut', target: 'volumemute', description: 'Mute', safe: true },
|
||||
},
|
||||
]
|
||||
|
||||
describe('matchVoiceActionPreset', () => {
|
||||
it('키워드가 단어로 있으면 맞춘다', () => {
|
||||
expect(matchVoiceActionPreset('크롬 열어줘', PRESETS)).toBeNull()
|
||||
expect(matchVoiceActionPreset('크롬 열어', PRESETS)?.action.target).toBe('chrome')
|
||||
expect(matchVoiceActionPreset('Please open Chrome.', PRESETS)?.action.target).toBe('chrome')
|
||||
expect(matchVoiceActionPreset('음소거', PRESETS)?.action.target).toBe('volumemute')
|
||||
})
|
||||
|
||||
it('다른 단어 속 부분 문자열은 맞추지 않는다', () => {
|
||||
expect(matchVoiceActionPreset('my commute sound was loud', PRESETS)).toBeNull()
|
||||
expect(matchVoiceActionPreset('크롬 캐시 지워줘', PRESETS)).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSafeAppName', () => {
|
||||
it('평범한 앱 이름은 허용한다', () => {
|
||||
expect(isSafeAppName('notepad')).toBe(true)
|
||||
expect(isSafeAppName('Visual Studio Code')).toBe(true)
|
||||
expect(isSafeAppName('메모장')).toBe(true)
|
||||
})
|
||||
|
||||
it('인용을 깨거나 명령을 이어 붙일 수 있는 값은 거부한다', () => {
|
||||
expect(isSafeAppName('notepad" & calc & "')).toBe(false)
|
||||
expect(isSafeAppName('a|b')).toBe(false)
|
||||
expect(isSafeAppName('%COMSPEC%')).toBe(false)
|
||||
expect(isSafeAppName(' ')).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
describe('toSendKeys', () => {
|
||||
it('수정자와 이름 있는 키를 SendKeys 표기로 바꾼다', () => {
|
||||
expect(toSendKeys('ctrl+c')).toBe('^c')
|
||||
expect(toSendKeys('alt+tab')).toBe('%{TAB}')
|
||||
expect(toSendKeys('ctrl+shift+esc')).toBe('^+{ESC}')
|
||||
expect(toSendKeys('f5')).toBe('{F5}')
|
||||
expect(toSendKeys('enter')).toBe('{ENTER}')
|
||||
})
|
||||
|
||||
it('모르는 키·수정자나 따옴표가 든 값은 null 이다', () => {
|
||||
expect(toSendKeys("ctrl+'); Remove-Item x; ('")).toBeNull()
|
||||
expect(toSendKeys('win+r')).toBeNull()
|
||||
expect(toSendKeys('')).toBeNull()
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue