@@ -432,6 +432,7 @@ describe("resolveDeliveryTarget", () => {
432432 to : "user:123456789" ,
433433 kind : "user" ,
434434 source : "directory" ,
435+ resolutionSource : "plugin" ,
435436 } ) ;
436437
437438 const cfg = makeCfg ( { bindings : [ ] } ) ;
@@ -588,6 +589,88 @@ describe("resolveDeliveryTarget", () => {
588589 expect ( result . threadId ) . toBeUndefined ( ) ;
589590 } ) ;
590591
592+ it ( "preserves plugin-canonical targets that begin with the selected channel prefix" , async ( ) => {
593+ setMainSessionEntry ( undefined ) ;
594+ const canonicalTarget = "Bncr:tgBot:-1003891624016:6278285192" ;
595+ setActivePluginRegistry (
596+ createTestRegistry ( [
597+ {
598+ pluginId : "bncr" ,
599+ source : "test" ,
600+ plugin : createOutboundTestPlugin ( {
601+ id : "bncr" ,
602+ outbound : createStubOutbound ( "Bncr" ) ,
603+ messaging : {
604+ targetPrefixes : [ "bncr" ] ,
605+ targetResolver : {
606+ resolveTarget : async ( { input } ) =>
607+ input === canonicalTarget
608+ ? { to : canonicalTarget , kind : "group" as const , source : "normalized" as const }
609+ : null ,
610+ } ,
611+ } ,
612+ } ) ,
613+ } ,
614+ ] ) ,
615+ ) ;
616+
617+ const result = await resolveDeliveryTarget ( makeCfg ( { bindings : [ ] } ) , AGENT_ID , {
618+ channel : "bncr" ,
619+ to : canonicalTarget ,
620+ } ) ;
621+
622+ expect ( result . ok ) . toBe ( true ) ;
623+ expect ( result . to ) . toBe ( canonicalTarget ) ;
624+ expect ( result . threadId ) . toBeUndefined ( ) ;
625+ } ) ;
626+
627+ it ( "uses plugin-resolved directory targets for route parsing" , async ( ) => {
628+ setMainSessionEntry ( undefined ) ;
629+ setActivePluginRegistry (
630+ createTestRegistry ( [
631+ {
632+ pluginId : "alpha" ,
633+ source : "test" ,
634+ plugin : createOutboundTestPlugin ( {
635+ id : "alpha" ,
636+ outbound : createStubOutbound ( "Alpha" ) ,
637+ messaging : {
638+ targetPrefixes : [ "alpha" ] ,
639+ targetResolver : {
640+ resolveTarget : async ( { input } ) =>
641+ input === "alice"
642+ ? { to : "user:123" , kind : "user" as const , source : "directory" as const }
643+ : null ,
644+ } ,
645+ resolveOutboundSessionRoute : ( { cfg, agentId, accountId, target } ) => {
646+ const isUser = target . startsWith ( "user:" ) ;
647+ return buildChannelOutboundSessionRoute ( {
648+ cfg,
649+ agentId,
650+ channel : "alpha" ,
651+ accountId,
652+ peer : { kind : isUser ? "direct" : "channel" , id : target } ,
653+ chatType : isUser ? "direct" : "channel" ,
654+ from : target ,
655+ to : isUser ? target : `channel:${ target } ` ,
656+ } ) ;
657+ } ,
658+ } ,
659+ } ) ,
660+ } ,
661+ ] ) ,
662+ ) ;
663+
664+ const result = await resolveDeliveryTarget ( makeCfg ( { bindings : [ ] } ) , AGENT_ID , {
665+ channel : "alpha" ,
666+ to : "alice" ,
667+ } ) ;
668+
669+ expect ( result . ok ) . toBe ( true ) ;
670+ expect ( result . to ) . toBe ( "user:123" ) ;
671+ expect ( result . threadId ) . toBeUndefined ( ) ;
672+ } ) ;
673+
591674 it ( "uses canonical route targets even when the route has no thread" , async ( ) => {
592675 setMainSessionEntry ( undefined ) ;
593676 setActivePluginRegistry (
0 commit comments