feat: 회의 파일 가져오기와 입력 엔진 배포 보완

This commit is contained in:
Yun Chan 2026-11-01 19:39:06 +09:00
parent 5a8c5cd792
commit b3519e5da7
54 changed files with 1129 additions and 116 deletions

View file

@ -0,0 +1,47 @@
import { execFile } from 'child_process'
import fs from 'fs'
import os from 'os'
import path from 'path'
import { promisify } from 'util'
import { afterEach, describe, expect, it, vi } from 'vitest'
import { getMeetingModeService } from '../../src/main/services/MeetingModeService'
import { getSTTManager } from '../../src/main/services/stt/STTManager'
import { getLicenseService } from '../../src/main/services/LicenseService'
import { getFfmpegPath } from '../../src/main/utils/paths'
import { localAudioPath } from '../../src/main/services/sync/audio-sync'
import { useRedHarness } from '../red/harness'
const execFileAsync = promisify(execFile)
useRedHarness()
const sources = new Set<string>()
afterEach(() => {
for (const source of sources) fs.rmSync(source, { force: true })
sources.clear()
})
describe.each(['mp3', 'm4a'])('실제 %s 녹음 파일 가져오기', (extension) => {
it('ffmpeg 변환 후 회의와 재생용 WAV를 만든다', async () => {
const source = path.join(os.tmpdir(), `d3ro-meeting-media-${process.pid}-${Date.now()}.${extension}`)
sources.add(source)
await execFileAsync(getFfmpegPath(), [
'-f', 'lavfi', '-i', 'sine=frequency=440:duration=1', '-y', source,
])
vi.spyOn(getLicenseService(), 'canUse').mockReturnValue({ allowed: true, reason: 'ok' })
vi.spyOn(getSTTManager(), 'transcribe').mockResolvedValue({
text: `${extension} 회의 발언`,
segments: [{ text: `${extension} 회의 발언`, start: 0, end: 1, confidence: 1 }],
})
const detail = await getMeetingModeService().importRecording(source, 'ko')
expect(detail.rawTranscript).toBe(`[00:00] ${extension} 회의 발언`)
expect(detail.durationMs).toBeGreaterThan(0)
const audioPath = localAudioPath('meeting', detail.id)
expect(audioPath).not.toBeNull()
const wav = fs.readFileSync(audioPath!)
expect(wav.subarray(0, 4).toString('ascii')).toBe('RIFF')
expect(wav.subarray(8, 12).toString('ascii')).toBe('WAVE')
getMeetingModeService().deleteSession(detail.id)
}, 30_000)
})

View file

@ -338,12 +338,12 @@ describe('RuntimeProvisioner', () => {
const markerPath = (): string => join(workDir, 'runtime', 'sidecar', '.runtime-version')
it('설치 후 마커를 쓰고, 다음 ensure 는 내려받지 않는다', async () => {
const feed = feedFor(sidecarTar('1.9.0'), '1.9.0')
const feed = feedFor(sidecarTar('1.16.0'), '1.16.0')
const p = provisioner(feed.fetchImpl)
const path = await p.ensure('sidecar')
expect(path).toBe(p.binaryPath('sidecar'))
expect(readFileSync(markerPath(), 'utf8')).toBe('1.9.0')
expect(readFileSync(markerPath(), 'utf8')).toBe('1.16.0')
feed.calls.length = 0
await p.ensure('sidecar')
@ -351,7 +351,7 @@ describe('RuntimeProvisioner', () => {
})
it('force 면 설치돼 있어도 다시 받아 손상된 트리를 복구한다', async () => {
const feed = feedFor(sidecarTar('1.9.0'), '1.9.0')
const feed = feedFor(sidecarTar('1.16.0'), '1.16.0')
const p = provisioner(feed.fetchImpl)
await p.ensure('sidecar')
@ -365,7 +365,7 @@ describe('RuntimeProvisioner', () => {
})
it('추출 중 항목 오류가 나면 실패하고 버전 마커를 남기지 않는다', async () => {
const feed = feedFor(brokenSidecarTar(), '1.9.0')
const feed = feedFor(brokenSidecarTar(), '1.16.0')
const p = provisioner(feed.fetchImpl)
await expect(p.ensure('sidecar')).rejects.toThrow()
@ -382,7 +382,7 @@ describe('RuntimeProvisioner', () => {
})
it('다운로드가 끝나면 임시 폴더를 남기지 않는다', async () => {
const feed = feedFor(sidecarTar('1.9.0'), '1.9.0')
const feed = feedFor(sidecarTar('1.16.0'), '1.16.0')
await provisioner(feed.fetchImpl).ensure('sidecar')
expect(existsSync(join(workDir, 'runtime', '.download-sidecar'))).toBe(false)
expect(existsSync(join(workDir, 'runtime', 'sidecar.staging'))).toBe(false)

View file

@ -0,0 +1,100 @@
import fs from 'fs'
import os from 'os'
import path from 'path'
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import type { FileTranscriptionResult } from '@d3ro/core/types'
import { ErrorCode } from '@d3ro/core/errors'
import { getMeetingModeService } from '../../src/main/services/MeetingModeService'
import { getFileTranscriptionService } from '../../src/main/services/FileTranscriptionService'
import { getHistoryService } from '../../src/main/services/HistoryService'
import { localAudioPath } from '../../src/main/services/sync/audio-sync'
import { emitAccountScopeChanged, LOCAL_SCOPE_ID } from '../../src/main/services/account-scope'
import { useRedHarness } from './harness'
useRedHarness()
function transcription(filePath: string, fullText = '가져온 회의 전사'): FileTranscriptionResult {
return {
jobId: 'job-1',
filePath,
fileName: path.basename(filePath),
fullText,
segments: [{ text: fullText, start: 0, end: 3, confidence: 1 }],
totalDurationSec: 3,
processingTimeMs: 25,
}
}
describe('기존 녹음 파일을 회의로 가져오기', () => {
let sourcePath: string
beforeEach(() => {
sourcePath = path.join(os.tmpdir(), `d3ro-meeting-import-${Date.now()}.mp3`)
fs.writeFileSync(sourcePath, 'normalized-audio')
})
afterEach(() => {
emitAccountScopeChanged(LOCAL_SCOPE_ID)
fs.rmSync(sourcePath, { force: true })
})
it('일반 기록 중복 없이 회의·타임스탬프 전사·재생용 WAV를 저장한다', async () => {
const historyCreate = vi.spyOn(getHistoryService(), 'create')
const transcribe = vi.spyOn(getFileTranscriptionService(), 'startTranscription')
.mockImplementation(async (filePath, _language, options) => {
await options?.onConverted?.(filePath)
return transcription(filePath)
})
const detail = await getMeetingModeService().importRecording(sourcePath, 'ko')
expect(detail.title).toBe(path.basename(sourcePath, '.mp3'))
expect(detail.status).toBe('completed')
expect(detail.rawTranscript).toBe('[00:00] 가져온 회의 전사')
expect(detail.durationMs).toBe(3_000)
expect(transcribe).toHaveBeenCalledWith(sourcePath, 'ko', {
saveToHistory: false,
onConverted: expect.any(Function),
})
expect(historyCreate).not.toHaveBeenCalled()
const storedAudio = localAudioPath('meeting', detail.id)
expect(storedAudio).not.toBeNull()
expect(fs.readFileSync(storedAudio!, 'utf8')).toBe('normalized-audio')
expect(getMeetingModeService().getSessions(1, 20).total).toBe(1)
})
it('빈 전사는 완료된 회의나 오디오로 남기지 않는다', async () => {
vi.spyOn(getFileTranscriptionService(), 'startTranscription')
.mockImplementation(async (filePath, _language, options) => {
await options?.onConverted?.(filePath)
return transcription(filePath, '')
})
await expect(getMeetingModeService().importRecording(sourcePath)).rejects.toThrow('발화가 없습니다')
expect(getMeetingModeService().getSessions(1, 20).total).toBe(0)
})
it.each(['before-copy', 'after-copy', 'round-trip'] as const)(
'가져오기 중 계정이 바뀌면 저장하지 않고 임시 오디오를 정리한다 (%s)',
async (timing) => {
const copy = vi.spyOn(fs.promises, 'copyFile')
vi.spyOn(getFileTranscriptionService(), 'startTranscription')
.mockImplementation(async (filePath, _language, options) => {
if (timing === 'before-copy') emitAccountScopeChanged('other-account')
await options?.onConverted?.(filePath)
if (timing !== 'before-copy') emitAccountScopeChanged('other-account')
if (timing === 'round-trip') emitAccountScopeChanged(LOCAL_SCOPE_ID)
return transcription(filePath)
})
await expect(getMeetingModeService().importRecording(sourcePath)).rejects.toMatchObject({
code: ErrorCode.FileTranscriptionCancelled,
})
expect(getMeetingModeService().getSessions(1, 20).total).toBe(0)
for (const [, destination] of copy.mock.calls) {
expect(fs.existsSync(destination)).toBe(false)
}
if (timing === 'before-copy') expect(copy).not.toHaveBeenCalled()
},
)
})

View file

@ -0,0 +1,31 @@
import { describe, expect, it } from 'vitest'
import { buildImportedMeetingTranscript } from '../../src/main/services/meeting/imported-recording'
describe('가져온 녹음의 회의 전사 변환', () => {
it('파일 이름을 회의 제목으로 쓰고 STT 구간을 상대 시각 전사로 바꾼다', () => {
expect(buildImportedMeetingTranscript({
fileName: '주간 제품 회의.mp4',
fullText: '첫 발언 두 번째 발언',
totalDurationSec: 65.4,
segments: [
{ text: ' 첫 발언 ', start: 1.25, end: 4, confidence: 0.9 },
{ text: '두 번째 발언', start: 61, end: 65, confidence: 0.8 },
],
})).toEqual({
title: '주간 제품 회의',
rawTranscript: '[00:01] 첫 발언\n[01:01] 두 번째 발언',
durationMs: 65_400,
})
})
it('구간 정보가 없으면 원문을 보존한다', () => {
const result = buildImportedMeetingTranscript({
fileName: 'memo.wav',
fullText: ' 전사 원문 ',
totalDurationSec: 3,
segments: [],
})
expect(result.rawTranscript).toBe('전사 원문')
expect(result.durationMs).toBe(3_000)
})
})