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/command-surface/src/capture/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`),
Expand Down
8 changes: 8 additions & 0 deletions packages/contracts/src/client-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ describe('public client permission vocabulary', () => {
expectTypeOf<Permission['state']>().toEqualTypeOf<'grant' | 'deny' | 'reset'>();
expectTypeOf<Permission['mode']>().toEqualTypeOf<'full' | 'limited' | undefined>();
});

test('takes a mode only with photos, the one target whose form has modes', () => {
type Grant<Target> = { setting: 'permission'; state: 'grant'; permission: Target };
expectTypeOf<Grant<'photos'> & { mode: 'limited' }>().toExtend<SettingsUpdateOptions>();
expectTypeOf<Grant<'camera'>>().toExtend<SettingsUpdateOptions>();
expectTypeOf<Grant<'camera'> & { mode: 'limited' }>().not.toExtend<SettingsUpdateOptions>();
expectTypeOf<Grant<'accessibility'> & { mode: 'full' }>().not.toExtend<SettingsUpdateOptions>();
});
});

describe('public client settings cover the catalog', () => {
Expand Down
39 changes: 25 additions & 14 deletions packages/contracts/src/client-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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<PermissionTarget, ModedPermissionTarget>;
mode?: never;
});
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/daemon/src/execution/handlers/snapshot-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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) };
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
},
);
},
Expand Down
Loading