diff --git a/command-snapshot.json b/command-snapshot.json index 624dfb0..138b240 100644 --- a/command-snapshot.json +++ b/command-snapshot.json @@ -28,7 +28,15 @@ }, { "alias": [], - "command": "agent:run:test", + "command": "agent:test:cancel", + "flagAliases": [], + "flagChars": ["i", "o", "r"], + "flags": ["flags-dir", "job-id", "json", "target-org", "use-most-recent"], + "plugin": "@salesforce/plugin-agent" + }, + { + "alias": [], + "command": "agent:test:run", "flagAliases": [], "flagChars": ["d", "i", "o", "w"], "flags": ["flags-dir", "id", "json", "output-dir", "target-org", "wait"], diff --git a/messages/agent.test.cancel.md b/messages/agent.test.cancel.md new file mode 100644 index 0000000..5d6f229 --- /dev/null +++ b/messages/agent.test.cancel.md @@ -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 diff --git a/messages/agent.run.test.md b/messages/agent.test.run.md similarity index 100% rename from messages/agent.run.test.md rename to messages/agent.test.run.md diff --git a/schemas/agent-test-cancel.json b/schemas/agent-test-cancel.json new file mode 100644 index 0000000..81f5cbf --- /dev/null +++ b/schemas/agent-test-cancel.json @@ -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 + } + } +} diff --git a/schemas/agent-run-test.json b/schemas/agent-test-run.json similarity index 53% rename from schemas/agent-run-test.json rename to schemas/agent-test-run.json index 76435b9..5ac6a22 100644 --- a/schemas/agent-run-test.json +++ b/schemas/agent-test-run.json @@ -1,21 +1,24 @@ { "$schema": "http://json-schema.org/draft-07/schema#", - "$ref": "#/definitions/AgentRunTestResult", + "$ref": "#/definitions/AgentTestRunResult", "definitions": { - "AgentRunTestResult": { + "AgentTestRunResult": { "type": "object", "properties": { - "buildVersion": { - "type": "number" - }, "jobId": { "type": "string" }, - "errorRepresentation": { + "success": { + "type": "boolean" + }, + "errorCode": { + "type": "string" + }, + "message": { "type": "string" } }, - "required": ["buildVersion", "jobId"], + "required": ["jobId", "success"], "additionalProperties": false } } diff --git a/src/commands/agent/test/cancel.ts b/src/commands/agent/test/cancel.ts new file mode 100644 index 0000000..a4e1f2c --- /dev/null +++ b/src/commands/agent/test/cancel.ts @@ -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 { + 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 { + 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 + }; + } +} diff --git a/src/commands/agent/run/test.ts b/src/commands/agent/test/run.ts similarity index 77% rename from src/commands/agent/run/test.ts rename to src/commands/agent/test/run.ts index 7ae1d38..2a55c7a 100644 --- a/src/commands/agent/run/test.ts +++ b/src/commands/agent/test/run.ts @@ -9,15 +9,16 @@ 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.run.test'); +const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.test.run'); -export type AgentRunTestResult = { - buildVersion: number; - jobId: string; - errorRepresentation?: string; +export type AgentTestRunResult = { + jobId: string; // AiEvaluation.Id + success: boolean; + errorCode?: string; + message?: string; }; -export default class AgentRunTest extends SfCommand { +export default class AgentTestRun extends SfCommand { public static readonly summary = messages.getMessage('summary'); public static readonly description = messages.getMessage('description'); public static readonly examples = messages.getMessages('examples'); @@ -50,16 +51,19 @@ export default class AgentRunTest extends SfCommand { // ??? api-version or build-version ??? }; - public async run(): Promise { - const { flags } = await this.parse(AgentRunTest); + public async run(): Promise { + const { flags } = await this.parse(AgentTestRun); this.log(`Starting tests for AiEvalDefinitionVersion: ${flags.id}`); // Call SF Eval Connect API passing AiEvalDefinitionVersion.Id + // POST to /einstein/ai-evaluations/{aiEvalDefinitionVersionId}/start + + // Returns: AiEvaluation.Id return { - buildVersion: 62.0, // looks like API version - jobId: '4KBSM000000003F4AQ', // evaluationJobId; needed for getting status and stopping + success: true, + jobId: '4KBSM000000003F4AQ', // AiEvaluation.Id; needed for getting status and stopping }; } } diff --git a/test/nut/agent-test-run.nut.ts b/test/nut/agent-test-run.nut.ts new file mode 100644 index 0000000..01a4f84 --- /dev/null +++ b/test/nut/agent-test-run.nut.ts @@ -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('agent test run -i 4KBSM000000003F4AQ --json', { ensureExitCode: 0 }) + .jsonOutput?.result; + expect(result?.success).to.equal(true); + expect(result?.jobId).to.be.ok; + }); +}); diff --git a/test/unit/agent-run-test.test.ts b/test/unit/agent-test-run.test.ts similarity index 87% rename from test/unit/agent-run-test.test.ts rename to test/unit/agent-test-run.test.ts index ddceb5f..0bb1cd1 100644 --- a/test/unit/agent-run-test.test.ts +++ b/test/unit/agent-test-run.test.ts @@ -7,7 +7,7 @@ import { MockTestOrgData, TestContext } from '@salesforce/core/testSetup'; import { expect } from 'chai'; import { stubSfCommandUx } from '@salesforce/sf-plugins-core'; -import AgentRunTest from '../../src/commands/agent/run/test.js'; +import AgentTestRun from '../../src/commands/agent/test/run.js'; describe('agent run test', () => { const $$ = new TestContext(); @@ -23,7 +23,7 @@ describe('agent run test', () => { }); it('runs agent run test', async () => { - await AgentRunTest.run(['-i', 'the-id', '-o', testOrg.username]); + await AgentTestRun.run(['-i', 'the-id', '-o', testOrg.username]); const output = sfCommandStubs.log .getCalls() .flatMap((c) => c.args)