diff --git a/messages/agent.generate.authoring-bundle.md b/messages/agent.generate.authoring-bundle.md index f98ff2f..4bad18f 100644 --- a/messages/agent.generate.authoring-bundle.md +++ b/messages/agent.generate.authoring-bundle.md @@ -150,4 +150,4 @@ When using --json, you must also specify either --spec or --no-spec. # error.jsonAabExists -An authoring bundle with the API name "%s" already exists in the project. Use --force-overwrite to overwrite it or specify a different authoring bundle using the --api-name flag. +An authoring bundle with the API name "%s" already exists in the project. Use --force-overwrite to overwrite it or specify a different authoring bundle using the --api-name flag. diff --git a/package.json b/package.json index bf6b101..c6b23ee 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "@inquirer/prompts": "^7.10.1", "@oclif/core": "^4", "@oclif/multi-stage-output": "^0.8.29", - "@salesforce/agents": "^0.23.3", + "@salesforce/agents": "^0.23.4", "@salesforce/core": "^8.26.2", "@salesforce/kit": "^3.2.4", "@salesforce/sf-plugins-core": "^12.2.6", diff --git a/src/commands/agent/preview.ts b/src/commands/agent/preview.ts index 3026841..d46faa3 100644 --- a/src/commands/agent/preview.ts +++ b/src/commands/agent/preview.ts @@ -86,6 +86,7 @@ export default class AgentPreview extends SfCommand { if (aabName) { // user specified --authoring-bundle, use the API name directly selectedAgent = await Agent.init({ connection: conn, project: this.project!, aabName }); + selectedAgent.preview.setMockMode(flags['use-live-actions'] ? 'Live Test' : 'Mock'); } else if (apiNameOrId) { selectedAgent = await Agent.init({ connection: conn, project: this.project!, apiNameOrId }); } else { @@ -173,9 +174,7 @@ export const getPreviewChoiceLabel = (agent: PreviewableAgent): string => ? `${agent.developerName ?? agent.name} (Published)` : `${agent.name} (Agent Script)`; -export const getPreviewChoices = ( - agents: PreviewableAgent[] -): Array<{ name: string; value: PreviewableAgent }> => +export const getPreviewChoices = (agents: PreviewableAgent[]): Array<{ name: string; value: PreviewableAgent }> => sortPreviewableAgents(agents).map((agent) => ({ name: getPreviewChoiceLabel(agent), value: agent, diff --git a/test/commands/agent/generate/authoring-bundle.test.ts b/test/commands/agent/generate/authoring-bundle.test.ts index 0db9c8b..412604d 100644 --- a/test/commands/agent/generate/authoring-bundle.test.ts +++ b/test/commands/agent/generate/authoring-bundle.test.ts @@ -473,7 +473,7 @@ describe('agent generate authoring-bundle', () => { ]); expect.fail('Expected error'); } catch (error) { - expect((error as Error).message).to.include('you must specify --name'); + expect((error as Error).message).to.include('you must also specify --name'); } }); @@ -490,7 +490,7 @@ describe('agent generate authoring-bundle', () => { ]); expect.fail('Expected error'); } catch (error) { - expect((error as Error).message).to.include('you must specify either --spec or --no-spec'); + expect((error as Error).message).to.include('you must also specify either --spec or --no-spec'); } }); diff --git a/test/commands/agent/preview/start.test.ts b/test/commands/agent/preview/start.test.ts new file mode 100644 index 0000000..f71c493 --- /dev/null +++ b/test/commands/agent/preview/start.test.ts @@ -0,0 +1,100 @@ +/* + * Copyright 2026, Salesforce, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any */ + +import { join } from 'node:path'; +import { expect } from 'chai'; +import sinon from 'sinon'; +import esmock from 'esmock'; +import { TestContext } from '@salesforce/core/testSetup'; +import { SfProject } from '@salesforce/core'; + +const MOCK_PROJECT_DIR = join(process.cwd(), 'test', 'mock-projects', 'agent-generate-template'); + +describe('agent preview start', () => { + const $$ = new TestContext(); + let setMockModeStub: sinon.SinonStub; + let initStub: sinon.SinonStub; + let createCacheStub: sinon.SinonStub; + let AgentPreviewStart: any; + + beforeEach(async () => { + setMockModeStub = $$.SANDBOX.stub(); + const mockPreview = { + setMockMode: setMockModeStub, + start: $$.SANDBOX.stub().resolves({ sessionId: 'test-session-id' }), + }; + class MockScriptAgent { + public preview = mockPreview; + public name = 'TestAgent'; + } + const mockAgent = new MockScriptAgent(); + initStub = $$.SANDBOX.stub().resolves(mockAgent); + createCacheStub = $$.SANDBOX.stub().resolves(); + + const mod = await esmock('../../../../src/commands/agent/preview/start.js', { + '@salesforce/agents': { + Agent: { init: initStub }, + ScriptAgent: MockScriptAgent, + ProductionAgent: class ProductionAgent {}, + }, + '../../../../src/previewSessionStore.js': { + createCache: createCacheStub, + }, + }); + + AgentPreviewStart = mod.default; + + $$.inProject(true); + + const mockProject = { + getPath: () => MOCK_PROJECT_DIR, + getDefaultPackage: () => ({ + fullPath: join(MOCK_PROJECT_DIR, 'force-app'), + }), + } as unknown as SfProject; + + $$.SANDBOX.stub(SfProject, 'resolve').resolves(mockProject); + $$.SANDBOX.stub(SfProject, 'getInstance').returns(mockProject); + }); + + afterEach(() => { + $$.restore(); + }); + + describe('setMockMode', () => { + it('should call setMockMode with "Mock" when --use-live-actions is not set', async () => { + await AgentPreviewStart.run(['--authoring-bundle', 'MyAgent', '--target-org', 'test@org.com']); + + expect(setMockModeStub.calledOnce).to.be.true; + expect(setMockModeStub.firstCall.args[0]).to.equal('Mock'); + }); + + it('should call setMockMode with "Live Test" when --use-live-actions is set', async () => { + await AgentPreviewStart.run([ + '--authoring-bundle', + 'MyAgent', + '--use-live-actions', + '--target-org', + 'test@org.com', + ]); + + expect(setMockModeStub.calledOnce).to.be.true; + expect(setMockModeStub.firstCall.args[0]).to.equal('Live Test'); + }); + }); +}); diff --git a/yarn.lock b/yarn.lock index 481a8ca..c0cdf18 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1743,10 +1743,10 @@ resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8" integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g== -"@salesforce/agents@^0.23.3": - version "0.23.3" - resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.23.3.tgz#3edfe84016cffc2d9604ca19dab4bca130bcc9b6" - integrity sha512-ls+fhZi2MTtd4mYNf78t8ImAyo6K2FsN8M5SEcS9+kmnL0lDX1WhpSzIc0YyPqHdZ7CC6a/PZJ0kQ1rx5r0HYw== +"@salesforce/agents@^0.23.4": + version "0.23.4" + resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.23.4.tgz#2f4537ebd033f0e63d0929f4743a918e8460ff8f" + integrity sha512-MKoiQvEX4fBggHDSEntFUzIheKd2NrTCaaWe+ExQoegqToN32RW1YqfeNQjayt4WpMNCnOAJ2jEHN4ecSu6HvQ== dependencies: "@salesforce/core" "^8.26.2" "@salesforce/kit" "^3.2.4"