@@ -204,9 +204,10 @@ test('cancelled acquisition does not start a fallback after the request aborts',
204204 expect ( fallback ) . not . toHaveBeenCalled ( ) ;
205205} ) ;
206206
207- test ( 'a slow app discovery yields to the XCTest fallback within its wait slice, then serves the bridge' , async ( ) => {
207+ test ( 'a slow app discovery yields to a live runner within its wait slice, then serves the bridge' , async ( ) => {
208208 // The production resolver over a simctl whose `launchctl list` answers only when released,
209- // the shape of a loaded CI host: the first capture must not sit on that probe.
209+ // the shape of a loaded CI host: with a runner that can answer at once, the first capture
210+ // must not sit on that probe.
210211 let release ! : ( ) => void ;
211212 const released = new Promise < void > ( ( resolve ) => {
212213 release = resolve ;
@@ -232,9 +233,11 @@ test('a slow app discovery yields to the XCTest fallback within its wait slice,
232233 producer : 'simulator-ax-bridge' as const ,
233234 nodes : [ { index : 0 , type : 'Application' } ] ,
234235 } ) ) ;
236+ const baseHost = platformRuntimeHostFixture ( ) ;
235237 const route = createAppleSnapshotRoute (
236238 {
237- ...platformRuntimeHostFixture ( ) ,
239+ ...baseHost ,
240+ appleApplications : { ...baseHost . appleApplications , hasLiveRunnerSession : async ( ) => true } ,
238241 snapshot : { captureSurface : vi . fn ( ) , presentIosAcquisition } ,
239242 } ,
240243 { source, resolveTarget : createSimulatorSnapshotTargetResolver ( ) } ,
@@ -302,3 +305,65 @@ function runnerResult() {
302305function signal ( ) : AbortSignal {
303306 return new AbortController ( ) . signal ;
304307}
308+
309+ test ( 'a slow app discovery keeps observation on the bridge while no runner can answer' , async ( ) => {
310+ // #2198: the open no longer awaits the runner, so right after a relaunch the fallback would
311+ // wait for a cold runner start. A capture with no live runner rides the single-flight
312+ // discovery instead, however many wait slices that takes.
313+ let release ! : ( ) => void ;
314+ const released = new Promise < void > ( ( resolve ) => {
315+ release = resolve ;
316+ } ) ;
317+ const run = vi . fn ( async ( args : string [ ] ) => {
318+ if ( args [ 0 ] === 'spawn' ) await released ;
319+ return {
320+ stdout :
321+ args [ 0 ] === 'spawn'
322+ ? `42\t0\tUIKitApplication:${ input . options . appBundleId } [launch-a][rb-legacy]`
323+ : JSON . stringify ( {
324+ devices : { 'com.apple.CoreSimulator.SimRuntime.iOS-26-0' : [ { udid : ios . id } ] } ,
325+ } ) ,
326+ stderr : '' ,
327+ exitCode : 0 ,
328+ } ;
329+ } ) ;
330+ const runCommand = vi . fn ( async ( ) => ( { stdout : 'start-a' , stderr : '' , exitCode : 0 } ) ) ;
331+ const fallback = vi . fn ( async ( ) => runnerResult ( ) ) ;
332+ const source = sourceReturning ( bridgeAcquisition ( ) ) ;
333+ const presentIosAcquisition = vi . fn ( async ( ) => ( {
334+ backend : 'xctest' as const ,
335+ producer : 'simulator-ax-bridge' as const ,
336+ nodes : [ { index : 0 , type : 'Application' } ] ,
337+ } ) ) ;
338+ const hasLiveRunnerSession = vi . fn ( async ( ) => false ) ;
339+ const baseHost = platformRuntimeHostFixture ( ) ;
340+ const route = createAppleSnapshotRoute (
341+ {
342+ ...baseHost ,
343+ appleApplications : { ...baseHost . appleApplications , hasLiveRunnerSession } ,
344+ snapshot : { captureSurface : vi . fn ( ) , presentIosAcquisition } ,
345+ } ,
346+ { source, resolveTarget : createSimulatorSnapshotTargetResolver ( ) } ,
347+ ) ;
348+ vi . useFakeTimers ( ) ;
349+ try {
350+ await withAppleToolProvider (
351+ createLocalAppleToolProvider ( { simctl : { run } , runCommand } ) ,
352+ async ( ) => {
353+ const capture = route . capture ( ios , input , signal ( ) , fallback ) ;
354+ await vi . advanceTimersByTimeAsync ( 4_500 ) ;
355+ expect ( fallback ) . not . toHaveBeenCalled ( ) ;
356+ expect ( hasLiveRunnerSession ) . toHaveBeenCalled ( ) ;
357+
358+ release ( ) ;
359+ await vi . advanceTimersByTimeAsync ( 0 ) ;
360+ const result = await capture ;
361+ expect ( result . producer ) . toBe ( 'simulator-ax-bridge' ) ;
362+ expect ( fallback ) . not . toHaveBeenCalled ( ) ;
363+ expect ( run . mock . calls . filter ( ( [ args ] ) => args [ 0 ] === 'spawn' ) ) . toHaveLength ( 1 ) ;
364+ } ,
365+ ) ;
366+ } finally {
367+ vi . useRealTimers ( ) ;
368+ }
369+ } ) ;
0 commit comments