@@ -14,6 +14,15 @@ const scope: PlatformRequestScope = {
1414 progress : { report : ( ) => undefined } ,
1515} ;
1616
17+ const RUNNING_EMULATOR_PROBES : ReadonlyArray < readonly [ string , string ] > = [
18+ [ 'ro.boot.qemu.avd_name' , 'Pixel_9_Pro_XL\n' ] ,
19+ [ 'sys.boot_completed' , '1\n' ] ,
20+ [ 'getprop ro.product.model; getprop ro.build.version.release' , 'sdk_gphone16k_arm64\n17\n' ] ,
21+ [ 'ro.build.characteristics' , 'phone\n' ] ,
22+ [ 'has-feature' , 'false\n' ] ,
23+ [ 'pm\0list\0features' , '' ] ,
24+ ] ;
25+
1726test . each ( [
1827 [ 'include-stopped' , true ] ,
1928 [ 'running-only' , false ] ,
@@ -30,11 +39,8 @@ test.each([
3039 'List of devices attached\nemulator-5554 device model:Pixel_9_Pro_XL\nphysical-1 device model:Phone\n' ,
3140 ) ;
3241 }
33- if ( key . includes ( 'ro.boot.qemu.avd_name' ) ) return result ( 'Pixel_9_Pro_XL\n' ) ;
34- if ( key . includes ( 'sys.boot_completed' ) ) return result ( '1\n' ) ;
35- if ( key . includes ( 'ro.build.characteristics' ) ) return result ( 'phone\n' ) ;
36- if ( key . includes ( 'has-feature' ) ) return result ( 'false\n' ) ;
37- if ( key . includes ( 'pm\0list\0features' ) ) return result ( '' ) ;
42+ const probe = RUNNING_EMULATOR_PROBES . find ( ( [ fragment ] ) => key . includes ( fragment ) ) ;
43+ if ( probe ) return result ( probe [ 1 ] ) ;
3844 throw new Error ( `Unexpected command: ${ request . executable } ${ request . args . join ( ' ' ) } ` ) ;
3945 } ) ;
4046
@@ -44,17 +50,67 @@ test.each([
4450 ) ;
4551
4652 assert . deepEqual (
47- devices . map ( ( candidate ) => [ candidate . id , candidate . name , candidate . booted ] ) ,
53+ devices . map ( ( candidate ) => [
54+ candidate . id ,
55+ candidate . name ,
56+ candidate . booted ,
57+ candidate . model ,
58+ candidate . osVersion ,
59+ ] ) ,
4860 [
49- [ 'emulator-5554' , 'Pixel 9 Pro XL' , true ] ,
50- ...( includesStoppedAvd ? [ [ 'Living_Room_TV' , 'Living_Room_TV' , false ] as const ] : [ ] ) ,
61+ [ 'emulator-5554' , 'Pixel 9 Pro XL' , true , 'sdk_gphone16k_arm64' , '17' ] ,
62+ ...( includesStoppedAvd
63+ ? [ [ 'Living_Room_TV' , 'Living_Room_TV' , false , undefined , undefined ] as const ]
64+ : [ ] ) ,
5165 ] ,
5266 ) ;
53- assert . ok ( calls . every ( ( call ) => call . timeoutMs === 10_000 ) ) ;
67+ const isDescriptionProbe = ( call : HostCommandRequest ) =>
68+ call . args . some ( ( arg ) => arg . includes ( 'ro.product.model' ) ) ;
69+ assert . deepEqual (
70+ calls . filter ( isDescriptionProbe ) . map ( ( call ) => call . timeoutMs ) ,
71+ [ 2_000 ] ,
72+ ) ;
73+ assert . ok (
74+ calls . filter ( ( call ) => ! isDescriptionProbe ( call ) ) . every ( ( call ) => call . timeoutMs === 10_000 ) ,
75+ ) ;
5476 assert . ok ( calls . every ( ( call ) => call . allowFailure === true ) ) ;
5577 } ,
5678) ;
5779
80+ test . each ( [
81+ [ 'exits non-zero' , async ( ) => result ( '' , 'error: closed' , 1 ) ] ,
82+ [
83+ 'times out' ,
84+ async ( ) => {
85+ throw new AppError ( 'COMMAND_FAILED' , 'adb timed out after 2000ms' , { timeoutMs : 2_000 } ) ;
86+ } ,
87+ ] ,
88+ ] as const ) (
89+ 'Android inventory leaves model and OS version unset when the description probe %s' ,
90+ async ( _case , describeProbe ) => {
91+ const host = createHost ( async ( request ) => {
92+ const key = request . args . join ( '\0' ) ;
93+ if ( key === 'devices\0-l' ) {
94+ return result ( 'List of devices attached\nR5CT1 device model:SM_S921B\n' ) ;
95+ }
96+ if ( key . includes ( 'ro.product.model' ) ) return await describeProbe ( ) ;
97+ const probe = RUNNING_EMULATOR_PROBES . find ( ( [ fragment ] ) => key . includes ( fragment ) ) ;
98+ if ( probe ) return result ( probe [ 1 ] ) ;
99+ throw new Error ( `Unexpected command: ${ request . executable } ${ request . args . join ( ' ' ) } ` ) ;
100+ } ) ;
101+
102+ const [ device ] = await createAndroidInventory ( host ) . discover (
103+ { androidAvdSelection : 'running-only' } ,
104+ scope ,
105+ ) ;
106+
107+ assert . equal ( device ?. name , 'SM S921B' ) ;
108+ assert . equal ( device ?. booted , true ) ;
109+ assert . equal ( device ?. model , undefined ) ;
110+ assert . equal ( device ?. osVersion , undefined ) ;
111+ } ,
112+ ) ;
113+
58114test ( 'Android inventory fails closed when adb is unavailable' , async ( ) => {
59115 const host = createHost ( async ( ) => result ( '' ) , { adb : undefined } ) ;
60116 await assert . rejects (
0 commit comments