@@ -161,7 +161,7 @@ test('direct daemon requests cannot bypass reject lock policy for existing sessi
161161 }
162162} ) ;
163163
164- test ( 'fresh named sessions with matching explicit serial bind and serialize on the selected device ' , async ( ) => {
164+ test ( 'a fresh named session with a matching explicit serial waits for the holder, then is refused ' , async ( ) => {
165165 const sessionStore = makeSessionStore ( 'agent-device-router-lock-' ) ;
166166 const dispatchGate = installGatedDispatch ( ) ;
167167
@@ -218,23 +218,22 @@ test('fresh named sessions with matching explicit serial bind and serialize on t
218218
219219 dispatchGate . releaseNext ( ) ;
220220
221- await vi . waitFor ( ( ) => {
222- expect ( dispatchGate . order ) . toEqual ( [
223- 'start-snapshot-emulator-5554' ,
224- 'end-snapshot-emulator-5554' ,
225- 'start-snapshot-emulator-5554' ,
226- ] ) ;
227- } ) ;
228-
229- dispatchGate . releaseNext ( ) ;
230-
231221 const [ firstResponse , secondResponse ] = await Promise . all ( [ first , second ] ) ;
232222
233223 expect ( firstResponse . ok ) . toBe ( true ) ;
234- expect ( secondResponse . ok ) . toBe ( true ) ;
235- expect ( dispatchGate . getMaxActive ( ) ) . toBe ( 1 ) ;
224+ expect ( secondResponse ) . toMatchObject ( {
225+ ok : false ,
226+ error : {
227+ code : 'DEVICE_IN_USE' ,
228+ details : { session : 'qa-android-a' , deviceId : 'emulator-5554' } ,
229+ } ,
230+ } ) ;
231+ expect ( dispatchGate . order ) . toEqual ( [
232+ 'start-snapshot-emulator-5554' ,
233+ 'end-snapshot-emulator-5554' ,
234+ ] ) ;
236235 expect ( sessionStore . get ( 'qa-android-a' ) ?. device . id ) . toBe ( 'emulator-5554' ) ;
237- expect ( sessionStore . get ( 'qa-android-b' ) ?. device . id ) . toBe ( 'emulator-5554' ) ;
236+ expect ( sessionStore . get ( 'qa-android-b' ) ) . toBeUndefined ( ) ;
238237} ) ;
239238
240239test ( 'fresh named sessions with the same name serialize first binding before rejecting another device' , async ( ) => {
@@ -316,7 +315,7 @@ test('fresh named sessions with the same name serialize first binding before rej
316315 expect ( sessionStore . get ( 'qa-android' ) ?. device . id ) . toBe ( 'emulator-5554' ) ;
317316} ) ;
318317
319- test ( 'fresh named sessions with only lock platform default serialize on the selected device ' , async ( ) => {
318+ test ( 'a fresh named session with only a lock platform default waits for the holder, then is refused ' , async ( ) => {
320319 const sessionStore = makeSessionStore ( 'agent-device-router-lock-' ) ;
321320 const dispatchGate = installGatedDispatch ( ) ;
322321
@@ -369,23 +368,22 @@ test('fresh named sessions with only lock platform default serialize on the sele
369368
370369 dispatchGate . releaseNext ( ) ;
371370
372- await vi . waitFor ( ( ) => {
373- expect ( dispatchGate . order ) . toEqual ( [
374- 'start-snapshot-emulator-5554' ,
375- 'end-snapshot-emulator-5554' ,
376- 'start-snapshot-emulator-5554' ,
377- ] ) ;
378- } ) ;
379-
380- dispatchGate . releaseNext ( ) ;
381-
382371 const [ firstResponse , secondResponse ] = await Promise . all ( [ first , second ] ) ;
383372
384373 expect ( firstResponse . ok ) . toBe ( true ) ;
385- expect ( secondResponse . ok ) . toBe ( true ) ;
386- expect ( dispatchGate . getMaxActive ( ) ) . toBe ( 1 ) ;
374+ expect ( secondResponse ) . toMatchObject ( {
375+ ok : false ,
376+ error : {
377+ code : 'DEVICE_IN_USE' ,
378+ details : { session : 'qa-default-a' , deviceId : 'emulator-5554' } ,
379+ } ,
380+ } ) ;
381+ expect ( dispatchGate . order ) . toEqual ( [
382+ 'start-snapshot-emulator-5554' ,
383+ 'end-snapshot-emulator-5554' ,
384+ ] ) ;
387385 expect ( sessionStore . get ( 'qa-default-a' ) ?. device . id ) . toBe ( 'emulator-5554' ) ;
388- expect ( sessionStore . get ( 'qa-default-b' ) ?. device . id ) . toBe ( 'emulator-5554' ) ;
386+ expect ( sessionStore . get ( 'qa-default-b' ) ) . toBeUndefined ( ) ;
389387} ) ;
390388
391389test ( 'fresh named sessions reject incompatible selector combinations before binding' , async ( ) => {
0 commit comments