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
28 changes: 28 additions & 0 deletions packages/platform-apple/src/core/__tests__/app-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,34 @@ test('setIosSetting reset-keychain resets the whole simulator keychain', async (
);
});

test.for([
['wifi', 'off'],
['airplane', 'on'],
] as const)(
'setIosSetting %s %s warns that only the status bar changed',
async ([setting, state]) => {
await withFakeAppleTool(
(args) => {
if (isSimctlListDevices(args)) return BOOTED_SIM_LIST_JSON;
if (args[0] === 'simctl' && args[1] === 'status_bar') return '';
return unexpectedArgs(args);
},
async () => {
const result = await setIosSetting(
IOS_TEST_SIMULATOR,
setting,
state,
undefined,
undefined,
process.env,
);
assert.ok(Array.isArray(result?.warnings));
assert.equal(result.warnings.length, 1);
},
);
},
);

test('setIosSetting reset-keychain rejects unsupported state', async () => {
await withFakeAppleTool(
(args) => {
Expand Down
13 changes: 11 additions & 2 deletions packages/platform-apple/src/core/app-settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ const APPLE_SIMULATOR_SETTINGS = [

export type AppleSimulatorSetting = (typeof APPLE_SIMULATOR_SETTINGS)[number];

/** `simctl` has no network switch, so these settings only redraw the status bar. */
function statusBarOnlyWarnings(setting: 'wifi' | 'airplane'): { warnings: string[] } {
return {
warnings: [
`settings ${setting} changes only the simulator status bar; the simulator keeps using the host Mac's network.`,
],
};
}

// fallow-ignore-next-line complexity
export async function setIosSetting(
device: DeviceInfo,
Expand Down Expand Up @@ -118,7 +127,7 @@ export async function setIosSetting(
},
signal,
);
return;
return statusBarOnlyWarnings('wifi');
}
case 'airplane': {
const enabled = parseSettingState(state);
Expand Down Expand Up @@ -161,7 +170,7 @@ export async function setIosSetting(
},
signal,
);
return;
return statusBarOnlyWarnings('airplane');
}
case 'faceid':
case 'touchid': {
Expand Down
29 changes: 25 additions & 4 deletions packages/platform-apple/src/foldable/fold-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,27 @@ test.each([
});

test.each([
['setPose', (helper: FoldHelper) => helper.setPose('open'), 'fold-hid-dispatch-failed'],
['readHingeAngle', (helper: FoldHelper) => helper.readHingeAngle(), 'fold-hinge-angle-no-sample'],
['setPose', (helper: FoldHelper) => helper.setPose('open'), 'fold-hid-dispatch-failed', {}],
[
'readHingeAngle',
(helper: FoldHelper) => helper.readHingeAngle(),
'fold-hinge-angle-no-sample',
{},
],
[
'readPanelPayload',
(helper: FoldHelper) => helper.readPanelPayload({ timeoutMs: 5000 }),
'fold-helper-panels-unreadable',
{},
],
// The rotation can land after the deadline, so the refusal discloses an unknown dispatch.
[
'rotate',
(helper: FoldHelper) => helper.rotate('landscape-left'),
'orientation-hid-dispatch-timed-out',
{ dispatched: 'unknown' },
],
] as const)('%s maps a helper timeout to its typed reason', async (_mode, use, reason) => {
] as const)('%s maps a helper timeout to its typed reason', async (_mode, use, reason, extra) => {
const value = await withAppleToolProvider(
createLocalAppleToolProvider({
runCommand: async () => {
Expand All @@ -223,10 +236,18 @@ test.each([
);
expect(value).toMatchObject({
code: 'COMMAND_FAILED',
details: { reason, deviceId: 'scoped-duo', timeoutMs: 4000 },
details: { reason, deviceId: 'scoped-duo', timeoutMs: 4000, ...extra },
});
});

test('rotate maps a failed helper exit to its dispatch-failed reason', async () => {
const { value } = await withHelper(scopedDuo, { stdout: '', exitCode: 1 }, (helper) =>
caught(helper.rotate('landscape-left')),
);
expect(value).toMatchObject({ details: { reason: 'orientation-hid-dispatch-failed' } });
expect((value as AppError).details).not.toHaveProperty('dispatched');
});

test('never spawns the helper for an already cancelled read or dispatch', async () => {
const controller = new AbortController();
controller.abort(new DOMException('request cancelled', 'AbortError'));
Expand Down
25 changes: 21 additions & 4 deletions packages/platform-apple/src/foldable/fold-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const FOLD_HELPER_REASONS = {
const FOLD_HELPER_ORIENTATION_REASONS = {
// The fold helper could not send the orientation to the iOS simulator.
hidDispatchFailed: { reason: 'orientation-hid-dispatch-failed' },
// The fold helper did not finish sending the orientation in time, so the rotation may have applied.
hidDispatchTimedOut: { reason: 'orientation-hid-dispatch-timed-out' },
} as const satisfies ReasonTable<'orientation'>;

const FOLD_HELPER_PANEL_REASONS = {
Expand Down Expand Up @@ -107,10 +109,11 @@ export function createFoldHelper(device: DeviceInfo): FoldHelper {
});
} catch (error) {
if (signal?.aborted || !isCommandTimeoutError(error)) throw error;
const timedOut = failure.timedOut ?? failure;
throw new AppError(
'COMMAND_FAILED',
failure.message,
{ ...error.details, deviceId: device.id, ...failure.details },
timedOut.message,
{ ...error.details, deviceId: device.id, ...timedOut.details },
error,
);
}
Expand Down Expand Up @@ -159,11 +162,17 @@ export function createFoldHelper(device: DeviceInfo): FoldHelper {
} satisfies FoldHelper);
}

type ModeFailure = Readonly<{
type ModeFailureShape = Readonly<{
message: string;
details: { reason: FoldHelperFailureReason; hint?: string };
details: { reason: FoldHelperFailureReason; hint?: string; dispatched?: 'unknown' };
}>;

type ModeFailure = ModeFailureShape &
Readonly<{
/** Replaces the failure on a timeout, for a mode whose dispatch may land after its deadline. */
timedOut?: ModeFailureShape;
}>;

const DISPATCH_FAILURE: ModeFailure = {
message: 'Unable to send the simulator hinge pose',
details: { reason: FOLD_HELPER_REASONS.hidDispatchFailed.reason },
Expand All @@ -172,6 +181,14 @@ const DISPATCH_FAILURE: ModeFailure = {
const ROTATE_FAILURE: ModeFailure = {
message: 'Unable to send the simulator orientation',
details: { reason: FOLD_HELPER_ORIENTATION_REASONS.hidDispatchFailed.reason },
timedOut: {
message: 'Timed out sending the simulator orientation; the rotation may have applied',
details: {
reason: FOLD_HELPER_ORIENTATION_REASONS.hidDispatchTimedOut.reason,
dispatched: 'unknown',
hint: 'Check the orientation with a screenshot or snapshot. A retry reads the lit panel first and sends nothing when it already shows the requested orientation.',
},
},
};

const NO_SAMPLE_FAILURE: ModeFailure = {
Expand Down
1 change: 1 addition & 0 deletions website/docs/docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1734,6 +1734,7 @@ Device settings:

- `settings animations off` (Android) stabilizes runs with heavy animation. Turn animations back on afterwards.
- `settings bluetooth` and `settings mobile-data` are Android only and need adb. `settings bluetooth` needs Android 8.1 or newer, and `settings airplane` needs Android 11 or newer. Connectivity takes a moment to settle, so poll the app instead of asserting offline behavior at once.
- On iOS simulators, `settings wifi` and `settings airplane` change only the status bar, and the output prints a warning that says so. The simulator keeps using the Mac's network, so these settings cannot test offline behavior.
- Pair `settings mobile-data on` with `settings wifi off` to move a session, such as a video stream, from Wi-Fi to cellular. On a multi-SIM device, or one without an active SIM, the command can fail even when the switch took effect.
- `settings text-size` without a category reads the current size. It works on iPhone and iPad simulators and on Android. A running app picks up a new size only after `open <app> --relaunch`.

Expand Down
1 change: 1 addition & 0 deletions website/docs/docs/error-reasons.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Treat a reason that this page does not list as unknown, not as an error in the r
| --- | --- |
| `fold-helper-build-failed` | The iOS simulator fold helper could not be built with the selected Xcode. |
| `orientation-hid-dispatch-failed` | The fold helper could not send the orientation to the iOS simulator. |
| `orientation-hid-dispatch-timed-out` | The fold helper did not finish sending the orientation in time, so the rotation may have applied. |
| `unsupported-foldable-orientation` | A foldable iOS simulator cannot rotate to portrait-upside-down. |
| `orientation-unverified` | The orientation was sent, but the panel table does not report it afterwards. |
| `orientation-panel-table-unavailable` | The foldable's guest panel table could not be read. |
Expand Down
Loading