fix(desktop): wrap pull and STT download aborts into D3ROError on dispose
Catch pre-header fetch and stream rejections in LocalLLMService._doPullModel and map disposed or aborted pulls to ErrorCode.LLMProcessingCancelled (and unexpected failures to ErrorCode.LLMServerUnreachable). Convert disposed fetch aborts and JSON body aborts in LocalSTTService._fetchDownload and downloadModel into ErrorCode.STTModelDownloadCancelled while wrapping network or timeout errors as ErrorCode.STTModelDownloadFailed.
This commit is contained in:
parent
fc5d45312c
commit
3f9e412257
4 changed files with 103 additions and 3 deletions
|
|
@ -424,4 +424,44 @@ describe('LocalSTTService — 사이드카 크래시 재시작', () => {
|
|||
await disposePromise
|
||||
expect(statusPollsAfterDispose).toBe(0)
|
||||
})
|
||||
|
||||
it('downloadModel_disposedWhileStartRequestPending_rejectsWithSTTModelDownloadCancelled', async () => {
|
||||
const h = createHarness()
|
||||
h.setHealthy(true)
|
||||
let startSignal: AbortSignal | undefined
|
||||
|
||||
const wrappedFetch = vi.fn((input: RequestInfo | URL, init?: RequestInit) => {
|
||||
const url = String(input)
|
||||
if (url.endsWith('/download')) {
|
||||
startSignal = init?.signal ?? undefined
|
||||
return new Promise<Response>((_resolve, reject) => {
|
||||
const timer = setTimeout(() => reject(new Error('download start fetch was not aborted')), 300)
|
||||
init?.signal?.addEventListener(
|
||||
'abort',
|
||||
() => {
|
||||
clearTimeout(timer)
|
||||
reject(new DOMException('The operation was aborted.', 'AbortError'))
|
||||
},
|
||||
{ once: true },
|
||||
)
|
||||
})
|
||||
}
|
||||
return h.fetch(url, init)
|
||||
})
|
||||
vi.stubGlobal('fetch', wrappedFetch)
|
||||
|
||||
const local = new LocalSTTService({ supervisor: h.supervisor })
|
||||
const downloadPromise = local.downloadModel('tiny')
|
||||
await vi.waitFor(() =>
|
||||
expect(wrappedFetch.mock.calls.some(([url]) => String(url).endsWith('/download'))).toBe(true),
|
||||
)
|
||||
|
||||
const disposePromise = local.dispose()
|
||||
|
||||
await expect(downloadPromise).rejects.toSatisfy(
|
||||
(err: unknown) => err instanceof D3ROError && err.code === ErrorCode.STTModelDownloadCancelled,
|
||||
)
|
||||
await disposePromise
|
||||
expect(startSignal?.aborted).toBe(true)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue