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

@ -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())
})
})