Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

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

OrcaWina4447426a3be
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<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
}
}