Skip to content

Commit b6fcb82

Browse files
Merge pull request #189 from salesforcecli/wr/addVerboseFlag
fix: add --verbose to agent test results/resume/run for generatedData @W-19345316@
2 parents 3516a3e + 0cb1568 commit b6fcb82

File tree

7 files changed

+42
-7
lines changed

7 files changed

+42
-7
lines changed

command-snapshot.json

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"command": "agent:test:results",
9797
"flagAliases": [],
9898
"flagChars": ["d", "i", "o"],
99-
"flags": ["api-version", "flags-dir", "job-id", "json", "output-dir", "result-format", "target-org"],
99+
"flags": ["api-version", "flags-dir", "job-id", "json", "output-dir", "result-format", "target-org", "verbose"],
100100
"plugin": "@salesforce/plugin-agent"
101101
},
102102
{
@@ -113,6 +113,7 @@
113113
"result-format",
114114
"target-org",
115115
"use-most-recent",
116+
"verbose",
116117
"wait"
117118
],
118119
"plugin": "@salesforce/plugin-agent"
@@ -122,7 +123,17 @@
122123
"command": "agent:test:run",
123124
"flagAliases": [],
124125
"flagChars": ["d", "n", "o", "w"],
125-
"flags": ["api-name", "api-version", "flags-dir", "json", "output-dir", "result-format", "target-org", "wait"],
126+
"flags": [
127+
"api-name",
128+
"api-version",
129+
"flags-dir",
130+
"json",
131+
"output-dir",
132+
"result-format",
133+
"target-org",
134+
"verbose",
135+
"wait"
136+
],
126137
"plugin": "@salesforce/plugin-agent"
127138
}
128139
]

messages/shared.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ Directory to write the agent test results into.
1010

1111
If the agent test run completes, write the results to the specified directory. If the test is still running, the test results aren't written.
1212

13+
# flags.verbose.summary
14+
15+
Show generated data in the test results output.
16+
17+
# flags.verbose.description
18+
19+
When enabled, includes detailed generated data (such as invoked actions) in the human-readable test results output. This is useful for debugging test failures and understanding what actions were actually invoked during the test run.
20+
21+
The generated data is in JSON format and includes the Apex classes or Flows that were invoked, the Salesforce objects that were touched, and so on. Use the JSON structure of this information to build the test case JSONPath expression when using custom evaluations.
22+
1323
# error.invalidAgentType
1424

1525
agentType must be either "customer" or "internal". Found: [%s]

src/commands/agent/test/results.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
99
import { Messages } from '@salesforce/core';
1010
import { AgentTester, AgentTestResultsResponse } from '@salesforce/agents';
11-
import { resultFormatFlag, testOutputDirFlag } from '../../../flags.js';
11+
import { resultFormatFlag, testOutputDirFlag, verboseFlag } from '../../../flags.js';
1212
import { handleTestResults } from '../../../handleTestResults.js';
1313

1414
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -31,6 +31,7 @@ export default class AgentTestResults extends SfCommand<AgentTestResultsResult>
3131
}),
3232
'result-format': resultFormatFlag(),
3333
'output-dir': testOutputDirFlag(),
34+
verbose: verboseFlag,
3435
};
3536

3637
public async run(): Promise<AgentTestResultsResult> {
@@ -44,6 +45,7 @@ export default class AgentTestResults extends SfCommand<AgentTestResultsResult>
4445
results: response,
4546
jsonEnabled: this.jsonEnabled(),
4647
outputDir: flags['output-dir'],
48+
verbose: flags.verbose,
4749
});
4850
return response;
4951
}

src/commands/agent/test/resume.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { Messages } from '@salesforce/core';
1010
import { AgentTester } from '@salesforce/agents';
1111
import { AgentTestCache } from '../../../agentTestCache.js';
1212
import { TestStages } from '../../../testStages.js';
13-
import { AgentTestRunResult, resultFormatFlag, testOutputDirFlag } from '../../../flags.js';
13+
import { AgentTestRunResult, resultFormatFlag, testOutputDirFlag, verboseFlag } from '../../../flags.js';
1414
import { handleTestResults } from '../../../handleTestResults.js';
1515

