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
13 changes: 12 additions & 1 deletion packages/command-surface/src/capture/settings.test.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion packages/command-surface/src/client-port.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ import type {
SessionSaveScriptOptions,
SessionSaveScriptResult,
SettingsUpdateOptions,
ModeFreePermissionUpdateOptions,
ShakeCommandOptions,
SwipeGestureOptions,
SwipeOptions,
Expand Down Expand Up @@ -253,6 +254,7 @@ export type AgentDeviceClient = {
trace: (options: TraceOptions) => Promise<CommandResult<'trace'>>;
};
settings: {
update: (options: SettingsUpdateOptions) => Promise<CommandRequestResult>;
update(options: ModeFreePermissionUpdateOptions): Promise<CommandRequestResult>;
update(options: SettingsUpdateOptions): Promise<CommandRequestResult>;
};
};
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 @@ -50,6 +50,14 @@ describe('public client permission vocabulary', () => {
expectTypeOf<Grant<'camera'> & { mode: 'limited' }>().not.toExtend<SettingsUpdateOptions>();
expectTypeOf<Grant<'accessibility'> & { mode: 'full' }>().not.toExtend<SettingsUpdateOptions>();
});

test('narrows permission options to the photos arm', () => {
expectTypeOf((options: Permission) => {
if (options.permission === 'photos') {
expectTypeOf(options).toEqualTypeOf<Extract<Permission, { permission: 'photos' }>>();
}
}).toBeFunction();
});
});

describe('public client settings cover the catalog', () => {
Expand Down
7 changes: 6 additions & 1 deletion packages/contracts/src/client-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<PermissionTarget, ModedPermissionTarget>;
mode?: never;
});

/** Call input for a permission that has not been narrowed to one target. */
export type ModeFreePermissionUpdateOptions = PermissionUpdateOptions & {
permission: PermissionTarget;
mode?: never;
};
6 changes: 5 additions & 1 deletion packages/contracts/src/facades/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/__tests__/cli-client-commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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',
Expand Down
Loading