@@ -2,12 +2,17 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
22
33const mocks = vi . hoisted ( ( ) => ( {
44 listChannelPlugins : vi . fn ( ) ,
5+ resolveOutboundChannelPlugin : vi . fn ( ) ,
56} ) ) ;
67
78vi . mock ( "../../channels/plugins/index.js" , ( ) => ( {
89 listChannelPlugins : mocks . listChannelPlugins ,
910} ) ) ;
1011
12+ vi . mock ( "./channel-resolution.js" , ( ) => ( {
13+ resolveOutboundChannelPlugin : mocks . resolveOutboundChannelPlugin ,
14+ } ) ) ;
15+
1116import {
1217 listConfiguredMessageChannels ,
1318 resolveMessageChannelSelection ,
@@ -36,6 +41,10 @@ describe("listConfiguredMessageChannels", () => {
3641 beforeEach ( ( ) => {
3742 mocks . listChannelPlugins . mockReset ( ) ;
3843 mocks . listChannelPlugins . mockReturnValue ( [ ] ) ;
44+ mocks . resolveOutboundChannelPlugin . mockReset ( ) ;
45+ mocks . resolveOutboundChannelPlugin . mockImplementation ( ( { channel } : { channel : string } ) => ( {
46+ id : channel ,
47+ } ) ) ;
3948 } ) ;
4049
4150 it ( "skips unknown plugin ids and plugins without accounts" , async ( ) => {
@@ -158,6 +167,35 @@ describe("resolveMessageChannelSelection", () => {
158167 ) . rejects . toThrow ( "Unknown channel: channel:c123" ) ;
159168 } ) ;
160169
170+ it ( "falls back when the explicit known channel is unavailable in the active plugin registry" , async ( ) => {
171+ mocks . resolveOutboundChannelPlugin . mockImplementation ( ( { channel } : { channel : string } ) =>
172+ channel === "slack" ? { id : "slack" } : undefined ,
173+ ) ;
174+
175+ const selection = await resolveMessageChannelSelection ( {
176+ cfg : { } as never ,
177+ channel : "discord" ,
178+ fallbackChannel : "slack" ,
179+ } ) ;
180+
181+ expect ( selection ) . toEqual ( {
182+ channel : "slack" ,
183+ configured : [ ] ,
184+ source : "tool-context-fallback" ,
185+ } ) ;
186+ } ) ;
187+
188+ it ( "throws unavailable when a known channel has no active plugin" , async ( ) => {
189+ mocks . resolveOutboundChannelPlugin . mockReturnValue ( undefined ) ;
190+
191+ await expect (
192+ resolveMessageChannelSelection ( {
193+ cfg : { } as never ,
194+ channel : "discord" ,
195+ } ) ,
196+ ) . rejects . toThrow ( "Channel is unavailable: discord" ) ;
197+ } ) ;
198+
161199 it ( "throws when no channel is provided and nothing is configured" , async ( ) => {
162200 await expect (
163201 resolveMessageChannelSelection ( {
0 commit comments