feat: ship Wave 5-6 multi-surface hygiene, optimization, and bug fixes
This commit is contained in:
parent
01ef3293cf
commit
66b6b45ba9
399 changed files with 17828 additions and 11330 deletions
137
apps/mobile-rn/__tests__/durable-queue-early-discard.test.ts
Normal file
137
apps/mobile-rn/__tests__/durable-queue-early-discard.test.ts
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
import AsyncStorage from '@react-native-async-storage/async-storage'
|
||||
import { FileSystem } from 'react-native-file-access'
|
||||
import type {
|
||||
AudioPipelineResult,
|
||||
LocalAudioInput,
|
||||
} from '../src/features/import/audio-import-types'
|
||||
|
||||
const mockProcessAudioInput = jest.fn<Promise<AudioPipelineResult>, [LocalAudioInput, unknown]>()
|
||||
const mockFailMeetingRecording = jest.fn(async () => undefined)
|
||||
const mockMarkMeetingProcessingFailure = jest.fn(async () => undefined)
|
||||
const mockQueueMeetingRecording = jest.fn(async () => undefined)
|
||||
|
||||
jest.mock('../src/features/import/audio-transcription-service', () => ({
|
||||
processAudioInput: (input: LocalAudioInput, options: unknown) =>
|
||||
mockProcessAudioInput(input, options),
|
||||
}))
|
||||
jest.mock('../src/features/meetings/meetings-service', () => ({
|
||||
failMeetingRecording: () => mockFailMeetingRecording(),
|
||||
markMeetingProcessingFailure: () => mockMarkMeetingProcessingFailure(),
|
||||
queueMeetingRecording: () => mockQueueMeetingRecording(),
|
||||
}))
|
||||
|
||||
import {
|
||||
clearQueuedAudioForUser,
|
||||
discardQueuedAudio,
|
||||
durableQueueTestContract,
|
||||
processQueuedAudioNow,
|
||||
type DurableQueueItem,
|
||||
} from '../src/features/recording/durable-processing-queue'
|
||||
|
||||
const FIXED_NOW_MS = 1_700_000_000_000
|
||||
const USER_A = '11111111-1111-4111-8111-111111111111'
|
||||
const MEETING_ID = '22222222-2222-4222-8222-222222222222'
|
||||
|
||||
const mockFileSystem = FileSystem as typeof FileSystem & { filesystem: Map<string, string> }
|
||||
|
||||
function makeItem(suffix: string): DurableQueueItem {
|
||||
const path = `${durableQueueTestContract.queueDirectory}/queued-${suffix}.wav`
|
||||
return {
|
||||
schemaVersion: 1,
|
||||
id: suffix,
|
||||
userId: USER_A,
|
||||
meetingId: MEETING_ID,
|
||||
path,
|
||||
uri: `file://${path}`,
|
||||
fileName: `${suffix}.wav`,
|
||||
mimeType: 'audio/wav',
|
||||
sizeBytes: 5,
|
||||
durationMs: 1_000,
|
||||
source: 'recording',
|
||||
languageCode: 'ko',
|
||||
status: 'pending',
|
||||
phase: null,
|
||||
attempts: 0,
|
||||
uploadedBytes: 0,
|
||||
nextAttemptAtMs: FIXED_NOW_MS,
|
||||
lastErrorCode: null,
|
||||
lastErrorMessage: null,
|
||||
createdAtMs: FIXED_NOW_MS,
|
||||
updatedAtMs: FIXED_NOW_MS,
|
||||
}
|
||||
}
|
||||
|
||||
describe('durable processing queue early discard race', () => {
|
||||
beforeEach(async () => {
|
||||
jest.useFakeTimers({ now: FIXED_NOW_MS })
|
||||
await AsyncStorage.clear()
|
||||
mockFileSystem.filesystem.clear()
|
||||
mockProcessAudioInput.mockReset()
|
||||
mockFailMeetingRecording.mockClear()
|
||||
mockMarkMeetingProcessingFailure.mockClear()
|
||||
mockQueueMeetingRecording.mockClear()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
jest.restoreAllMocks()
|
||||
await clearQueuedAudioForUser(USER_A).catch(() => undefined)
|
||||
jest.useRealTimers()
|
||||
})
|
||||
|
||||
test('discardQueuedAudio_파일존재확인중폐기호출시_전사나실패기록없이안전하게중단', async () => {
|
||||
const first = makeItem('aaa111')
|
||||
mockFileSystem.filesystem.set(first.path, 'audio-bytes')
|
||||
await AsyncStorage.setItem(durableQueueTestContract.storageKey, JSON.stringify([first]))
|
||||
|
||||
let resolveExists: (present: boolean) => void = () => undefined
|
||||
const existsGate = new Promise<boolean>((resolve) => {
|
||||
resolveExists = resolve
|
||||
})
|
||||
let gateUsed = false
|
||||
jest.spyOn(FileSystem, 'exists').mockImplementation(async (path) => {
|
||||
if (path === first.path && !gateUsed) {
|
||||
gateUsed = true
|
||||
return existsGate
|
||||
}
|
||||
return mockFileSystem.filesystem.has(path)
|
||||
})
|
||||
|
||||
const runPromise = processQueuedAudioNow(USER_A, first.id).catch((error: unknown) => error)
|
||||
for (let index = 0; index < 5; index += 1) {
|
||||
await jest.advanceTimersByTimeAsync(0)
|
||||
}
|
||||
|
||||
await discardQueuedAudio(USER_A, first.id)
|
||||
resolveExists(true)
|
||||
|
||||
const outcome = await runPromise
|
||||
expect(outcome).toMatchObject({ code: 'cancelled' })
|
||||
expect(mockProcessAudioInput).not.toHaveBeenCalled()
|
||||
expect(mockFailMeetingRecording).not.toHaveBeenCalled()
|
||||
expect(mockMarkMeetingProcessingFailure).not.toHaveBeenCalled()
|
||||
|
||||
const persisted = durableQueueTestContract.parseQueue(
|
||||
await AsyncStorage.getItem(durableQueueTestContract.storageKey),
|
||||
)
|
||||
expect(persisted).toEqual([])
|
||||
|
||||
const replacement = makeItem('aaa111')
|
||||
mockFileSystem.filesystem.set(replacement.path, 'audio-bytes-2')
|
||||
await AsyncStorage.setItem(durableQueueTestContract.storageKey, JSON.stringify([replacement]))
|
||||
mockProcessAudioInput.mockResolvedValueOnce({
|
||||
historyId: null,
|
||||
audioFileId: 'audio-2',
|
||||
meetingId: MEETING_ID,
|
||||
processingJobId: null,
|
||||
transcript: 'ok',
|
||||
provider: 'test',
|
||||
language: 'ko',
|
||||
durationSeconds: 1,
|
||||
deduplicated: false,
|
||||
})
|
||||
|
||||
const replayResult = await processQueuedAudioNow(USER_A, replacement.id)
|
||||
expect(replayResult.transcript).toBe('ok')
|
||||
expect(mockProcessAudioInput).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue