fix(mobile): delete cleanup audio files on retry and isolate screen busy state across user switches
This commit is contained in:
parent
bd3c1a98d9
commit
cc3f7460be
5 changed files with 376 additions and 45 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import React from 'react'
|
||||
import { TextInput } from 'react-native'
|
||||
import { Modal, TextInput } from 'react-native'
|
||||
import { act, create, type ReactTestRenderer } from 'react-test-renderer'
|
||||
import type { Meeting } from '@d3ro/api-client'
|
||||
import { AudioPipelineError, type LocalAudioInput } from '../src/features/import/audio-import-types'
|
||||
|
|
@ -57,6 +57,7 @@ const mockStartPlayer = jest.fn(async () => 'started')
|
|||
const mockStopPlayer = jest.fn(async () => 'stopped')
|
||||
const mockLoadSyncedCommandCatalog = jest.fn()
|
||||
const mockCreateSyncedCommand = jest.fn()
|
||||
const mockExecuteSyncedCommand = jest.fn()
|
||||
const mockListTeams = jest.fn()
|
||||
const mockCreateTeam = jest.fn()
|
||||
|
||||
|
|
@ -237,7 +238,7 @@ jest.mock('../src/features/commands/command-service', () => {
|
|||
CommandSyncError: MockCommandSyncError,
|
||||
createSyncedCommand: (...args: unknown[]) => mockCreateSyncedCommand(...args),
|
||||
deleteSyncedCommand: jest.fn(),
|
||||
executeSyncedCommand: jest.fn(),
|
||||
executeSyncedCommand: (...args: unknown[]) => mockExecuteSyncedCommand(...args),
|
||||
loadSyncedCommandCatalog: (...args: unknown[]) => mockLoadSyncedCommandCatalog(...args),
|
||||
reorderSyncedCommand: jest.fn(),
|
||||
setActiveSyncedCommand: jest.fn(),
|
||||
|
|
@ -337,6 +338,7 @@ describe('screen async lifecycle and race guards', () => {
|
|||
mockStopPlayer.mockClear()
|
||||
mockLoadSyncedCommandCatalog.mockReset()
|
||||
mockCreateSyncedCommand.mockReset()
|
||||
mockExecuteSyncedCommand.mockReset()
|
||||
mockListTeams.mockReset()
|
||||
mockCreateTeam.mockReset()
|
||||
})
|
||||
|
|
@ -829,4 +831,233 @@ describe('screen async lifecycle and race guards', () => {
|
|||
|
||||
expect(mockNavigate).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
test('TeamsScreen_팀생성중계정전환후신규계정생성시_이전계정완료가현재생성중상태를해제하지않음', async () => {
|
||||
mockListTeams.mockResolvedValue([])
|
||||
const createGateA = deferred<{
|
||||
id: string
|
||||
name: string
|
||||
ownerId: string
|
||||
role: 'owner'
|
||||
memberCount: number
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}>()
|
||||
const createGateB = deferred<{
|
||||
id: string
|
||||
name: string
|
||||
ownerId: string
|
||||
role: 'owner'
|
||||
memberCount: number
|
||||
createdAt: string
|
||||
updatedAt: string
|
||||
}>()
|
||||
mockCreateTeam
|
||||
.mockReturnValueOnce(createGateA.promise)
|
||||
.mockReturnValueOnce(createGateB.promise)
|
||||
|
||||
let renderer!: ReactTestRenderer
|
||||
await act(async () => {
|
||||
renderer = create(<TeamsScreen navigation={mockNavigation as never} />)
|
||||
activeRenderer = renderer
|
||||
await flush()
|
||||
})
|
||||
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'teams-create' }).props.onPress()
|
||||
})
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'team-name-input' }).props.onChangeText('Team A')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'team-create-submit' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.disabled).toBe(true)
|
||||
|
||||
// Switch account from USER_A to USER_B while USER_A's createTeam is pending.
|
||||
mockCurrentUser = { id: USER_B, email: 'b@example.com' }
|
||||
await act(async () => {
|
||||
renderer.update(<TeamsScreen navigation={mockNavigation as never} />)
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(renderer.root.findAllByType(Modal)[0]?.props.visible).toBe(false)
|
||||
|
||||
// User B opens modal and starts creating their own team.
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'teams-create' }).props.onPress()
|
||||
})
|
||||
expect(renderer.root.findByProps({ testID: 'team-name-input' }).props.value).toBe('')
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.label).toBe('mobile.teams.create')
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'team-name-input' }).props.onChangeText('Team B')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'team-create-submit' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.disabled).toBe(true)
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.label).toBe('mobile.teams.creating')
|
||||
|
||||
// Stale USER_A creation finishes now; must NOT clear USER_B's editorBusy or navigate.
|
||||
await act(async () => {
|
||||
createGateA.resolve({
|
||||
id: TEAM_ID,
|
||||
name: 'Team A',
|
||||
ownerId: USER_A,
|
||||
role: 'owner',
|
||||
memberCount: 1,
|
||||
createdAt: '2026-08-21T00:00:00.000Z',
|
||||
updatedAt: '2026-08-21T00:00:00.000Z',
|
||||
})
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(mockNavigate).not.toHaveBeenCalled()
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.disabled).toBe(true)
|
||||
expect(renderer.root.findByProps({ testID: 'team-create-submit' }).props.label).toBe('mobile.teams.creating')
|
||||
|
||||
await act(async () => {
|
||||
createGateB.resolve({
|
||||
id: '99999999-9999-4999-8999-999999999998',
|
||||
name: 'Team B',
|
||||
ownerId: USER_B,
|
||||
role: 'owner',
|
||||
memberCount: 1,
|
||||
createdAt: '2026-08-21T00:00:00.000Z',
|
||||
updatedAt: '2026-08-21T00:00:00.000Z',
|
||||
})
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(mockNavigate).toHaveBeenCalledWith('TeamDetail', { teamId: '99999999-9999-4999-8999-999999999998' })
|
||||
activeRenderer = null
|
||||
act(() => renderer.unmount())
|
||||
})
|
||||
|
||||
test('CommandsScreen_명령변경및실행중계정전환시_이전계정완료가현재계정상태를해제하지않음', async () => {
|
||||
const commandA: SyncedCommand = {
|
||||
id: COMMAND_ID,
|
||||
userId: USER_A,
|
||||
builtinKey: null,
|
||||
name: 'Cmd A',
|
||||
description: '',
|
||||
prompt: 'A: {{text}}',
|
||||
icon: 'bolt',
|
||||
sortOrder: 0,
|
||||
revision: 1,
|
||||
createdAt: '2026-08-21T00:00:00.000Z',
|
||||
updatedAt: '2026-08-21T00:00:00.000Z',
|
||||
}
|
||||
const commandB: SyncedCommand = {
|
||||
...commandA,
|
||||
id: '77777777-7777-4777-8777-777777777778',
|
||||
userId: USER_B,
|
||||
name: 'Cmd B',
|
||||
}
|
||||
mockLoadSyncedCommandCatalog
|
||||
.mockResolvedValueOnce({ commands: [commandA], activeInstructionId: null })
|
||||
.mockResolvedValueOnce({ commands: [commandB], activeInstructionId: null })
|
||||
|
||||
const saveGateA = deferred<SyncedCommand>()
|
||||
const saveGateB = deferred<SyncedCommand>()
|
||||
mockCreateSyncedCommand
|
||||
.mockReturnValueOnce(saveGateA.promise)
|
||||
.mockReturnValueOnce(saveGateB.promise)
|
||||
|
||||
const runGateA = deferred<{ text: string; generationId: string }>()
|
||||
const runGateB = deferred<{ text: string; generationId: string }>()
|
||||
mockExecuteSyncedCommand
|
||||
.mockReturnValueOnce(runGateA.promise)
|
||||
.mockReturnValueOnce(runGateB.promise)
|
||||
|
||||
let renderer!: ReactTestRenderer
|
||||
await act(async () => {
|
||||
renderer = create(<CommandsScreen />)
|
||||
activeRenderer = renderer
|
||||
await flush()
|
||||
})
|
||||
|
||||
// Start both a command execution and a create mutation as USER_A.
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'commands-input' }).props.onChangeText('input A')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'commands-run' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'commands-add' }).props.onPress()
|
||||
})
|
||||
const editorA = renderer.root.findByProps({ testID: 'commands-editor' })
|
||||
const inputsA = editorA.findAllByType(TextInput)
|
||||
act(() => {
|
||||
inputsA[0]?.props.onChangeText('New Cmd A')
|
||||
inputsA[2]?.props.onChangeText('Prompt A: {{text}}')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'commands-editor-save' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(renderer.root.findByProps({ testID: 'commands-run' }).props.label).toBe('mobile.commands.running')
|
||||
expect(renderer.root.findByProps({ testID: 'commands-editor-save' }).props.label).toBe('mobile.commands.saving')
|
||||
|
||||
// Switch account to USER_B while both USER_A requests are still pending.
|
||||
mockCurrentUser = { id: USER_B, email: 'b@example.com' }
|
||||
await act(async () => {
|
||||
renderer.update(<CommandsScreen />)
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(renderer.root.findAllByProps({ testID: 'commands-editor' })).toHaveLength(0)
|
||||
expect(renderer.root.findByProps({ testID: 'commands-add' }).props.disabled).toBe(false)
|
||||
expect(renderer.root.findByProps({ testID: 'commands-run' }).props.label).toBe('mobile.commands.run')
|
||||
|
||||
// Start new execution and save as USER_B.
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'commands-input' }).props.onChangeText('input B')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'commands-run' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
act(() => {
|
||||
renderer.root.findByProps({ testID: 'commands-add' }).props.onPress()
|
||||
})
|
||||
const editorB = renderer.root.findByProps({ testID: 'commands-editor' })
|
||||
const inputsB = editorB.findAllByType(TextInput)
|
||||
act(() => {
|
||||
inputsB[0]?.props.onChangeText('New Cmd B')
|
||||
inputsB[2]?.props.onChangeText('Prompt B: {{text}}')
|
||||
})
|
||||
await act(async () => {
|
||||
renderer.root.findByProps({ testID: 'commands-editor-save' }).props.onPress()
|
||||
await Promise.resolve()
|
||||
})
|
||||
expect(renderer.root.findByProps({ testID: 'commands-run' }).props.label).toBe('mobile.commands.running')
|
||||
expect(renderer.root.findByProps({ testID: 'commands-editor-save' }).props.label).toBe('mobile.commands.saving')
|
||||
|
||||
// Stale USER_A save and run reject; USER_B's busy states must remain active.
|
||||
await act(async () => {
|
||||
saveGateA.reject(new CommandSyncError('server', 'late A failure'))
|
||||
runGateA.reject(new Error('late A run failure'))
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(renderer.root.findByProps({ testID: 'commands-run' }).props.label).toBe('mobile.commands.running')
|
||||
expect(renderer.root.findByProps({ testID: 'commands-editor-save' }).props.label).toBe('mobile.commands.saving')
|
||||
expect(renderer.root.findByProps({ testID: 'commands-add' }).props.disabled).toBe(true)
|
||||
|
||||
await act(async () => {
|
||||
saveGateB.resolve({ ...commandB, id: '77777777-7777-4777-8777-777777777779', name: 'New Cmd B' })
|
||||
runGateB.resolve({ text: 'ok B', generationId: 'gen-b' })
|
||||
await flush()
|
||||
})
|
||||
|
||||
expect(renderer.root.findByProps({ testID: 'commands-run' }).props.label).toBe('mobile.commands.run')
|
||||
expect(renderer.root.findAllByProps({ testID: 'commands-editor' })).toHaveLength(0)
|
||||
activeRenderer = null
|
||||
act(() => renderer.unmount())
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue