Skip to content

Commit 0161e36

Browse files
authored
Merge pull request #48 from salesforcecli/mdonnalley/improve-gen-testset
fix: require all expectations
2 parents c9104e7 + e977dc0 commit 0161e36

8 files changed

Lines changed: 151 additions & 70 deletions

File tree

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ EXAMPLES
111111
$ sf agent create --name CustomerSupportAgent --spec ./config/agentSpec.json --target-org my-org
112112
```
113113

114-
_See code: [src/commands/agent/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/create.ts)_
114+
_See code: [src/commands/agent/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/create.ts)_
115115

116116
## `sf agent generate definition`
117117

@@ -136,7 +136,7 @@ EXAMPLES
136136
$ sf agent generate definition
137137
```
138138

139-
_See code: [src/commands/agent/generate/definition.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/generate/definition.ts)_
139+
_See code: [src/commands/agent/generate/definition.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/generate/definition.ts)_
140140

141141
## `sf agent generate spec`
142142

@@ -197,7 +197,7 @@ EXAMPLES
197197
$ sf agent generate spec --output-dir specs --target-org my-org
198198
```
199199

200-
_See code: [src/commands/agent/generate/spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/generate/spec.ts)_
200+
_See code: [src/commands/agent/generate/spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/generate/spec.ts)_
201201

202202
## `sf agent generate testset`
203203

@@ -220,7 +220,7 @@ EXAMPLES
220220
$ sf agent generate testset
221221
```
222222

223-
_See code: [src/commands/agent/generate/testset.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/generate/testset.ts)_
223+
_See code: [src/commands/agent/generate/testset.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/generate/testset.ts)_
224224

225225
## `sf agent preview`
226226

@@ -255,7 +255,7 @@ FLAG DESCRIPTIONS
255255
the API name of the agent? (TBD based on agents library)
256256
```
257257

258-
_See code: [src/commands/agent/preview.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/preview.ts)_
258+
_See code: [src/commands/agent/preview.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/preview.ts)_
259259

260260
## `sf agent test cancel`
261261

@@ -292,7 +292,7 @@ EXAMPLES
292292
$ sf agent test cancel --job-id 4KBfake0000003F4AQ --target-org my-org
293293
```
294294

295-
_See code: [src/commands/agent/test/cancel.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/test/cancel.ts)_
295+
_See code: [src/commands/agent/test/cancel.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/test/cancel.ts)_
296296

297297
## `sf agent test results`
298298

@@ -348,7 +348,7 @@ FLAG DESCRIPTIONS
348348
test results aren't written.
349349
```
350350

351-
_See code: [src/commands/agent/test/results.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/test/results.ts)_
351+
_See code: [src/commands/agent/test/results.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/test/results.ts)_
352352

353353
## `sf agent test resume`
354354

@@ -411,7 +411,7 @@ FLAG DESCRIPTIONS
411411
test results aren't written.
412412
```
413413

414-
_See code: [src/commands/agent/test/resume.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/test/resume.ts)_
414+
_See code: [src/commands/agent/test/resume.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/test/resume.ts)_
415415

416416
## `sf agent test run`
417417

@@ -474,6 +474,6 @@ FLAG DESCRIPTIONS
474474
test results aren't written.
475475
```
476476

477-
_See code: [src/commands/agent/test/run.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.1/src/commands/agent/test/run.ts)_
477+
_See code: [src/commands/agent/test/run.ts](https://github.com/salesforcecli/plugin-agent/blob/1.7.2-dev.1/src/commands/agent/test/run.ts)_
478478

479479
<!-- commandsstop -->

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@salesforce/plugin-agent",
33
"description": "Commands to interact with Salesforce agents",
4-
"version": "1.7.1",
4+
"version": "1.7.2-dev.1",
55
"author": "Salesforce",
66
"bugs": "https://github.com/forcedotcom/cli/issues",
77
"dependencies": {
@@ -11,7 +11,7 @@
1111
"@inquirer/select": "^4.0.1",
1212
"@oclif/core": "^4",
1313
"@oclif/multi-stage-output": "^0.7.12",
14-
"@salesforce/agents": "^0.5.1",
14+
"@salesforce/agents": "^0.5.2",
1515
"@salesforce/core": "^8.8.0",
1616
"@salesforce/kit": "^3.2.1",
1717
"@salesforce/sf-plugins-core": "^12.1.0",

schemas/agent-test-results.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656
"number": {
5757
"type": "string"
5858
},
59+
"utterance": {
60+
"type": "string"
61+
},
5962
"startTime": {
6063
"type": "string"
6164
},
@@ -151,7 +154,7 @@
151154
}
152155
}
153156
},
154-
"required": ["status", "number", "startTime", "generatedData", "expectationResults"],
157+
"required": ["status", "number", "utterance", "startTime", "generatedData", "expectationResults"],
155158
"additionalProperties": false
156159
}
157160
}

src/commands/agent/generate/testset.ts

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ import { mkdir, writeFile } from 'node:fs/promises';
99
import { SfCommand } from '@salesforce/sf-plugins-core';
1010
import { Messages } from '@salesforce/core';
1111
import input from '@inquirer/input';
12-
import select from '@inquirer/select';
1312
import confirm from '@inquirer/confirm';
1413
import { theme } from '../../../inquirer-theme.js';
1514

1615
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
1716
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.generate.testset');
1817

19-
type ExpectationType = 'topic_sequence_match' | 'action_sequence_match' | 'bot_response_rating';
20-
2118
export type TestSetInputs = {
2219
utterance: string;
23-
expectationType: ExpectationType;
24-
expectedValue: string;
20+
actionSequenceExpectedValue: string;
21+
botRatingExpectedValue: string;
22+
topicSequenceExpectedValue: string;
2523
};
2624

2725
async function promptForTestCase(): Promise<TestSetInputs> {
@@ -31,21 +29,33 @@ async function promptForTestCase(): Promise<TestSetInputs> {
3129
theme,
3230
});
3331

34-
const expectationType = await select<ExpectationType>({
35-
message: 'What type of expectation would you like to test for the utterance?',
36-
choices: ['topic_sequence_match', 'action_sequence_match', 'bot_response_rating'],
32+
const topicSequenceExpectedValue = await input({
33+
message: 'What is the expected value for the topic expectation?',
34+
validate: (d: string): boolean | string => {
35+
if (!d.length) {
36+
return 'expected value cannot be empty';
37+
}
38+
return true;
39+
},
3740
theme,
3841
});
3942

40-
const expectedValue = await input({
41-
message: 'What is the expected value for the expectation?',
43+
const actionSequenceExpectedValue = await input({
44+
message: 'What is the expected value for the action expectation?',
4245
validate: (d: string): boolean | string => {
4346
if (!d.length) {
4447
return 'expected value cannot be empty';
4548
}
49+
return true;
50+
},
51+
theme,
52+
});
4653

47-
if (expectationType === 'action_sequence_match') {
48-
return d.split(',').length > 1 || 'expected value must be a comma-separated list of actions';
54+
const botRatingExpectedValue = await input({
55+
message: 'What is the expected value for the bot rating expectation?',
56+
validate: (d: string): boolean | string => {
57+
if (!d.length) {
58+
return 'expected value cannot be empty';
4959
}
5060

5161
return true;
@@ -55,31 +65,36 @@ async function promptForTestCase(): Promise<TestSetInputs> {
5565

5666
return {
5767
utterance,
58-
expectationType,
59-
expectedValue,
68+
actionSequenceExpectedValue,
69+
botRatingExpectedValue,
70+
topicSequenceExpectedValue,
6071
};
6172
}
6273

6374
export function constructTestSetXML(testCases: TestSetInputs[]): string {
6475
const tab = ' ';
6576
let xml = `<?xml version="1.0" encoding="UTF-8"?>\n<AiEvaluationTestSet>\n${tab}<subjectType>AGENT</subjectType>\n`;
6677
testCases.forEach((testCase, i) => {
67-
const expectedValue =
68-
testCase.expectationType === 'action_sequence_match'
69-
? `[${testCase.expectedValue
70-
.split(',')
71-
.map((v) => `"${v}"`)
72-
.join(',')}]`
73-
: testCase.expectedValue;
7478
xml += ` <testCase>
7579
<number>${i + 1}</number>
7680
<inputs>
7781
<utterance>${testCase.utterance}</utterance>
7882
</inputs>
7983
<expectations>
8084
<expectation>
81-
<name>${testCase.expectationType}</name>
82-
<expectedValue>${expectedValue}</expectedValue>
85+
<name>topic_sequence_match</name>
86+
<expectedValue>${testCase.topicSequenceExpectedValue}</expectedValue>
87+
</expectation>
88+
<expectation>
89+
<name>action_sequence_match</name>
90+
<expectedValue>${`[${testCase.actionSequenceExpectedValue
91+
.split(',')
92+
.map((v) => `"${v}"`)
93+
.join(',')}]`}</expectedValue>
94+
</expectation>
95+
<expectation>
96+
<name>bot_response_rating</name>
97+
<expectedValue>${testCase.botRatingExpectedValue}</expectedValue>
8398
</expectation>
8499
</expectations>
85100
</testCase>\n`;

src/testStages.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class TestStages {
4343
{
4444
stage: 'Polling for Test Results',
4545
type: 'dynamic-key-value',
46-
label: 'Completed Tests',
46+
label: 'Completed Test Cases',
4747
get: (data): string | undefined =>
4848
data?.totalTestCases && data?.passingTestCases && data?.failingTestCases
4949
? `${data?.passingTestCases + data?.failingTestCases}/${data?.totalTestCases}`
@@ -52,13 +52,13 @@ export class TestStages {
5252
{
5353
stage: 'Polling for Test Results',
5454
type: 'dynamic-key-value',
55-
label: 'Passing Tests',
55+
label: 'Passing Test Cases',
5656
get: (data): string | undefined => data?.passingTestCases?.toString(),
5757
},
5858
{
5959
stage: 'Polling for Test Results',
6060
type: 'dynamic-key-value',
61-
label: 'Failing Tests',
61+
label: 'Failing Test Cases',
6262
get: (data): string | undefined => data?.failingTestCases?.toString(),
6363
},
6464
],

test/commands/agent/generate/testset.test.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,21 @@ describe('constructTestSetXML', () => {
1212
const testCases = [
1313
{
1414
utterance: 'hello',
15-
expectationType: 'topic_sequence_match',
16-
expectedValue: 'greeting',
15+
actionSequenceExpectedValue: 'foo,bar',
16+
botRatingExpectedValue: 'baz',
17+
topicSequenceExpectedValue: 'qux',
1718
},
1819
{
1920
utterance: 'goodbye',
20-
expectationType: 'action_sequence_match',
21-
expectedValue: 'farewell,seeya',
21+
actionSequenceExpectedValue: 'foo,bar',
22+
botRatingExpectedValue: 'baz',
23+
topicSequenceExpectedValue: 'qux',
2224
},
2325
{
2426
utterance: 'how are you',
25-
expectationType: 'bot_response_rating',
26-
expectedValue: '.5',
27+
actionSequenceExpectedValue: 'foo,bar',
28+
botRatingExpectedValue: 'baz',
29+
topicSequenceExpectedValue: 'qux',
2730
},
2831
] satisfies TestSetInputs[];
2932

@@ -40,7 +43,15 @@ describe('constructTestSetXML', () => {
4043
<expectations>
4144
<expectation>
4245
<name>topic_sequence_match</name>
43-
<expectedValue>greeting</expectedValue>
46+
<expectedValue>qux</expectedValue>
47+
</expectation>
48+
<expectation>
49+
<name>action_sequence_match</name>
50+
<expectedValue>["foo","bar"]</expectedValue>
51+
</expectation>
52+
<expectation>
53+
<name>bot_response_rating</name>
54+
<expectedValue>baz</expectedValue>
4455
</expectation>
4556
</expectations>
4657
</testCase>
@@ -50,9 +61,17 @@ describe('constructTestSetXML', () => {
5061
<utterance>goodbye</utterance>
5162
</inputs>
5263
<expectations>
64+
<expectation>
65+
<name>topic_sequence_match</name>
66+
<expectedValue>qux</expectedValue>
67+
</expectation>
5368
<expectation>
5469
<name>action_sequence_match</name>
55-
<expectedValue>["farewell","seeya"]</expectedValue>
70+
<expectedValue>["foo","bar"]</expectedValue>
71+
</expectation>
72+
<expectation>
73+
<name>bot_response_rating</name>
74+
<expectedValue>baz</expectedValue>
5675
</expectation>
5776
</expectations>
5877
</testCase>
@@ -62,9 +81,17 @@ describe('constructTestSetXML', () => {
6281
<utterance>how are you</utterance>
6382
</inputs>
6483
<expectations>
84+
<expectation>
85+
<name>topic_sequence_match</name>
86+
<expectedValue>qux</expectedValue>
87+
</expectation>
88+
<expectation>
89+
<name>action_sequence_match</name>
90+
<expectedValue>["foo","bar"]</expectedValue>
91+
</expectation>
6592
<expectation>
6693
<name>bot_response_rating</name>
67-
<expectedValue>.5</expectedValue>
94+
<expectedValue>baz</expectedValue>
6895
</expectation>
6996
</expectations>
7097
</testCase>

0 commit comments

Comments
 (0)