From 1b3c25a78a39efa3240471a869c799ebd7ee2f64 Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 23 Nov 2026 13:13:52 +0530 Subject: [PATCH 1/2] fix(orientation): report a timed-out foldable rotation as possibly applied, not unsent --- .../src/foldable/fold-helper.test.ts | 29 ++++++++++++++++--- .../src/foldable/fold-helper.ts | 25 +++++++++++++--- website/docs/docs/error-reasons.md | 1 + 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/packages/platform-apple/src/foldable/fold-helper.test.ts b/packages/platform-apple/src/foldable/fold-helper.test.ts index 6049158393..9945e31f9a 100644 --- a/packages/platform-apple/src/foldable/fold-helper.test.ts +++ b/packages/platform-apple/src/foldable/fold-helper.test.ts @@ -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 () => { @@ -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')); diff --git a/packages/platform-apple/src/foldable/fold-helper.ts b/packages/platform-apple/src/foldable/fold-helper.ts index 339a66834b..7e2f4d3f87 100644 --- a/packages/platform-apple/src/foldable/fold-helper.ts +++ b/packages/platform-apple/src/foldable/fold-helper.ts @@ -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 = { @@ -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, ); } @@ -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 }, @@ -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 = { diff --git a/website/docs/docs/error-reasons.md b/website/docs/docs/error-reasons.md index fa20e94c1f..cdfc379b88 100644 --- a/website/docs/docs/error-reasons.md +++ b/website/docs/docs/error-reasons.md @@ -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. | From 342917b6f2a9d86bfb4aadf5cbf59453d006cfb7 Mon Sep 17 00:00:00 2001 From: parbez Date: Mon, 23 Nov 2026 13:15:02 +0530 Subject: [PATCH 2/2] fix(settings): warn that iOS simulator wifi and airplane settings change only the status bar --- .../src/core/__tests__/app-settings.test.ts | 28 +++++++++++++++++++ .../platform-apple/src/core/app-settings.ts | 13 +++++++-- website/docs/docs/commands.md | 1 + 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/platform-apple/src/core/__tests__/app-settings.test.ts b/packages/platform-apple/src/core/__tests__/app-settings.test.ts index 8b3da532f0..e370699865 100644 --- a/packages/platform-apple/src/core/__tests__/app-settings.test.ts +++ b/packages/platform-apple/src/core/__tests__/app-settings.test.ts @@ -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) => { diff --git a/packages/platform-apple/src/core/app-settings.ts b/packages/platform-apple/src/core/app-settings.ts index c156cd835d..e1727cb8a3 100644 --- a/packages/platform-apple/src/core/app-settings.ts +++ b/packages/platform-apple/src/core/app-settings.ts @@ -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, @@ -118,7 +127,7 @@ export async function setIosSetting( }, signal, ); - return; + return statusBarOnlyWarnings('wifi'); } case 'airplane': { const enabled = parseSettingState(state); @@ -161,7 +170,7 @@ export async function setIosSetting( }, signal, ); - return; + return statusBarOnlyWarnings('airplane'); } case 'faceid': case 'touchid': { diff --git a/website/docs/docs/commands.md b/website/docs/docs/commands.md index 18c5f1cc1c..7872cf45a2 100644 --- a/website/docs/docs/commands.md +++ b/website/docs/docs/commands.md @@ -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 --relaunch`.