-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from salesforcecli/sh/add-test-cancel-command
fix: add test cancel command
- Loading branch information
Showing
9 changed files
with
176 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# summary | ||
|
||
Cancel a running test for an Agent. | ||
|
||
# description | ||
|
||
Cancel a running test for an Agent, providing the AiEvaluation ID. | ||
|
||
# flags.id.summary | ||
|
||
The AiEvaluation ID. | ||
|
||
# flags.use-most-recent.summary | ||
|
||
Use the job ID of the most recent test evaluation. | ||
|
||
# examples | ||
|
||
- Cancel a test for an Agent: | ||
|
||
<%= config.bin %> <%= command.id %> --id AiEvalId |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
{ | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"$ref": "#/definitions/AgentTestCancelResult", | ||
"definitions": { | ||
"AgentTestCancelResult": { | ||
"type": "object", | ||
"properties": { | ||
"jobId": { | ||
"type": "string" | ||
}, | ||
"success": { | ||
"type": "boolean" | ||
}, | ||
"errorCode": { | ||
"type": "string" | ||
}, | ||
"message": { | ||
"type": "string" | ||
} | ||
}, | ||
"required": ["jobId", "success"], | ||
"additionalProperties": false | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2024, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { SfCommand, Flags } from '@salesforce/sf-plugins-core'; | ||
import { Messages } from '@salesforce/core'; | ||
|
||
Messages.importMessagesDirectoryFromMetaUrl(import.meta.url); | ||
const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.cancel'); | ||
|
||
export type AgentTestCancelResult = { | ||
jobId: string; // AiEvaluation.Id | ||
success: boolean; | ||
errorCode?: string; | ||
message?: string; | ||
}; | ||
|
||
export default class AgentTestCancel extends SfCommand<AgentTestCancelResult> { | ||
public static readonly summary = messages.getMessage('summary'); | ||
public static readonly description = messages.getMessage('description'); | ||
public static readonly examples = messages.getMessages('examples'); | ||
|
||
public static readonly flags = { | ||
'target-org': Flags.requiredOrg(), | ||
'job-id': Flags.string({ | ||
char: 'i', | ||
required: true, | ||
summary: messages.getMessage('flags.id.summary'), | ||
}), | ||
'use-most-recent': Flags.boolean({ | ||
char: 'r', | ||
summary: messages.getMessage('flags.use-most-recent.summary'), | ||
exactlyOne: ['use-most-recent', 'job-id'], | ||
}), | ||
// | ||
// Future flags: | ||
// ??? api-version ??? | ||
}; | ||
|
||
public async run(): Promise<AgentTestCancelResult> { | ||
const { flags } = await this.parse(AgentTestCancel); | ||
|
||
this.log(`Canceling tests for AiEvaluation Job: ${flags['job-id']}`); | ||
|
||
// Call SF Eval Connect API passing AiEvaluation.Id | ||
// POST to /einstein/ai-evaluations/{aiEvaluationId}/stop | ||
|
||
// Returns: AiEvaluation.Id | ||
|
||
return { | ||
success: true, | ||
jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright (c) 2021, salesforce.com, inc. | ||
* All rights reserved. | ||
* Licensed under the BSD 3-Clause license. | ||
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
*/ | ||
|
||
import { execCmd, TestSession } from '@salesforce/cli-plugins-testkit'; | ||
import { expect } from 'chai'; | ||
import { AgentTestRunResult } from '../../src/commands/agent/test/run.js'; | ||
|
||
let testSession: TestSession; | ||
|
||
describe('agent test run NUTs', () => { | ||
before('prepare session', async () => { | ||
testSession = await TestSession.create({ | ||
devhubAuthStrategy: 'AUTO', | ||
scratchOrgs: [ | ||
{ | ||
edition: 'developer', | ||
setDefault: true, | ||
}, | ||
], | ||
}); | ||
}); | ||
|
||
after(async () => { | ||
await testSession?.clean(); | ||
}); | ||
|
||
it('should return a job ID', () => { | ||
const result = execCmd<AgentTestRunResult>('agent test run -i 4KBSM000000003F4AQ --json', { ensureExitCode: 0 }) | ||
.jsonOutput?.result; | ||
expect(result?.success).to.equal(true); | ||
expect(result?.jobId).to.be.ok; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters