@@ -599,6 +599,45 @@ describe("SessionWebSocketManagerImpl", () => {
599599 expect ( called ) . toHaveLength ( 0 ) ;
600600 } ) ;
601601
602+ it ( "broadcast pattern delivers to authenticated clients and skips unauthenticated" , ( ) => {
603+ const { manager, sockets, mockRepo } = createManager ( ) ;
604+
605+ // Authenticated client (in-memory)
606+ const authedWs = createFakeWebSocket ( ) ;
607+ sockets . set ( authedWs , [ "wsid:ws-authed" ] ) ;
608+ manager . setClient ( authedWs , createClientInfo ( { ws : authedWs } ) ) ;
609+
610+ // Post-hibernation client (persisted mapping only, no in-memory ClientInfo)
611+ const hibernatedWs = createFakeWebSocket ( ) ;
612+ sockets . set ( hibernatedWs , [ "wsid:ws-hibernated" ] ) ;
613+ mockRepo . addMapping ( "ws-hibernated" , {
614+ participant_id : "p-2" ,
615+ client_id : "c-2" ,
616+ user_id : "u-2" ,
617+ github_name : null ,
618+ github_login : null ,
619+ } ) ;
620+
621+ // Unauthenticated client (connected but never subscribed)
622+ const unauthWs = createFakeWebSocket ( ) ;
623+ sockets . set ( unauthWs , [ "wsid:ws-unauth" ] ) ;
624+
625+ // Sandbox (should never receive)
626+ const sandboxWs = createFakeWebSocket ( ) ;
627+ sockets . set ( sandboxWs , [ "sandbox" , "sid:sb-1" ] ) ;
628+
629+ // Simulate the DO's broadcast() pattern
630+ const message = JSON . stringify ( { type : "sandbox_status" , status : "ready" } ) ;
631+ manager . forEachClientSocket ( "authenticated_only" , ( ws ) => {
632+ manager . send ( ws , message ) ;
633+ } ) ;
634+
635+ expect ( authedWs . send ) . toHaveBeenCalledWith ( message ) ;
636+ expect ( hibernatedWs . send ) . toHaveBeenCalledWith ( message ) ;
637+ expect ( unauthWs . send ) . not . toHaveBeenCalled ( ) ;
638+ expect ( sandboxWs . send ) . not . toHaveBeenCalled ( ) ;
639+ } ) ;
640+
602641 it ( "never calls fn for sandbox sockets regardless of mode" , ( ) => {
603642 const { manager, sockets } = createManager ( ) ;
604643 const sandboxWs = createFakeWebSocket ( ) ;
0 commit comments