Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion messages/agent.generate.authoring-bundle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 2 additions & 3 deletions src/commands/agent/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
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 {
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/commands/agent/generate/authoring-bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
});

Expand All @@ -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');
}
});

Expand Down
100 changes: 100 additions & 0 deletions test/commands/agent/preview/start.test.ts
Original file line number Diff line number Diff line change
@@ -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');
});
});
});
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading