@@ -22,7 +22,8 @@ describe('ForwardingController', () => {
2222 const scanCatalog : ProtocolResponse = { kind : 'switchProfileCatalog' , id : 'catalog' , catalog : { catalogRevision : 1 , profiles : [ { id : 'builtin.switchify-scanning' , version : 1 , name : 'Switchify scanning' , kind : 'scanning' , bindings : [ { switchId : 1 , label : 'Select' , behavior : 'stateful' } ] } ] } } ;
2323 const connection = { request : jest . fn ( async ( ) => scanCatalog ) , send : jest . fn ( async ( ) => true ) } ;
2424 const pc = profile ( generic , [ 'switch.edge' ] ) ; pc . capabilities . switchScanning = true ;
25- const controller = new ForwardingController ( connection , bridge , pc , 5000 , fakeTimers ( ) , ( ) => 'session' ) ;
25+ const onSafetyStop = jest . fn ( ) ;
26+ const controller = new ForwardingController ( connection , bridge , pc , 5000 , fakeTimers ( ) , ( ) => 'session' , onSafetyStop ) ;
2627 await controller . loadProfiles ( ) ; await controller . start ( ) ;
2728 bridge . emit ( { type : 'switchEdge' , generation : 41 , sequence : 1 , keyCode : 20 , down : true , downTimeMs : 0 , eventTimeMs : 0 , cancelled : false } ) ;
2829 for ( let i = 0 ; i < 10 ; i ++ ) await Promise . resolve ( ) ;
@@ -37,7 +38,12 @@ describe('ForwardingController', () => {
3738 expect ( controller . snapshot ( ) . phase ) . toBe ( 'idle' ) ;
3839 const edges = ( connection . send as jest . Mock ) . mock . calls . filter ( ( [ command ] ) => command === 'switch.edge' ) . map ( ( [ , payload ] ) => payload . state ) ;
3940 expect ( edges ) . toEqual ( [ 'down' , 'up' , 'down' ] ) ;
40- expect ( connection . send ) . toHaveBeenCalledWith ( 'switch.session.stop' , expect . anything ( ) ) ;
41+ // The stop is a safety stop and follows the last edge, so the PC never
42+ // sees an edge after the session has ended.
43+ expect ( onSafetyStop ) . toHaveBeenCalledTimes ( 1 ) ;
44+ const commands = ( connection . send as jest . Mock ) . mock . calls . map ( ( [ command ] ) => command ) . filter ( ( command ) => command === 'switch.edge' || command === 'switch.session.stop' ) ;
45+ expect ( commands . at ( - 1 ) ) . toBe ( 'switch.session.stop' ) ;
46+ expect ( commands . filter ( ( command ) => command === 'switch.session.stop' ) ) . toHaveLength ( 1 ) ;
4147 await controller . cleanup ( ) ;
4248 } ) ;
4349 it . each ( [ 'cancelled' , 'replaced' ] ) ( 'keeps a scanning session alive and never selects on its own when %s' , async ( reason ) => {
0 commit comments