Skip to content

Commit 68dac57

Browse files
committed
refactor(maestro): keep permission support in the backends
The Maestro adapter held a second copy of what each backend serves (per-platform admission lists plus hints), which is what let the hint and admission disagree. - Map Maestro names and values to `settings permission` mutations in the projection module, with a Maestro-only name table. Each backend refuses the targets it does not serve with its own hint. No lazy import, no contracts edge, no MAESTRO_PERMISSION_VALUES export from the package index. - Drop IOS_/ANDROID_/MAESTRO_ANDROID_/MAESTRO_IOS_PERMISSION_TARGETS from contracts. Android keeps its target list next to its table; iOS maps every target through one exhaustive simctl service table. - The runtime port only lowercases values; the parser checks literal values and the adapter checks each value against its permission after ${VAR} lookups. - One `dumpsys package` reader for every Android permission path. - Android refuses any permission mode with an accurate message.
1 parent a7131ca commit 68dac57

15 files changed

Lines changed: 234 additions & 592 deletions

‎packages/contracts/src/settings.test.ts‎

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
import { describe, expect, expectTypeOf, test } from 'vitest';
22
import {
3-
ANDROID_PERMISSION_TARGETS,
43
getUnsupportedMacOsSettingMessage,
5-
IOS_PERMISSION_TARGETS,
64
isMacOsSettingSupported,
75
MACOS_PERMISSION_TARGETS,
8-
MAESTRO_ANDROID_PERMISSION_TARGETS,
9-
MAESTRO_IOS_PERMISSION_TARGETS,
106
MOBILE_PERMISSION_TARGETS,
117
parsePermissionAction,
128
parsePermissionTarget,
@@ -92,47 +88,6 @@ describe('the declared permission vocabulary', () => {
9288
expect([...PERMISSION_ACTIONS]).toEqual(['grant', 'deny', 'reset']);
9389
expect([...PERMISSION_MODES]).toEqual(['full', 'limited']);
9490
});
95-
96-
test('per-platform targets stay subsets of the accepted vocabulary', () => {
97-
expect([...IOS_PERMISSION_TARGETS]).toEqual([...MOBILE_TARGETS]);
98-
expect([...ANDROID_PERMISSION_TARGETS]).toEqual([
99-
'all',
100-
'camera',
101-
'microphone',
102-
'photos',
103-
'contacts',
104-
'notifications',
105-
'calendar',
106-
'location',
107-
'media-library',
108-
]);
109-
for (const target of ANDROID_PERMISSION_TARGETS) {
110-
expect(MOBILE_TARGETS).toContain(target);
111-
}
112-
});
113-
114-
test('Maestro admission sets are explicit allowlists, not native denylists', () => {
115-
expect([...MAESTRO_ANDROID_PERMISSION_TARGETS]).toEqual([...ANDROID_PERMISSION_TARGETS]);
116-
expect([...MAESTRO_IOS_PERMISSION_TARGETS]).toEqual([
117-
'all',
118-
'camera',
119-
'microphone',
120-
'photos',
121-
'contacts',
122-
'notifications',
123-
'calendar',
124-
'location',
125-
'media-library',
126-
'motion',
127-
'reminders',
128-
'siri',
129-
]);
130-
for (const target of MAESTRO_IOS_PERMISSION_TARGETS) {
131-
expect(MOBILE_TARGETS).toContain(target);
132-
}
133-
expect(MAESTRO_IOS_PERMISSION_TARGETS).not.toContain('contacts-limited');
134-
expect(MAESTRO_IOS_PERMISSION_TARGETS).not.toContain('location-always');
135-
});
13691
});
13792

