@@ -7,11 +7,11 @@ import { appleRemotePressCommand } from './os/tvos/remote.ts';
77import { runMacOsScreenshotAction } from './os/macos/helper.ts' ;
88import { actOnAppleAlert , awaitAppleAlert , readAppleAlert } from './alert.ts' ;
99import { runAppleRunnerCommand } from './core/runner-client.ts' ;
10- import type { AppleRunnerCommandOptions } from './runner/runner-provider.ts' ;
1110import {
1211 withAppleRunnerProvider ,
1312 type AppleRunnerCommandExecutor ,
1413 type AppleRunnerProvider ,
14+ type RunnerCommand ,
1515} from './runner/index.ts' ;
1616import { toAppleTvRemoteButton } from '@agent-device/contracts/tv-remote' ;
1717import { SCREENSHOT_FULLSCREEN_REASONS } from '@agent-device/contracts/capture' ;
@@ -23,12 +23,7 @@ import {
2323import { DEVICE_ROTATIONS , type DeviceRotation } from '@agent-device/contracts/device' ;
2424import { normalizeSnapshotScope } from '@agent-device/contracts/snapshot' ;
2525import { withDiagnosticTimer } from '@agent-device/host-kit/diagnostics' ;
26- import {
27- isHandheldAppleDevice ,
28- isMacOs ,
29- isTvOsDevice ,
30- type DeviceInfo ,
31- } from '@agent-device/kernel/device' ;
26+ import { isMacOs , isTvOsDevice , type DeviceInfo } from '@agent-device/kernel/device' ;
3227import { AppError } from '@agent-device/kernel/errors' ;
3328import { withMethodScope } from '@agent-device/kernel/scoped-provider' ;
3429import type { Point , SnapshotQualityVerdict } from '@agent-device/kernel/snapshot' ;
@@ -233,12 +228,6 @@ async function captureAppleSnapshot(
233228 runnerOpts : RunnerCallOptions ,
234229 helper : MacOsHelperSurface | undefined ,
235230) {
236- if ( options ?. observeOnly === true && ! isHandheldAppleDevice ( device ) ) {
237- throw new AppError (
238- 'UNSUPPORTED_OPERATION' ,
239- 'observe-only snapshot is supported on iOS and iPadOS only.' ,
240- ) ;
241- }
242231 if ( helper ) {
243232 return await captureMacOsSurfaceSnapshot ( { ...options , surface : helper } , options ?. signal ) ;
244233 }
@@ -250,25 +239,14 @@ async function captureAppleRunnerSnapshot(
250239 options : SnapshotOptions | undefined ,
251240 runnerOpts : RunnerCallOptions ,
252241) {
253- const observationPolicy = await snapshotObservationPolicy ( device , options , runnerOpts ) ;
254242 const result = readAppleSnapshotResult (
255243 await withDiagnosticTimer (
256244 'snapshot_capture' ,
257245 async ( ) =>
258246 await runAppleRunnerCommand (
259247 device ,
260- {
261- command : 'snapshot' ,
262- appBundleId : options ?. appBundleId ,
263- interactiveOnly : options ?. interactiveOnly ,
264- preferredBackend : options ?. preferredBackend ,
265- customActions : options ?. customActions ,
266- ...observationPolicy . request ,
267- depth : options ?. depth ,
268- scope : options ?. scope ,
269- raw : options ?. raw ,
270- } ,
271- mergeRunnerCallSignal ( observationPolicy . runnerOpts , options ?. signal ) ,
248+ runnerSnapshotCommand ( options ) ,
249+ mergeRunnerCallSignal ( runnerOpts , options ?. signal ) ,
272250 ) ,
273251 { backend : 'xctest' } ,
274252 ) ,
@@ -292,33 +270,19 @@ async function captureAppleRunnerSnapshot(
292270 } ;
293271}
294272
295- async function snapshotObservationPolicy (
296- device : DeviceInfo ,
297- options : SnapshotOptions | undefined ,
298- runnerOpts : RunnerCallOptions ,
299- ) : Promise < {
300- request : { observeOnly ?: true } ;
301- runnerOpts : RunnerCallOptions & Pick < AppleRunnerCommandOptions , 'expectedRunnerSessionId' > ;
302- } > {
303- if ( options ?. observeOnly !== true ) return { request : { } , runnerOpts } ;
304- const capabilities = await runAppleRunnerCommand (
305- device ,
306- { command : 'uptime' , observeOnly : true } ,
307- mergeRunnerCallSignal ( runnerOpts , options . signal ) ,
308- ) ;
309- if (
310- capabilities . supportsObserveOnlySnapshot !== true ||
311- typeof capabilities . runnerSessionId !== 'string' ||
312- capabilities . runnerSessionId . length === 0
313- ) {
314- throw new AppError ( 'COMMAND_FAILED' , 'Runner does not support observe-only snapshots.' , {
315- reason : 'observation-unavailable' ,
316- dispatched : 'no' ,
317- } ) ;
318- }
273+ function runnerSnapshotCommand ( options : SnapshotOptions | undefined ) : RunnerCommand {
274+ const { appBundleId, interactiveOnly, preferredBackend, customActions, depth, scope, raw } =
275+ options ?? { } ;
319276 return {
320- request : { observeOnly : true } ,
321- runnerOpts : { ...runnerOpts , expectedRunnerSessionId : capabilities . runnerSessionId } ,
277+ command : 'snapshot' ,
278+ appBundleId,
279+ interactiveOnly,
280+ preferredBackend,
281+ customActions,
282+ ...( options ?. observeOnly === true ? { observeOnly : true } : { } ) ,
283+ depth,
284+ scope,
285+ raw,
322286 } ;
323287}
324288
0 commit comments