@@ -12,6 +12,7 @@ import {
1212 ComponentSet ,
1313 ComponentSetBuilder ,
1414 ComponentSetOptions ,
15+ RegistryAccess ,
1516 SourceComponent ,
1617} from '@salesforce/source-deploy-retrieve' ;
1718import { Lifecycle , SfProject } from '@salesforce/core' ;
@@ -40,6 +41,30 @@ export const exampleSourceComponent: ComponentProperties = {
4041 content : '/dreamhouse-lwc/force-app/main/default/classes/GeocodingService.cls' ,
4142} ;
4243
44+ const registry = new RegistryAccess ( ) ;
45+ const agentComponents : SourceComponent [ ] = [
46+ new SourceComponent ( {
47+ name : 'My_Agent' ,
48+ type : registry . getTypeByName ( 'Bot' ) ,
49+ xml : '/dreamhouse-lwc/force-app/main/default/bots/My_Agent.bot-meta.xml' ,
50+ } ) ,
51+ new SourceComponent ( {
52+ name : 'Test_Planner' ,
53+ type : registry . getTypeByName ( 'GenAiPlanner' ) ,
54+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlanners/Test_Planner.genAiPlanner-meta.xml' ,
55+ } ) ,
56+ new SourceComponent ( {
57+ name : 'Test_Plugin1' ,
58+ type : registry . getTypeByName ( 'GenAiPlugin' ) ,
59+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlugins/Test_Plugin1.genAiPlugin-meta.xml' ,
60+ } ) ,
61+ new SourceComponent ( {
62+ name : 'Test_Plugin2' ,
63+ type : registry . getTypeByName ( 'GenAiPlugin' ) ,
64+ xml : '/dreamhouse-lwc/force-app/main/default/genAiPlugins/Test_Plugin2.genAiPlugin-meta.xml' ,
65+ } ) ,
66+ ] ;
67+
4368export const exampleDeleteResponse = {
4469 // required but ignored by the delete UT
4570 getFileResponses : ( ) : void => { } ,
@@ -118,6 +143,7 @@ describe('project delete source', () => {
118143 let resolveProjectConfigStub : sinon . SinonStub ;
119144 let rmStub : sinon . SinonStub ;
120145 let compSetFromSourceStub : sinon . SinonStub ;
146+ let handlePromptStub : sinon . SinonStub ;
121147
122148 class TestDelete extends Source {
123149 public async runIt ( ) {
@@ -128,7 +154,13 @@ describe('project delete source', () => {
128154 }
129155 }
130156
131- const runDeleteCmd = async ( params : string [ ] , options ?: { sourceApiVersion ?: string } ) => {
157+ const runDeleteCmd = async (
158+ params : string [ ] ,
159+ options ?: {
160+ sourceApiVersion ?: string ;
161+ inquirerMock ?: { checkbox : sinon . SinonStub } ;
162+ }
163+ ) => {
132164 const cmd = new TestDelete ( params , oclifConfigStub ) ;
133165 cmd . project = SfProject . getInstance ( ) ;
134166 $$ . SANDBOX . stub ( cmd . project , 'getDefaultPackage' ) . returns ( { name : '' , path : '' , fullPath : defaultPackagePath } ) ;
@@ -151,7 +183,14 @@ describe('project delete source', () => {
151183 onCancel : ( ) => { } ,
152184 onError : ( ) => { } ,
153185 } ) ;
154- stubMethod ( $$ . SANDBOX , cmd , 'handlePrompt' ) . returns ( confirm ) ;
186+ handlePromptStub = stubMethod ( $$ . SANDBOX , cmd , 'handlePrompt' ) . returns ( confirm ) ;
187+ if ( options ?. inquirerMock ) {
188+ // @ts -expect-error stubbing private member of the command
189+ cmd . inquirer = options . inquirerMock ;
190+ } else {
191+ // @ts -expect-error stubbing private member of the command
192+ cmd . inquirer = { checkbox : $$ . SANDBOX . stub ( ) . resolves ( [ ] ) } ;
193+ }
155194 rmStub = stubMethod ( $$ . SANDBOX , fs . promises , 'rm' ) . resolves ( ) ;
156195 stubMethod ( $$ . SANDBOX , DeployCache , 'update' ) . resolves ( ) ;
157196
@@ -233,9 +272,45 @@ describe('project delete source', () => {
233272 ensureHookArgs ( ) ;
234273 } ) ;
235274
236- it ( 'should pass along metadata and org for pseudo-type matching' , async ( ) => {
275+ it ( 'should pass along metadata and org for pseudo-type matching with plugins' , async ( ) => {
276+ const agentCompSet = new ComponentSet ( ) ;
277+ const pluginNames = [ agentComponents [ 2 ] . name , agentComponents [ 3 ] . name ] ;
278+ agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
279+ compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
280+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( pluginNames ) ;
281+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
282+ const metadata = [ 'Agent:My_Agent' ] ;
283+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
284+ ensureCreateComponentSetArgs ( {
285+ metadata : {
286+ metadataEntries : metadata ,
287+ directoryPaths : [ defaultPackagePath ] ,
288+ } ,
289+ org : {
290+ username : testOrg . username ,
291+ exclude : [ ] ,
292+ } ,
293+ } ) ;
294+ ensureHookArgs ( ) ;
295+ expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
296+ expect ( inquirerCheckboxStub . calledOnce ) . to . be . true ;
297+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . property ( 'message' , 'Select related topics to delete' ) ;
298+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . deep . property ( 'choices' , [
299+ { name : 'Test_Plugin1' , value : 'Test_Plugin1' } ,
300+ { name : 'Test_Plugin2' , value : 'Test_Plugin2' } ,
301+ ] ) ;
302+ expect ( handlePromptStub . calledOnce ) . to . be . true ;
303+ expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( agentComponents ) ;
304+ } ) ;
305+
306+ it ( 'should pass along metadata and org for pseudo-type matching without plugins' , async ( ) => {
307+ const agentCompSet = new ComponentSet ( ) ;
308+ agentComponents . map ( ( comp ) => agentCompSet . add ( comp ) ) ;
309+ compSetFromSourceStub = compSetFromSourceStub . returns ( agentCompSet ) ;
310+ const inquirerCheckboxStub = $$ . SANDBOX . stub ( ) . resolves ( [ ] ) ;
311+ const inquirerMock = { checkbox : inquirerCheckboxStub } ;
237312 const metadata = [ 'Agent:My_Agent' ] ;
238- await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] ) ;
313+ await runDeleteCmd ( [ '--metadata' , metadata [ 0 ] , '--json' ] , { inquirerMock } ) ;
239314 ensureCreateComponentSetArgs ( {
240315 metadata : {
241316 metadataEntries : metadata ,
@@ -248,6 +323,13 @@ describe('project delete source', () => {
248323 } ) ;
249324 ensureHookArgs ( ) ;
250325 expect ( compSetFromSourceStub . calledOnce ) . to . be . true ;
326+ expect ( inquirerCheckboxStub . calledOnce ) . to . be . true ;
327+ expect ( inquirerCheckboxStub . firstCall . firstArg ) . has . deep . property ( 'choices' , [
328+ { name : 'Test_Plugin1' , value : 'Test_Plugin1' } ,
329+ { name : 'Test_Plugin2' , value : 'Test_Plugin2' } ,
330+ ] ) ;
331+ expect ( handlePromptStub . calledOnce ) . to . be . true ;
332+ expect ( lifecycleEmitStub . firstCall . args [ 1 ] ) . to . deep . equal ( [ agentComponents [ 0 ] , agentComponents [ 1 ] ] ) ;
251333 } ) ;
252334
253335 it ( 'should pass along apiversion' , async ( ) => {
0 commit comments