@@ -3,6 +3,7 @@ import assert from 'node:assert/strict';
33import fs from 'node:fs' ;
44import path from 'node:path' ;
55import { beforeEach , test , vi } from 'vitest' ;
6+ import type { DeviceInfo } from '@agent-device/kernel/device' ;
67import { IOS_DEVICE , IOS_SIMULATOR } from './device-fixtures.ts' ;
78import { appleRunnerTestHost } from '../test-host.ts' ;
89import { AppError } from '@agent-device/kernel/errors' ;
@@ -369,6 +370,67 @@ test('runner session startup diagnostics include logical lease context', async (
369370 assert . match ( diagnostics , / " d e v i c e K e y " : " r u n n e r - s e s s i o n - l e a s e - c o n t e x t - s i m " / ) ;
370371} ) ;
371372
373+ async function readStartupTimingsDiagnostic (
374+ device : DeviceInfo ,
375+ ) : Promise < { durationMs : number ; timings : Record < string , number > } > {
376+ let reported : { durationMs : number ; timings : Record < string , number > } | undefined ;
377+ appleRunnerTestHost . update ( {
378+ emitDiagnostic : ( event ) => {
379+ if ( event . phase !== 'ios_runner_session_startup_timings' ) return ;
380+ reported = {
381+ durationMs : event . durationMs as number ,
382+ timings : ( event . data as { timings : Record < string , number > } ) . timings ,
383+ } ;
384+ } ,
385+ } ) ;
386+ const session = await ensureRunnerSession ( device , { } ) ;
387+ await executeRunnerCommandWithSession (
388+ device ,
389+ session ,
390+ { command : 'snapshot' , appBundleId : 'com.example.demo' } ,
391+ '/tmp/runner.log' ,
392+ 30_000 ,
393+ ) ;
394+ assert . ok ( reported , 'expected ios_runner_session_startup_timings' ) ;
395+ return reported ;
396+ }
397+
398+ const sumValues = ( timings : Record < string , number > ) =>
399+ Object . values ( timings ) . reduce ( ( sum , value ) => sum + value , 0 ) ;
400+
401+ test ( 'runner session startup total excludes the build nested in ensure_xctestrun on a cache miss' , async ( ) => {
402+ mockWaitForRunner . mockResolvedValue ( runnerResponse ( { nodes : [ ] , truncated : false } ) ) ;
403+
404+ const { durationMs, timings } = await readStartupTimingsDiagnostic ( {
405+ ...IOS_SIMULATOR ,
406+ id : 'runner-session-timings-miss-sim' ,
407+ } ) ;
408+
409+ assert . equal ( timings . build_xctestrun , 12 ) ;
410+ assert . equal ( durationMs , sumValues ( timings ) - 12 ) ;
411+ } ) ;
412+
413+ test ( 'runner session startup total is the plain sum of phases on a cache hit' , async ( ) => {
414+ mockEnsureXctestrunArtifact . mockResolvedValue ( {
415+ xctestrunPath : '/tmp/cached-runner.xctestrun' ,
416+ derived : '/tmp/derived' ,
417+ cacheKey : RUNNER_CACHE_KEY_FIXTURE ,
418+ cache : 'hit' ,
419+ artifact : 'valid' ,
420+ buildMs : 0 ,
421+ xctestrunPathSource : 'manifest' ,
422+ } ) ;
423+ mockWaitForRunner . mockResolvedValue ( runnerResponse ( { nodes : [ ] , truncated : false } ) ) ;
424+
425+ const { durationMs, timings } = await readStartupTimingsDiagnostic ( {
426+ ...IOS_SIMULATOR ,
427+ id : 'runner-session-timings-hit-sim' ,
428+ } ) ;
429+
430+ assert . equal ( timings . build_xctestrun , 0 ) ;
431+ assert . equal ( durationMs , sumValues ( timings ) ) ;
432+ } ) ;
433+
372434test ( 'runner session fails early for physical iOS devices when Apple developer mode is disabled' , async ( ) => {
373435 const device = { ...IOS_DEVICE , id : 'runner-session-devtools-disabled-device' } ;
374436 mockDevToolsSecurityDisabled ( ) ;
0 commit comments