Skip to content

Commit a33cafe

Browse files
committed
fix(apple): reveal Simulator.app after a boot without taking focus
open -a Simulator activated the app, so every cold boot through open or boot pulled the Simulator window in front of whatever the user was working in. open -g keeps the frontmost app focused. The timeout constant drops 'focus' from its name.
1 parent 50e45f1 commit a33cafe

5 files changed

Lines changed: 31 additions & 15 deletions

File tree

‎packages/platform-apple/src/core/__tests__/simulator.test.ts‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
openIosSimulatorApp,
66
wasSimulatorRecentlyObservedBooted,
77
} from '../simulator.ts';
8-
import { IOS_BOOT_TIMEOUT_MS, IOS_SIMULATOR_FOCUS_TIMEOUT_MS } from '../config.ts';
8+
import { IOS_BOOT_TIMEOUT_MS, IOS_SIMULATOR_SHOW_TIMEOUT_MS } from '../config.ts';
99
import { AppError } from '@agent-device/kernel/errors';
1010
import { runCmd } from '@agent-device/host-kit/command';
1111
import { IOS_TEST_SIMULATOR } from './apple-core-stub-helpers.ts';
@@ -66,29 +66,29 @@ test('ensureBootedSimulator opens Simulator after cold boot', async () => {
6666
'xcrun simctl list devices -j': simulatorStateSequence('Shutdown', 'Booted'),
6767
'xcrun simctl boot sim-1': OK_RESULT,
6868
'xcrun simctl bootstatus sim-1 -b': OK_RESULT,
69-
'open -a Simulator': OK_RESULT,
69+
'open -g -a Simulator': OK_RESULT,
7070
});
7171

7272
await ensureBootedSimulator(IOS_TEST_SIMULATOR);
7373

7474
assert.equal(
7575
mockRunCmd.mock.calls.some(
76-
([cmd, args]) => cmd === 'open' && args.join(' ') === '-a Simulator',
76+
([cmd, args]) => cmd === 'open' && args.join(' ') === '-g -a Simulator',
7777
),
7878
true,
7979
);
8080
});
8181

8282
test('openIosSimulatorApp opens Simulator', async () => {
8383
mockRunCmdResponses({
84-
'open -a Simulator': OK_RESULT,
84+
'open -g -a Simulator': OK_RESULT,
8585
});
8686

8787
await openIosSimulatorApp();
8888

8989
assert.deepEqual(
9090
mockRunCmd.mock.calls.map(([cmd, args]) => [cmd, args.join(' ')]),
91-
[['open', '-a Simulator']],
91+
[['open', '-g -a Simulator']],
9292
);
9393
});
9494

@@ -108,8 +108,8 @@ test('ensureBootedSimulator leaves the Simulator app alone when already booted',
108108
test('openIosSimulatorApp times out instead of hanging indefinitely', async () => {
109109
mockRunCmd.mockImplementation(async (cmd, args, options) => {
110110
assert.equal(cmd, 'open');
111-
assert.deepEqual(args, ['-a', 'Simulator']);
112-
assert.equal(options?.timeoutMs, IOS_SIMULATOR_FOCUS_TIMEOUT_MS);
111+
assert.deepEqual(args, ['-g', '-a', 'Simulator']);
112+
assert.equal(options?.timeoutMs, IOS_SIMULATOR_SHOW_TIMEOUT_MS);
113113
throw new AppError('COMMAND_FAILED', 'open timed out after 10000ms', {
114114
timeoutMs: options?.timeoutMs,
115115
});
@@ -174,7 +174,7 @@ test('ensureBootedSimulator retries a transient simctl boot failure and boots on
174174
return bootCalls === 1 ? failedSimctlBoot('Unable to boot sim-1 right now') : OK_RESULT;
175175
},
176176
'xcrun simctl bootstatus sim-1 -b': OK_RESULT,
177-
'open -a Simulator': OK_RESULT,
177+
'open -g -a Simulator': OK_RESULT,
178178
});
179179

180180
await settleBoot(ensureBootedSimulator(IOS_TEST_SIMULATOR));
@@ -184,7 +184,7 @@ test('ensureBootedSimulator retries a transient simctl boot failure and boots on
184184
assert.equal(bootCalls, 2);
185185
assert.equal(
186186
mockRunCmd.mock.calls.some(
187-
([cmd, args]) => cmd === 'open' && args.join(' ') === '-a Simulator',
187+
([cmd, args]) => cmd === 'open' && args.join(' ') === '-g -a Simulator',
188188
),
189189
true,
190190
);
@@ -298,7 +298,7 @@ test('ensureBootedSimulator reports a simulator that never reaches Booted after
298298
assert.equal(mockRunCmd.mock.calls.filter(([, args]) => args[1] === 'boot').length, 3);
299299
assert.equal(
300300
mockRunCmd.mock.calls.some(
301-
([cmd, args]) => cmd === 'open' && args.join(' ') === '-a Simulator',
301+
([cmd, args]) => cmd === 'open' && args.join(' ') === '-g -a Simulator',
302302
),
303303
false,
304304
);

‎packages/platform-apple/src/core/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const IOS_DEVICECTL_MIN_TIMEOUT_SECONDS = 5;
1010

1111
export const IOS_DEVICE_INSTALL_TIMEOUT_MS = 120_000;
1212

13-
export const IOS_SIMULATOR_FOCUS_TIMEOUT_MS = 10_000;
13+
export const IOS_SIMULATOR_SHOW_TIMEOUT_MS = 10_000;
1414

1515
export const IOS_SIMULATOR_TERMINATE_TIMEOUT_MS = 15_000;
1616

‎packages/platform-apple/src/core/simulator.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { bootFailureHint, classifyBootFailure } from '@agent-device/provision-ki
99
import {
1010
IOS_BOOT_TIMEOUT_MS,
1111
IOS_SIMCTL_LIST_TIMEOUT_MS,
12-
IOS_SIMULATOR_FOCUS_TIMEOUT_MS,
12+
IOS_SIMULATOR_SHOW_TIMEOUT_MS,
1313
} from './config.ts';
1414
import { buildSimctlArgsForDevice, readSimctlDeviceState } from './simctl.ts';
1515
import { runAppleToolCommand, runXcrun } from './tool-provider.ts';
@@ -51,10 +51,10 @@ export function requireSimulatorDevice(device: DeviceInfo, command: string): voi
5151
}
5252

5353
export async function openIosSimulatorApp(options: SimulatorCommandOptions = {}): Promise<void> {
54-
await runAppleToolCommand('open', ['-a', 'Simulator'], {
54+
await runAppleToolCommand('open', ['-g', '-a', 'Simulator'], {
5555
allowFailure: true,
5656
signal: options.signal,
57-
timeoutMs: IOS_SIMULATOR_FOCUS_TIMEOUT_MS,
57+
timeoutMs: IOS_SIMULATOR_SHOW_TIMEOUT_MS,
5858
});
5959
}
6060

‎packages/platform-apple/src/readiness/runtime.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,22 @@ test('physical readiness forwards the request signal to the focused host port',
224224
expect(ensureConnected).toHaveBeenCalledWith(expect.anything(), controller.signal);
225225
});
226226

227+
test('a cold boot reveals Simulator.app without taking focus from the frontmost app', async () => {
228+
const { host } = coldSimulatorHost({});
229+
const commandRun = vi.fn(async () => ({ stdout: '', stderr: '', exitCode: 0 }));
230+
231+
await ensureAppleReady(
232+
{ ...host, commands: { ...host.commands, run: commandRun } },
233+
simulator(),
234+
new AbortController().signal,
235+
);
236+
237+
expect(commandRun).toHaveBeenCalledWith(
238+
expect.objectContaining({ executable: 'open', args: ['-g', '-a', 'Simulator'] }),
239+
expect.anything(),
240+
);
241+
});
242+
227243
/** A Shutdown Simulator whose boot, bootstatus, and post-boot listing run the given hooks first. */
228244
function coldSimulatorHost(hooks: {
229245
onBoot?: () => void;

‎packages/platform-apple/src/readiness/runtime.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ async function simulatorState(
187187

188188
async function showSimulator(host: AppleReadinessHost, signal: AbortSignal): Promise<void> {
189189
await host.commands.run(
190-
{ executable: 'open', args: ['-a', 'Simulator'], allowFailure: true, timeoutMs: 10_000 },
190+
{ executable: 'open', args: ['-g', '-a', 'Simulator'], allowFailure: true, timeoutMs: 10_000 },
191191
signal,
192192
);
193193
}

0 commit comments

Comments
 (0)