fix(mobile): delete cleanup audio files on retry and isolate screen busy state across user switches

This commit is contained in:
Yun Chan 2026-11-14 15:17:52 +09:00
parent bd3c1a98d9
commit cc3f7460be
5 changed files with 376 additions and 45 deletions

View file

@ -61,7 +61,10 @@ import {
} from '../src/features/recording/durable-processing-queue'
import { useHistorySync } from '../src/features/history/use-history-sync'
const mockFileSystem = FileSystem as typeof FileSystem & { filesystem: Map<string, string> }
const mockFileSystem = FileSystem as typeof FileSystem & {
filesystem: Map<string, string>
unlink: jest.Mock
}
function makeQueueItem(
userId: string,
@ -148,6 +151,7 @@ describe('durable queue and history sync race guards', () => {
jest.useFakeTimers({ now: START_MS })
await AsyncStorage.clear()
mockFileSystem.filesystem.clear()
mockFileSystem.unlink.mockClear()
mockProcessAudioInput.mockReset()
mockListHistoryPage.mockReset()
mockLoadHistoryCache.mockReset()
@ -227,9 +231,10 @@ describe('durable queue and history sync race guards', () => {
await AsyncStorage.getItem(durableQueueTestContract.storageKey),
)
const cleanupState = afterCleanupRetry.find((candidate) => candidate.id === cleaningItem.id)
// cleanup item must not be downgraded to retry and re-transcribed.
// cleanup item must not be downgraded to retry and re-transcribed, and its local file must be removed.
expect(mockProcessAudioInput).not.toHaveBeenCalled()
expect(cleanupState).toBeUndefined()
expect(mockFileSystem.filesystem.has(cleaningItem.path)).toBe(false)
await retryQueuedAudio(USER_A, runningItem.id)
const afterRunningRetry = durableQueueTestContract.parseQueue(
@ -238,6 +243,35 @@ describe('durable queue and history sync race guards', () => {
expect(afterRunningRetry.find((candidate) => candidate.id === runningItem.id)?.status).toBe('running')
})
test('durableQueue_정리단계재시도중파일삭제실패시_큐항목을유지하고정리재시도를예약함', async () => {
const cleaningItem = makeQueueItem(USER_A, 'aaaa0004', {
status: 'cleanup',
phase: 'saving',
})
mockFileSystem.filesystem.set(cleaningItem.path, 'audio-bytes')
await AsyncStorage.setItem(durableQueueTestContract.storageKey, JSON.stringify([cleaningItem]))
mockFileSystem.unlink.mockRejectedValueOnce(new Error('filesystem busy'))
await retryQueuedAudio(USER_A, cleaningItem.id)
const retained = durableQueueTestContract.parseQueue(
await AsyncStorage.getItem(durableQueueTestContract.storageKey),
)
expect(retained.find((candidate) => candidate.id === cleaningItem.id)?.status).toBe('cleanup')
expect(mockFileSystem.filesystem.has(cleaningItem.path)).toBe(true)
expect(jest.getTimerCount()).toBe(1)
await jest.advanceTimersByTimeAsync(60_000)
await flushMicrotasks()
const afterScheduledCleanup = durableQueueTestContract.parseQueue(
await AsyncStorage.getItem(durableQueueTestContract.storageKey),
)
expect(afterScheduledCleanup.find((candidate) => candidate.id === cleaningItem.id)).toBeUndefined()
expect(mockFileSystem.filesystem.has(cleaningItem.path)).toBe(false)
expect(mockProcessAudioInput).not.toHaveBeenCalled()
})
test('useHistorySync_오프라인캐시조회중새요청이나언마운트시_오래된캐시로덮어쓰지않음', async () => {
jest.useRealTimers()
let latestState: ReturnType<typeof useHistorySync> | null = null