fix(desktop): harden cancellation, dispose, and lifecycle races across main services

Cancel pending result-popup measure timers on hideResultPopup; track CaptionService aux-model load state, stop deduplication, and refine abort epochs across restarts; forward per-call AbortSignal through VoiceModeService and LlmGateway to LocalLLMService and abort pull streams plus availability polling on dispose; clear aborted response pointers and gate stale mic start errors in VoiceConversationService; guard AudioCaptureService stopping resume against exited SoX processes and cleanup failed starts; abort LocalSTTService downloadModel polling on dispose; and fail closed when desktopCapturer.getSources rejects in caption loopback setup.
This commit is contained in:
Yun Chan 2026-11-14 15:06:25 +09:00
parent 4bf0f0df12
commit fc5d45312c
19 changed files with 922 additions and 94 deletions

View file

@ -7,6 +7,7 @@
import { describe, it, expect, beforeEach, afterEach, vi } from 'vitest'
import { EventEmitter } from 'events'
import { spawn } from 'child_process'
import { ipcMain } from 'electron'
import { IPC_CHANNELS } from '@d3ro/core/ipc-channels'
@ -228,3 +229,37 @@ describe('마이크 테스트 IPC', () => {
expect(proc(0).kill).toHaveBeenCalledTimes(1)
})
})
describe('정지/시작 레이스 및 실패 정리', () => {
it('start_calledWhileStoppingAfterSoxClosed_spawnsFreshSoxProcess', async () => {
const audio = mod.getAudioCaptureService()
await audio.start()
const stopping = audio.stop()
proc(0).emit('close', 1)
await audio.start()
await stopping
expect(spawned.list).toHaveLength(2)
expect(audio.state).toBe('capturing')
await audio.stop()
expect(proc(1).kill).toHaveBeenCalledTimes(1)
})
it('start_spawnedProcessMissingStdout_cleansUpChildProcess', async () => {
const brokenChild = Object.assign(new EventEmitter(), {
stdout: null,
stderr: new EventEmitter(),
kill: vi.fn(),
})
vi.mocked(spawn).mockReturnValueOnce(brokenChild as never)
const audio = mod.getAudioCaptureService()
await expect(audio.start()).rejects.toMatchObject({ message: expect.stringMatching(/stdout/i) })
expect(audio.state).toBe('error')
expect(brokenChild.kill).toHaveBeenCalledTimes(1)
})
})