Skip to content
Closed
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/contracts/src/settings-catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ export const SETTINGS = {
],
app: 'input',
appScope: { apple: 'app-scoped', mobile: 'app-scoped', 'macos-host': 'device-level' },
help: 'Changes a permission of the --app app or the session app. An iOS simulator, local or Limrun, resolves --app to an installed bundle id or display name, and Android to an installed package. On Android, deny|reset of a held permission kills a running app; the response reports priorGrantState and warns, and open <app> --relaunch restores it. Android needs a resolvable foreground user and changes nothing without one. On the macOS host, grant|reset change the host TCC grants for the three desktop targets and take no --app.',
help: 'Changes a permission of the --app app or the session app. An iOS simulator, local or Limrun, resolves --app to an installed bundle id or display name, and Android to an installed package. On an iOS simulator, a notifications change restarts SpringBoard and brings back the app if it was running, fresh if iOS ended it. On Android, deny|reset of a held permission kills a running app; the response reports priorGrantState and warns, and open <app> --relaunch restores it. Android needs a resolvable foreground user and changes nothing without one. On the macOS host, grant|reset change the host TCC grants for the three desktop targets and take no --app.',
},
} as const satisfies Record<string, SettingDefinition>;

Expand Down
4 changes: 2 additions & 2 deletions packages/maestro/src/internal/support-matrix.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export const MAESTRO_COMPAT_SUPPORTED_CAPABILITIES = [
'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants, denials, and resets; all resolves in the backend — each simctl privacy service on iOS, the declared permissions on Android — with specific entries overriding after it); runFlow file/inline; runFlow.when and repeat.while conditions (platform, visible, notVisible, and true, all re-evaluated before every repeat iteration); onFlowStart/onFlowComplete; repeat with times, while, or both; and retry.',
'Flows: launchApp (with clearState, permissions, and Apple-only launch arguments; permissions apply after state clearing but before launch, and a launchApp without permissions touches nothing — there is no silent all: allow default); setPermissions (mid-flow permission grants, denials, and resets; all resolves in the backend — each simctl privacy service and notifications on iOS, the declared permissions on Android — with specific entries overriding after it); runFlow file/inline; runFlow.when and repeat.while conditions (platform, visible, notVisible, and true, all re-evaluated before every repeat iteration); onFlowStart/onFlowComplete; repeat with times, while, or both; and retry.',
'Interactions: tapOn, doubleTapOn, longPressOn, inputText on the focused element, eraseText (up to 10000 characters), openLink, hideKeyboard, basic pressKey, and back; selector targets poll until available and support recursive index, childOf, above, below, leftOf, rightOf, containsChild, containsDescendants, points, and optional; outer command labels are metadata, not target selectors.',
'Assertions and navigation: assertVisible, assertNotVisible, assertTrue (literal values and ${VAR} lookups only; "", "false", "0", "null", and "undefined" are falsy, everything else is truthy), extendedWaitUntil, scroll, scrollUntilVisible, absolute/percentage/target swipe, takeScreenshot, waitForAnimationToEnd, clearState, stopApp, and killApp (system-initiated process death: am kill on ADB-backed Android devices, which refuse a foreground target with android-kill-requires-background-app — background the app first, for example pressKey: Home — and fail a target whose process survives with android-kill-process-survived; iOS, Limrun, and WebDriver-provider backends run it as stopApp).',
'Scripts: ordered runScript file/env scripts with http.post, json, and output variables; evalScript inline expressions run flow-scoped JavaScript and write output.* leaves for later steps.',
] as const;

