Skip to content

Commit ab84e0d

Browse files
committed
fix(ios): read privacy support from simctl, not its help text
`simctl privacy` has no capability query, and its help text is not one. Xcode 26 (17C52) omits `camera` from the service list while granting it: the probe gate refused `settings permission grant camera` and a Maestro `camera: allow` as UNSUPPORTED_OPERATION on every flow that asked for the camera, while the raw command worked (TCC `kTCCServiceCamera` 0 -> 2). The same omission was reported for notifications on the runtimes in #2363. Delegate the verdict to the command that would make the change. A service the runtime cannot change answers EPERM — for a real service it withheld and for a name it does not know alike — so generalize the notifications classifier to every target and read the refusal from that call. Xcode 26 words grant/revoke failures as "Failed to set access", which the old matcher did not look for, so the generalization is required and not merely a widening. Deletes the cached help probe, its parser, and the `privacy help` spawn before the first permission change; a grant is now one simctl call. Records why a Maestro `location: inuse` or `location: never` reaching the plain Android target is correct rather than an unguarded iOS leak: `pm grant` leaves a location appop of `foreground`, which is Android's only allow level. The fan-out's ordered, stop-at-first-refusal shape is now stated in the versioned Maestro compatibility reference, the replay docs, and the changelog, and the "iOS all does not cover notifications" line is corrected: notifications has no service on current runtimes, named or under `all`.
1 parent 12d00dd commit ab84e0d

9 files changed

Lines changed: 89 additions & 197 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,18 @@
44

55
- Added (maestro): `setPermissions` and `launchApp.permissions` support `all: allow|deny|unset`
66
on iOS simulators and Android, with specific entries overriding `all`. Both accept a
7-
Maestro-style permissions map. iOS `all` does not cover notifications: simctl has no
8-
notifications service on these runtimes, so targeted notifications fails loudly and `all`
9-
leaves it unchanged.
7+
Maestro-style permissions map. Entries apply in order until the selected platform refuses one,
8+
and the error then names what landed. Android's only allow level is while-in-use, so
9+
`location: inuse|never` apply `allow`/`deny` there; `location: always` and `photos: limited`
10+
stay Apple-only.
11+
- Fixed (ios): `settings permission` no longer refuses a privacy service that `simctl privacy`
12+
accepts but omits from its own help text — Xcode 26 does that for `camera`, so
13+
`settings permission grant camera` and a Maestro `camera: allow` failed as unsupported while
14+
the raw command worked. Support is now `simctl privacy`'s own verdict per runtime, and a
15+
service it refuses fails with `UNSUPPORTED_OPERATION`. This also drops the cached
16+
`simctl privacy help` probe and the `privacy help` spawn before the first permission change.
17+
iOS `all` still does not cover notifications: current runtimes have no notifications service,
18+
so a targeted notifications change fails loudly and `all` leaves it unchanged.
1019
- Fixed (daemon): `close` now stops an active app-log stream (and audio probe / perf capture /
1120
recording) on an implicitly cwd-scoped session. Teardown addressed those resources by
1221
`session.name` (`default`) instead of the store address (`cwd:<hash>:default`), so the record

