diff --git a/packages/command-surface/src/capture/settings.ts b/packages/command-surface/src/capture/settings.ts index 464b02e14c..530d7ae443 100644 --- a/packages/command-surface/src/capture/settings.ts +++ b/packages/command-surface/src/capture/settings.ts @@ -105,7 +105,7 @@ export const settingsCommandFacet = defineCommandFacet({ cliDetail: [ 'A bare readable setting reads the value the target holds. A target that does not serve a setting refuses it with UNSUPPORTED_OPERATION before anything changes.', '', - 'On an iOS simulator, settings wifi and settings airplane wait for screenshots and other status bar writes. The request timeout includes this wait (90 seconds for a standalone CLI request). Once the write starts, its status bar command has a separate 10-second timeout. A request or write that times out may already have changed the bar; check the bar before relying on it. Cancelling while still queued guarantees nothing was written.', + "On an iOS simulator, settings wifi and settings airplane change only the status bar; the simulator keeps using the host Mac's network, so they cannot test offline behavior. They wait for screenshots and other status bar writes. The request timeout includes this wait (90 seconds for a standalone CLI request). Once the write starts, its status bar command has a separate 10-second timeout. A request or write that times out may already have changed the bar; check the bar before relying on it. Cancelling while still queued guarantees nothing was written.", '', 'Settings:', ...settingsHelpLines().map((line) => ` ${line}`), diff --git a/packages/contracts/src/client-settings.test.ts b/packages/contracts/src/client-settings.test.ts index faacb34c2b..4599ea3185 100644 --- a/packages/contracts/src/client-settings.test.ts +++ b/packages/contracts/src/client-settings.test.ts @@ -42,6 +42,14 @@ describe('public client permission vocabulary', () => { expectTypeOf().toEqualTypeOf<'grant' | 'deny' | 'reset'>(); expectTypeOf().toEqualTypeOf<'full' | 'limited' | undefined>(); }); + + test('takes a mode only with photos, the one target whose form has modes', () => { + type Grant = { setting: 'permission'; state: 'grant'; permission: Target }; + expectTypeOf & { mode: 'limited' }>().toExtend(); + expectTypeOf>().toExtend(); + expectTypeOf & { mode: 'limited' }>().not.toExtend(); + expectTypeOf & { mode: 'full' }>().not.toExtend(); + }); }); describe('public client settings cover the catalog', () => { diff --git a/packages/contracts/src/client-settings.ts b/packages/contracts/src/client-settings.ts index 102b034243..8759711c28 100644 --- a/packages/contracts/src/client-settings.ts +++ b/packages/contracts/src/client-settings.ts @@ -54,6 +54,26 @@ type DeviceLevelToggleOptions = { }; }[DeviceLevelToggleSetting]; +/** The permission targets whose catalog form declares `modes`; no other target takes a mode. */ +type ModedPermissionTarget = Extract< + (typeof SETTINGS)['permission']['forms'][number], + { modes: readonly string[] } +>['targets'][number]; + +type PermissionUpdateOptions = DeviceCommandBaseOptions & { + setting: 'permission'; + state: PermissionAction; + /** + * The app the permission changes, by bundle id, package name, or app name, resolved as `open` + * resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an + * installed bundle id, and Android accepts only an installed package and refuses a name that + * resolves to an intent with `setting_app_not_package`. Without it the session app is used; + * no app has to be running or open. macOS permissions are host-level TCC grants, so naming an + * app there is refused. + */ + app?: string; +}; + export type SettingsUpdateOptions = | StateOnlySettingOptions | DeviceLevelToggleOptions @@ -75,18 +95,9 @@ export type SettingsUpdateOptions = longitude: number; app?: string; }) - | (DeviceCommandBaseOptions & { - setting: 'permission'; - state: PermissionAction; - permission: PermissionTarget; - mode?: PermissionMode; - /** - * The app the permission changes, by bundle id, package name, or app name, resolved as `open` - * resolves it: an iOS simulator, local or Limrun, matches display names and accepts only an - * installed bundle id, and Android accepts only an installed package and refuses a name that - * resolves to an intent with `setting_app_not_package`. Without it the session app is used; - * no app has to be running or open. macOS permissions are host-level TCC grants, so naming an - * app there is refused. - */ - app?: string; + | (PermissionUpdateOptions & { permission: ModedPermissionTarget; mode?: PermissionMode }) + /** Every other target refuses a mode at runtime, so the type refuses it too. */ + | (PermissionUpdateOptions & { + permission: Exclude; + mode?: never; }); diff --git a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts index 5c5ec6890d..caf08db492 100644 --- a/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts +++ b/packages/daemon/src/execution/handlers/__tests__/snapshot-settings-handler.test.ts @@ -392,6 +392,35 @@ test('settings usage hint documents canonical faceid states', async () => { } }); +// Positionals sent straight to the daemon skip the CLI reader, so the parse refusal must keep its +// typed details and --app hint on this route too. +test('settings permission with an app id in the mode slot keeps the --app hint', async () => { + const sessionStore = makeSessionStore(); + const response = await handleSnapshotCommands({ + createCommandSurface: fakeCreateCommandSurface, + platformServices: daemonPlatformServicesFixture(), + req: snapshotRequest('default', 'settings', { + positionals: ['permission', 'deny', 'notifications', 'com.example.app'], + }), + sessionName: 'default', + logPath: '/tmp/daemon.log', + sessionStore, + }); + + expect(response?.ok).toBe(false); + expect(fixtureSettingsMutations).toHaveLength(0); + if (response && !response.ok) { + expect(response.error.code).toBe('INVALID_ARGS'); + expect(response.error.hint).toBe('Pass the app with --app com.example.app.'); + expect(response.error.details).toMatchObject({ + reason: 'setting_permission_app_positional', + dispatched: 'no', + permission: 'notifications', + app: 'com.example.app', + }); + } +}); + // #3179: an app-scoped change can name an app the session never opened. The app rides the request // input; the owner receives it as the resolved app id whether or not a session is bound. test('settings permission grant targets an explicit app with no session app bound', async () => { diff --git a/packages/daemon/src/execution/handlers/snapshot-settings.ts b/packages/daemon/src/execution/handlers/snapshot-settings.ts index 22e53771aa..56b1befa2d 100644 --- a/packages/daemon/src/execution/handlers/snapshot-settings.ts +++ b/packages/daemon/src/execution/handlers/snapshot-settings.ts @@ -30,7 +30,7 @@ import { recordSessionAction } from '../../core/session-action-recorder.ts'; import { expireRefFrame } from '../../core/ref-frame.ts'; import { emitDiagnostic } from '@agent-device/host-kit/diagnostics'; import { readLocationCoordinate } from '@agent-device/kernel/location-coordinates'; -import { AppError, sessionAppRequiredDetails } from '@agent-device/kernel/errors'; +import { AppError, normalizeError, sessionAppRequiredDetails } from '@agent-device/kernel/errors'; import { successText, withSuccessText } from '@agent-device/kernel/success-text'; import type { @@ -74,7 +74,7 @@ export function parseSettingsArgs( return { ok: true, parsed: { leg: 'write', args: parseSettingsMutation(positionals) } }; } catch (error) { if (!(error instanceof AppError)) throw error; - return errorResponse(error.code, error.message); + return { ok: false, error: normalizeError(error) }; } } 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 e370699865..ba44053a01 100644 --- a/packages/platform-apple/src/core/__tests__/app-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/app-settings.test.ts @@ -573,6 +573,8 @@ test.for([ ); assert.ok(Array.isArray(result?.warnings)); assert.equal(result.warnings.length, 1); + assert.match(result.warnings[0], new RegExp(`^settings ${setting} `)); + assert.match(result.warnings[0], /status bar/); }, ); },