@@ -105,5 +105,105 @@ describe('agentResolver', () => {
105105 ] ;
106106 expect ( await resolveAgentMdEntries ( agentPseudoConfig ) ) . to . deep . equal ( expectedAgentMdEntries ) ;
107107 } ) ;
108+
109+ describe ( 'with a connection' , ( ) => {
110+ const genAiPlannerId = '16jWJ000000275RYAQ' ;
111+
112+ const plannerIdQuery = "SELECT Id FROM GenAiPlannerDefinition WHERE DeveloperName = 'The_Campus_Assistant'" ;
113+ const plannerToPluginsQuery = `SELECT Plugin FROM GenAiPlannerFunctionDef WHERE PlannerId = '${ genAiPlannerId } '` ;
114+ let queryStub : sinon . SinonStub ;
115+ let singleRecordQueryStub : sinon . SinonStub ;
116+
117+ beforeEach ( ( ) => {
118+ connection . setApiVersion ( '64.0' ) ;
119+ singleRecordQueryStub = $$ . SANDBOX . stub ( connection , 'singleRecordQuery' ) ;
120+ singleRecordQueryStub . withArgs ( plannerIdQuery , { tooling : true } ) . resolves ( { Id : genAiPlannerId } ) ;
121+ queryStub = $$ . SANDBOX . stub ( connection . tooling , 'query' ) ;
122+ } ) ;
123+
124+ it ( 'should return metadata for agent (with plugins) from the org' , async ( ) => {
125+ const pluginIds = [ '179WJ0000004VI9YAM' , '179WJ0000004VIAYA2' , '179WJ0000004VIBYA2' , '179WJ0000004VICYA2' ] ;
126+ const plannerToPlugins = [
127+ { Plugin : pluginIds [ 0 ] } ,
128+ { Plugin : pluginIds [ 1 ] } ,
129+ { Plugin : pluginIds [ 2 ] } ,
130+ { Plugin : pluginIds [ 3 ] } ,
131+ ] ;
132+ const pluginDeveloperNames = [
133+ { DeveloperName : 'p_16jQP0000000PG9_Climbing_Routes_Information' } ,
134+ { DeveloperName : 'p_16jQP0000000PG9_Gym_Hours_and_Schedule' } ,
135+ { DeveloperName : 'p_16jQP0000000PG9_Membership_Plans' } ,
136+ { DeveloperName : 'Topic_Goal' } ,
137+ ] ;
138+ const genAiPluginNamesQuery = `SELECT DeveloperName FROM GenAiPluginDefinition WHERE Id IN ('${ pluginIds . join (
139+ "','"
140+ ) } ')`;
141+ queryStub . withArgs ( plannerToPluginsQuery ) . resolves ( { records : plannerToPlugins } ) ;
142+ queryStub . withArgs ( genAiPluginNamesQuery ) . resolves ( { records : pluginDeveloperNames } ) ;
143+
144+ const agentPseudoConfig = { botName : 'The_Campus_Assistant' , connection } ;
145+ const result = await resolveAgentMdEntries ( agentPseudoConfig ) ;
146+
147+ // Should include Bot, Planner, and only the non-p_plannerId plugins
148+ expect ( result ) . to . deep . equal ( [
149+ 'Bot:The_Campus_Assistant' ,
150+ 'GenAiPlannerBundle:The_Campus_Assistant' ,
151+ 'GenAiPlugin:p_16jQP0000000PG9_Climbing_Routes_Information' ,
152+ 'GenAiPlugin:p_16jQP0000000PG9_Gym_Hours_and_Schedule' ,
153+ 'GenAiPlugin:p_16jQP0000000PG9_Membership_Plans' ,
154+ 'GenAiPlugin:Topic_Goal' ,
155+ ] ) ;
156+ } ) ;
157+
158+ it ( 'should handle the case where the planner has no plugins' , async ( ) => {
159+ queryStub . withArgs ( plannerToPluginsQuery ) . resolves ( { records : [ ] } ) ;
160+
161+ const agentPseudoConfig = { botName : 'The_Campus_Assistant' , connection } ;
162+ const result = await resolveAgentMdEntries ( agentPseudoConfig ) ;
163+
164+ // Should include Bot, Planner, and only the non-p_plannerId plugins
165+ expect ( result ) . to . deep . equal ( [ 'Bot:The_Campus_Assistant' , 'GenAiPlannerBundle:The_Campus_Assistant' ] ) ;
166+ } ) ;
167+
168+ it ( 'should handle the case where the planner has global plugins only' , async ( ) => {
169+ const pluginIds = [ 'someStandardPlugin' ] ;
170+ const plannerToPlugins = [ { Plugin : pluginIds [ 0 ] } ] ;
171+ const genAiPluginNamesQuery = `SELECT DeveloperName FROM GenAiPluginDefinition WHERE Id IN ('${ pluginIds [ 0 ] } ')` ;
172+ queryStub . withArgs ( plannerToPluginsQuery ) . resolves ( { records : plannerToPlugins } ) ;
173+ queryStub . withArgs ( genAiPluginNamesQuery ) . resolves ( { records : [ ] } ) ;
174+
175+ const agentPseudoConfig = { botName : 'The_Campus_Assistant' , connection } ;
176+ const result = await resolveAgentMdEntries ( agentPseudoConfig ) ;
177+
178+ // Should include Bot, Planner, and only the non-p_plannerId plugins
179+ expect ( result ) . to . deep . equal ( [ 'Bot:The_Campus_Assistant' , 'GenAiPlannerBundle:The_Campus_Assistant' ] ) ;
180+ } ) ;
181+
182+ it ( 'should list customized plugins only' , async ( ) => {
183+ // in this case, the planner has global plugins and customized plugins
184+ const pluginIds = [ '179WJ0000004VI9YAM' , '179WJ0000004VIAYA2' , 'someStandardPlugin' ] ;
185+ const plannerToPlugins = [ { Plugin : pluginIds [ 0 ] } , { Plugin : pluginIds [ 1 ] } , { Plugin : pluginIds [ 2 ] } ] ;
186+ const pluginDeveloperNames = [
187+ { DeveloperName : 'p_16jQP0000000PG9_Climbing_Routes_Information' } ,
188+ { DeveloperName : 'p_16jQP0000000PG9_Gym_Hours_and_Schedule' } ,
189+ ] ;
190+ const genAiPluginNamesQuery = `SELECT DeveloperName FROM GenAiPluginDefinition WHERE Id IN ('${ pluginIds . join (
191+ "','"
192+ ) } ')`;
193+ queryStub . withArgs ( plannerToPluginsQuery ) . resolves ( { records : plannerToPlugins } ) ;
194+ queryStub . withArgs ( genAiPluginNamesQuery ) . resolves ( { records : pluginDeveloperNames } ) ;
195+
196+ const agentPseudoConfig = { botName : 'The_Campus_Assistant' , connection } ;
197+ const result = await resolveAgentMdEntries ( agentPseudoConfig ) ;
198+
199+ // Should include Bot, Planner, and only the non-p_plannerId plugins
200+ expect ( result ) . to . deep . equal ( [
201+ 'Bot:The_Campus_Assistant' ,
202+ 'GenAiPlannerBundle:The_Campus_Assistant' ,
203+ 'GenAiPlugin:p_16jQP0000000PG9_Climbing_Routes_Information' ,
204+ 'GenAiPlugin:p_16jQP0000000PG9_Gym_Hours_and_Schedule' ,
205+ ] ) ;
206+ } ) ;
207+ } ) ;
108208 } ) ;
109209} ) ;
0 commit comments