diff --git a/src/main/emulator/emulator-bridge.test.ts b/src/main/emulator/emulator-bridge.test.ts index 1bbbd32bbc7..4dc2025f306 100644 --- a/src/main/emulator/emulator-bridge.test.ts +++ b/src/main/emulator/emulator-bridge.test.ts @@ -92,6 +92,33 @@ describe('EmulatorBridge helper ownership', () => { netFetchMock.mockReset() }) + it('routes a registered explicit device without inventory and rediscovers after kill', async () => { + const bridge = new EmulatorBridge() + bridge.registerActiveEmulator('wt-1', session('device-1'), { managed: true }) + + await bridge.tap(0.25, 0.75, { device: 'device-1' }) + expect(execServeSimCommandMock).toHaveBeenCalledWith( + { command: '/serve-sim', env: {} }, + ['tap', '0.25', '0.75', '-d', 'device-1'], + undefined + ) + expect(listSimulatorDevicesMock).not.toHaveBeenCalled() + + await bridge.kill('device-1') + expect(bridge.getActiveForWorktree('wt-1')).toBeNull() + expect(listSimulatorDevicesMock).not.toHaveBeenCalled() + listSimulatorDevicesMock.mockResolvedValue([ + { udid: 'device-1', name: 'iPhone', state: 'Booted', runtime: 'iOS' } + ]) + await bridge.tap(0.5, 0.5, { device: 'device-1' }) + expect(listSimulatorDevicesMock).toHaveBeenCalledOnce() + expect(execServeSimCommandMock).toHaveBeenLastCalledWith( + { command: '/serve-sim', env: {} }, + ['tap', '0.5', '0.5', '-d', 'device-1'], + undefined + ) + }) + it('stops the previous Orca-managed helper when a worktree switches devices', async () => { const bridge = new EmulatorBridge() bridge.registerActiveEmulator('wt-1', session('device-old'), { managed: true }) diff --git a/src/main/emulator/emulator-bridge.ts b/src/main/emulator/emulator-bridge.ts index f578dec8ee3..00c4b4f10f5 100644 --- a/src/main/emulator/emulator-bridge.ts +++ b/src/main/emulator/emulator-bridge.ts @@ -325,8 +325,9 @@ export class EmulatorBridge { } private async backendForDevice(device: string): Promise { + const registered = this.sessionRegistry.getSession(device) for (const backend of this.backends) { - if (await backend.ownsDevice(device)) { + if (registered ? backend.kind === registered.backend : await backend.ownsDevice(device)) { return backend } }