@salesforce/agents
    Preparing search index...

    Class AgentTest

    A client side representation of an agent test (AiEvaluationDefinition) within an org. Also provides utilities such as creating and listing agent tests, and converting between agent test spec and AiEvaluationDefinition.

    Examples

    Create a new instance from an agent test spec:

    const agentTest = new AgentTest({ specPath: path/to/specfile });

    Get the metadata content of an agent test:

    const metadataContent = await agentTest.getMetadata();

    Write the metadata content to a file:

    await agentTest.writeMetadata('path/to/metadataFile');

    Index

    Constructors

    • Create an AgentTest based on one of:

      1. AiEvaluationDefinition API name.
      2. Path to a local AiEvaluationDefinition metadata file.
      3. Path to a local agent test spec file.
      4. Agent test spec data.

      Parameters

      Returns AgentTest

    Methods

    • Get the metadata content for this agent test.

      Returns the AiEvaluationDefinition metadata if already generated. Otherwise it will get it by:

      1. Read from an existing local AiEvaluationDefinition metadata file.
      2. Read from an existing local spec file and convert it.
      3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.

      Parameters

      • Optionalconnection: Connection<Schema>

        Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.

      Returns Promise<AiEvaluationDefinition>

      Promise

    • Get the specification for this agent test.

      Returns the test spec data if already generated. Otherwise it will generate the spec by:

      1. Read from an existing local spec file.
      2. Read from an existing local AiEvaluationDefinition metadata file and convert it.
      3. Use the provided org connection to read the remote AiEvaluationDefinition metadata.

      Parameters

      • Optionalconnection: Connection<Schema>

        Org connection to use if this AgentTest only has an AiEvaluationDefinition API name.

      Returns Promise<TestSpec>

      Promise

    • Write AiEvaluationDefinition metadata file.

      Parameters

      • outputFile: string

        The file path where the metadata file should be written.

      Returns Promise<void>

    • Write a test specification file in YAML format.

      Parameters

      • outputFile: string

        The file path where the YAML test spec should be written.

      Returns Promise<void>

    • Creates and deploys a test definition from a specification file.

      Two metadata types are supported, selected via options.testRunner: 'testing-center' (default) — legacy AiEvaluationDefinition. Filename <apiName>.aiEvaluationDefinition-meta.xml. 'agentforce-studio' — new AiTestingDefinition (NGT). Filename <apiName>.aiTestingDefinition-meta.xml. Requires Metadata API v66.0 or later on the target org; the server gates this and the lib does not preflight.

      Parameters

      • connection: Connection

        Connection to the org where the agent test will be created.

      • apiName: string

        The API name of the test definition to create.

      • specFilePath: string

        The path to the YAML specification file.

      • options: { outputDir: string; preview?: boolean; testRunner?: TestRunnerType }

        Configuration options for creating the definition.

        • outputDir: string

          The directory where the metadata file will be written.

        • Optionalpreview?: boolean

          If true, writes the metadata file to <apiName>-preview-<timestamp>.xml in the current working directory and does not deploy.

        • OptionaltestRunner?: TestRunnerType

          Which test runner to author for. Defaults to 'testing-center'.

      Returns Promise<{ contents: string; deployResult?: DeployResult; path: string }>

      Promise containing:

      • path: The filesystem path to the created metadata file.
      • contents: The metadata XML as a string.
      • deployResult: The deployment result (if not in preview mode).

      When validation or deployment fails.