‎packages/maestro/src/daemon-port/daemon-runtime-public-operation.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,13 @@ const MAESTRO_PERMISSION_TARGETS: Readonly<Record<string, string>> = {
180180

181181
const MAESTRO_PERMISSION_STATES = { allow: 'grant', deny: 'deny', unset: 'reset' } as const;
182182

183-
/** Maestro's granular values, each already a complete mutation. */
183+
/**
184+
* Maestro's granular values, each already a complete mutation. `inuse` and `never` are not
185+
* Apple-only spellings to refuse elsewhere: `pm grant` leaves a location appop of `foreground`,
186+
* which is Android's only allow level, so the plain target is the faithful Android reading of
187+
* both. `always` and `limited` have no Android mutation to project onto and the Android backend
188+
* refuses them.
189+
*/
184190
const MAESTRO_GRANULAR_PERMISSIONS: Readonly<
185191
Record<string, Readonly<Record<string, MaestroPermissionMutation>>>
186192
> = {

‎packages/maestro/src/internal/support-matrix.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
export const MAESTRO_COMPAT_SUPPORTED_CAPABILITIES = [
2-
'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants/denials/resets; all resolves in the backend — one simctl call on iOS, the declared permissions on Android — with specifics overriding after it; unservable names fail loudly instead of being skipped; unset fully resets and location: never denies on iOS; iOS all does not cover notifications — simctl has no notifications service on these runtimes, so targeted notifications fails loudly and all leaves it unchanged); runFlow file/inline with platform, visibility, and limited boolean conditions; onFlowStart/onFlowComplete; repeat.times and retry.',
2+
'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants, denials, and resets; all resolves in the backend — one simctl call on iOS, the declared permissions on Android — with specific entries overriding after it); runFlow file/inline with platform, visibility, and limited boolean conditions; onFlowStart/onFlowComplete; repeat.times and retry.',
33
'Interactions: tapOn, doubleTapOn, longPressOn, inputText on the focused element, eraseText, openLink, hideKeyboard, basic pressKey, and back; selector targets poll until available and support recursive index, childOf, above, below, leftOf, rightOf, containsChild, containsDescendants, points, and optional; outer command labels are metadata, not target selectors.',
44
'Assertions and navigation: assertVisible, assertNotVisible, assertTrue (literal values and ${VAR} lookups only; "", "false", "0", "null", and "undefined" are falsy, everything else is truthy), extendedWaitUntil, scroll, scrollUntilVisible, absolute/percentage/target swipe, takeScreenshot, waitForAnimationToEnd, clearState, and stopApp.',
55
'Scripts: ordered runScript file/env scripts with http.post, json, and output variables; evalScript inline expressions run flow-scoped JavaScript and write output.* leaves for later steps.',
66
] as const;
77

88
export const MAESTRO_COMPAT_LIMITATIONS = [
9+
'Permissions: every entry is one settings permission call, applied in order with all first; the step stops at the first entry the selected platform refuses, earlier entries stay applied, and the error names what landed. Android’s only allow level is while-in-use, so location: inuse and location: never mean allow and deny there, while location: always and photos: limited are Apple-only and fail. On iOS, which service a runtime changes is simctl privacy’s own verdict: current runtimes refuse a targeted notifications change and leave notifications untouched under all.',
910
'Runtime: iOS and Android only; launchApp.clearState and standalone clearState support Android and iOS simulators, launch arguments are Apple-only, and other standalone device utility/state commands are unsupported.',
1011
'Expressions: evalScript is the only command whose payload is evaluated as JavaScript (flow env and prior output leaves are string-typed); with that exception, fields stay literal or ${VAR} lookup-only — assertTrue supports literals and bare lookups, repeat.while is unsupported, and other expression-shaped payloads fail loud.',
1112
'Environment: flow env is the default, AD_VAR_* overrides it, and CLI -e KEY=VALUE wins over both.',

‎packages/platform-apple/src/__tests__/fake-apple-tool.ts‎

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,6 @@ import { IOS_DEVICE } from './device-fixtures.ts';
88
export type FakeAppleToolResponse = string | Partial<ExecResult> | Error;
99
export type FakeAppleToolScript = (args: string[]) => FakeAppleToolResponse | undefined;
1010

11-
const SIMCTL_PRIVACY_HELP = `Usage: simctl privacy <device> <action> <service> [<bundle identifier>]
12-
13-
service
14-
The service:
15-
all - Apply the action to all services.
16-
calendar - Allow access to calendar.
17-
contacts-limited - Allow access to basic contact info.
18-
contacts - Allow access to full contact details.
19-
location - Allow access to location services when app is in use.
20-
location-always - Allow access to location services at all times.
21-
photos-add - Allow adding photos to the photo library.
22-
photos - Allow full access to the photo library.
23-
media-library - Allow access to the media library.
24-
microphone - Allow access to audio input.
25-
motion - Allow access to motion and fitness data.
26-
reminders - Allow access to reminders.
27-
siri - Allow use of the app with Siri.
28-
camera - Allow access to the camera.
29-
notifications - Allow access to notifications.`;
30-
3111
export async function withFakeAppleTool<T>(
3212
script: FakeAppleToolScript,
3313
run: (ctx: { calls: string[][]; device: DeviceInfo }) => Promise<T>,
@@ -42,15 +22,7 @@ export async function withFakeAppleTool<T>(
4222
allowFailure: boolean | undefined,
4323
): Promise<ExecResult> => {
4424
calls.push([...flat]);
45-
let response = script(flat);
46-
if (
47-
response === undefined &&
48-
flat[0] === 'simctl' &&
49-
flat[1] === 'privacy' &&
50-
flat.includes('help')
51-
) {
52-
response = SIMCTL_PRIVACY_HELP;
53-
}
25+
const response = script(flat);
5426
if (response instanceof Error) throw response;
5527
const result: ExecResult =
5628
typeof response === 'string'

‎packages/platform-apple/src/core/__tests__/app-settings.test.ts‎

Lines changed: 25 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ const simulatorActual = await vi.importActual<typeof import('../simulator.ts')>(
2828
import { setIosSetting } from '../app-settings.ts';
2929
import { withMockedMacOsHelper } from './macos-helper-test-utils.ts';
3030
import { ensureBootedSimulator } from '../simulator.ts';
31-
import type { DeviceInfo } from '@agent-device/kernel/device';
3231
import { AppError } from '@agent-device/kernel/errors';
3332
import { runCmd } from '@agent-device/host-kit/command';
3433
import { retryWithPolicy } from '@agent-device/host-kit/retry';
@@ -301,8 +300,6 @@ test('setIosSetting permission grant calendar uses simctl privacy calendar targe
301300
await withFakeAppleTool(
302301
(args) => {
303302
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
304-
// simctl privacy help falls through to the fake's canned service listing.
305-
if (args[0] === 'simctl' && args[1] === 'privacy' && args[2] === 'help') return undefined;
306303
if (args.join(' ') === 'simctl privacy sim-1 grant calendar com.example.app') return '';
307304
return unexpectedArgs(args);
308305
},
@@ -417,7 +414,6 @@ test('setIosSetting permission grant photos limited maps to photos-add', async (
417414
await withFakeAppleTool(
418415
(args) => {
419416
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
420-
if (args[0] === 'simctl' && args[1] === 'privacy' && args[2] === 'help') return undefined;
421417
if (args.join(' ') === 'simctl privacy sim-1 grant photos-add com.example.app') return '';
422418
return unexpectedArgs(args);
423419
},
@@ -456,14 +452,12 @@ test('setIosSetting permission rejects mode for non-photos target', async () =>
456452
});
457453

458454
test('setIosSetting permission reset notifications fails targeted when direct reset is blocked', async () => {
459-
// A listed-but-blocked notifications service must not fall back to `reset
460-
// all`: a notifications-only reset would clear microphone, location, and
461-
// other grants. The targeted reset fails instead, leaving the earlier grant
462-
// in place.
455+
// A blocked notifications reset must not fall back to `reset all`: a
456+
// notifications-only reset would clear microphone, location, and other
457+
// grants. The targeted reset fails instead, leaving the earlier grant in place.
463458
await withFakeAppleTool(
464459
(args) => {
465460
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
466-
if (args[0] === 'simctl' && args[1] === 'privacy' && args[2] === 'help') return undefined;
467461
if (args.join(' ') === 'simctl privacy sim-1 grant microphone com.example.app') return '';
468462
if (args.join(' ') === 'simctl privacy sim-1 reset notifications com.example.app') {
469463
return { stderr: 'Failed to reset access\nOperation not permitted', exitCode: 1 };
@@ -504,47 +498,29 @@ test('setIosSetting permission reset notifications fails targeted when direct re
504498
);
505499
});
506500

507-
test('setIosSetting permission reset notifications fails explicitly without touching other services', async () => {
508-
// Runtimes like iOS 26.3 omit notifications from `simctl privacy help`, where
509-
// no targeted reset exists: the probe gate rejects before any privacy call,
510-
// so an earlier microphone grant survives the failed reset.
511-
const device: DeviceInfo = {
512-
...IOS_TEST_SIMULATOR,
513-
simulatorSetPath: '/fake/privacy-help-no-notifications',
514-
};
515-
const HELP_WITHOUT_NOTIFICATIONS = `Usage: simctl privacy <device> <action> <service> [<bundle identifier>]
516-
517-
service
518-
The service:
519-
microphone - Allow access to audio input.`;
501+
test('setIosSetting permission grant camera needs no capability probe', async () => {
502+
// Xcode 26 omits `camera` from `simctl privacy help` while still changing it, so a
503+
// help-derived gate refused a service every runtime here serves. The privacy call is
504+
// itself the probe, so nothing else may be issued for a grant.
520505
await withFakeAppleTool(
521506
(args) => {
522507
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
523-
if (args.includes('help')) return HELP_WITHOUT_NOTIFICATIONS;
524-
const flat = args.join(' ');
525-
if (flat.includes('grant microphone com.example.app')) return '';
508+
if (args.join(' ') === 'simctl privacy sim-1 grant camera com.example.app') return '';
526509
return unexpectedArgs(args);
527510
},
528511
async ({ calls }) => {
529-
await setIosSetting(device, 'permission', 'grant', 'com.example.app', {
530-
permissionTarget: 'microphone',
512+
await setIosSetting(IOS_TEST_SIMULATOR, 'permission', 'grant', 'com.example.app', {
513+
permissionTarget: 'camera',
531514
});
532-
await assertRejectsAppError(
533-
() =>
534-
setIosSetting(device, 'permission', 'reset', 'com.example.app', {
535-
permissionTarget: 'notifications',
536-
}),
537-
{ code: 'UNSUPPORTED_OPERATION', message: /does not support service "notifications"/i },
538-
);
539515
const flat = calls.map((args) => args.join(' '));
540516
assert.equal(
541-
flat.some((line) => line.includes('reset all com.example.app')),
542-
false,
517+
flat.includes('simctl privacy sim-1 grant camera com.example.app'),
518+
true,
543519
flat.join('; '),
544520
);
545521
assert.equal(
546-
flat.some((line) => line.includes('grant microphone com.example.app')),
547-
true,
522+
flat.some((line) => line.includes('privacy help')),
523+
false,
548524
flat.join('; '),
549525
);
550526
},
@@ -555,7 +531,6 @@ test('setIosSetting permission deny notifications returns unsupported on runtime
555531
await withFakeAppleTool(
556532
(args) => {
557533
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
558-
if (args[0] === 'simctl' && args[1] === 'privacy' && args[2] === 'help') return undefined;
559534
if (args.join(' ') === 'simctl privacy sim-1 revoke notifications com.example.app') {
560535
return { stderr: 'Failed to revoke access\nOperation not permitted', exitCode: 1 };
561536
}
@@ -582,42 +557,32 @@ test('setIosSetting permission deny notifications returns unsupported on runtime
582557
);
583558
});
584559

585-
test('setIosSetting permission rejects service missing from simctl privacy help', async () => {
586-
// A distinct simulator set path busts the module-level privacy-services
587-
// cache, whose key is `PATH + set path` — the PATH half no longer varies
588-
// now that no PATH stubbing happens, so the set path must.
589-
const device: DeviceInfo = { ...IOS_TEST_SIMULATOR, simulatorSetPath: '/fake/privacy-help-set' };
590-
const CUSTOM_PRIVACY_HELP = `Usage: simctl privacy <device> <action> <service> [<bundle identifier>]
591-
592-
service
593-
The service:
594-
camera - Allow access to camera.
595-
microphone - Allow access to audio input.`;
596-
560+
test('setIosSetting permission reports a runtime-refused service as unsupported', async () => {
561+
// A service the runtime cannot change answers EPERM, and Xcode 26 words grant/revoke
562+
// failures as "Failed to set access" — not "failed to grant access" — for both a real
563+
// service it withheld and a name it does not know at all.
597564
await withFakeAppleTool(
598565
(args) => {
599566
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
600-
if (args[0] === 'simctl' && args.includes('privacy') && args.includes('help')) {
601-
return CUSTOM_PRIVACY_HELP;
567+
if (args.join(' ') === 'simctl privacy sim-1 grant calendar com.example.app') {
568+
return { stderr: 'Failed to set access\nOperation not permitted', exitCode: 1 };
602569
}
603570
return unexpectedArgs(args);
604571
},
605572
async ({ calls }) => {
606573
await assertRejectsAppError(
607574
() =>
608-
setIosSetting(device, 'permission', 'grant', 'com.example.app', {
575+
setIosSetting(IOS_TEST_SIMULATOR, 'permission', 'grant', 'com.example.app', {
609576
permissionTarget: 'calendar',
610577
}),
611-
{ code: 'UNSUPPORTED_OPERATION', message: /does not support service "calendar"/i },
578+
{
579+
code: 'UNSUPPORTED_OPERATION',
580+
message: /does not support setting calendar permission/i,
581+
},
612582
);
613583
const flat = calls.map((args) => args.join(' '));
614584
assert.equal(
615585
flat.some((line) => line.includes('privacy help')),
616-
true,
617-
flat.join('; '),
618-
);
619-
assert.equal(
620-
flat.some((line) => line.includes('grant calendar')),
621586
false,
622587
flat.join('; '),
623588
);

0 commit comments

Comments
 (0)