export const MAESTRO_COMPAT_LIMITATIONS = [
'On the native iOS runner, use tapOn on a visible dismissal control. If the app supports drag dismissal, use a swipe that stays above the keyboard.',
'Permissions: every entry is one settings permission call, applied in order with all first; the step stops at the first entry the selected platform refuses, earlier entries stay applied, and the error names what landed. Android’s only allow level is while-in-use, so location: inuse and location: never mean allow and deny there, while location: always and photos: limited are Apple-only and fail. On iOS, which service a runtime changes is simctl privacy’s own verdict: current runtimes refuse a targeted notifications change and leave notifications untouched under all.',
'Permissions: every entry is one settings permission call, applied in order with all first; the step stops at the first entry the selected platform refuses, earlier entries stay applied, and the error names what landed. Android’s only allow level is while-in-use, so location: inuse and location: never mean allow and deny there, while location: always and photos: limited are Apple-only and fail. On iOS, which service a runtime changes is simctl privacy’s own verdict. Notifications are written to SpringBoard’s notification settings instead, which restarts SpringBoard and brings back an app that was running, fresh if iOS ended it.',
'Runtime: iOS and Android only; launchApp.clearState and standalone clearState support Android and iOS simulators, launch arguments are Apple-only (a map-form argument key gains a leading - unless its value is a boolean, as in Maestro), and other standalone device utility/state commands are unsupported.',
'Expressions: evalScript and condition true: fields (runFlow.when and repeat.while share one evaluator) are evaluated as JavaScript (flow env and prior output leaves are string-typed); a true: field that is a boolean, a maestro.platform comparison, or plain literal text after ${VAR} lookups is decided without JavaScript, with the assertTrue falsy table for literal text. Other fields stay literal or ${VAR} lookup-only — assertTrue supports literals and bare lookups, and other expression-shaped payloads fail loud.',
'Environment: flow env is the default, AD_VAR_* overrides it, and CLI -e KEY=VALUE wins over both; override keys follow the flow variable grammar (mixed case and dots allowed), and AD_* stays reserved.',
Expand Down
17 changes: 17 additions & 0 deletions packages/platform-apple/src/core/__tests__/app-resolution.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,23 @@ test('detectSoleRunningIosSimulatorApp cross-references launchctl against instal
});
});

test('detectSoleRunningIosSimulatorApp counts an app job that launchctl lists without a process', async () => {
mockRunSimctl.mockImplementation(async (args: string[]) => {
if (args[0] === 'spawn') {
return {
exitCode: 0,
stdout: 'PID\tStatus\tLabel\n-\t0\tUIKitApplication:com.example.demo[abcd][rb-legacy]',
};
}
return { stdout: JSON.stringify({ 'com.example.demo': { CFBundleDisplayName: 'Demo' } }) };
});

assert.deepEqual(await detectSoleRunningIosSimulatorApp(bootedSimulator), {
bundleId: 'com.example.demo',
name: 'Demo',
});
});

