@@ -823,29 +823,42 @@ describe('session sandbox lease', () => {
823823
824824 it ( 'attributes a warm shell call’s wall time to the phase that spent it' , async ( ) => {
825825 const { handle } = fakeSandbox ( 'phase-timing' )
826+ mockFindSessionSandbox . mockResolvedValue ( handle )
827+ const request = {
828+ code : 'true' ,
829+ envs : { } ,
830+ timeoutMs : 10_000 ,
831+ session : { key : 'phase-timing' , cli : CLI } ,
832+ }
833+ await executeShellInSandbox ( request )
834+
835+ let nowMs = 0
836+ const clock = vi . spyOn ( performance , 'now' ) . mockImplementation ( ( ) => nowMs )
837+ const writes = vi . fn ( handle . writeFile . bind ( handle ) )
838+ handle . writeFile = writes
826839 const runCommand = handle . runCommand . bind ( handle )
827840 handle . runCommand = async ( command , options ) => {
828- await sleep ( options . envs ?. SIM_CLI_PATH ? 30 : 60 )
841+ nowMs += options . envs ?. SIM_CLI_PATH ? 30 : 60
829842 return runCommand ( command , options )
830843 }
831844 mockFindSessionSandbox . mockImplementation ( async ( ) => {
832- await sleep ( 40 )
845+ nowMs += 40
833846 return handle
834847 } )
835848
836- const result = await executeShellInSandbox ( {
837- code : 'true' ,
838- envs : { } ,
839- timeoutMs : 10_000 ,
840- session : { key : 'phase-timing' , cli : CLI } ,
841- } )
849+ try {
850+ const result = await executeShellInSandbox ( request )
842851
843- const phases = result . phaseMs ?? { }
844- expect ( result . sandboxSession ) . toBe ( 'reused' )
845- expect ( phases . lookup ) . toBeGreaterThanOrEqual ( 38 )
846- expect ( phases . cli ) . toBeGreaterThanOrEqual ( 28 )
847- expect ( phases . run ) . toBeGreaterThanOrEqual ( 58 )
848- expect ( phases . lease ) . toBeGreaterThanOrEqual ( ( phases . lookup ?? 0 ) + ( phases . cli ?? 0 ) )
852+ const phases = result . phaseMs ?? { }
853+ expect ( result . sandboxSession ) . toBe ( 'reused' )
854+ expect ( writes ) . not . toHaveBeenCalled ( )
855+ expect ( phases . lookup ) . toBe ( 40 )
856+ expect ( phases . cli ) . toBe ( 30 )
857+ expect ( phases . run ) . toBe ( 60 )
858+ expect ( phases . lease ) . toBeGreaterThanOrEqual ( 70 )
859+ } finally {
860+ clock . mockRestore ( )
861+ }
849862 } )
850863
851864 it ( 'pins shell CLI resolution ahead of caller environment paths' , async ( ) => {
0 commit comments