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
2 changes: 1 addition & 1 deletion packages/contracts/src/settings-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ export const SETTINGS = {
],
app: 'input',
appScope: { apple: 'app-scoped', mobile: 'app-scoped', 'macos-host': 'device-level' },
help: 'Changes a permission of the --app app or the session app. An iOS simulator, local or Limrun, resolves --app to an installed bundle id or display name, and Android to an installed package. On Android, deny|reset of a held permission kills a running app; the response reports priorGrantState and warns, and open <app> --relaunch restores it. Android needs a resolvable foreground user and changes nothing without one. On the macOS host, grant|reset change the host TCC grants for the three desktop targets and take no --app.',
help: 'Changes a permission of the --app app or the session app. An iOS simulator, local or Limrun, resolves --app to an installed bundle id or display name, and Android to an installed package. On iOS simulators, settings permission refuses an explicit notifications target. Use alert accept or alert dismiss to answer the notification prompt. On Android, deny|reset of a held permission kills a running app; the response reports priorGrantState and warns, and open <app> --relaunch restores it. Android needs a resolvable foreground user and changes nothing without one. On the macOS host, grant|reset change the host TCC grants for the three desktop targets and take no --app.',
},
} as const satisfies Record<string, SettingDefinition>;

Expand Down
2 changes: 1 addition & 1 deletion packages/maestro/src/internal/support-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const MAESTRO_COMPAT_SUPPORTED_CAPABILITIES = [

export const MAESTRO_COMPAT_LIMITATIONS = [
'On the native iOS runner, use tapOn on a visible dismissal control. If the app supports drag dismissal, use a swipe that stays above the keyboard.',
'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.',
'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 simulators, grant, deny, or reset on notifications returns ios-notification-permission-unsupported. Answer the notification prompt with the CLI command alert accept or alert dismiss, which this Maestro subset does not include. For all, simctl privacy determines which services the runtime can change, and current runtimes leave notifications untouched.',
'Runtime: iOS and Android only; launchApp.clearState and standalone clearState support Android and iOS simulators, launch arguments are Apple-only (a map-form argument key gains a leading - unless its value is a boolean, as in Maestro), and other standalone device utility/state commands are unsupported.',
'Expressions: evalScript and condition true: fields (runFlow.when and repeat.while share one evaluator) are evaluated as JavaScript (flow env and prior output leaves are string-typed); a true: field that is a boolean, a maestro.platform comparison, or plain literal text after ${VAR} lookups is decided without JavaScript, with the assertTrue falsy table for literal text. Other fields stay literal or ${VAR} lookup-only — assertTrue supports literals and bare lookups, and other expression-shaped payloads fail loud.',
'Environment: flow env is the default, AD_VAR_* overrides it, and CLI -e KEY=VALUE wins over both; override keys follow the flow variable grammar (mixed case and dots allowed), and AD_* stays reserved.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ test('setIosSetting permission runs the simctl plan on the simulator udid and su
await withFakeAppleTool(
(args) => {
if (isSimctlListApps(args)) return INSTALLED_APPS_JSON;
if (args.join(' ') === 'simctl privacy sim-1 revoke notifications com.example.app') {
if (args.join(' ') === 'simctl privacy sim-1 revoke camera com.example.app') {
return { stderr: 'Failed to revoke access\nOperation not permitted', exitCode: 1 };
}
return unexpectedArgs(args);
Expand All @@ -626,21 +626,21 @@ test('setIosSetting permission runs the simctl plan on the simulator udid and su
'deny',
'com.example.app',
{
permissionTarget: 'notifications',
permissionTarget: 'camera',
},
process.env,
),
{
code: 'UNSUPPORTED_OPERATION',
message: /does not support setting notifications permission/i,
message: /does not support setting camera permission/i,
},
);
assert.deepEqual(calls.at(-1), [
'simctl',
'privacy',
'sim-1',
'revoke',
'notifications',
'camera',
'com.example.app',
]);
},
Expand Down
49 changes: 38 additions & 11 deletions packages/platform-apple/src/core/__tests__/simctl-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,35 @@ test('grant all stops at a failure that is not a refusal', async () => {
expect(failed.details).toEqual({ stderr: 'Invalid device: booted', permissions: ['calendar'] });
});

test.for(['grant', 'deny', 'reset'])(
'%s notifications refuses before resolving the app or running simctl',
async (state) => {
const runSimctl = recordingRunner([refusal('Failed to set access')]);
const resolveApp = vi.fn(async (app: string) => app);

const error = await appErrorFrom(
applySimctlSetting(
request(runSimctl, {
setting: 'permission',
state,
appBundleId: 'com.example.app',
resolveApp,
options: { permissionTarget: 'notifications' },
}),
),
);

expect(runSimctl).not.toHaveBeenCalled();
expect(resolveApp).not.toHaveBeenCalled();
expect(error).toMatchObject({
code: 'UNSUPPORTED_OPERATION',
details: { reason: 'ios-notification-permission-unsupported', dispatched: 'no' },
});
expect(error.details?.hint).toContain('alert accept');
expect(error.details?.hint).toContain('alert dismiss');
},
);

test('a privacy service the runtime refuses is unsupported; other failures pass through', async () => {
const refused = new AppError('COMMAND_FAILED', 'simctl exited with code 1', {
stderr: 'Failed to grant access to com.example.app\nOperation not permitted',
Expand All @@ -270,13 +299,13 @@ test('a privacy service the runtime refuses is unsupported; other failures pass
setting: 'permission',
state: 'grant',
appBundleId: 'com.example.app',
options: { permissionTarget: 'notifications' },
options: { permissionTarget: 'camera' },
});

await expect(applySimctlSetting(grant)).rejects.toMatchObject({
code: 'UNSUPPORTED_OPERATION',
message:
'iOS simulator does not support setting notifications permission via simctl privacy on this runtime.',
'iOS simulator does not support setting camera permission via simctl privacy on this runtime.',
details: { deviceId: 'SIM-1', appBundleId: 'com.example.app' },
cause: refused,
});
Expand All @@ -297,25 +326,23 @@ test('a refused privacy service reports the device id the caller names, not the
setting: 'permission',
state: 'grant',
appBundleId: 'com.example.app',
options: { permissionTarget: 'notifications' },
options: { permissionTarget: 'camera' },
}),
),
).rejects.toMatchObject({
code: 'UNSUPPORTED_OPERATION',
details: { deviceId: 'limrun:ios:lease-a', appBundleId: 'com.example.app' },
});
expect(argvs(runSimctl)).toEqual([
['privacy', 'booted', 'grant', 'notifications', 'com.example.app'],
]);
expect(argvs(runSimctl)).toEqual([['privacy', 'booted', 'grant', 'camera', 'com.example.app']]);
});

test.for([
{ state: 'deny', action: 'revoke', target: 'notifications', wording: 'Failed to revoke access' },
{ state: 'deny', action: 'revoke', target: 'camera', wording: 'Failed to revoke access' },
{ state: 'grant', action: 'grant', target: 'calendar', wording: 'Failed to set access' },
{
state: 'grant',
action: 'grant',
target: 'notifications',
target: 'camera',
wording:
'Underlying error (domain=NSPOSIXErrorDomain, code=1):\n\tFailed to create TCC authorization record',
},
Expand Down Expand Up @@ -362,18 +389,18 @@ test('a refused targeted reset fails instead of a reset all that would clear ear
});

await applySimctlSetting(permission('grant', 'microphone'));
const error = await appErrorFrom(applySimctlSetting(permission('reset', 'notifications')));
const error = await appErrorFrom(applySimctlSetting(permission('reset', 'camera')));

expect(error).toMatchObject({
code: 'UNSUPPORTED_OPERATION',
message:
'iOS simulator does not support resetting notifications permission via simctl privacy on this runtime.',
'iOS simulator does not support resetting camera permission via simctl privacy on this runtime.',
details: { deviceId: 'SIM-1', appBundleId: 'com.example.app' },
cause: refused,
});
expect(argvs(runSimctl)).toEqual([
['privacy', 'SIM-1', 'grant', 'microphone', 'com.example.app'],
['privacy', 'SIM-1', 'reset', 'notifications', 'com.example.app'],
['privacy', 'SIM-1', 'reset', 'camera', 'com.example.app'],
]);
});

