55 DeviceOperationError ,
66 LOCAL_DEVICE_HOST_ID ,
77 ThreadId ,
8+ type DeviceSummary ,
89 type DeviceServiceState ,
910 type ServerSettings as Settings ,
1011 type SshDeviceHostConfig ,
@@ -90,13 +91,18 @@ const fixture = Effect.fn("fixture")(function* (
9091 const agentStarts : string [ ] = [ ] ;
9192 const agentStops : string [ ] = [ ] ;
9293 const requests : string [ ] = [ ] ;
94+ const devices : Array < Omit < DeviceSummary , "hostId" > > = [ ] ;
95+ const encoderResult = yield * Ref . make ( { code : 0 , stdout : " V....D libx264" , stderr : "" } ) ;
9396 let booted = false ;
9497 let shutDown = false ;
9598 const ready : DeviceHost . DeviceHostReady = {
9699 nodePath : process . execPath ,
97100 hub : { origin : "http://device.test" } ,
98101 helpers : { serveSimAxSettings : null , serveSimCli : null } ,
99- run : ( ) => Effect . succeed ( { code : 0 , stdout : "Pixel_API_35\n" , stderr : "" } ) ,
102+ run : ( command ) =>
103+ command === "emulator"
104+ ? Effect . succeed ( { code : 0 , stdout : "Pixel_API_35\n" , stderr : "" } )
105+ : Ref . get ( encoderResult ) ,
100106 } ;
101107 const host : DeviceHost . DeviceHost [ "Service" ] = {
102108 ...( inspectError
@@ -115,7 +121,10 @@ const fixture = Effect.fn("fixture")(function* (
115121 id : LOCAL_DEVICE_HOST_ID ,
116122 kind : "local" ,
117123 label : "Test server" ,
118- platforms : [ { platform : "android" , available : true } ] ,
124+ platforms : [
125+ { platform : "android" , available : true } ,
126+ { platform : "ios" , available : true } ,
127+ ] ,
119128 hubInstalled : true ,
120129 agentDeviceInstalled : false ,
121130 } ) ,
@@ -207,29 +216,35 @@ const fixture = Effect.fn("fixture")(function* (
207216 ) ,
208217 ) ;
209218 }
219+ if ( request . url . endsWith ( "/grid/api/start" ) ) {
220+ return HttpClientResponse . fromWeb ( request , Response . json ( { ok : true } ) ) ;
221+ }
210222 return HttpClientResponse . fromWeb (
211223 request ,
212224 Response . json ( {
213- simulators : [ ] ,
214- emulators : booted
215- ? [
216- {
217- id : "emulator-5554" ,
218- name : "Pixel_API_35" ,
219- platform : "android" ,
220- version : "Android 15" ,
221- booted : true ,
222- physical : false ,
223- } ,
224- ]
225- : [ ] ,
225+ simulators : devices . filter ( ( device ) => device . platform === "ios" ) ,
226+ emulators : [
227+ ...devices . filter ( ( device ) => device . platform === "android" ) ,
228+ ...( booted
229+ ? [
230+ {
231+ id : "emulator-5554" ,
232+ name : "Pixel_API_35" ,
233+ platform : "android" ,
234+ version : "Android 15" ,
235+ booted : true ,
236+ physical : false ,
237+ } ,
238+ ]
239+ : [ ] ) ,
240+ ] ,
226241 } ) ,
227242 ) ;
228243 } ) ,
229244 ) ,
230245 ) ,
231246 ) ;
232- return { service, starts, agentStarts, agentStops, requests, settings } ;
247+ return { service, starts, agentStarts, agentStops, requests, settings, devices , encoderResult } ;
233248} ) ;
234249
235250describe ( "device setup consent" , ( ) => {
@@ -349,6 +364,88 @@ describe("device setup consent", () => {
349364 } ) . pipe ( Effect . scoped ) ,
350365 ) ;
351366
367+ it . effect ( "blocks only emulator video until ffmpeg is usable, then allows retry" , ( ) =>
368+ Effect . gen ( function * ( ) {
369+ const { service, requests, devices, encoderResult } = yield * fixture ( ) ;
370+ devices . push (
371+ {
372+ id : DeviceId . make ( "physical-android" ) ,
373+ name : "Pixel" ,
374+ platform : "android" ,
375+ version : "Android 15" ,
376+ booted : true ,
377+ physical : true ,
378+ } ,
379+ {
380+ id : DeviceId . make ( "ios-simulator" ) ,
381+ name : "iPhone" ,
382+ platform : "ios" ,
383+ version : "iOS 18" ,
384+ booted : true ,
385+ physical : false ,
386+ } ,
387+ ) ;
388+ yield * Ref . set ( encoderResult , { code : 127 , stdout : "" , stderr : "spawn ffmpeg ENOENT" } ) ;
389+ const state = yield * service . configure ( { enabled : true } ) ;
390+ expect ( state . devices . map ( ( device ) => device . id ) ) . toEqual ( [
391+ "ios-simulator" ,
392+ "physical-android" ,
393+ "Pixel_API_35" ,
394+ ] ) ;
395+ const threadId = ThreadId . make ( "emulator-video-readiness" ) ;
396+ const physical = yield * service . open ( {
397+ threadId,
398+ deviceId : "physical-android" ,
399+ platform : "android" ,
400+ } ) ;
401+ const ios = yield * service . open ( { threadId, deviceId : "ios-simulator" , platform : "ios" } ) ;
402+ expect ( physical . deviceId ) . toBe ( "physical-android" ) ;
403+ expect ( ios . deviceId ) . toBe ( "ios-simulator" ) ;
404+
405+ const openEmulator = service . open ( {
406+ threadId,
407+ deviceId : "Pixel_API_35" ,
408+ platform : "android" ,
409+ } ) ;
410+ const missing = yield * openEmulator . pipe ( Effect . flip ) ;
411+ expect ( missing . message ) . toMatch ( / f f m p e g / i) ;
412+ expect ( missing . message ) . toMatch ( / e m u l a t o r / i) ;
413+ expect ( requests . filter ( ( url ) => url . endsWith ( "/boot" ) ) ) . toEqual ( [ ] ) ;
414+ expect ( ( yield * service . state ) . sessions ) . toEqual ( [ physical , ios ] ) ;
415+ expect ( ( yield * service . state ) . bootingDevices ?? [ ] ) . toEqual ( [ ] ) ;
416+
417+ yield * Ref . set ( encoderResult , { code : 1 , stdout : "" , stderr : "cannot execute ffmpeg" } ) ;
418+ expect ( ( yield * openEmulator . pipe ( Effect . flip ) ) . message ) . toMatch ( / f f m p e g / i) ;
419+ yield * Ref . set ( encoderResult , {
420+ code : 0 ,
421+ stdout : " V....D libx264rgb libx264 H.264 / AVC RGB (codec h264)" ,
422+ stderr : "" ,
423+ } ) ;
424+ expect ( ( yield * openEmulator . pipe ( Effect . flip ) ) . message ) . toMatch ( / l i b x 2 6 4 / i) ;
425+ expect ( requests . filter ( ( url ) => url . endsWith ( "/boot" ) ) ) . toEqual ( [ ] ) ;
426+ expect ( ( yield * service . state ) . sessions ) . toEqual ( [ physical , ios ] ) ;
427+
428+ devices . push ( {
429+ id : DeviceId . make ( "emulator-5556" ) ,
430+ name : "Already_booted" ,
431+ platform : "android" ,
432+ version : "Android 15" ,
433+ booted : true ,
434+ physical : false ,
435+ } ) ;
436+ expect (
437+ ( yield * service
438+ . open ( { threadId, deviceId : "emulator-5556" , platform : "android" } )
439+ . pipe ( Effect . flip ) ) . message ,
440+ ) . toMatch ( / l i b x 2 6 4 / i) ;
441+
442+ yield * Ref . set ( encoderResult , { code : 0 , stdout : " V....D libx264" , stderr : "" } ) ;
443+ const emulator = yield * openEmulator ;
444+ expect ( emulator . deviceId ) . toBe ( "emulator-5554" ) ;
445+ expect ( requests . filter ( ( url ) => url . endsWith ( "/boot" ) ) ) . toHaveLength ( 1 ) ;
446+ } ) . pipe ( Effect . scoped ) ,
447+ ) ;
448+
352449 it . effect ( "installs agent support only after the separate agent permission" , ( ) =>
353450 Effect . gen ( function * ( ) {
354451 const { service, agentStarts, agentStops, settings } = yield * fixture ( ) ;
0 commit comments