From 325ae151ba1ac00f14ccaaa4c2d7a4d2ecf78ef5 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Thu, 19 Feb 2026 10:13:20 -0700 Subject: [PATCH 1/4] fix: fix --json error output to remove color info --- .../agent/validate/authoring-bundle.ts | 65 ++++++++----------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/src/commands/agent/validate/authoring-bundle.ts b/src/commands/agent/validate/authoring-bundle.ts index c402eef..d6180a3 100644 --- a/src/commands/agent/validate/authoring-bundle.ts +++ b/src/commands/agent/validate/authoring-bundle.ts @@ -14,7 +14,7 @@ * limitations under the License. */ import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; -import { Messages, SfError } from '@salesforce/core'; +import { Messages } from '@salesforce/core'; import { MultiStageOutput } from '@oclif/multi-stage-output'; import { Agent } from '@salesforce/agents'; import { colorize } from '@oclif/core/ux'; @@ -88,44 +88,35 @@ export default class AgentValidateAuthoringBundle extends SfCommand { - count += 1; - const type = line.split(':')[0]; - const rest = line.includes(':') ? line.substring(line.indexOf(':')).trim() : ''; - return `- ${colorize('red', type)}${rest}`; - }) - .join('\n'); - - mso.updateData({ errors: count.toString(), status: 'ERROR' }); - mso.error(); - - this.error(messages.getMessage('error.compilationFailed', [formattedError])); + mso.skipTo('Validating Authoring Bundle'); + const targetOrg = flags['target-org']; + const conn = targetOrg.getConnection(flags['api-version']); + const agent = await Agent.init({ connection: conn, project: this.project!, aabName }); + const result = await agent.compile(); + if (result.status === 'success') { + mso.updateData({ status: 'COMPLETED' }); + mso.stop('completed'); return { - success: false, - errors: err.message.split('\n'), + success: true, }; + } else if (this.jsonEnabled()) { + // we have errors, and --json + throwAgentCompilationError(result.errors); + } else { + // we have errors, in non --json + mso.updateData({ errors: result.errors.length.toString(), status: 'ERROR' }); + mso.error(); + + this.error( + messages.getMessage('error.compilationFailed', [ + result.errors + .map( + (line) => + `- ${colorize('red', line.errorType)}: ${line.description} [Ln ${line.lineStart}, Col ${line.colStart}]` + ) + .join('\n'), + ]) + ); } } } From 09eec424738d27d2efa5c76d40d54c71b9178474 Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Thu, 19 Feb 2026 10:15:37 -0700 Subject: [PATCH 2/4] chore: create errors key --- src/common.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common.ts b/src/common.ts index fdffbfb..09ab8fe 100644 --- a/src/common.ts +++ b/src/common.ts @@ -37,6 +37,6 @@ export function throwAgentCompilationError(compilationErrors: CompilationError[] throw SfError.create({ name: 'CompileAgentScriptError', message: errors.map((e) => `${e.errorType}: ${e.description} [Ln ${e.lineStart}, Col ${e.colStart}]`).join(EOL), - data: errors, + data: { errors }, }); } From 959441149745de33d330976bcf3270f863fe1bdb Mon Sep 17 00:00:00 2001 From: Willie Ruemmele Date: Thu, 19 Feb 2026 10:33:12 -0700 Subject: [PATCH 3/4] chore: simplify --- src/commands/agent/validate/authoring-bundle.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/commands/agent/validate/authoring-bundle.ts b/src/commands/agent/validate/authoring-bundle.ts index d6180a3..24ac1d2 100644 --- a/src/commands/agent/validate/authoring-bundle.ts +++ b/src/commands/agent/validate/authoring-bundle.ts @@ -99,15 +99,12 @@ export default class AgentValidateAuthoringBundle extends SfCommand Date: Thu, 19 Feb 2026 11:30:39 -0700 Subject: [PATCH 4/4] chore: update based on library changes --- .../agent/validate/authoring-bundle.ts | 32 +++++++++---------- src/common.ts | 7 +++- .../agent/validate/authoring-bundle.test.ts | 2 ++ test/nuts/z1.agent.validate.nut.ts | 3 +- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/commands/agent/validate/authoring-bundle.ts b/src/commands/agent/validate/authoring-bundle.ts index 24ac1d2..32d02a1 100644 --- a/src/commands/agent/validate/authoring-bundle.ts +++ b/src/commands/agent/validate/authoring-bundle.ts @@ -92,6 +92,7 @@ export default class AgentValidateAuthoringBundle extends SfCommand - `- ${colorize('red', line.errorType)}: ${line.description} [Ln ${line.lineStart}, Col ${line.colStart}]` - ) - .join('\n'), - ]) - ); - throwAgentCompilationError(result.errors); } + // Validation failed with compilation errors -> exit 1 (404/500 set by @salesforce/agents) + mso.updateData({ errors: result.errors.length.toString(), status: 'ERROR' }); + mso.error(); + + this.log( + messages.getMessage('error.compilationFailed', [ + result.errors + .map( + (line) => + `- ${colorize('red', line.errorType)}: ${line.description} [Ln ${line.lineStart}, Col ${line.colStart}]` + ) + .join('\n'), + ]) + ); + throwAgentCompilationError(result.errors); } } diff --git a/src/common.ts b/src/common.ts index 09ab8fe..3f09486 100644 --- a/src/common.ts +++ b/src/common.ts @@ -15,7 +15,10 @@ */ import { EOL } from 'node:os'; import { SfError } from '@salesforce/core'; -import { CompilationError } from '@salesforce/agents'; +import { CompilationError, COMPILATION_API_EXIT_CODES } from '@salesforce/agents'; + +/** Re-export so consumers can use the library's exit code contract (404 → 2, 500 → 3). */ +export { COMPILATION_API_EXIT_CODES }; /** * Utility function to generate SfError when there are agent compilation errors. @@ -29,6 +32,7 @@ export function throwAgentCompilationError(compilationErrors: CompilationError[] name: 'CompileAgentScriptError', message: 'Unknown compilation error occurred', data: compilationErrors, + exitCode: 1, }); } @@ -38,5 +42,6 @@ export function throwAgentCompilationError(compilationErrors: CompilationError[] name: 'CompileAgentScriptError', message: errors.map((e) => `${e.errorType}: ${e.description} [Ln ${e.lineStart}, Col ${e.colStart}]`).join(EOL), data: { errors }, + exitCode: 1, }); } diff --git a/test/commands/agent/validate/authoring-bundle.test.ts b/test/commands/agent/validate/authoring-bundle.test.ts index 703a58a..28ca60b 100644 --- a/test/commands/agent/validate/authoring-bundle.test.ts +++ b/test/commands/agent/validate/authoring-bundle.test.ts @@ -73,6 +73,7 @@ describe('Agent Validate Authoring Bundle', () => { } catch (error) { expect(error).to.be.instanceOf(SfError); expect((error as SfError).name).to.equal('CompileAgentScriptError'); + expect((error as SfError).exitCode).to.equal(1); expect((error as SfError).message).to.include('SyntaxError: Invalid syntax [Ln 10, Col 5]'); expect((error as SfError).message).to.include('SyntaxError: Unknown error [Ln 15, Col 1]'); } @@ -85,6 +86,7 @@ describe('Agent Validate Authoring Bundle', () => { } catch (error) { expect(error).to.be.instanceOf(SfError); expect((error as SfError).name).to.equal('CompileAgentScriptError'); + expect((error as SfError).exitCode).to.equal(1); expect((error as SfError).message).to.equal('Unknown compilation error occurred'); } }); diff --git a/test/nuts/z1.agent.validate.nut.ts b/test/nuts/z1.agent.validate.nut.ts index ab81a16..6fb2010 100644 --- a/test/nuts/z1.agent.validate.nut.ts +++ b/test/nuts/z1.agent.validate.nut.ts @@ -53,10 +53,9 @@ describe('agent validate authoring-bundle NUTs', function () { // Retry up to 3 times total (1 initial + 2 retries) to handle transient failures this.retries(2); - // Use the invalid authoring bundle (expects exit code 2 for compilation errors) execCmd( `agent validate authoring-bundle --api-name invalid --target-org ${getUsername()} --json`, - { ensureExitCode: 2 } + { ensureExitCode: 1 } ); }); });