fix(meeting): keep learned text from injecting prompt lines
Learned text becomes part of a prompt, so a dictionary word or phrase containing a newline could add its own instruction line. Every value that reaches the recognition hint or the polish block is now flattened to one line and length-capped, and a test proves an injected line stays plain text. Also cover the invariants that keep the correction safe (random inputs, Hangul untouched, idempotent, no token growth, large transcript) and the file-transcription wiring that attaches the learned hint to every chunk and corrects each chunk and segment before it is stored.
This commit is contained in:
parent
03e7b7f507
commit
bcd0cf4f23
3 changed files with 260 additions and 3 deletions
|
|
@ -0,0 +1,100 @@
|
|||
// 파일 전사가 학습 어휘 힌트·교정을 실제로 쓰는지 (MTG-14 배선 검증).
|
||||
|
||||
import { EventEmitter } from 'events'
|
||||
import fs from 'fs'
|
||||
import os from 'os'
|
||||
import path from 'path'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
spawn: vi.fn(),
|
||||
transcribe: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('child_process', () => ({ spawn: hoisted.spawn }))
|
||||
vi.mock('../../../src/main/utils/paths', () => ({ getFfmpegPath: () => '/bundled/ffmpeg.exe' }))
|
||||
vi.mock('../../../src/main/services/RuntimeProvisioner', () => ({ getRuntimeProvisioner: () => ({ ensure: 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/ConfigService', () => ({ configGet: vi.fn(() => undefined) }))
|
||||
vi.mock('../../../src/main/services/stt/STTManager', () => ({
|
||||
getSTTManager: () => ({ transcribe: hoisted.transcribe }),
|
||||
}))
|
||||
vi.mock('../../../src/main/services/HistoryService', () => ({ getHistoryService: () => ({ create: vi.fn() }) }))
|
||||
vi.mock('../../../src/main/services/LicenseService', () => ({
|
||||
getLicenseService: () => ({ canUse: () => ({ allowed: true }), promptUpgrade: vi.fn() }),
|
||||
}))
|
||||
vi.mock('../../../src/main/windows/WindowManager', () => ({ getMainWindow: () => null }))
|
||||
vi.mock('../../../src/main/services/TranscriptGlossaryService', () => ({
|
||||
getTranscriptGlossaryService: () => ({
|
||||
sttHint: (base: string) => (base ? `${base} 용어: VSCode.` : '용어: VSCode.'),
|
||||
// 실제 서비스의 결정적 교정을 흉내낸다 (라틴 식별자 1글자 오인식 복원)
|
||||
correct: (text: string) => ({
|
||||
text: text.replace(/VSCod\b/g, 'VSCode'),
|
||||
corrections: [],
|
||||
}),
|
||||
correctLearned: (text: string) => ({ text, corrections: [] }),
|
||||
promptSection: () => '',
|
||||
}),
|
||||
}))
|
||||
|
||||
function fakeSpawn(_command: string, args: string[]): EventEmitter {
|
||||
const proc = Object.assign(new EventEmitter(), {
|
||||
stdout: new EventEmitter(),
|
||||
stderr: new EventEmitter(),
|
||||
exitCode: null as number | null,
|
||||
killed: false,
|
||||
kill: () => true,
|
||||
})
|
||||
queueMicrotask(() => {
|
||||
// 60초 = 30초 조각 2개
|
||||
if (args.includes('null')) proc.stderr.emit('data', Buffer.from('Duration: 00:01:00.00'))
|
||||
if (args.includes('pipe:1')) proc.stdout.emit('data', Buffer.from('pcm'))
|
||||
proc.exitCode = 0
|
||||
proc.emit('close', 0)
|
||||
})
|
||||
return proc
|
||||
}
|
||||
|
||||
describe('FileTranscriptionService 학습 어휘 배선', () => {
|
||||
let inputFile: string
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetModules()
|
||||
vi.clearAllMocks()
|
||||
hoisted.spawn.mockImplementation(fakeSpawn)
|
||||
inputFile = path.join(os.tmpdir(), `d3ro-ft-glossary-${Date.now()}.mp3`)
|
||||
fs.writeFileSync(inputFile, 'x')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmSync(inputFile, { force: true })
|
||||
})
|
||||
|
||||
it('매 조각에 학습 용어 힌트를 붙이고, 전사 결과를 학습 표기로 교정한다', async () => {
|
||||
const prompts: Array<string | undefined> = []
|
||||
const replies = ['VSCod 설정을 확인합니다.', 'VSCod 테마도 바꿉니다.']
|
||||
hoisted.transcribe.mockImplementation(async (_buf: Buffer, opts: { initialPrompt?: string }) => {
|
||||
prompts.push(opts.initialPrompt)
|
||||
const text = replies[prompts.length - 1]
|
||||
return { text, segments: [{ text, start: 0, end: 3 }] }
|
||||
})
|
||||
|
||||
const mod = await import('../../../src/main/services/FileTranscriptionService')
|
||||
mod.resetFileTranscriptionServiceForTests()
|
||||
const result = await mod.getFileTranscriptionService().startTranscription(inputFile, 'ko')
|
||||
|
||||
// 첫 조각은 문맥이 없어도 힌트만 붙는다
|
||||
expect(prompts[0]).toBe('용어: VSCode.')
|
||||
expect(prompts).toHaveLength(2)
|
||||
for (const prompt of prompts) expect(prompt).toContain('용어: VSCode.')
|
||||
|
||||
expect(result.fullText).toBe('VSCode 설정을 확인합니다. VSCode 테마도 바꿉니다.')
|
||||
expect(result.fullText).not.toContain('VSCod ')
|
||||
expect(result.segments.map((segment) => segment.text)).toEqual([
|
||||
'VSCode 설정을 확인합니다.',
|
||||
'VSCode 테마도 바꿉니다.',
|
||||
])
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue