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
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,37 @@ test('the booted simulator with the app installed carries its own selected-by re
assert.equal(selection.source, 'local');
});

test('a cross-platform tie fails undispatched, naming only the tied devices and their ids', async () => {
const error = await resolveInventoryDeviceSelection({
devices: [
ANDROID_EMULATOR,
IOS_SIMULATOR,
{ ...IOS_SIMULATOR, id: 'sim-stopped-1', name: 'iPhone 17', booted: false },
{ ...IOS_SIMULATOR, id: 'sim-stopped-2', name: 'iPhone Air', booted: false },
],
selector: {},
source: 'local',
}).catch((error: unknown) => error);

assert.ok(error instanceof AppError);
assert.equal(error.code, 'AMBIGUOUS_MATCH');
assert.equal(error.details?.dispatched, 'no');
assert.deepEqual(error.details?.devices, [
{ id: ANDROID_EMULATOR.id, name: ANDROID_EMULATOR.name },
{ id: IOS_SIMULATOR.id, name: IOS_SIMULATOR.name },
]);
assert.deepEqual(error.details?.retrySelectors, [
{ flag: '--serial', value: ANDROID_EMULATOR.id },
{ flag: '--device', value: ANDROID_EMULATOR.name },
{ flag: '--udid', value: IOS_SIMULATOR.id },
{ flag: '--device', value: IOS_SIMULATOR.name },
]);
assert.equal(
error.details?.hint,
`Retry with the id of the intended device: --serial ${ANDROID_EMULATOR.id} or --udid ${IOS_SIMULATOR.id}.`,
);
});

test('successful local virtual preparation records the boot event without changing provider evidence', () => {
const localSelection = markSelectionBootOccurred({
device: STOPPED_ANDROID_EMULATOR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ test('resolveTargetDevice refuses ambiguous booted simulator app matches', async
assert.equal(error.code, 'AMBIGUOUS_MATCH');
assert.match(error.message, /Multiple booted iOS simulators have com\.example\.demo installed/);
assert.equal(error.details?.hint, 'Pass --udid to select the intended simulator explicitly.');
assert.equal(error.details?.dispatched, 'no');
assert.deepEqual(error.details?.devices, [
{ id: bootedSimulator.id, name: bootedSimulator.name },
{ id: secondBootedSimulator.id, name: secondBootedSimulator.name },
Expand Down
10 changes: 8 additions & 2 deletions packages/device-selection/src/device-selection-resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
matchesDeviceSelector,
matchesDeviceNameSelector,
platformSelectorsConflict,
preferredDeviceCandidates,
type PlatformSelector,
pickNewestBootableDevice,
resolveDevice,
Expand Down Expand Up @@ -171,9 +172,10 @@
throw new AppError('AMBIGUOUS_MATCH', 'Multiple provider devices match this request.', {
...deviceCandidateDetails(candidates),
matches: candidates.length,
dispatched: 'no',
hint: 'Select the leased provider device explicitly with --device, --udid, or --serial.',
retrySelectors: retrySelectorsFor(candidates),
});

Check failure on line 178 in packages/device-selection/src/device-selection-resolver.ts

View check run for this annotation

apex-sentinel-staging / Apex Sentinel

major: The claimed cross-platform installed-app tie-break is not implemented in this diff

A platform-less `open <app>` with one booted iOS simulator and one booted Android emulator, where the app is installed only on the emulator, still fails with AMBIGUOUS\_MATCH: `resolveAppInstalledSimulatorSelection` filters to `isIosFamily(device) && device.kind === 'simulator' && device.booted === true` only, and no `findAndroidInstalledApp` exists anywhere in the tree. The one new test asserts only that a cross-platform tie fails undispatched and passes no app target, so nothing covers the claimed `selection.reason: 'single-app-installed-local'` across platforms. ### Also raised here Also raised at this location by persona `senior-developer`: Headline fix is absent: a cross-platform open tie still fails AMBIGUOUS\_MATCH — The case the PR title promises to fix — a platform-less `open <app>` with one booted iOS simulator and one booted Android emulator, the app installed on only one — still fails: `resolveAppInstalledSimulatorSelection` probes only `isIosFamily(device) && device.kind === 'simulator'` and returns undefined when fewer than two booted iOS simulators match, so control falls through to the kernel tie and the new test in this diff asserts exactly that failure (`a cross-platform tie fails undispatched...`). None of the machinery the description claims is in this checkout: there is no `findAndroidInstalledApp` anywhere in the repo, the probe is unchanged and iOS-only, `appleSimulatorAppTarget` was not renamed to `openAppTarget` (dispatch-resolve.ts, open-target.ts, replay-port and daemon tests all still use the old name), and the diff is 4 files, not the 21 described. …
Comment thread
thymikee marked this conversation as resolved.
Resolved
}

/**
Expand Down Expand Up @@ -235,6 +237,7 @@
{
appTarget,
...deviceCandidateDetails(matches),
dispatched: 'no',
hint: 'Pass --udid to select the intended simulator explicitly.',
retrySelectors: retrySelectorsFor(matches),
},
Expand All @@ -247,13 +250,16 @@
extraHint?: string,
): unknown {
if (!(error instanceof AppError) || error.code !== 'AMBIGUOUS_MATCH') return error;
// The kernel refuses only its equally preferred devices; a lower-ranked or shut-down match is
// no answer to the tie, so only the tied devices become retry selectors.
const tied = preferredDeviceCandidates([...candidates]);
return new AppError(
error.code,
error.message,
{
...(error.details ?? {}),
...deviceCandidateDetails(candidates),
retrySelectors: retrySelectorsFor(candidates),
...deviceCandidateDetails(tied),
retrySelectors: retrySelectorsFor(tied),
...(extraHint ? { hint: [error.details?.hint, extraHint].filter(Boolean).join(' ') } : {}),
},
error,
Expand Down
15 changes: 6 additions & 9 deletions packages/kernel/src/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -780,21 +780,18 @@ function throwAmbiguousDeviceSelection(candidates: DeviceInfo[]): never {
// and MCP renderers print these candidates without a new shape to learn.
devices: listed.map((device) => ({ id: device.id, name: device.name })),
matches: candidates.length,
// Selection precedes every device operation, so a refused tie never reached a device.
dispatched: 'no',
hint: buildAmbiguousDeviceHint(listed),
},
);
}

function buildAmbiguousDeviceHint(candidates: DeviceInfo[]): string {
const first = candidates[0];
const identitySelector = first
? `--${deviceIdentityFlag(first.platform) ?? 'udid'} ${first.id}`
: `--udid <id>`;
return (
`Select the intended device explicitly, for example ${identitySelector} ` +
`or --device ${JSON.stringify(first?.name ?? '<name>')}. ` +
`Run agent-device devices to list them.`
const selectors = candidates.map(
(device) => `--${deviceIdentityFlag(device.platform) ?? 'udid'} ${device.id}`,
);
return `Retry with the id of the intended device: ${selectors.join(' or ')}.`;
}

/**
Expand All @@ -803,7 +800,7 @@ function buildAmbiguousDeviceHint(candidates: DeviceInfo[]): string {
* comparator's remaining tie-breaks are name order and discovery order, which encode nothing about
* intent.
*/
function preferredDeviceCandidates(candidates: DeviceInfo[]): DeviceInfo[] {
export function preferredDeviceCandidates(candidates: DeviceInfo[]): DeviceInfo[] {
const ranked = isAppleDeviceCandidateSet(candidates)
? candidatesWithBestAppleRank(candidates)
: preferVirtualCandidates(candidates);
Expand Down
Loading