13893
describe('settings usage and error strings', () => {

‎packages/contracts/src/settings.ts‎

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -37,59 +37,9 @@ export const MACOS_PERMISSION_TARGETS = [
3737
'input-monitoring',
3838
] as const;
3939

40-
/**
41-
* The names each mobile backend serves individually (`all` travels as one
42-
* backend call and resolves there). iOS serves the whole mobile vocabulary;
43-
* Android serves the subset below. Declared once so the Android table, the
44-
* Maestro adapter lists, and the hint text cannot drift from each other —
45-
* which is what left `bluetooth`/`phone`/`sms`/`storage` advertised but
46-
* unreachable.
47-
*/
48-
export const IOS_PERMISSION_TARGETS = MOBILE_PERMISSION_TARGETS;
49-
50-
export const ANDROID_PERMISSION_TARGETS = [
51-
'all',
52-
'camera',
53-
'microphone',
54-
'photos',
55-
'contacts',
56-
'notifications',
57-
'calendar',
58-
'location',
59-
'media-library',
60-
] as const;
61-
62-
/**
63-
* The Maestro `setPermissions` names each platform accepts. An explicit
64-
* allowlist on purpose: the native `settings permission` vocabulary may grow
65-
* a target Maestro never names (today `contacts-limited` and
66-
* `location-always`, whose Maestro spellings are `photos: limited` and
67-
* `location: always`), and that target must not become a Maestro name
68-
* without a deliberate decision here. The daemon adapter derives both its
69-
* admission set and its unsupported-name hint from these lists, so the two
70-
* cannot disagree.
71-
*/
72-
export const MAESTRO_ANDROID_PERMISSION_TARGETS = ANDROID_PERMISSION_TARGETS;
73-
74-
export const MAESTRO_IOS_PERMISSION_TARGETS = [
75-
'all',
76-
'camera',
77-
'microphone',
78-
'photos',
79-
'contacts',
80-
'notifications',
81-
'calendar',
82-
'location',
83-
'media-library',
84-
'motion',
85-
'reminders',
86-
'siri',
87-
] as const;
88-
8940
export type PermissionAction = (typeof PERMISSION_ACTIONS)[number];
9041
export type PermissionMode = (typeof PERMISSION_MODES)[number];
9142
export type MobilePermissionTarget = (typeof MOBILE_PERMISSION_TARGETS)[number];
92-
export type AndroidPermissionTarget = (typeof ANDROID_PERMISSION_TARGETS)[number];
9343
/**
9444
* The app-scoped vocabulary `parsePermissionTarget` returns. The public client's `PermissionTarget`
9545
* in `client-settings.ts` is wider: it also names the macOS targets.

‎packages/maestro/src/daemon-port/__tests__/daemon-runtime-port-set-permissions.test.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ test('launchApp with rejected permissions launches nothing', async () => {
161161
env: {},
162162
invalidateObservation() {},
163163
}),
164-
).rejects.toThrow(/health.*not supported on android/i);
164+
).rejects.toThrow(/health.*not supported/i);
165165
expect(requests).toEqual([]);
166166
});
167167

‎packages/maestro/src/daemon-port/__tests__/daemon-runtime-public-operation.test.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { buildGesturePlan } from '@agent-device/contracts/gesture-plan';
44
import assert from 'node:assert/strict';
55
import { describe, expect, test } from 'vitest';
66
import {
7+
mapMaestroSetPermissions,
78
projectMaestroPublicOperation,
89
type MaestroPublicOperation,
910
} from '../daemon-runtime-public-operation.ts';
@@ -250,3 +251,67 @@ describe('Maestro public operation projection', () => {
250251
assert.equal(plan.durationMs, 400);
251252
});
252253
});
254+
255+
describe('Maestro setPermissions mapping', () => {
256+
test('maps plain values and sends all first so specific entries override it', () => {
257+
expect(
258+
mapMaestroSetPermissions({ notifications: 'unset', ALL: 'deny', camera: 'allow' }),
259+
).toEqual([
260+
{ state: 'deny', permission: 'all' },
261+
{ state: 'reset', permission: 'notifications' },
262+
{ state: 'grant', permission: 'camera' },
263+
]);
264+
});
265+
266+
test('maps the granular values and the medialibrary spelling', () => {
267+
expect(
268+
mapMaestroSetPermissions({
269+
location: 'always',
270+
photos: 'limited',
271+
medialibrary: 'allow',
272+
}),
273+
).toEqual([
274+
{ state: 'grant', permission: 'location-always' },
275+
{ state: 'grant', permission: 'photos', mode: 'limited' },
276+
{ state: 'grant', permission: 'media-library' },
277+
]);
278+
expect(mapMaestroSetPermissions({ location: 'inuse' })).toEqual([
279+
{ state: 'grant', permission: 'location' },
280+
]);
281+
expect(mapMaestroSetPermissions({ location: 'never' })).toEqual([
282+
{ state: 'deny', permission: 'location' },
283+
]);
284+
});
285+
286+
test.each([
287+
'bluetooth',
288+
'speech',
289+
'health',
290+
'contacts-limited',
291+
'location-always',
292+
'constructor',
293+
'android.permission.MANAGE_EXTERNAL_STORAGE',
294+
])('refuses the name %s before any mutation', (name) => {
295+
expect(() => mapMaestroSetPermissions({ camera: 'allow', [name]: 'allow' })).toThrow(
296+
expect.objectContaining({
297+
code: 'UNSUPPORTED_OPERATION',
298+
message: `Maestro permission "${name.toLowerCase()}" is not supported.`,
299+
}),
300+
);
301+
});
302+
303+
test.each([
304+
['camera', 'always', 'Use allow|deny|unset.'],
305+
['all', 'never', 'Use allow|deny|unset.'],
306+
['photos', 'always', 'Use allow|deny|unset|limited.'],
307+
['location', 'toString', 'Use allow|deny|unset|always|inuse|never.'],
308+
])('refuses %s: %s', (name, value, hint) => {
309+
expect(() => mapMaestroSetPermissions({ [name]: value })).toThrow(
310+
expect.objectContaining({ code: 'INVALID_ARGS', details: { hint } }),
311+
);
312+
});
313+
314+
test('refuses an empty map', () => {
315+
expect(() => mapMaestroSetPermissions({})).toThrow(/at least one permission/);
316+
});
317+
});

0 commit comments

Comments
 (0)