@@ -417,6 +417,56 @@ describe("WsTransport", () => {
417417 await transport . dispose ( ) ;
418418 } , 5_000 ) ;
419419
420+ it ( "clears slow unary request tracking when the transport reconnects" , async ( ) => {
421+ const slowAckThresholdMs = 25 ;
422+ setSlowRpcAckThresholdMsForTests ( slowAckThresholdMs ) ;
423+ const transport = createTransport ( "ws://localhost:3020" ) ;
424+
425+ const requestPromise = transport . request ( ( client ) =>
426+ client [ WS_METHODS . serverUpsertKeybinding ] ( {
427+ command : "terminal.toggle" ,
428+ key : "ctrl+k" ,
429+ } ) ,
430+ ) ;
431+
432+ await waitFor ( ( ) => {
433+ expect ( sockets ) . toHaveLength ( 1 ) ;
434+ } ) ;
435+
436+ const firstSocket = getSocket ( ) ;
437+ firstSocket . open ( ) ;
438+
439+ await waitFor ( ( ) => {
440+ expect ( firstSocket . sent ) . toHaveLength ( 1 ) ;
441+ } ) ;
442+
443+ const firstRequest = JSON . parse ( firstSocket . sent [ 0 ] ?? "{}" ) as { id : string } ;
444+
445+ await waitFor ( ( ) => {
446+ expect ( getSlowRpcAckRequests ( ) ) . toMatchObject ( [
447+ {
448+ requestId : firstRequest . id ,
449+ tag : WS_METHODS . serverUpsertKeybinding ,
450+ } ,
451+ ] ) ;
452+ } , 1_000 ) ;
453+
454+ void requestPromise . catch ( ( ) => undefined ) ;
455+
456+ await transport . reconnect ( ) ;
457+
458+ expect ( getSlowRpcAckRequests ( ) ) . toEqual ( [ ] ) ;
459+
460+ await waitFor ( ( ) => {
461+ expect ( sockets ) . toHaveLength ( 2 ) ;
462+ } ) ;
463+
464+ const secondSocket = getSocket ( ) ;
465+ secondSocket . open ( ) ;
466+
467+ await transport . dispose ( ) ;
468+ } , 5_000 ) ;
469+
420470 it ( "sends unary RPC requests and resolves successful exits" , async ( ) => {
421471 const transport = createTransport ( "ws://localhost:3020" ) ;
422472
0 commit comments