Skip to content

Commit b65a4e4

Browse files
Merge pull request #1291 from salesforcecli/sh/delete-agent-pseudo
W-17804365 - feat: delete by agent pseudo type
2 parents b4e93ca + 16c8fa0 commit b65a4e4

File tree

4 files changed

+43
-4
lines changed

4 files changed

+43
-4
lines changed

src/commands/project/delete/source.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import { resolveApi, validateTests } from '../../../utils/deploy.js';
4242
import { DeployResultFormatter } from '../../../formatters/deployResultFormatter.js';
4343
import { DeleteResultFormatter } from '../../../formatters/deleteResultFormatter.js';
4444
import { DeployCache } from '../../../utils/deployCache.js';
45-
import { testLevelFlag, testsFlag } from '../../../utils/flags.js';
45+
import { isPseudoType, testLevelFlag, testsFlag } from '../../../utils/flags.js';
4646
const testFlags = 'Test';
4747

4848
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -163,8 +163,10 @@ export class Source extends SfCommand<DeleteSourceJson> {
163163
}
164164
}
165165

166+
// eslint-disable-next-line complexity
166167
protected async delete(): Promise<void> {
167168
const sourcepaths = this.flags['source-dir'];
169+
const resolveFromOrg = this.flags.metadata?.some(isPseudoType) ? this.flags['target-org'].getUsername() : undefined;
168170

169171
this.componentSet = await ComponentSetBuilder.build({
170172
apiversion: this.flags['api-version'],
@@ -177,7 +179,18 @@ export class Source extends SfCommand<DeleteSourceJson> {
177179
}
178180
: undefined,
179181
projectDir: this.project?.getPath(),
182+
...(resolveFromOrg ? { org: { username: resolveFromOrg, exclude: [] } } : {}),
180183
});
184+
185+
// If we built a component set from an org connection, we have to resolve
186+
// components from the project.
187+
if (resolveFromOrg) {
188+
this.componentSet = ComponentSet.fromSource({
189+
fsPaths: await getPackageDirs(),
190+
include: this.componentSet,
191+
});
192+
}
193+
181194
if (this.flags['track-source'] && !this.flags['force-overwrite']) {
182195
await this.filterConflictsByComponentSet();
183196
}

src/commands/project/retrieve/start.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import { SourceTracking, SourceConflictError } from '@salesforce/source-tracking
2929
import { Duration } from '@salesforce/kit';
3030
import { Interfaces } from '@oclif/core';
3131

32-
import { DEFAULT_ZIP_FILE_NAME, ensuredDirFlag, zipFileFlag } from '../../../utils/flags.js';
32+
import { DEFAULT_ZIP_FILE_NAME, ensuredDirFlag, isPseudoType, zipFileFlag } from '../../../utils/flags.js';
3333
import { RetrieveResultFormatter } from '../../../formatters/retrieveResultFormatter.js';
3434
import { MetadataRetrieveResultFormatter } from '../../../formatters/metadataRetrieveResultFormatter.js';
3535
import { getOptionalProject, getPackageDirs } from '../../../utils/project.js';
@@ -512,5 +512,3 @@ const isRegexMatch = (mdEntry: string): boolean => {
512512
const mdName = mdEntry.split(':')[1];
513513
return mdName?.includes('*') && mdName?.length > 1 && !mdName?.includes('.*');
514514
};
515-
516-
const isPseudoType = (mdEntry: string): boolean => mdEntry.split(':')[0] === 'Agent';

src/utils/flags.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,3 +121,9 @@ const commaWarningForMultipleFlags = async (input: string, warningText: string):
121121
}
122122
return input;
123123
};
124+
125+
/**
126+
* Returns `true` if the metadata entry (e.g., --metadata) contains a pseudo type
127+
* such as "Agent" or "Agent:My_Agent".
128+
*/
129+
export const isPseudoType = (mdEntry: string): boolean => mdEntry.split(':')[0] === 'Agent';

test/commands/delete/source.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ describe('project delete source', () => {
117117
let lifecycleEmitStub: sinon.SinonStub;
118118
let resolveProjectConfigStub: sinon.SinonStub;
119119
let rmStub: sinon.SinonStub;
120+
let compSetFromSourceStub: sinon.SinonStub;
120121

121122
class TestDelete extends Source {
122123
public async runIt() {
@@ -167,6 +168,10 @@ describe('project delete source', () => {
167168
});
168169
const lifecycle = Lifecycle.getInstance();
169170
lifecycleEmitStub = $$.SANDBOX.stub(lifecycle, 'emit');
171+
172+
compSetFromSourceStub = stubMethod($$.SANDBOX, ComponentSet, 'fromSource').returns({
173+
toArray: () => [new SourceComponent(exampleSourceComponent)],
174+
});
170175
});
171176

172177
afterEach(() => {
@@ -228,6 +233,23 @@ describe('project delete source', () => {
228233
ensureHookArgs();
229234
});
230235

236+
it('should pass along metadata and org for pseudo-type matching', async () => {
237+
const metadata = ['Agent:My_Agent'];
238+
await runDeleteCmd(['--metadata', metadata[0], '--json']);
239+
ensureCreateComponentSetArgs({
240+
metadata: {
241+
metadataEntries: metadata,
242+
directoryPaths: [defaultPackagePath],
243+
},
244+
org: {
245+
username: testOrg.username,
246+
exclude: [],
247+
},
248+
});
249+
ensureHookArgs();
250+
expect(compSetFromSourceStub.calledOnce).to.be.true;
251+
});
252+
231253
it('should pass along apiversion', async () => {
232254
const metadata = ['ApexClass:MyClass'];
233255

0 commit comments

Comments
 (0)