From 5a045c4e9376956e35b6cf0243bee11b603b9e20 Mon Sep 17 00:00:00 2001 From: shahjahan Date: Wed, 25 Nov 2026 20:57:10 +0500 Subject: [PATCH 1/2] fix(ios): refuse simulator notification permission changes Co-authored-by: GPT-6.2 Sol (Codex) --- packages/contracts/src/settings-catalog.ts | 2 +- .../core/__tests__/simctl-settings.test.ts | 49 ++++++++++++++----- .../src/core/simctl-settings.ts | 18 ++++++- .../limrun-ios-settings.test.ts | 30 ++++++++++-- website/docs/docs/commands.md | 3 +- website/docs/docs/error-reasons.md | 1 + website/docs/docs/run-maestro-flows.md | 2 +- 7 files changed, 87 insertions(+), 18 deletions(-) diff --git a/packages/contracts/src/settings-catalog.ts b/packages/contracts/src/settings-catalog.ts index bc34381134..90a606586d 100644 --- a/packages/contracts/src/settings-catalog.ts +++ b/packages/contracts/src/settings-catalog.ts @@ -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 --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 --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; diff --git a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts index 3e1b717709..3c7c7ae9aa 100644 --- a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts @@ -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' }, + }); + 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', @@ -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, }); @@ -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', }, @@ -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'], ]); }); diff --git a/packages/platform-apple/src/core/simctl-settings.ts b/packages/platform-apple/src/core/simctl-settings.ts index 7394ef8954..45debbdeeb 100644 --- a/packages/platform-apple/src/core/simctl-settings.ts +++ b/packages/platform-apple/src/core/simctl-settings.ts @@ -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. */ @@ -46,6 +46,11 @@ 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 | void> { @@ -53,6 +58,17 @@ async function setPermission( 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, + 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); diff --git a/test/integration/provider-scenarios/limrun-ios-settings.test.ts b/test/integration/provider-scenarios/limrun-ios-settings.test.ts index c17a788c93..46ed769570 100644 --- a/test/integration/provider-scenarios/limrun-ios-settings.test.ts +++ b/test/integration/provider-scenarios/limrun-ios-settings.test.ts @@ -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 () => ({ @@ -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(); diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 75313e2803..1430025358 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -1811,7 +1811,8 @@ Permissions: - On iOS and Android, `permission` applies to the session app. Pass `--app ` 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 ` 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 --relaunch` when the warning says so. - On macOS, `grant` opens System Settings when access needs your approval; it never grants silently. `deny` is unsupported. diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index 059485983a..754c4101ab 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -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` diff --git a/website/docs/docs/run-maestro-flows.md b/website/docs/docs/run-maestro-flows.md index e82e224193..1a93b3f602 100644 --- a/website/docs/docs/run-maestro-flows.md +++ b/website/docs/docs/run-maestro-flows.md @@ -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, targeting `notifications` returns `ios-notification-permission-unsupported`. Use `alert accept` or `alert dismiss` to answer the notification prompt. 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. From b88bae0e118c65402f794cca668d3ea3b38f48e3 Mon Sep 17 00:00:00 2001 From: shahjahan Date: Thu, 26 Nov 2026 17:28:43 +0500 Subject: [PATCH 2/2] fix(ios): sync Maestro help, keep the simctl refusal test on camera, mark the refusal undispatched Co-authored-by: GPT-6.2 Sol (Codex) Co-authored-by: Claude Opus 5.5 --- packages/maestro/src/internal/support-matrix.ts | 2 +- .../src/core/__tests__/app-settings.test.ts | 8 ++++---- .../src/core/__tests__/simctl-settings.test.ts | 2 +- packages/platform-apple/src/core/simctl-settings.ts | 1 + website/docs/docs/run-maestro-flows.md | 2 +- 5 files changed, 8 insertions(+), 7 deletions(-) diff --git a/packages/maestro/src/internal/support-matrix.ts b/packages/maestro/src/internal/support-matrix.ts index 7e130ab643..ef7d0192bb 100644 --- a/packages/maestro/src/internal/support-matrix.ts +++ b/packages/maestro/src/internal/support-matrix.ts @@ -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.', diff --git a/packages/platform-apple/src/core/__tests__/app-settings.test.ts b/packages/platform-apple/src/core/__tests__/app-settings.test.ts index ba44053a01..c225bff50d 100644 --- a/packages/platform-apple/src/core/__tests__/app-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/app-settings.test.ts @@ -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); @@ -626,13 +626,13 @@ 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), [ @@ -640,7 +640,7 @@ test('setIosSetting permission runs the simctl plan on the simulator udid and su 'privacy', 'sim-1', 'revoke', - 'notifications', + 'camera', 'com.example.app', ]); }, diff --git a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts index 3c7c7ae9aa..fee4149859 100644 --- a/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/simctl-settings.test.ts @@ -280,7 +280,7 @@ test.for(['grant', 'deny', 'reset'])( expect(resolveApp).not.toHaveBeenCalled(); expect(error).toMatchObject({ code: 'UNSUPPORTED_OPERATION', - details: { reason: 'ios-notification-permission-unsupported' }, + details: { reason: 'ios-notification-permission-unsupported', dispatched: 'no' }, }); expect(error.details?.hint).toContain('alert accept'); expect(error.details?.hint).toContain('alert dismiss'); diff --git a/packages/platform-apple/src/core/simctl-settings.ts b/packages/platform-apple/src/core/simctl-settings.ts index 45debbdeeb..6778fe8dd8 100644 --- a/packages/platform-apple/src/core/simctl-settings.ts +++ b/packages/platform-apple/src/core/simctl-settings.ts @@ -64,6 +64,7 @@ async function setPermission( 'iOS simulators do not support changing notification permissions through settings permission.', { reason: SIMCTL_SETTINGS_REASONS.notificationsUnsupported.reason, + dispatched: 'no', deviceId, hint: 'Use `alert accept` or `alert dismiss` to answer the notification prompt.', }, diff --git a/website/docs/docs/run-maestro-flows.md b/website/docs/docs/run-maestro-flows.md index 1a93b3f602..fdf4e5d760 100644 --- a/website/docs/docs/run-maestro-flows.md +++ b/website/docs/docs/run-maestro-flows.md @@ -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 simulators, targeting `notifications` returns `ios-notification-permission-unsupported`. Use `alert accept` or `alert dismiss` to answer the notification prompt. For `all`, `simctl privacy` determines which services the runtime can change, and current runtimes leave notifications untouched. +- 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.