perf(emulator): reuse registered device backend routing (#35616)

Co-authored-by: OrcaWin <293788423+OrcaWin@users.noreply.github.com>
This commit is contained in:
OrcaWin
2026-10-29 15:00:20 -07:00
committed by GitHub
co-authored by OrcaWin
parent 7ad81415e7
commit a4447426a3
2 changed files with 29 additions and 1 deletions
+27
View File
@@ -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 })
+2 -1
View File
@@ -325,8 +325,9 @@ export class EmulatorBridge {
}
private async backendForDevice(device: string): Promise<EmulatorBackend> {
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
}
}