@@ -46,7 +46,9 @@ function selectionHandler(
4646 deviceInventoryGateways : createTestDeviceInventoryGateways ( {
4747 local : async ( request ) => {
4848 inventoryRequests . push ( request ) ;
49- return devices ;
49+ return request . androidAvdSelection === 'running-only'
50+ ? devices . filter ( ( device ) => device . platform !== 'android' || device . booted === true )
51+ : devices ;
5052 } ,
5153 } ) ,
5254 deviceRuntimeGateway : { ...lifecycleDeviceRuntimeGateway , inspectFacts } ,
@@ -80,33 +82,37 @@ test('fresh no-app foreground open selects iOS from mixed Android and iOS invent
8082 expect ( sessionStore . get ( 'foreground' ) ?. device . id ) . toBe ( ios . id ) ;
8183} ) ;
8284
83- test ( 'shutdown selects a stopped Android AVD and rejects an invalid selector before facts' , async ( ) => {
84- const inventoryRequests : Array < { platform ?: string ; androidAvdSelection ?: string } > = [ ] ;
85- const stopped = { ...android , booted : false } ;
86- const { handler, inspectFacts } = selectionHandler ( [ stopped ] , inventoryRequests ) ;
87- const selected = await handler ( {
88- token : 'test-token' ,
89- session : 'no-session' ,
90- command : 'shutdown' ,
91- positionals : [ ] ,
92- flags : { platform : 'android' , device : stopped . name } ,
93- meta : { requestId : 'shutdown-stopped' } ,
94- } ) ;
95- expect (
96- inventoryRequests . some ( ( request ) => request . androidAvdSelection === 'include-stopped' ) ,
97- ) . toBe ( true ) ;
98- if ( ! selected . ok ) expect ( selected . error . code ) . not . toBe ( 'DEVICE_NOT_FOUND' ) ;
99- expect ( inspectFacts ) . toHaveBeenCalledWith ( stopped ) ;
100- const factsBeforeInvalid = inspectFacts . mock . calls . length ;
85+ test . each ( [ 'boot' , 'shutdown' , 'capabilities' , 'apps' ] as const ) (
86+ '%s keeps stopped-AVD selection consistent through request admission' ,
87+ async ( command ) => {
88+ const inventoryRequests : Array < { platform ?: string ; androidAvdSelection ?: string } > = [ ] ;
89+ const stopped = { ...android , id : android . name , booted : false } ;
90+ const { handler, inspectFacts } = selectionHandler ( [ stopped ] , inventoryRequests ) ;
91+ const selected = await handler ( {
92+ token : 'test-token' ,
93+ session : 'no-session' ,
94+ command,
95+ positionals : [ ] ,
96+ flags : { platform : 'android' , device : stopped . name } ,
97+ meta : { requestId : `${ command } -stopped` } ,
98+ } ) ;
99+ expect (
100+ inventoryRequests . length > 0 &&
101+ inventoryRequests . every ( ( request ) => request . androidAvdSelection === 'include-stopped' ) ,
102+ ) . toBe ( true ) ;
103+ if ( ! selected . ok ) expect ( selected . error . code ) . not . toBe ( 'DEVICE_NOT_FOUND' ) ;
104+ expect ( inspectFacts ) . toHaveBeenCalledWith ( stopped ) ;
105+ const factsBeforeInvalid = inspectFacts . mock . calls . length ;
101106
102- const invalid = await handler ( {
103- token : 'test-token' ,
104- session : 'no-session' ,
105- command : 'shutdown' ,
106- positionals : [ ] ,
107- flags : { platform : 'android' , device : 'missing-avd' } ,
108- meta : { requestId : 'shutdown-missing' } ,
109- } ) ;
110- expect ( invalid ) . toMatchObject ( { ok : false , error : { code : 'DEVICE_NOT_FOUND' } } ) ;
111- expect ( inspectFacts ) . toHaveBeenCalledTimes ( factsBeforeInvalid ) ;
112- } ) ;
107+ const invalid = await handler ( {
108+ token : 'test-token' ,
109+ session : 'no-session' ,
110+ command,
111+ positionals : [ ] ,
112+ flags : { platform : 'android' , device : 'missing-avd' } ,
113+ meta : { requestId : `${ command } -missing` } ,
114+ } ) ;
115+ expect ( invalid ) . toMatchObject ( { ok : false , error : { code : 'DEVICE_NOT_FOUND' } } ) ;
116+ expect ( inspectFacts ) . toHaveBeenCalledTimes ( factsBeforeInvalid ) ;
117+ } ,
118+ ) ;
0 commit comments