test('detectSoleRunningIosSimulatorApp refuses to guess between two running apps', async () => {
mockLaunchctlAndListapps(['com.apple.Preferences', 'com.example.demo']);

Expand Down
94 changes: 90 additions & 4 deletions packages/platform-apple/src/core/__tests__/app-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ import { retryWithPolicy } from '@agent-device/host-kit/retry';
import { assertRejectsAppError } from '../../__tests__/app-error.ts';
import { withFakeAppleTool, type FakeAppleToolResponse } from '../../__tests__/fake-apple-tool.ts';
import { IOS_TEST_SIMULATOR, MACOS_TEST_DEVICE } from './apple-core-stub-helpers.ts';
import { build as buildPlist, parse as parsePlist } from 'plist';
import {
SIMULATOR_NOTIFICATION_REASONS,
SIMULATOR_NOTIFICATION_SETTINGS_FILE,
} from '../simulator-notification-permission.ts';

bindTestCommandHost();

Expand Down Expand Up @@ -612,7 +617,7 @@ test('setIosSetting permission runs the simctl plan on the simulator udid and su
await withFakeAppleTool(
(args) => {
if (isSimctlListApps(args)) return INSTALLED_APPS_JSON;
if (args.join(' ') === 'simctl privacy sim-1 revoke notifications com.example.app') {
if (args.join(' ') === 'simctl privacy sim-1 revoke siri com.example.app') {
return { stderr: 'Failed to revoke access\nOperation not permitted', exitCode: 1 };
}
return unexpectedArgs(args);
Expand All @@ -626,27 +631,108 @@ test('setIosSetting permission runs the simctl plan on the simulator udid and su
'deny',
'com.example.app',
{
permissionTarget: 'notifications',
permissionTarget: 'siri',
},
process.env,
),
{
code: 'UNSUPPORTED_OPERATION',
message: /does not support setting notifications permission/i,
message: /does not support setting siri permission/i,
},
);
assert.deepEqual(calls.at(-1), [
'simctl',
'privacy',
'sim-1',
'revoke',
'notifications',
'siri',
'com.example.app',
]);
},
);
});

/** A simulator set holding sim-1 with a notification settings file in SpringBoard's layout. */
async function simulatorSetWithNotificationSettings(): Promise<{ set: string; file: string }> {
const set = await mkdtempForTest('agent-device-ios-notification-set-');
const file = path.join(set, 'sim-1/data', SIMULATOR_NOTIFICATION_SETTINGS_FILE);
await fs.mkdir(path.dirname(file), { recursive: true });
await fs.writeFile(file, buildPlist({ sectionInfo: {}, sectionInfoVersionNumber: 3 }));
return { set, file };
}

test('setIosSetting notifications writes the settings file of the simulator on this host', async () => {
mockEnsureBootedSimulator.mockResolvedValue(undefined);
const { set, file } = await simulatorSetWithNotificationSettings();
const simctl: string[][] = [];
// `launchctl list` shows SpringBoard's process between its stop and its start.
let springBoardPid = '1';
mockRunCmd.mockImplementation(async (cmd, args) => {
assert.equal(cmd, 'xcrun');
const unscoped = args.slice(args.indexOf('--set') + 2);
simctl.push(unscoped);
const command = unscoped.join(' ');
if (command === 'spawn sim-1 launchctl stop com.apple.SpringBoard') springBoardPid = '-';
if (command === 'spawn sim-1 launchctl start com.apple.SpringBoard') springBoardPid = '2';
const stdout =
command === 'listapps sim-1'
? INSTALLED_APPS_JSON
: command === 'spawn sim-1 launchctl list'
? `${springBoardPid}\t0\tcom.apple.SpringBoard`
: '';
return { stdout, stderr: '', exitCode: 0 };
});

const result = await setIosSetting(
{ ...IOS_TEST_SIMULATOR, simulatorSetPath: set },
'permission',
'grant',
'Example',
{ permissionTarget: 'notifications' },
process.env,
);

assert.equal(result?.permission, 'notifications');
const store = parsePlist(await fs.readFile(file, 'utf8')) as {
sectionInfo: Record<string, Uint8Array>;
};
assert.deepEqual(Object.keys(store.sectionInfo), ['com.example.app']);
assert.ok(
simctl.some((args) => args.join(' ') === 'spawn sim-1 launchctl start com.apple.SpringBoard'),
);
});

test('setIosSetting notifications refuses a simulator a scoped tool provider runs', async () => {
mockEnsureBootedSimulator.mockResolvedValue(undefined);
const { set, file } = await simulatorSetWithNotificationSettings();
const before = await fs.readFile(file);

const tool = (args: string[]) =>
installedAppsTool(args.filter((arg) => arg !== '--set' && arg !== set));
await withFakeAppleTool(tool, async ({ calls }) => {
await assertRejectsAppError(
() =>
setIosSetting(
{ ...IOS_TEST_SIMULATOR, simulatorSetPath: set },
'permission',
'grant',
'com.example.app',
{ permissionTarget: 'notifications' },
process.env,
),
{
code: 'UNSUPPORTED_OPERATION',
reason: SIMULATOR_NOTIFICATION_REASONS.unreachable.reason,
},
);
assert.equal(
calls.some((args) => args.includes('launchctl')),
false,
);
});
assert.deepEqual(await fs.readFile(file), before);
});

function installedAppsTool(args: string[]): FakeAppleToolResponse {
if (isSimctlListApps(args)) return INSTALLED_APPS_JSON;
if (args[0] === 'simctl' && args[1] === 'privacy') return '';
Expand Down
37 changes: 37 additions & 0 deletions packages/platform-apple/src/core/__tests__/launchctl-jobs.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { expect, test } from 'vitest';
import { readLaunchctlJobs, uiKitApplicationBundleId } from '../launchctl-jobs.ts';

test('a launchctl list row reads as its label and pid, with no pid for a job without a process', () => {
const output = [
'PID\tStatus\tLabel',
'-\t0\tcom.apple.cfprefsd',
'412\t0\tcom.apple.SpringBoard',
'0\t0\tcom.apple.zero',
'1.5\t0\tcom.apple.fraction',
'',
' 98 -9 UIKitApplication:com.example.app[1a2b][rb-legacy] ',
'truncated',
].join('\n');

expect(readLaunchctlJobs(output)).toEqual([
{ label: 'Label', pid: undefined },
{ label: 'com.apple.cfprefsd', pid: undefined },
{ label: 'com.apple.SpringBoard', pid: 412 },
{ label: 'com.apple.zero', pid: undefined },
{ label: 'com.apple.fraction', pid: undefined },
{ label: 'UIKitApplication:com.example.app[1a2b][rb-legacy]', pid: 98 },
]);
});

test.for([
{ label: 'UIKitApplication:com.example.app[1a2b][rb-legacy]', bundleId: 'com.example.app' },
{
label: 'UIKitApplication:com.example.app.beta[ff][rb-legacy]',
bundleId: 'com.example.app.beta',
},
{ label: 'UIKitApplication:com.example.app', bundleId: undefined },
{ label: 'com.apple.SpringBoard', bundleId: undefined },
{ label: 'x.UIKitApplication:com.example.app[1a2b]', bundleId: undefined },
])('$label names the app $bundleId', ({ label, bundleId }) => {
expect(uiKitApplicationBundleId(label)).toBe(bundleId);
});
Loading
Loading