1616
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -43,6 +43,7 @@ export default class AgentTestResume extends SfCommand<AgentTestRunResult> {
4343
}),
4444
'result-format': resultFormatFlag(),
4545
'output-dir': testOutputDirFlag(),
46+
verbose: verboseFlag,
4647
};
4748

4849
public async run(): Promise<AgentTestRunResult> {
@@ -72,6 +73,7 @@ export default class AgentTestResume extends SfCommand<AgentTestRunResult> {
7273
results: response,
7374
jsonEnabled: this.jsonEnabled(),
7475
outputDir: outputDir ?? flags['output-dir'],
76+
verbose: flags.verbose,
7577
});
7678

7779
return { ...response!, runId, status: 'COMPLETED' };

src/commands/agent/test/run.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
promptForAiEvaluationDefinitionApiName,
1818
resultFormatFlag,
1919
testOutputDirFlag,
20+
verboseFlag,
2021
} from '../../../flags.js';
2122
import { AgentTestCache } from '../../../agentTestCache.js';
2223
import { TestStages } from '../../../testStages.js';
@@ -65,6 +66,7 @@ export default class AgentTestRun extends SfCommand<AgentTestRunResult> {
6566
}),
6667
'result-format': resultFormatFlag(),
6768
'output-dir': testOutputDirFlag(),
69+
verbose: verboseFlag,
6870
};
6971

7072
private mso: TestStages | undefined;
@@ -109,6 +111,7 @@ export default class AgentTestRun extends SfCommand<AgentTestRunResult> {
109111
results: detailsResponse,
110112
jsonEnabled: this.jsonEnabled(),
111113
outputDir: flags['output-dir'],
114+
verbose: flags.verbose,
112115
});
113116

114117
return { ...detailsResponse!, status: 'COMPLETED', runId: response.runId };

src/flags.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ export const testOutputDirFlag = Flags.custom<string>({
5353
summary: messages.getMessage('flags.output-dir.summary'),
5454
});
5555

56+
export const verboseFlag = Flags.boolean({
57+
summary: messages.getMessage('flags.verbose.summary'),
58+
description: messages.getMessage('flags.verbose.description'),
59+
});
60+
5661
function validateInput(input: string, validate: (input: string) => boolean | string): never | string {
5762
const result = validate(input);
5863
if (typeof result === 'string') throw new Error(result);

src/handleTestResults.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function readableTime(time: number, decimalPlaces = 2): string {
6969
return `${hours}h ${minutes}m`;
7070
}
7171

72-
export function humanFormat(results: AgentTestResultsResponse): string {
72+
export function humanFormat(results: AgentTestResultsResponse, verbose = false): string {
7373
const ux = new Ux();
7474

7575
const tables: string[] = [];
@@ -128,7 +128,7 @@ export function humanFormat(results: AgentTestResultsResponse): string {
128128
metricResults.push(...metrics);
129129
}
130130
// it's not a real string[], more like just a string "[&#39;IdentifyRecordByName&#39;]", so >2 means more than "[]"
131-
if (testCase.generatedData?.actionsSequence?.length > 2) {
131+
if (verbose && testCase.generatedData?.actionsSequence?.length > 2) {
132132
tables.push(
133133
ux.makeTable({
134134
title: 'Generated Data',
@@ -214,12 +214,14 @@ export async function handleTestResults({
214214
results,
215215
jsonEnabled,
216216
outputDir,
217+
verbose = false,
217218
}: {
218219
id: string;
219220
format: 'human' | 'json' | 'junit' | 'tap';
220221
results: AgentTestResultsResponse | undefined;
221222
jsonEnabled: boolean;
222223
outputDir?: string;
224+
verbose?: boolean;
223225
}): Promise<void> {
224226
if (!results) {
225227
// do nothing since there are no results to handle
@@ -229,7 +231,7 @@ export async function handleTestResults({
229231
const ux = new Ux({ jsonEnabled });
230232

231233
if (format === 'human') {
232-
const formatted = humanFormat(results);
234+
const formatted = humanFormat(results, verbose);
233235
if (outputDir) {
234236
const file = `test-result-${id}.txt`;
235237
await writeFileToDir(outputDir, file, stripVTControlCharacters(formatted));

0 commit comments

Comments
 (0)