Skip to content

Commit b55a2e0

Browse files
chore: remove test cases and improve error handling
1 parent 7a53b1c commit b55a2e0

File tree

2 files changed

+4
-52
lines changed

2 files changed

+4
-52
lines changed

src/commands/agent/validate/authoring-bundle.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
1919
import { Messages, SfError } from '@salesforce/core';
2020
import { MultiStageOutput } from '@oclif/multi-stage-output';
2121
import { Agent, findAuthoringBundle } from '@salesforce/agents';
22-
import { Duration, sleep } from '@salesforce/kit';
2322
import { colorize } from '@oclif/core/ux';
2423
import { throwAgentCompilationError } from '../../../common.js';
2524
import { FlaggablePrompt, promptForAgentFiles } from '../../../flags.js';
@@ -104,8 +103,6 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
104103
mso.skipTo('Validating Authoring Bundle');
105104
const targetOrg = flags['target-org'];
106105
const conn = targetOrg.getConnection(flags['api-version']);
107-
// Call Agent.compileAgent() API
108-
await sleep(Duration.seconds(2));
109106
const result = await Agent.compileAgentScript(
110107
conn,
111108
readFileSync(join(authoringBundleDir, `${apiName}.agent`), 'utf8')
@@ -123,12 +120,13 @@ export default class AgentValidateAuthoringBundle extends SfCommand<AgentValidat
123120
// Handle validation errors
124121
const err = SfError.wrap(error);
125122
let count = 0;
126-
const formattedError = err.message
123+
const rawError = err.message ? err.message : err.name;
124+
const formattedError = rawError
127125
.split('\n')
128126
.map((line) => {
129127
count += 1;
130128
const type = line.split(':')[0];
131-
const rest = line.substring(line.indexOf(':')).trim();
129+
const rest = line.includes(':') ? line.substring(line.indexOf(':')).trim() : '';
132130
return `- ${colorize('red', type)}${rest}`;
133131
})
134132
.join('\n');

test/commands/agent/validate/authoring-bundle.test.ts

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -23,57 +23,11 @@ import AgentValidateAuthoringBundle, {
2323
import { throwAgentCompilationError } from '../../../../src/common.js';
2424

2525
describe('Agent Validate Authoring Bundle', () => {
26-
describe('command configuration', () => {
27-
it('should have correct summary', () => {
28-
expect(AgentValidateAuthoringBundle.summary).to.equal('Validate an Agent Authoring Bundle');
29-
});
30-
31-
it('should require project', () => {
32-
expect(AgentValidateAuthoringBundle.requiresProject).to.be.true;
33-
});
34-
35-
it('should have correct flags', () => {
36-
const flags = AgentValidateAuthoringBundle.flags;
37-
expect(flags).to.have.property('target-org');
38-
expect(flags).to.have.property('api-version');
39-
expect(flags).to.have.property('api-name');
40-
});
41-
});
42-
43-
describe('flag validation', () => {
44-
it('should validate API name format', () => {
45-
const prompts = AgentValidateAuthoringBundle['FLAGGABLE_PROMPTS'];
46-
47-
// Valid API names
48-
expect(prompts['api-name'].validate('ValidApiName')).to.equal(true);
49-
expect(prompts['api-name'].validate('Valid_Api_Name_123')).to.equal(true);
50-
expect(prompts['api-name'].validate('aa')).to.equal(true);
51-
expect(prompts['api-name'].validate('MyAgent_Test_1')).to.equal(true);
52-
53-
// Invalid API names - empty
54-
expect(prompts['api-name'].validate('')).to.equal('Invalid API name.');
55-
56-
// Invalid API names - starts with invalid character
57-
expect(prompts['api-name'].validate('Invalid-Name')).to.equal('Invalid API name.');
58-
expect(prompts['api-name'].validate('123StartsWithNumber')).to.equal('Invalid API name.');
59-
expect(prompts['api-name'].validate('_StartsWithUnderscore')).to.equal('Invalid API name.');
60-
expect(prompts['api-name'].validate('-StartsWithDash')).to.equal('Invalid API name.');
61-
62-
// Invalid API names - too long
63-
expect(prompts['api-name'].validate('a'.repeat(81))).to.equal('API name cannot be over 80 characters.');
64-
65-
// Invalid API names - invalid characters
66-
expect(prompts['api-name'].validate('Invalid.Name')).to.equal('Invalid API name.');
67-
expect(prompts['api-name'].validate('Invalid Name')).to.equal('Invalid API name.');
68-
expect(prompts['api-name'].validate('Invalid@Name')).to.equal('Invalid API name.');
69-
});
70-
});
71-
7226
describe('prompt configuration', () => {
7327
it('should have correct prompt messages', () => {
7428
const prompts = AgentValidateAuthoringBundle['FLAGGABLE_PROMPTS'];
7529

76-
expect(prompts['api-name'].message).to.equal('API name of the Agent Authoring Bundle to validate.');
30+
expect(prompts['api-name'].message).to.equal('API name of the authoring bundle you want to validate.');
7731
expect(prompts['api-name'].promptMessage).to.equal('API name of the authoring bundle to validate');
7832
});
7933
});

0 commit comments

Comments
 (0)