Expand Down
19 changes: 18 additions & 1 deletion packages/platform-apple/src/core/simctl-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
type SimctlSettingRequest,
} from '@agent-device/contracts/settings';
import { type MobilePermissionTarget } from '@agent-device/contracts/settings-catalog';
import { AppError, sessionAppRequiredDetails } from '@agent-device/kernel/errors';
import { AppError, sessionAppRequiredDetails, type ReasonTable } from '@agent-device/kernel/errors';
import { requireLocationCoordinates } from '@agent-device/kernel/location-coordinates';

/** Changes one simulator setting through `simctl`; the Apple package owns this plan for every runner. */
Expand Down Expand Up @@ -46,13 +46,30 @@ async function setAppearance({ runSimctl, udid, state }: SimctlSettingRequest):
await runSimctl(['ui', udid, 'appearance', target]);
}

const SIMCTL_SETTINGS_REASONS = {
// iOS simulator notification prompts must be answered with `alert accept` or `alert dismiss`.
notificationsUnsupported: { reason: 'ios-notification-permission-unsupported' },
} as const satisfies ReasonTable<'settings'>;

async function setPermission(
request: SimctlSettingRequest,
): Promise<Record<string, unknown> | void> {
const { runSimctl, udid, deviceId, state, options } = request;
const permissionAction = parsePermissionAction(state);
const action = permissionAction === 'deny' ? 'revoke' : permissionAction;
const target = parseIosPrivacyService(options?.permissionTarget, options?.permissionMode);
if (target === 'notifications') {
throw new AppError(
'UNSUPPORTED_OPERATION',
'iOS simulators do not support changing notification permissions through settings permission.',
{
reason: SIMCTL_SETTINGS_REASONS.notificationsUnsupported.reason,
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
Resolved
dispatched: 'no',
deviceId,
hint: 'Use `alert accept` or `alert dismiss` to answer the notification prompt.',
},
);
}
const appBundleId = await requireAppBundleId(request);
if (target === 'all' && action !== 'reset') {
return await setEveryIosPrivacyService(request, action, appBundleId);
Expand Down
30 changes: 27 additions & 3 deletions test/integration/provider-scenarios/limrun-ios-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,30 @@ afterEach(() => {
vi.clearAllMocks();
});

test('Limrun iOS refuses an explicit notifications permission before calling simctl', async () => {
const { binding, dispose } = await bindLimrunDeployment(
'ios',
new AbortController().signal,
createLimrunRuntimeDependencies({ env: {}, cwd: process.cwd() }).ios,
);
try {
await expect(
binding.operations.setSetting!({
setting: 'permission',
state: 'grant',
appBundleId: 'com.example.ios',
options: { permissionTarget: 'notifications' },
}),
).rejects.toMatchObject({
code: 'UNSUPPORTED_OPERATION',
details: { reason: 'ios-notification-permission-unsupported' },
});
expect(state.simctl).not.toHaveBeenCalled();
} finally {
await dispose();
}
});

test('a Limrun iOS permission the runtime refuses reports the local unsupported verdict', async () => {
state.simctl.mockImplementation(() => ({
wait: async () => ({
Expand All @@ -73,17 +97,17 @@ test('a Limrun iOS permission the runtime refuses reports the local unsupported
setting: 'permission',
state: 'grant',
appBundleId: 'com.example.ios',
options: { permissionTarget: 'notifications' },
options: { permissionTarget: 'camera' },
});

await expect(refusal).rejects.toMatchObject({
code: 'UNSUPPORTED_OPERATION',
message:
'iOS simulator does not support setting notifications permission via simctl privacy on this runtime.',
'iOS simulator does not support setting camera permission via simctl privacy on this runtime.',
details: { appBundleId: 'com.example.ios' },
});
expect(state.simctl.mock.calls).toEqual([
[['privacy', 'booted', 'grant', 'notifications', 'com.example.ios']],
[['privacy', 'booted', 'grant', 'camera', 'com.example.ios']],
]);
} finally {
await dispose();
Expand Down
3 changes: 2 additions & 1 deletion website/docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,8 @@ Permissions:

- On iOS and Android, `permission` applies to the session app. Pass `--app <bundle-id, package, or name>` to target an installed app without opening it, for example to grant a permission before first launch. `--app` counts only on the command line; `AGENT_DEVICE_TARGET_APP` never retargets a settings change.
- Refusals change nothing: `app_not_installed` (install the app or fix the id), `session_app_required` (run `open <app>` or name the app), `setting_app_not_package` (an Android intent alias such as `settings` is not a package), and `setting_app_not_consumed` (a device-wide setting such as `location set`, `mobile-data`, or `bluetooth` takes no app).
- On iOS simulators, the simulator decides which permissions it can change and refuses the rest. `grant all` skips a refused service with a warning.
- On iOS simulators, targeting `notifications` with `grant`, `deny`, or `reset` returns `ios-notification-permission-unsupported`. Use `alert accept` or `alert dismiss` to answer the notification prompt.
- On iOS simulators, the simulator decides which other permissions it can change and refuses the rest. `grant all` skips a refused service with a warning.
- On Android, a permission group applies only the permissions the app declares. `full|limited` applies only to iOS `photos`.
- Android kills a running app when you revoke one of its granted permissions. After `deny` or `reset`, run `open <app> --relaunch` when the warning says so.
- On macOS, `grant` opens System Settings when access needs your approval; it never grants silently. `deny` is unsupported.
Expand Down
1 change: 1 addition & 0 deletions website/docs/docs/error-reasons.md
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ Treat a reason that this page does not list as unknown, not as an error in the r
| `keep-awake-unreadable` | The device answered the keep-awake read-back with a value that is not a stay-on mask. |
| `setting_app_not_package` | The named app resolves to an intent such as `settings`, not to an installed package. |
| `app-no-data-container` | `clear-app-state` was refused because the installed app owns no data container. |
| `ios-notification-permission-unsupported` | iOS simulator notification prompts must be answered with `alert accept` or `alert dismiss`. |

### `shake`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/docs/run-maestro-flows.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Keep the target binding, such as `--platform ios`, on the `replay` or `test` com

## Boundaries

- 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`.
- 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 simulators, `grant`, `deny`, or `reset` on `notifications` returns `ios-notification-permission-unsupported`. Answer the notification prompt with the CLI command `alert accept` or `alert dismiss`, which this Maestro subset does not include. For `all`, `simctl privacy` determines which services the runtime can change, and current runtimes leave notifications untouched.
- Runtime: iOS and Android only; `launchApp.clearState` and standalone `clearState` support Android and iOS simulators, launch arguments are Apple-only (a map-form argument key gains a leading `-` unless its value is a boolean, as in Maestro), and other standalone device utility/state commands are unsupported.
- Expressions: `evalScript` and condition `true:` fields (`runFlow.when` and `repeat.while` share one evaluator) are evaluated as JavaScript (flow `env` and prior `output` leaves are string-typed); a `true:` field that is a boolean, a `maestro.platform` comparison, or plain literal text after `${VAR}` lookups is decided without JavaScript, with the `assertTrue` falsy table for literal text. Other fields stay literal or `${VAR}` lookup-only — `assertTrue` supports literals and bare lookups, and other expression-shaped payloads fail loud.
- Environment: flow `env` is the default, `AD_VAR_*` overrides it, and CLI `-e KEY=VALUE` wins over both; override keys follow the flow variable grammar (mixed case and dots allowed), and `AD_*` stays reserved.
Expand Down
Loading