diff --git a/packages/command-surface/src/capture/settings.test.ts b/packages/command-surface/src/capture/settings.test.ts index 7b4e5c540b..1e9ae17e6d 100644 --- a/packages/command-surface/src/capture/settings.test.ts +++ b/packages/command-surface/src/capture/settings.test.ts @@ -1,6 +1,7 @@ -import { describe, expect, test } from 'vitest'; +import { describe, expect, expectTypeOf, test } from 'vitest'; import type { CliFlags } from '@agent-device/contracts/command'; import { SETTING_NAMES, TEXT_SIZE_CATEGORIES } from '@agent-device/contracts/settings-catalog'; +import type { AgentDeviceClient } from '../client-port.ts'; import { settingsCliReader, settingsCommandFacet, settingsDaemonWriter } from './settings.ts'; function flags(): CliFlags { @@ -37,6 +38,16 @@ describe('settings CLI', () => { }); }); +test('the public settings method accepts a target union only without a mode', () => { + type Update = AgentDeviceClient['settings']['update']; + type Grant = { setting: 'permission'; permission: 'camera' | 'photos'; state: 'grant' }; + expectTypeOf((update: Update, grant: Grant) => { + void update(grant); + // @ts-expect-error A union can name a target that does not accept a mode. + void update({ ...grant, mode: 'limited' }); + }).toBeFunction(); +}); + describe('settings CLI permission', () => { test('rejects an unknown permission mode', () => { expectInvalidArgs( diff --git a/packages/command-surface/src/client-port.ts b/packages/command-surface/src/client-port.ts index d072a476c9..1e5f16e81a 100644 --- a/packages/command-surface/src/client-port.ts +++ b/packages/command-surface/src/client-port.ts @@ -80,6 +80,7 @@ import type { SessionSaveScriptOptions, SessionSaveScriptResult, SettingsUpdateOptions, + ModeFreePermissionUpdateOptions, ShakeCommandOptions, SwipeGestureOptions, SwipeOptions, @@ -253,6 +254,7 @@ export type AgentDeviceClient = { trace: (options: TraceOptions) => Promise>; }; settings: { - update: (options: SettingsUpdateOptions) => Promise; + update(options: ModeFreePermissionUpdateOptions): Promise; + update(options: SettingsUpdateOptions): Promise; }; }; diff --git a/packages/contracts/src/client-settings.test.ts b/packages/contracts/src/client-settings.test.ts index 4599ea3185..800a8341c2 100644 --- a/packages/contracts/src/client-settings.test.ts +++ b/packages/contracts/src/client-settings.test.ts @@ -50,6 +50,14 @@ describe('public client permission vocabulary', () => { expectTypeOf & { mode: 'limited' }>().not.toExtend(); expectTypeOf & { mode: 'full' }>().not.toExtend(); }); + + test('narrows permission options to the photos arm', () => { + expectTypeOf((options: Permission) => { + if (options.permission === 'photos') { + expectTypeOf(options).toEqualTypeOf>(); + } + }).toBeFunction(); + }); }); describe('public client settings cover the catalog', () => { diff --git a/packages/contracts/src/client-settings.ts b/packages/contracts/src/client-settings.ts index 8759711c28..f2c3b9756a 100644 --- a/packages/contracts/src/client-settings.ts +++ b/packages/contracts/src/client-settings.ts @@ -96,8 +96,13 @@ export type SettingsUpdateOptions = 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; }); + +/** Call input for a permission that has not been narrowed to one target. */ +export type ModeFreePermissionUpdateOptions = PermissionUpdateOptions & { + permission: PermissionTarget; + mode?: never; +}; diff --git a/packages/contracts/src/facades/client.ts b/packages/contracts/src/facades/client.ts index a71a2b4589..8d69b01398 100644 --- a/packages/contracts/src/facades/client.ts +++ b/packages/contracts/src/facades/client.ts @@ -117,7 +117,11 @@ export type { SessionSaveScriptOptions, SessionSaveScriptResult, } from '../client-session.ts'; -export type { PermissionTarget, SettingsUpdateOptions } from '../client-settings.ts'; +export type { + ModeFreePermissionUpdateOptions, + PermissionTarget, + SettingsUpdateOptions, +} from '../client-settings.ts'; export type { AlertCommandOptions, AppStateCommandOptions, diff --git a/src/__tests__/cli-client-commands.test.ts b/src/__tests__/cli-client-commands.test.ts index 4ab0fd8cc3..c34028667c 100644 --- a/src/__tests__/cli-client-commands.test.ts +++ b/src/__tests__/cli-client-commands.test.ts @@ -9,6 +9,7 @@ import type { AgentDeviceClient } from '@agent-device/command-surface'; import type { AppInstallFromSourceOptions, AppOpenOptions, + ModeFreePermissionUpdateOptions, SettingsUpdateOptions, } from '@agent-device/contracts/client'; import type { MetroPrepareOptions, MetroReloadOptions } from '@agent-device/contracts/remote'; @@ -892,7 +893,7 @@ test('install prints command-owned success output in human mode', async () => { }); test('settings location set forwards coordinates to client settings update', async () => { - let observed: SettingsUpdateOptions | undefined; + let observed: SettingsUpdateOptions | ModeFreePermissionUpdateOptions | undefined; const client = createStubClient({ installFromSource: async () => ({ launchTarget: 'com.example.demo',