Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions packages/device-selection/src/__tests__/dispatch-resolve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,40 @@ test('resolveTargetDevice reuses request-scoped device resolution cache for iden
assert.equal(mockListAppleDevices.mock.calls.length, 1);
});

test('resolveTargetDevice reuses the request cache after the inventory configures the host env', async () => {
const env: Record<string, string | undefined> = { PATH: '/usr/bin' };
mockListAppleDevices.mockImplementation(async () => {
env.ANDROID_HOME = '/sdk';
env.PATH = `/sdk/platform-tools:${env.PATH}`;
return [bootedSimulator];
});

await withResolveTargetDeviceCacheScope(async () => {
const first = await resolveTargetDevice({ udid: 'sim-2' }, { env });
const inventoryReads = mockListAppleDevices.mock.calls.length;
const second = await resolveTargetDevice({ udid: 'sim-2' }, { env });

assert.equal(first.id, 'sim-2');
assert.equal(second.id, 'sim-2');
assert.equal(mockListAppleDevices.mock.calls.length, inventoryReads);
});
});

test('resolveTargetDevice request cache key separates env-derived device allowlists', async () => {
mockListAppleDevices.mockResolvedValue([bootedSimulator]);

await withResolveTargetDeviceCacheScope(async () => {
await resolveTargetDevice({ udid: 'sim-2' }, { env: {} });
const inventoryReads = mockListAppleDevices.mock.calls.length;
await resolveTargetDevice(
{ udid: 'sim-2' },
{ env: { AGENT_DEVICE_ANDROID_DEVICE_ALLOWLIST: 'emulator-5554' } },
);

assert.equal(mockListAppleDevices.mock.calls.length, inventoryReads * 2);
});
});

test('resolveTargetDevice request cache key separates device selectors', async () => {
mockListAppleDevices.mockResolvedValue([simulator, bootedSimulator]);

Expand Down
4 changes: 3 additions & 1 deletion packages/device-selection/src/dispatch-resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,8 +309,10 @@ function buildResolveTargetDeviceCacheKey(
): string {
// The app target only informs the first device choice. Once a request has
// chosen a device, every later resolution must reuse that same device even
// when dispatch has no app target to pass back through this seam.
// when dispatch has no app target to pass back through this seam. The request
// holds every value selection derives from env, so env itself stays out.
const {
env: _env,
appleSimulatorAppTarget: _appleSimulatorAppTarget,
appDeviceTarget: _appDeviceTarget,
webSession: _webSession,
Expand Down
Loading