@@ -9,6 +9,7 @@ const mocks = vi.hoisted(() => ({
99 listChannelPluginCatalogEntries : vi . fn ( ) ,
1010 getChannelPluginCatalogEntry : vi . fn ( ) ,
1111 getChannelPlugin : vi . fn ( ) ,
12+ getLoadedChannelPlugin : vi . fn ( ) ,
1213 loadChannelSetupPluginRegistrySnapshotForChannel : vi . fn ( ) ,
1314 ensureChannelSetupPluginInstalled : vi . fn ( ) ,
1415 createClackPrompter : vi . fn ( ( ) => ( { } ) as never ) ,
@@ -26,6 +27,7 @@ vi.mock("../../channels/plugins/catalog.js", () => ({
2627
2728vi . mock ( "../../channels/plugins/index.js" , ( ) => ( {
2829 getChannelPlugin : mocks . getChannelPlugin ,
30+ getLoadedChannelPlugin : mocks . getLoadedChannelPlugin ,
2931 normalizeChannelId : ( value : unknown ) => ( typeof value === "string" ? value . trim ( ) || null : null ) ,
3032} ) ) ;
3133
@@ -78,14 +80,104 @@ function firstMockArg(mock: { mock: { calls: ReadonlyArray<ReadonlyArray<unknown
7880describe ( "resolveInstallableChannelPlugin" , ( ) => {
7981 beforeEach ( ( ) => {
8082 vi . clearAllMocks ( ) ;
83+ mocks . resolveAgentWorkspaceDir . mockReturnValue ( "/tmp/workspace" ) ;
84+ mocks . resolveDefaultAgentId . mockReturnValue ( "default" ) ;
8185 mocks . getChannelPlugin . mockReturnValue ( undefined ) ;
86+ mocks . getLoadedChannelPlugin . mockReturnValue ( undefined ) ;
8287 mocks . getChannelPluginCatalogEntry . mockReturnValue ( undefined ) ;
8388 mocks . ensureChannelSetupPluginInstalled . mockResolvedValue ( {
8489 cfg : { } ,
8590 installed : false ,
8691 } ) ;
8792 } ) ;
8893
94+ it ( "returns a registered plugin before resolving a multi-agent workspace owner" , async ( ) => {
95+ const registeredPlugin = {
96+ ...createPlugin ( "telegram" ) ,
97+ directory : { self : vi . fn ( ) } ,
98+ } as ChannelPlugin ;
99+ mocks . getLoadedChannelPlugin . mockReturnValue ( registeredPlugin ) ;
100+ mocks . resolveDefaultAgentId . mockImplementation ( ( ) => {
101+ throw new Error ( "agent selection required" ) ;
102+ } ) ;
103+
104+ const result = await resolveInstallableChannelPlugin ( {
105+ cfg : {
106+ agents : {
107+ list : [ { id : "alpha" } , { id : "beta" } ] ,
108+ } ,
109+ } ,
110+ runtime : { } as never ,
111+ rawChannel : "telegram" ,
112+ allowInstall : true ,
113+ preferRegisteredPlugin : true ,
114+ supports : ( plugin ) => Boolean ( plugin . directory ) ,
115+ } ) ;
116+
117+ expect ( result ) . toMatchObject ( {
118+ channelId : "telegram" ,
119+ plugin : registeredPlugin ,
120+ configChanged : false ,
121+ pluginInstalled : false ,
122+ supportsRequestedCapability : true ,
123+ } ) ;
124+ expect ( mocks . resolveDefaultAgentId ) . not . toHaveBeenCalled ( ) ;
125+ expect ( mocks . getLoadedChannelPlugin ) . toHaveBeenCalledWith ( "telegram" ) ;
126+ expect ( mocks . getChannelPlugin ) . not . toHaveBeenCalled ( ) ;
127+ expect ( mocks . listChannelPluginCatalogEntries ) . not . toHaveBeenCalled ( ) ;
128+ expect ( mocks . loadChannelSetupPluginRegistrySnapshotForChannel ) . not . toHaveBeenCalled ( ) ;
129+ } ) ;
130+
131+ it ( "requires a workspace owner before falling back to an unloaded bundled plugin" , async ( ) => {
132+ mocks . getChannelPlugin . mockReturnValue ( createPlugin ( "telegram" ) ) ;
133+ mocks . resolveDefaultAgentId . mockImplementation ( ( ) => {
134+ throw new Error ( "agent selection required" ) ;
135+ } ) ;
136+
137+ await expect (
138+ resolveInstallableChannelPlugin ( {
139+ cfg : {
140+ agents : {
141+ list : [ { id : "alpha" } , { id : "beta" } ] ,
142+ } ,
143+ } ,
144+ runtime : { } as never ,
145+ rawChannel : "telegram" ,
146+ allowInstall : false ,
147+ preferRegisteredPlugin : true ,
148+ } ) ,
149+ ) . rejects . toThrow ( "agent selection required" ) ;
150+
151+ expect ( mocks . getLoadedChannelPlugin ) . toHaveBeenCalledWith ( "telegram" ) ;
152+ expect ( mocks . getChannelPlugin ) . not . toHaveBeenCalled ( ) ;
153+ expect ( mocks . resolveDefaultAgentId ) . toHaveBeenCalledTimes ( 1 ) ;
154+ } ) ;
155+
156+ it ( "still requires a workspace owner before resolving an unregistered plugin" , async ( ) => {
157+ mocks . resolveDefaultAgentId . mockImplementation ( ( ) => {
158+ throw new Error ( "agent selection required" ) ;
159+ } ) ;
160+
161+ await expect (
162+ resolveInstallableChannelPlugin ( {
163+ cfg : {
164+ agents : {
165+ list : [ { id : "alpha" } , { id : "beta" } ] ,
166+ } ,
167+ } ,
168+ runtime : { } as never ,
169+ rawChannel : "workspace-channel" ,
170+ allowInstall : false ,
171+ preferRegisteredPlugin : true ,
172+ } ) ,
173+ ) . rejects . toThrow ( "agent selection required" ) ;
174+
175+ expect ( mocks . getLoadedChannelPlugin ) . toHaveBeenCalledWith ( "workspace-channel" ) ;
176+ expect ( mocks . getChannelPlugin ) . not . toHaveBeenCalled ( ) ;
177+ expect ( mocks . resolveDefaultAgentId ) . toHaveBeenCalledTimes ( 1 ) ;
178+ expect ( mocks . listChannelPluginCatalogEntries ) . not . toHaveBeenCalled ( ) ;
179+ } ) ;
180+
89181 it ( "ignores untrusted workspace channel shadows during setup resolution" , async ( ) => {
90182 const config = {
91183 agents : { entries : { ops : { } , research : { } } } ,
0 commit comments