@@ -432,7 +432,59 @@ describe("mattermost inbound user posts", () => {
432432 expect ( ctx ?. Provider ) . toBe ( "mattermost" ) ;
433433 } ) ;
434434
435- it ( "drops posts when channel type cannot be resolved" , async ( ) => {
435+ it ( "uses websocket channel type when REST channel lookup fails" , async ( ) => {
436+ const socket = new FakeWebSocket ( ) ;
437+ const abortController = new AbortController ( ) ;
438+ mockState . abortController = abortController ;
439+ const runtimeCore = createRuntimeCore ( testConfig ) ;
440+ mockState . runtimeCore = runtimeCore ;
441+ mockState . resolveChannelInfo . mockResolvedValue ( null ) ;
442+
443+ const monitor = monitorMattermostProvider ( {
444+ config : testConfig ,
445+ runtime : testRuntime ( ) ,
446+ abortSignal : abortController . signal ,
447+ webSocketFactory : ( ) => socket ,
448+ } ) ;
449+
450+ await vi . waitFor ( ( ) => {
451+ expect ( socket . openListenerCount ) . toBeGreaterThan ( 0 ) ;
452+ } ) ;
453+ socket . emitOpen ( ) ;
454+
455+ await socket . emitMessage ( {
456+ event : "posted" ,
457+ data : {
458+ channel_id : "chan-1" ,
459+ channel_name : "town-square" ,
460+ channel_display_name : "Town Square" ,
461+ channel_type : "O" ,
462+ sender_name : "alice" ,
463+ post : JSON . stringify ( {
464+ id : "post-ws-kind" ,
465+ channel_id : "chan-1" ,
466+ user_id : "user-1" ,
467+ message : "hello with websocket kind" ,
468+ create_at : 1_714_000_000_000 ,
469+ } ) ,
470+ } ,
471+ broadcast : {
472+ channel_id : "chan-1" ,
473+ user_id : "user-1" ,
474+ } ,
475+ } ) ;
476+ socket . emitClose ( 1000 ) ;
477+ await monitor ;
478+
479+ expect ( mockState . dispatchReplyFromConfig ) . toHaveBeenCalledTimes ( 1 ) ;
480+ const ctx = mockState . dispatchReplyFromConfig . mock . calls . at ( 0 ) ?. [ 0 ] . ctx ;
481+ expect ( ctx ?. BodyForAgent ) . toBe ( "hello with websocket kind" ) ;
482+ expect ( ctx ?. ChatType ) . toBe ( "channel" ) ;
483+ expect ( ctx ?. ConversationLabel ) . toBe ( "Town Square id:chan-1" ) ;
484+ expect ( runtimeCore . channel . session . recordInboundSession ) . toHaveBeenCalledTimes ( 1 ) ;
485+ } ) ;
486+
487+ it ( "drops posts when neither REST nor websocket channel type can be resolved" , async ( ) => {
436488 const socket = new FakeWebSocket ( ) ;
437489 const abortController = new AbortController ( ) ;
438490 mockState . abortController = abortController ;
0 commit comments