Skip to content

Commit 565581b

Browse files
authored
Merge pull request #334 from salesforcecli/wr/liveTestCommonErrors
fix: allow --use-live-actions to affect --authoring-bundle @W-21306529@
2 parents b0092e0 + ac363ee commit 565581b

6 files changed

Lines changed: 110 additions & 11 deletions

File tree

messages/agent.generate.authoring-bundle.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@ When using --json, you must also specify either --spec or --no-spec.
150150

151151
# error.jsonAabExists
152152

153-
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.
153+
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.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@inquirer/prompts": "^7.10.1",
1313
"@oclif/core": "^4",
1414
"@oclif/multi-stage-output": "^0.8.29",
15-
"@salesforce/agents": "^0.23.3",
15+
"@salesforce/agents": "^0.23.4",
1616
"@salesforce/core": "^8.26.2",
1717
"@salesforce/kit": "^3.2.4",
1818
"@salesforce/sf-plugins-core": "^12.2.6",

src/commands/agent/preview.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ export default class AgentPreview extends SfCommand<AgentPreviewResult> {
8686
if (aabName) {
8787
// user specified --authoring-bundle, use the API name directly
8888
selectedAgent = await Agent.init({ connection: conn, project: this.project!, aabName });
89+
selectedAgent.preview.setMockMode(flags['use-live-actions'] ? 'Live Test' : 'Mock');
8990
} else if (apiNameOrId) {
9091
selectedAgent = await Agent.init({ connection: conn, project: this.project!, apiNameOrId });
9192
} else {
@@ -173,9 +174,7 @@ export const getPreviewChoiceLabel = (agent: PreviewableAgent): string =>
173174
? `${agent.developerName ?? agent.name} (Published)`
174175
: `${agent.name} (Agent Script)`;
175176

176-
export const getPreviewChoices = (
177-
agents: PreviewableAgent[]
178-
): Array<{ name: string; value: PreviewableAgent }> =>
177+
export const getPreviewChoices = (agents: PreviewableAgent[]): Array<{ name: string; value: PreviewableAgent }> =>
179178
sortPreviewableAgents(agents).map((agent) => ({
180179
name: getPreviewChoiceLabel(agent),
181180
value: agent,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe('agent generate authoring-bundle', () => {
473473
]);
474474
expect.fail('Expected error');
475475
} catch (error) {
476-
expect((error as Error).message).to.include('you must specify --name');
476+
expect((error as Error).message).to.include('you must also specify --name');
477477
}
478478
});
479479

@@ -490,7 +490,7 @@ describe('agent generate authoring-bundle', () => {
490490
]);
491491
expect.fail('Expected error');
492492
} catch (error) {
493-
expect((error as Error).message).to.include('you must specify either --spec or --no-spec');
493+
expect((error as Error).message).to.include('you must also specify either --spec or --no-spec');
494494
}
495495
});
496496

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright 2026, Salesforce, Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
/* eslint-disable @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-explicit-any */
18+
19+
import { join } from 'node:path';
20+
import { expect } from 'chai';
21+
import sinon from 'sinon';
22+
import esmock from 'esmock';
23+
import { TestContext } from '@salesforce/core/testSetup';
24+
import { SfProject } from '@salesforce/core';
25+
26+
const MOCK_PROJECT_DIR = join(process.cwd(), 'test', 'mock-projects', 'agent-generate-template');
27+
28+
describe('agent preview start', () => {
29+
const $$ = new TestContext();
30+
let setMockModeStub: sinon.SinonStub;
31+
let initStub: sinon.SinonStub;
32+
let createCacheStub: sinon.SinonStub;
33+
let AgentPreviewStart: any;
34+
35+
beforeEach(async () => {
36+
setMockModeStub = $$.SANDBOX.stub();
37+
const mockPreview = {
38+
setMockMode: setMockModeStub,
39+
start: $$.SANDBOX.stub().resolves({ sessionId: 'test-session-id' }),
40+
};
41+
class MockScriptAgent {
42+
public preview = mockPreview;
43+
public name = 'TestAgent';
44+
}
45+
const mockAgent = new MockScriptAgent();
46+
initStub = $$.SANDBOX.stub().resolves(mockAgent);
47+
createCacheStub = $$.SANDBOX.stub().resolves();
48+
49+
const mod = await esmock('../../../../src/commands/agent/preview/start.js', {
50+
'@salesforce/agents': {
51+
Agent: { init: initStub },
52+
ScriptAgent: MockScriptAgent,
53+
ProductionAgent: class ProductionAgent {},
54+
},
55+
'../../../../src/previewSessionStore.js': {
56+
createCache: createCacheStub,
57+
},
58+
});
59+
60+
AgentPreviewStart = mod.default;
61+
62+
$$.inProject(true);
63+
64+
const mockProject = {
65+
getPath: () => MOCK_PROJECT_DIR,
66+
getDefaultPackage: () => ({
67+
fullPath: join(MOCK_PROJECT_DIR, 'force-app'),
68+
}),
69+
} as unknown as SfProject;
70+
71+
$$.SANDBOX.stub(SfProject, 'resolve').resolves(mockProject);
72+
$$.SANDBOX.stub(SfProject, 'getInstance').returns(mockProject);
73+
});
74+
75+
afterEach(() => {
76+
$$.restore();
77+
});
78+
79+
describe('setMockMode', () => {
80+
it('should call setMockMode with "Mock" when --use-live-actions is not set', async () => {
81+
await AgentPreviewStart.run(['--authoring-bundle', 'MyAgent', '--target-org', 'test@org.com']);
82+
83+
expect(setMockModeStub.calledOnce).to.be.true;
84+
expect(setMockModeStub.firstCall.args[0]).to.equal('Mock');
85+
});
86+
87+
it('should call setMockMode with "Live Test" when --use-live-actions is set', async () => {
88+
await AgentPreviewStart.run([
89+
'--authoring-bundle',
90+
'MyAgent',
91+
'--use-live-actions',
92+
'--target-org',
93+
'test@org.com',
94+
]);
95+
96+
expect(setMockModeStub.calledOnce).to.be.true;
97+
expect(setMockModeStub.firstCall.args[0]).to.equal('Live Test');
98+
});
99+
});
100+
});

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,10 +1743,10 @@
17431743
resolved "https://registry.yarnpkg.com/@rtsao/scc/-/scc-1.1.0.tgz#927dd2fae9bc3361403ac2c7a00c32ddce9ad7e8"
17441744
integrity sha512-zt6OdqaDoOnJ1ZYsCYGt9YmWzDXl4vQdKTyJev62gFhRGKdx7mcT54V9KIjg+d2wi9EXsPvAPKe7i7WjfVWB8g==
17451745

1746-
"@salesforce/agents@^0.23.3":
1747-
version "0.23.3"
1748-
resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.23.3.tgz#3edfe84016cffc2d9604ca19dab4bca130bcc9b6"
1749-
integrity sha512-ls+fhZi2MTtd4mYNf78t8ImAyo6K2FsN8M5SEcS9+kmnL0lDX1WhpSzIc0YyPqHdZ7CC6a/PZJ0kQ1rx5r0HYw==
1746+
"@salesforce/agents@^0.23.4":
1747+
version "0.23.4"
1748+
resolved "https://registry.yarnpkg.com/@salesforce/agents/-/agents-0.23.4.tgz#2f4537ebd033f0e63d0929f4743a918e8460ff8f"
1749+
integrity sha512-MKoiQvEX4fBggHDSEntFUzIheKd2NrTCaaWe+ExQoegqToN32RW1YqfeNQjayt4WpMNCnOAJ2jEHN4ecSu6HvQ==
17501750
dependencies:
17511751
"@salesforce/core" "^8.26.2"
17521752
"@salesforce/kit" "^3.2.4"

0 commit comments

Comments
 (0)