Skip to content
Open
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
1 change: 1 addition & 0 deletions src/core/dispatch-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type DispatchContext = ScreenshotDispatchFlags & {
snapshotScope?: string;
snapshotRaw?: boolean;
snapshotIncludeRects?: boolean;
skipIosSimulatorBootCheck?: boolean;
count?: number;
intervalMs?: number;
delayMs?: number;
Expand Down
1 change: 1 addition & 0 deletions src/core/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ async function handleScreenshotCommand(
fullscreen: screenshotOptions.fullscreen,
stabilize: screenshotOptions.stabilize,
surface: context?.surface,
skipIosSimulatorBootCheck: context?.skipIosSimulatorBootCheck,
});
return { path: screenshotPath, ...successText(`Saved screenshot: ${screenshotPath}`) };
}
Expand Down
1 change: 1 addition & 0 deletions src/core/interactor-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export type ScreenshotOptions = {
fullscreen?: boolean;
stabilize?: boolean;
surface?: SessionSurface;
skipIosSimulatorBootCheck?: boolean;
};

export type ElementSelectorKey = 'id' | 'label' | 'text' | 'value';
Expand Down
4 changes: 3 additions & 1 deletion src/core/interactors/apple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ export function createAppleInteractor(
});
return;
}
await screenshotIos(device, outPath, options?.appBundleId, options?.fullscreen, runnerOpts);
await screenshotIos(device, outPath, options?.appBundleId, options?.fullscreen, runnerOpts, {
skipSimulatorBootCheck: options?.skipIosSimulatorBootCheck,
});
},
snapshot: async (options) => {
const result = readAppleSnapshotResult(
Expand Down
21 changes: 21 additions & 0 deletions src/daemon/__tests__/request-router-screenshot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,27 @@ test('default screenshot temp directory is cleaned when capture fails', async ()
expect(fs.existsSync(path.dirname(capturedPath!))).toBe(false);
});

test('session-backed iOS simulator screenshots skip redundant boot probe', async () => {
const session = makeIosSession('ios');
const outPath = path.join(os.tmpdir(), 'agent-device-ios-session-screenshot.png');
let capturedContext: Parameters<typeof dispatchCommand>[4];

mockDispatch.mockImplementation(async (_device, _command, _positionals, _outPath, context) => {
capturedContext = context;
return { path: outPath };
});

await dispatchScreenshotViaRuntime({
session,
sessionName: session.name,
outPath,
outputPlacement: 'positional',
dispatchContext: {},
});

expect(capturedContext?.skipIosSimulatorBootCheck).toBe(true);
});

test('router serializes concurrent commands for the same device across sessions', async () => {
const sessionStore = makeSessionStore('agent-device-router-screenshot-');
sessionStore.set('session-a', makeSession('session-a'));
Expand Down
3 changes: 3 additions & 0 deletions src/daemon/screenshot-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function createDispatchScreenshotBackend(params: {
...dispatchContext,
...screenshotFlagsFromOptions(options),
surface: options?.surface,
skipIosSimulatorBootCheck:
dispatchContext.skipIosSimulatorBootCheck ??
(session.device.platform === 'ios' && session.device.kind === 'simulator'),
};
if (outputPlacement === 'out') {
return readScreenshotResultData(
Expand Down
20 changes: 20 additions & 0 deletions src/platforms/ios/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,26 @@ test('captureSimulatorScreenshotWithFallback continues when status bar preparati
assert.equal(mockRunIosRunnerCommand.mock.calls.length, 0);
});

test('captureSimulatorScreenshotWithFallback can skip session-backed simulator boot probe', async () => {
mockEnsureBootedSimulator.mockRejectedValue(new Error('should not probe boot state'));
mockPrepareStatusBarForScreenshot.mockResolvedValue(async () => {});
mockRetryWithPolicy.mockResolvedValue(undefined);

await captureSimulatorScreenshotWithFallback(
IOS_TEST_SIMULATOR,
'/tmp/out.png',
'com.example.app',
undefined,
undefined,
undefined,
{ skipBootCheck: true },
);

assert.equal(mockEnsureBootedSimulator.mock.calls.length, 0);
assert.equal(mockRetryWithPolicy.mock.calls.length, 1);
assert.equal(mockRunIosRunnerCommand.mock.calls.length, 0);
});

test('captureSimulatorScreenshotWithFallback ignores status bar restore failures', async () => {
mockPrepareStatusBarForScreenshot.mockResolvedValue(async () => {
throw new AppError('COMMAND_FAILED', 'status_bar clear failed');
Expand Down
15 changes: 14 additions & 1 deletion src/platforms/ios/screenshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@ type SimulatorScreenshotFlowDeps = {
shouldFallbackToRunner: (error: unknown) => boolean;
};

type SimulatorScreenshotFlowOptions = {
skipBootCheck?: boolean;
};

type IosScreenshotOptions = {
skipSimulatorBootCheck?: boolean;
};

const defaultSimulatorScreenshotFlowDeps: SimulatorScreenshotFlowDeps = {
ensureBooted: ensureBootedSimulator,
prepareStatusBarForScreenshot: prepareSimulatorStatusBarForScreenshot,
Expand All @@ -53,6 +61,7 @@ export async function screenshotIos(
appBundleId?: string,
fullscreen?: boolean,
runnerOptions?: AppleRunnerCommandOptions,
options: IosScreenshotOptions = {},
): Promise<void> {
if (device.platform === 'macos') {
await captureScreenshotViaRunner(device, outPath, appBundleId, fullscreen, runnerOptions);
Expand All @@ -66,6 +75,7 @@ export async function screenshotIos(
fullscreen,
undefined,
runnerOptions,
{ skipBootCheck: options.skipSimulatorBootCheck },
);
return;
}
Expand Down Expand Up @@ -93,6 +103,7 @@ export async function captureSimulatorScreenshotWithFallback(
fullscreenOrDeps?: boolean | SimulatorScreenshotFlowDeps,
deps: SimulatorScreenshotFlowDeps = defaultSimulatorScreenshotFlowDeps,
runnerOptions?: AppleRunnerCommandOptions,
options: SimulatorScreenshotFlowOptions = {},
): Promise<void> {
if (device.kind !== 'simulator') {
throw new AppError(
Expand All @@ -105,7 +116,9 @@ export async function captureSimulatorScreenshotWithFallback(
const effectiveDeps =
typeof fullscreenOrDeps === 'object' && fullscreenOrDeps !== null ? fullscreenOrDeps : deps;

await effectiveDeps.ensureBooted(device);
if (!options.skipBootCheck) {
await effectiveDeps.ensureBooted(device);
}
let restoreStatusBar = async () => {};
try {
restoreStatusBar = await effectiveDeps.prepareStatusBarForScreenshot(device);
Expand Down
Loading