fix(mobile): harden recorder, queue, context, and screen async lifecycles
This commit is contained in:
parent
3f9e412257
commit
bd3c1a98d9
25 changed files with 2279 additions and 68 deletions
87
apps/mobile-rn/__tests__/abort-and-stream-guards.test.ts
Normal file
87
apps/mobile-rn/__tests__/abort-and-stream-guards.test.ts
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import {
|
||||
AdminServiceError,
|
||||
listAdminUsers,
|
||||
} from '../src/features/admin/admin-service'
|
||||
import {
|
||||
ChatServiceError,
|
||||
sendChatMessage,
|
||||
} from '../src/features/chat/chat-service'
|
||||
import { streamTalkResponse } from '../src/features/talk/llm-stream-service'
|
||||
|
||||
const originalFetch = global.fetch
|
||||
|
||||
afterEach(() => {
|
||||
global.fetch = originalFetch
|
||||
jest.restoreAllMocks()
|
||||
jest.useRealTimers()
|
||||
})
|
||||
|
||||
describe('abort and streaming lifecycle guards', () => {
|
||||
test('sendChatMessage_이미중단된시그널전달시_fetch없이즉시CANCELLED거부', async () => {
|
||||
const fetchMock = jest.fn()
|
||||
global.fetch = fetchMock
|
||||
const controller = new AbortController()
|
||||
controller.abort()
|
||||
|
||||
await expect(
|
||||
sendChatMessage([{ role: 'user', content: 'hello' }], {
|
||||
accessToken: 'signed-access-token',
|
||||
timeoutMs: 60_000,
|
||||
signal: controller.signal,
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
name: 'ChatServiceError',
|
||||
code: 'CANCELLED',
|
||||
retryable: false,
|
||||
})
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
expect(ChatServiceError.name).toBe('ChatServiceError')
|
||||
})
|
||||
|
||||
test('adminService_이미중단된시그널전달시_비재시도네트워크오류로즉시거부', async () => {
|
||||
const fetchMock = jest.fn()
|
||||
global.fetch = fetchMock
|
||||
const controller = new AbortController()
|
||||
controller.abort()
|
||||
|
||||
await expect(
|
||||
listAdminUsers({
|
||||
accessToken: 'authenticated-admin-access-token',
|
||||
signal: controller.signal,
|
||||
}),
|
||||
).rejects.toMatchObject({
|
||||
code: 'network',
|
||||
retryable: false,
|
||||
})
|
||||
expect(fetchMock).not.toHaveBeenCalled()
|
||||
expect(AdminServiceError.name).toBe('AdminServiceError')
|
||||
})
|
||||
|
||||
test('streamTalkResponse_생성영수증ID누락시_응답스트림을취소하고실패종료', async () => {
|
||||
const cancelMock = jest.fn(async () => undefined)
|
||||
global.fetch = jest.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
status: 200,
|
||||
headers: {
|
||||
get: (name: string) => (
|
||||
name.toLowerCase() === 'content-type' ? 'text/event-stream' : null
|
||||
),
|
||||
},
|
||||
body: {
|
||||
cancel: cancelMock,
|
||||
getReader: () => ({
|
||||
read: async () => ({ done: true, value: undefined }),
|
||||
releaseLock: jest.fn(),
|
||||
}),
|
||||
},
|
||||
} as unknown as Response)
|
||||
|
||||
await expect(
|
||||
streamTalkResponse([{ role: 'user', content: 'hello' }], {
|
||||
accessToken: 'signed-talk-token',
|
||||
onTextDelta: jest.fn(),
|
||||
}),
|
||||
).rejects.toMatchObject({ code: 'INVALID_RESPONSE', retryable: true })
|
||||
expect(cancelMock).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue