@@ -25,7 +25,6 @@ vi.mock('../../device-ready.ts', () => ({ ensureDeviceReady: vi.fn(async () => {
2525vi . mock ( '@agent-device/platform-apple/runner/operations' , async ( importOriginal ) => {
2626 const actual =
2727 await importOriginal < typeof import ( '@agent-device/platform-apple/runner/operations' ) > ( ) ;
28- const stopIosRunnerSession = vi . fn ( async ( _deviceId : string ) => { } ) ;
2928 return {
3029 ...actual ,
3130 prepareIosRunner : vi . fn ( async ( ) => ( {
@@ -38,11 +37,8 @@ vi.mock('@agent-device/platform-apple/runner/operations', async (importOriginal)
3837 notifyIosRunnerAppRelaunched : vi . fn ( async ( ) => { } ) ,
3938 // A retained Simulator runner survives the relaunch, so its cached target is reset.
4039 hasLiveIosRunnerSession : vi . fn ( ( ) => true ) ,
41- stopIosRunnerSession,
42- // Mirrors the runner module: a retained close keeps warm reuse; any other close stops it.
43- releaseIosRunnerOnClose : vi . fn ( async ( deviceId : string , options : { retain : boolean } ) => {
44- if ( ! options . retain ) await stopIosRunnerSession ( deviceId ) ;
45- } ) ,
40+ stopIosRunnerSession : vi . fn ( async ( ) => { } ) ,
41+ releaseIosRunnerOnClose : vi . fn ( async ( ) => { } ) ,
4642 } ;
4743} ) ;
4844vi . mock ( '@agent-device/platform-apple/macos' , async ( importOriginal ) => {
@@ -115,7 +111,7 @@ beforeEach(() => {
115111 mockNotifyIosRunnerAppRelaunched . mockResolvedValue ( undefined ) ;
116112 mockStopIosRunner . mockReset ( ) ;
117113 mockStopIosRunner . mockResolvedValue ( undefined ) ;
118- mockReleaseRunnerOnClose . mockClear ( ) ;
114+ mockReleaseRunnerOnClose . mockReset ( ) ;
119115 mockDismissMacOsAlert . mockReset ( ) ;
120116 mockDismissMacOsAlert . mockResolvedValue ( { } as any ) ;
121117} ) ;
@@ -523,8 +519,8 @@ test('close on macOS session stops runner and dismisses automation alert before
523519 ) ;
524520
525521 const calls : string [ ] = [ ] ;
526- mockStopIosRunner . mockImplementation ( async ( deviceId ) => {
527- calls . push ( `stop -runner:${ deviceId } ` ) ;
522+ mockReleaseRunnerOnClose . mockImplementation ( async ( deviceId , options ) => {
523+ calls . push ( `release -runner:${ deviceId } : ${ options . retain ? 'retain' : 'stop' } ` ) ;
528524 } ) ;
529525 mockDismissMacOsAlert . mockImplementation ( async ( action , options ) => {
530526 calls . push (
@@ -537,7 +533,7 @@ test('close on macOS session stops runner and dismisses automation alert before
537533
538534 expect ( response . ok ) . toBe ( true ) ;
539535 expect ( calls ) . toEqual ( [
540- 'stop -runner:host-macos-local' ,
536+ 'release -runner:host-macos-local:stop ' ,
541537 'dismiss-alert:dismiss:com.apple.systempreferences' ,
542538 ] ) ;
543539 expect ( sessionStore . get ( sessionName ) ) . toBe ( undefined ) ;
@@ -589,7 +585,7 @@ test('close on iOS simulator with scoped simulator set stops runner before delet
589585 const response = await createHandler ( sessionStore ) ( sessionRequest ( sessionName , 'close' ) ) ;
590586
591587 expect ( response . ok ) . toBe ( true ) ;
592- expect ( mockStopIosRunner ) . toHaveBeenCalledWith ( 'sim-1' ) ;
588+ expect ( mockReleaseRunnerOnClose ) . toHaveBeenCalledWith ( 'sim-1' , { retain : false } ) ;
593589 expect ( sessionStore . get ( sessionName ) ) . toBeUndefined ( ) ;
594590} ) ;
595591
@@ -633,7 +629,7 @@ test('close on leased iOS simulator session stops runner before deleting session
633629 ) ( sessionRequest ( sessionName , 'close' ) ) ;
634630
635631 expect ( response . ok ) . toBe ( true ) ;
636- expect ( mockStopIosRunner ) . toHaveBeenCalledWith ( 'sim-1' ) ;
632+ expect ( mockReleaseRunnerOnClose ) . toHaveBeenCalledWith ( 'sim-1' , { retain : false } ) ;
637633 expect ( sessionStore . get ( sessionName ) ) . toBeUndefined ( ) ;
638634} ) ;
639635
@@ -659,7 +655,7 @@ test('close --shutdown on iOS simulator stops runner before deleting session', a
659655 ) ;
660656
661657 expect ( response . ok ) . toBe ( true ) ;
662- expect ( mockStopIosRunner ) . toHaveBeenCalledWith ( 'sim-1' ) ;
658+ expect ( mockReleaseRunnerOnClose ) . toHaveBeenCalledWith ( 'sim-1' , { retain : false } ) ;
663659 expect ( sessionStore . get ( sessionName ) ) . toBeUndefined ( ) ;
664660} ) ;
665661
@@ -684,6 +680,9 @@ test('close <app> on iOS stops runner before app close dispatch and performs fin
684680 mockStopIosRunner . mockImplementation ( async ( ) => {
685681 calls . push ( 'stop-runner' ) ;
686682 } ) ;
683+ mockReleaseRunnerOnClose . mockImplementation ( async ( _deviceId , options ) => {
684+ calls . push ( `release-runner:${ options . retain ? 'retain' : 'stop' } ` ) ;
685+ } ) ;
687686 mockDispatch . mockImplementation ( async ( _device , command , positionals ) => {
688687 calls . push ( `${ command } :${ ( positionals ?? [ ] ) . join ( ' ' ) } ` ) ;
689688 return { } ;
@@ -694,7 +693,7 @@ test('close <app> on iOS stops runner before app close dispatch and performs fin
694693 ) ;
695694
696695 expect ( response . ok ) . toBe ( true ) ;
697- expect ( calls ) . toEqual ( [ 'stop-runner' , 'close:com.example.app' , 'stop -runner' ] ) ;
696+ expect ( calls ) . toEqual ( [ 'stop-runner' , 'close:com.example.app' , 'release -runner:stop ' ] ) ;
698697} ) ;
699698
700699test ( 'close <app> on iOS simulator retains runner while terminating app' , async ( ) => {
@@ -718,6 +717,9 @@ test('close <app> on iOS simulator retains runner while terminating app', async
718717 mockStopIosRunner . mockImplementation ( async ( ) => {
719718 calls . push ( 'stop-runner' ) ;
720719 } ) ;
720+ mockReleaseRunnerOnClose . mockImplementation ( async ( _deviceId , options ) => {
721+ calls . push ( `release-runner:${ options . retain ? 'retain' : 'stop' } ` ) ;
722+ } ) ;
721723 mockDispatch . mockImplementation ( async ( _device , command , positionals ) => {
722724 calls . push ( `${ command } :${ ( positionals ?? [ ] ) . join ( ' ' ) } ` ) ;
723725 return { } ;
@@ -728,7 +730,7 @@ test('close <app> on iOS simulator retains runner while terminating app', async
728730 ) ;
729731
730732 expect ( response . ok ) . toBe ( true ) ;
731- expect ( calls ) . toEqual ( [ 'close:com.example.app' ] ) ;
733+ expect ( calls ) . toEqual ( [ 'close:com.example.app' , 'release-runner:retain' ] ) ;
732734} ) ;
733735
734736test ( 'app-only close terminates an iOS simulator app without ending its session' , async ( ) => {
@@ -794,6 +796,9 @@ test('close <app> on macOS stops runner before app close dispatch and dismisses
794796 mockStopIosRunner . mockImplementation ( async ( deviceId ) => {
795797 calls . push ( `stop-runner:${ deviceId } ` ) ;
796798 } ) ;
799+ mockReleaseRunnerOnClose . mockImplementation ( async ( deviceId , options ) => {
800+ calls . push ( `release-runner:${ deviceId } :${ options . retain ? 'retain' : 'stop' } ` ) ;
801+ } ) ;
797802 mockDismissMacOsAlert . mockImplementation ( async ( action , options ) => {
798803 calls . push (
799804 `dismiss-alert:${ action } :${ ( options as any ) ?. bundleId ?? ( options as any ) ?. surface ?? 'frontmost' } ` ,
@@ -813,7 +818,7 @@ test('close <app> on macOS stops runner before app close dispatch and dismisses
813818 expect ( calls ) . toEqual ( [
814819 'stop-runner:host-macos-local' ,
815820 'close:System Settings' ,
816- 'stop -runner:host-macos-local' ,
821+ 'release -runner:host-macos-local:stop ' ,
817822 'dismiss-alert:dismiss:com.apple.systempreferences' ,
818823 ] ) ;
819824} ) ;
0 commit comments