@@ -24,6 +24,7 @@ import {
2424 captureSimulatorScreenshotWithFallback ,
2525 resolveSimulatorRunnerScreenshotCandidatePaths ,
2626} from '../screenshot.ts' ;
27+ import { focusIosSimulatorWindow } from '../simulator.ts' ;
2728import type { DeviceInfo } from '../../../utils/device.ts' ;
2829import { withDiagnosticsScope } from '../../../utils/diagnostics.ts' ;
2930import { AppError } from '../../../utils/errors.ts' ;
@@ -260,6 +261,31 @@ test('captureSimulatorScreenshotWithFallback emits fallback diagnostic before us
260261 }
261262} ) ;
262263
264+ test ( 'focusIosSimulatorWindow times out instead of hanging indefinitely' , async ( ) => {
265+ const tmpDir = await fs . mkdtemp ( path . join ( os . tmpdir ( ) , 'agent-device-ios-focus-timeout-test-' ) ) ;
266+ const openPath = path . join ( tmpDir , 'open' ) ;
267+ await fs . writeFile ( openPath , '#!/bin/sh\nsleep 10\n' , 'utf8' ) ;
268+ await fs . chmod ( openPath , 0o755 ) ;
269+
270+ const previousPath = process . env . PATH ;
271+ process . env . PATH = `${ tmpDir } ${ path . delimiter } ${ previousPath ?? '' } ` ;
272+
273+ try {
274+ await assert . rejects (
275+ ( ) => focusIosSimulatorWindow ( ) ,
276+ ( error : unknown ) => {
277+ assert . equal ( error instanceof AppError , true ) ;
278+ assert . equal ( ( error as AppError ) . code , 'COMMAND_FAILED' ) ;
279+ assert . match ( ( error as AppError ) . message , / o p e n t i m e d o u t a f t e r 5 0 0 0 m s / ) ;
280+ return true ;
281+ } ,
282+ ) ;
283+ } finally {
284+ process . env . PATH = previousPath ;
285+ await fs . rm ( tmpDir , { recursive : true , force : true } ) ;
286+ }
287+ } ) ;
288+
263289async function waitForFileText ( filePath : string , attempts = 20 ) : Promise < string > {
264290 let lastError : unknown ;
265291 for ( let attempt = 0 ; attempt < attempts ; attempt += 1 ) {
0 commit comments