Skip to content

Commit 9251a29

Browse files
committed
refactor: simplify ios physical device transport
1 parent c7348b9 commit 9251a29

13 files changed

Lines changed: 139 additions & 164 deletions

src/core/__tests__/dispatch-resolve.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,13 @@ test('resolveTargetDevice uses injected device inventory without local discovery
285285
assert.equal(mockListAppleDevices.mock.calls.length, 0);
286286
});
287287

288-
test('resolveTargetDevice preserves backend evidence from injected inventory', async () => {
288+
test('resolveTargetDevice preserves physical-device backend evidence from injected inventory', async () => {
289289
const result = await withDeviceInventoryProvider(
290-
async () => [{ ...physical, backend: 'xctest' }],
290+
async () => [{ ...physical, iosPhysicalDeviceBackend: 'xctest' }],
291291
async () => await resolveTargetDevice({ platform: 'ios', udid: physical.id }),
292292
);
293293

294-
assert.equal(result.backend, 'xctest');
294+
assert.equal(result.iosPhysicalDeviceBackend, 'xctest');
295295
assert.equal(mockListAppleDevices.mock.calls.length, 0);
296296
});
297297

src/daemon/handlers/__tests__/session-inventory-appleos.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,12 @@ test('devices omits appleOs for non-Apple devices', async () => {
9393
expect(ios?.appleOs).toBe('ios');
9494
});
9595

96-
test('devices omits internal backend evidence', async () => {
97-
const devices = await listPublicDevices([{ ...IOS_SIMULATOR, backend: 'xctest' }]);
96+
test('devices omits internal physical-device backend evidence', async () => {
97+
const devices = await listPublicDevices([
98+
{ ...IOS_SIMULATOR, iosPhysicalDeviceBackend: 'xctest' },
99+
]);
98100

99-
expect(devices[0]).not.toHaveProperty('backend');
101+
expect(devices[0]).not.toHaveProperty('iosPhysicalDeviceBackend');
100102
});
101103

102104
test('devices drops a stray appleOs on a non-Apple device (gated to Apple platforms)', async () => {

src/daemon/handlers/session-inventory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ export async function handleSessionInventoryCommands(params: {
179179

180180
function publicDeviceInfo({
181181
simulatorSetPath: _simulatorSetPath,
182-
backend: _backend,
182+
iosPhysicalDeviceBackend: _iosPhysicalDeviceBackend,
183183
appleOs,
184184
...device
185185
}: DeviceInfo): Record<string, unknown> {

src/kernel/device.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ export type DeviceInfo = {
3838
appleOs?: AppleOS;
3939
booted?: boolean;
4040
simulatorSetPath?: string;
41-
// Internal execution-backend evidence attached by discovery/provider inventory.
41+
// Internal physical-iOS execution backend selected during discovery.
4242
// Public device projections strip this field.
43-
backend?: string;
43+
iosPhysicalDeviceBackend?: 'coredevice' | 'xctest';
4444
};
4545

4646
export type DeviceSelector = {

src/platforms/apple/core/__tests__/devices.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ test('parseXctracePhysicalAppleDevices parses only physical devices from the Dev
183183
kind: 'device',
184184
target: 'mobile',
185185
appleOs: 'ios',
186-
backend: 'xctest',
186+
iosPhysicalDeviceBackend: 'xctest',
187187
booted: true,
188188
},
189189
{
@@ -193,7 +193,7 @@ test('parseXctracePhysicalAppleDevices parses only physical devices from the Dev
193193
kind: 'device',
194194
target: 'tv',
195195
appleOs: 'tvos',
196-
backend: 'xctest',
196+
iosPhysicalDeviceBackend: 'xctest',
197197
booted: true,
198198
},
199199
]);
@@ -211,7 +211,7 @@ test('parseXctracePhysicalAppleDevices tags physical iPads as iPadOS', () => {
211211
kind: 'device',
212212
target: 'mobile',
213213
appleOs: 'ipados',
214-
backend: 'xctest',
214+
iosPhysicalDeviceBackend: 'xctest',
215215
booted: true,
216216
},
217217
]);
@@ -229,7 +229,7 @@ test('parseXctracePhysicalAppleDevices tags Apple Vision devices as visionOS', (
229229
kind: 'device',
230230
target: 'mobile',
231231
appleOs: 'visionos',
232-
backend: 'xctest',
232+
iosPhysicalDeviceBackend: 'xctest',
233233
booted: true,
234234
},
235235
]);
@@ -253,7 +253,7 @@ test('parseXctracePhysicalAppleDevices parses the parenthesized physical device
253253
kind: 'device',
254254
target: 'mobile',
255255
appleOs: 'ios',
256-
backend: 'xctest',
256+
iosPhysicalDeviceBackend: 'xctest',
257257
booted: true,
258258
},
259259
{
@@ -263,7 +263,7 @@ test('parseXctracePhysicalAppleDevices parses the parenthesized physical device
263263
kind: 'device',
264264
target: 'mobile',
265265
appleOs: 'ipados',
266-
backend: 'xctest',
266+
iosPhysicalDeviceBackend: 'xctest',
267267
booted: true,
268268
},
269269
{
@@ -273,7 +273,7 @@ test('parseXctracePhysicalAppleDevices parses the parenthesized physical device
273273
kind: 'device',
274274
target: 'tv',
275275
appleOs: 'tvos',
276-
backend: 'xctest',
276+
iosPhysicalDeviceBackend: 'xctest',
277277
booted: true,
278278
},
279279
]);
@@ -292,7 +292,7 @@ test('parseXctracePhysicalAppleDevices preserves parentheses in bracket-format n
292292
kind: 'device',
293293
target: 'mobile',
294294
appleOs: 'ios',
295-
backend: 'xctest',
295+
iosPhysicalDeviceBackend: 'xctest',
296296
booted: true,
297297
},
298298
{
@@ -302,7 +302,7 @@ test('parseXctracePhysicalAppleDevices preserves parentheses in bracket-format n
302302
kind: 'device',
303303
target: 'mobile',
304304
appleOs: 'ios',
305-
backend: 'xctest',
305+
iosPhysicalDeviceBackend: 'xctest',
306306
booted: true,
307307
},
308308
]);
@@ -611,7 +611,7 @@ test('listAppleDevices falls back to xctrace parenthesized devices when devicect
611611
assert.equal(physicalDevices.length, 1);
612612
assert.equal(physicalDevices[0]?.id, '00008020-001C2D2234567890');
613613
assert.equal(physicalDevices[0]?.name, 'iPhone 8 Plus');
614-
assert.equal(physicalDevices[0]?.backend, 'xctest');
614+
assert.equal(physicalDevices[0]?.iosPhysicalDeviceBackend, 'xctest');
615615
});
616616

617617
test('listAppleDevices keeps physical discovery disabled for simulator-set scoped runs', async () => {

src/platforms/apple/core/__tests__/physical-device-control.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const IOS_DEVICE: DeviceInfo = {
2121

2222
const XCTEST_IOS_DEVICE: DeviceInfo = {
2323
...IOS_DEVICE,
24-
backend: 'xctest',
24+
iosPhysicalDeviceBackend: 'xctest',
2525
};
2626

2727
test('physical-device backend defaults to CoreDevice and honors discovery evidence', () => {

src/platforms/apple/core/__tests__/runner-transport.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const iosDevice: DeviceInfo = {
5151

5252
const xctestIosDevice: DeviceInfo = {
5353
...iosDevice,
54-
backend: 'xctest',
54+
iosPhysicalDeviceBackend: 'xctest',
5555
};
5656

5757
beforeEach(() => {

src/platforms/apple/core/devices.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function mapDevicectlAppleDevices(payload: DevicectlListDevicesPayload): DeviceI
249249
resolveDevicectlAppleProductType(device),
250250
...resolveDevicectlAppleLabels(device),
251251
]),
252-
backend: 'coredevice',
252+
iosPhysicalDeviceBackend: 'coredevice',
253253
booted: true,
254254
});
255255
}
@@ -285,7 +285,7 @@ function buildXctracePhysicalDevice(
285285
kind: 'device',
286286
target,
287287
appleOs: resolveAppleOs(target, osVersion ? [name, osVersion] : [name]),
288-
backend: 'xctest',
288+
iosPhysicalDeviceBackend: 'xctest',
289289
// xctrace lists currently connected devices in the "Devices" section.
290290
// The "Devices Offline" section is excluded above, so treating these as
291291
// booted preserves the existing physical-device selection semantics.

src/platforms/apple/core/physical-device-control.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ const CONTROLS: Record<IosPhysicalDeviceBackend, IosPhysicalDeviceControl> = {
7272
};
7373

7474
export function resolveIosPhysicalDeviceControl(device: DeviceInfo): IosPhysicalDeviceControl {
75-
return CONTROLS[device.backend === 'xctest' ? 'xctest' : 'coredevice'];
75+
return CONTROLS[device.iosPhysicalDeviceBackend === 'xctest' ? 'xctest' : 'coredevice'];
7676
}
7777

7878
async function ensureXctestDeviceReady(device: DeviceInfo): Promise<void> {

src/platforms/apple/core/runner/runner-command-route.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ export function createRunnerCommandRouteResolver(device: DeviceInfo, port: numbe
3434
}
3535
const control = resolveIosPhysicalDeviceControl(device);
3636
if (control.backend === 'xctest') {
37+
const transport = await control.resolveRunnerTransport(device, timeoutBudgetMs);
3738
return {
38-
kind: 'usbmux',
39+
kind: transport.kind,
3940
endpoints: [`usbmux://${device.id}:${port}/command`],
4041
cachedTunnelIp: false,
4142
};
@@ -48,7 +49,14 @@ export function createRunnerCommandRouteResolver(device: DeviceInfo, port: numbe
4849
}
4950
}
5051
const transport = await control.resolveRunnerTransport(device, timeoutBudgetMs);
51-
const tunnelIp = transport.kind === 'network' ? transport.tunnelIp : null;
52+
if (transport.kind === 'usbmux') {
53+
return {
54+
kind: 'usbmux',
55+
endpoints: [`usbmux://${device.id}:${port}/command`],
56+
cachedTunnelIp: false,
57+
};
58+
}
59+
const tunnelIp = transport.tunnelIp;
5260
requestTunnelIp = tunnelIp;
5361
if (tunnelIp) writeDeviceTunnelIpCache(device.id, tunnelIp);
5462
return buildNetworkRoute(device, port, tunnelIp, false);

0 commit comments

Comments
 (0)