Skip to content

Commit c4f9ca6

Browse files
committed
fix(contracts): keep the settings vocabulary module device-shape-free (#3179)
The eager-closure gate caught what the affected lane did not: importing the kernel device predicates into packages/contracts/src/settings.ts dragged the device model into a vocabulary facade the public client imports. The scope table now keys on a resolved target family, and the daemon maps the device to that family with the kernel predicates at the one call site. Refs #3179
1 parent 600cda7 commit c4f9ca6

3 files changed

Lines changed: 40 additions & 22 deletions

File tree

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,38 +338,34 @@ describe('appearance vocabulary types', () => {
338338
});
339339

340340
describe('settings app scope (#3179)', () => {
341-
const iosSimulator = { platform: 'apple' as const };
342-
const android = { platform: 'android' as const };
343-
const macHost = { platform: 'apple' as const, appleOs: 'macos' as const };
344-
345341
test.each([
346342
['permission', 'grant'],
347343
['permission', 'deny'],
348344
['permission', 'reset'],
349345
['location', 'on'],
350346
['location', 'off'],
351347
['clear-app-state', 'clear'],
352-
])('treats %s %s as app-scoped on a simulator', (setting, state) => {
353-
expect(settingsAppScope(iosSimulator, setting, state)).toBe('app-scoped');
348+
])('treats %s %s as app-scoped on the iOS family', (setting, state) => {
349+
expect(settingsAppScope('ios-family', setting, state)).toBe('app-scoped');
354350
});
355351

356352
test.each([
357353
['location', 'on'],
358354
['location', 'off'],
359355
])('treats %s %s as device-level on Android', (setting, state) => {
360-
expect(settingsAppScope(android, setting, state)).toBe('device-level');
356+
expect(settingsAppScope('other', setting, state)).toBe('device-level');
361357
});
362358

363359
test('treats Android permission as app-scoped', () => {
364-
expect(settingsAppScope(android, 'permission', 'grant')).toBe('app-scoped');
360+
expect(settingsAppScope('other', 'permission', 'grant')).toBe('app-scoped');
365361
});
366362

367363
test.each([
368364
['permission', 'grant'],
369365
['appearance', 'dark'],
370366
['location', 'on'],
371367
])('treats %s %s as device-level on the macOS host', (setting, state) => {
372-
expect(settingsAppScope(macHost, setting, state)).toBe('device-level');
368+
expect(settingsAppScope('macos', setting, state)).toBe('device-level');
373369
});
374370

375371
test.each([
@@ -384,17 +380,17 @@ describe('settings app scope (#3179)', () => {
384380
])(
385381
'treats %s %s as device-level everywhere: an unclaimed app is refused, never dropped',
386382
(setting, state) => {
387-
expect(settingsAppScope(iosSimulator, setting, state)).toBe('device-level');
388-
expect(settingsAppScope(android, setting, state)).toBe('device-level');
383+
expect(settingsAppScope('ios-family', setting, state)).toBe('device-level');
384+
expect(settingsAppScope('other', setting, state)).toBe('device-level');
389385
},
390386
);
391387

392388
test('normalizes case and padding on both the setting and the state', () => {
393-
expect(settingsAppScope(iosSimulator, ' Permission ', ' grant')).toBe('app-scoped');
389+
expect(settingsAppScope('ios-family', ' Permission ', ' grant')).toBe('app-scoped');
394390
// Only the state's normalized `set` moves an iOS on/off grant to the device-level row, so this
395391
// is the case that fails if the state stops being normalized.
396-
expect(settingsAppScope(iosSimulator, ' LOCATION ', ' SET ')).toBe('device-level');
397-
expect(settingsAppScope(iosSimulator, ' LOCATION ', ' ON ')).toBe('app-scoped');
392+
expect(settingsAppScope('ios-family', ' LOCATION ', ' SET ')).toBe('device-level');
393+
expect(settingsAppScope('ios-family', ' LOCATION ', ' ON ')).toBe('app-scoped');
398394
});
399395
});
400396

‎packages/contracts/src/settings.ts‎

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { isIosFamily, isMacOs, type DeviceInfo } from '@agent-device/kernel/device';
21
import { AppError } from '@agent-device/kernel/errors';
32

43
/**
@@ -168,27 +167,34 @@ export type SettingOptions = {
168167
*/
169168
export type SettingsAppScope = 'app-scoped' | 'device-level';
170169

170+
/**
171+
* The target family the scope table keys on. The caller resolves it with the kernel's device
172+
* predicates (`isMacOs`, `isIosFamily`) where the device shape is known; the vocabulary module
173+
* stays device-shape-free so the public client's import closure never evaluates the device model.
174+
*/
175+
export type SettingsTargetFamily = 'ios-family' | 'macos' | 'other';
176+
171177
/**
172178
* The one table deciding whether an app named on a `settings` request is consumed. It is keyed on
173179
* the target family rather than the resolved device so the daemon can answer before binding a
174180
* runtime, and it stays honest by settling only the combinations whose owner behavior is already
175181
* fixed elsewhere: `clear-app-state` is app-scoped wherever it is served, `permission` is app-scoped
176-
* on every mobile target and host-level on macOS, and on/off `location` is app-scoped only on Apple
177-
* simulators, where it maps to a privacy grant.
182+
* on every mobile target and host-level on macOS, and on/off `location` is app-scoped only on the
183+
* iOS family, where it maps to a privacy grant.
178184
*/
179185
export function settingsAppScope(
180-
device: Pick<DeviceInfo, 'platform' | 'appleOs'>,
186+
family: SettingsTargetFamily,
181187
setting: string,
182188
state: string | undefined,
183189
): SettingsAppScope {
184190
const normalizedSetting = setting.trim().toLowerCase();
185191
if (normalizedSetting === 'clear-app-state') return 'app-scoped';
186192
if (normalizedSetting === 'permission') {
187-
return isMacOs(device) ? 'device-level' : 'app-scoped';
193+
return family === 'macos' ? 'device-level' : 'app-scoped';
188194
}
189195
if (normalizedSetting === 'location') {
190196
if (state?.trim().toLowerCase() === 'set') return 'device-level';
191-
return isIosFamily(device) ? 'app-scoped' : 'device-level';
197+
return family === 'ios-family' ? 'app-scoped' : 'device-level';
192198
}
193199
return 'device-level';
194200
}

‎src/daemon/handlers/snapshot-settings.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
isApplePlatform,
33
isHandheldAppleSimulator,
4+
isIosFamily,
45
isMacOs,
56
resolveDeviceAppleOs,
67
} from '@agent-device/kernel/device';
@@ -19,6 +20,7 @@ import {
1920
type ReadableSetting,
2021
type SettingOptions,
2122
type SettingsAppRefusal,
23+
type SettingsTargetFamily,
2224
} from '@agent-device/contracts/settings';
2325
import type { SetSettingInput } from '@agent-device/contracts/settings-runtime';
2426
import {
@@ -182,7 +184,9 @@ function settingsDiagnosticData(
182184
state,
183185
permissionTarget: parsed.permissionTarget,
184186
permissionMode: parsed.permissionMode,
185-
...(settingsAppScope(device, setting, state) === 'app-scoped' ? { appBundleId } : {}),
187+
...(settingsAppScope(settingsTargetFamily(device), setting, state) === 'app-scoped'
188+
? { appBundleId }
189+
: {}),
186190
platform,
187191
};
188192
}
@@ -384,6 +388,16 @@ function settingsWriteTarget(
384388
return { explicitApp: namedApp.trim(), refusal: undefined };
385389
}
386390

391+
/**
392+
* The family the scope table keys on, resolved with the kernel's device predicates here so the
393+
* vocabulary module that owns the table stays device-shape-free.
394+
*/
395+
function settingsTargetFamily(device: SessionState['device']): SettingsTargetFamily {
396+
if (isMacOs(device)) return 'macos';
397+
if (isIosFamily(device)) return 'ios-family';
398+
return 'other';
399+
}
400+
387401
/**
388402
* The refusal for an app the CALLER named that this leg cannot use: one with no name in it (which
389403
* would otherwise land the change on the session app while the caller believes they aimed it
@@ -401,7 +415,9 @@ function settingsNamedAppRefusal(
401415
if (namedApp.trim().length === 0) {
402416
return errorFrom(settingsAppNotNamedRefusal(namedApp));
403417
}
404-
if (settingsAppScope(device, setting, state) === 'app-scoped') return undefined;
418+
if (settingsAppScope(settingsTargetFamily(device), setting, state) === 'app-scoped') {
419+
return undefined;
420+
}
405421
return errorFrom(settingsAppNotConsumedRefusal(setting, state, namedApp.trim()));
406422
}
407423

0 commit comments

Comments
 (0)