@@ -10,12 +10,14 @@ const {
1010 mockEnsureRunnerSession,
1111 mockExecuteRunnerCommandWithSession,
1212 mockEmitDiagnostic,
13+ mockGetRunnerSessionSnapshot,
1314 mockInvalidateRunnerSession,
1415 mockMarkRunnerXctestrunArtifactBadForRun,
1516} = vi . hoisted ( ( ) => ( {
1617 mockEnsureRunnerSession : vi . fn ( ) ,
1718 mockExecuteRunnerCommandWithSession : vi . fn ( ) ,
1819 mockEmitDiagnostic : vi . fn ( ) ,
20+ mockGetRunnerSessionSnapshot : vi . fn ( ) ,
1921 mockInvalidateRunnerSession : vi . fn ( ) ,
2022 mockMarkRunnerXctestrunArtifactBadForRun : vi . fn ( ) ,
2123} ) ) ;
@@ -38,6 +40,7 @@ vi.mock('../runner/runner-session.ts', async () => {
3840 ...actual ,
3941 ensureRunnerSession : mockEnsureRunnerSession ,
4042 executeRunnerCommandWithSession : mockExecuteRunnerCommandWithSession ,
43+ getRunnerSessionSnapshot : mockGetRunnerSessionSnapshot ,
4144 invalidateRunnerSession : mockInvalidateRunnerSession ,
4245 } ;
4346} ) ;
@@ -63,6 +66,7 @@ import type { RunnerXctestrunArtifact } from '../runner/runner-xctestrun.ts';
6366beforeEach ( ( ) => {
6467 vi . resetAllMocks ( ) ;
6568 resetRunnerRecycleLedgerForTests ( ) ;
69+ mockGetRunnerSessionSnapshot . mockReturnValue ( null ) ;
6670 mockMarkRunnerXctestrunArtifactBadForRun . mockResolvedValue ( undefined ) ;
6771} ) ;
6872
@@ -1207,6 +1211,37 @@ test('a failed replacement boot does not consume the request recycle budget', as
12071211 assert . equal ( mockEnsureRunnerSession . mock . calls . length , 3 ) ;
12081212} ) ;
12091213
1214+ test ( 'alive session reuse in the same request does not consume recycle budget' , async ( ) => {
1215+ const requestId = 'req-alive-reuse-before-recycle' ;
1216+ mockGetRunnerSessionSnapshot
1217+ . mockReturnValueOnce ( null )
1218+ . mockReturnValueOnce ( { alive : true } )
1219+ . mockReturnValueOnce ( null ) ;
1220+ mockEnsureRunnerSession
1221+ . mockResolvedValueOnce ( makeRunnerSession ( { port : 8100 , ready : true } ) )
1222+ . mockResolvedValueOnce ( makeRunnerSession ( { port : 8100 , ready : true } ) )
1223+ . mockResolvedValueOnce ( makeRunnerSession ( { port : 8101 , ready : true } ) ) ;
1224+ mockExecuteRunnerCommandWithSession
1225+ . mockResolvedValueOnce ( { message : 'first tap' } )
1226+ . mockResolvedValueOnce ( { message : 'second tap' } )
1227+ . mockResolvedValueOnce ( { message : 'recovered tap' } ) ;
1228+
1229+ assert . deepEqual (
1230+ await runAppleRunnerCommand ( IOS_SIMULATOR , { command : 'tap' , x : 120 , y : 240 } , { requestId } ) ,
1231+ { message : 'first tap' } ,
1232+ ) ;
1233+ assert . deepEqual (
1234+ await runAppleRunnerCommand ( IOS_SIMULATOR , { command : 'tap' , x : 120 , y : 240 } , { requestId } ) ,
1235+ { message : 'second tap' } ,
1236+ ) ;
1237+ assert . deepEqual (
1238+ await runAppleRunnerCommand ( IOS_SIMULATOR , { command : 'tap' , x : 120 , y : 240 } , { requestId } ) ,
1239+ { message : 'recovered tap' } ,
1240+ ) ;
1241+
1242+ assert . equal ( mockEnsureRunnerSession . mock . calls . length , 3 ) ;
1243+ } ) ;
1244+
12101245test ( 'a later command in the same request cannot pay for a second recycle boot' , async ( ) => {
12111246 const requestId = 'req-restart-cap' ;
12121247 const staleSession = makeRunnerSession ( { port : 8100 , ready : true } ) ;
0 commit comments