@@ -547,6 +547,51 @@ describe("createApplicationGateway connection phase", () => {
547547 expect ( gateway . snapshot . phase ) . toBe ( "offline" ) ;
548548 } ) ;
549549
550+ it ( "schedules the guarded reload and publishes a terminal phase for a stale build" , ( ) => {
551+ const { gateway, current } = createStore ( ) ;
552+ gateway . start ( ) ;
553+
554+ current ( ) . opts . onClose ?.( {
555+ code : 1008 ,
556+ reason : "protocol mismatch: Control UI updated; reload this page to continue" ,
557+ error : {
558+ code : "UNAVAILABLE" ,
559+ message : "protocol mismatch: Control UI updated; reload this page to continue" ,
560+ details : {
561+ code : ConnectErrorDetailCodes . PROTOCOL_MISMATCH ,
562+ gatewayBuildId : "replacement-build" ,
563+ reloadRequired : true ,
564+ } ,
565+ } ,
566+ willRetry : false ,
567+ } ) ;
568+
569+ expect ( scheduleStaleChunkReloadMock ) . toHaveBeenCalledExactlyOnceWith ( {
570+ buildId : "replacement-build" ,
571+ } ) ;
572+ expect ( gateway . snapshot . phase ) . toBe ( "reload-required" ) ;
573+ } ) ;
574+
575+ it ( "keeps a bare protocol mismatch in the login-gate path" , ( ) => {
576+ const { gateway, current } = createStore ( ) ;
577+ gateway . start ( ) ;
578+
579+ current ( ) . opts . onClose ?.( {
580+ code : 1008 ,
581+ reason : "protocol mismatch" ,
582+ error : {
583+ code : "INVALID_REQUEST" ,
584+ message : "protocol mismatch" ,
585+ details : { code : ConnectErrorDetailCodes . PROTOCOL_MISMATCH } ,
586+ } ,
587+ willRetry : false ,
588+ } ) ;
589+
590+ expect ( scheduleStaleChunkReloadMock ) . not . toHaveBeenCalled ( ) ;
591+ expect ( gateway . snapshot . phase ) . toBe ( "stopped" ) ;
592+ expect ( gateway . snapshot . lastErrorCode ) . toBe ( ConnectErrorDetailCodes . PROTOCOL_MISMATCH ) ;
593+ } ) ;
594+
550595 it ( "keeps reconnecting across event-gap recovery with a fresh client" , ( ) => {
551596 const { gateway, clients, current } = createStore ( ) ;
552597 gateway . start ( ) ;
0 commit comments