Skip to content

Conversation

EstebanRomero84
Copy link
Contributor

What does this PR do?

Adds support for Agentforce agent tests.

What issues does this PR fix or reference?

@W-19638348@

@EstebanRomero84 EstebanRomero84 requested a review from a team as a code owner September 17, 2025 14:54
*/

private formatAgentTestResult(
agentTestResults: ApexTestResult[]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure agentTestResults should be typed as AgentTestResult based on the comment?

I'm confused why we're forcing agent->apex results... there's not a lot of overlap, and if the library can't handle that, we need to fix it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a schema perspective, agent and apex test results are both ApexTestResult records. However, not all fields are populated consistently. For example, agent test results do not have the apexClass field populated, which requires a normalization step. This is necessary to prevent null pointers in downstream methods that expect complete ApexTestResult records.

flowTestIds: records
.filter((r) => r.ApexClassId === null)
.map((r) => r.Id)
apexTestResults,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we keep flow test items as IDs rather than results like Apex/Agent?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApexTestResult has the information about apex,agent and flow test. For agent and apex test it contains all information needed but for flow tests it doesn't have enough information so we need to query a second object called FlowTestResult.
Here we keep the agent and apex test records because that' all we need. For flow tests we need the Ids to use them in getFlowTestResults method to query FlowTestResult.

*/
TestTimestamp: string;
/**
* Indicates the type or test. Undefines(Apex), flowTesting(Flow) or agentTesting(Agent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ApexTesting(Apex)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are the posible values that come from the server. For apex tests the value will be undefined.

if (isFlow) {
namespaceInfos = await this.processFlowTest(
if (isFlowOrAgent) {
namespaceInfos = await this.processFlowOrAgentTest(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make sense to processes these as

  1. isFlow
  2. isAgent
  3. else (isApex)

why combine flow and agent tests, let's keep the methods specific to their types of testing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The testName for agent and flow tests have a prefix (AgentTesting and FlowTesting). This means the logic to extract the namespace from the testName is different than for apex test.
Agent and Flow test: prefix.namespace.testName
Apex: namespace.testName

The logic to extract the extract the namespace for agent and flow test is the same, that's why I'm calling the same method.
I'll rename the method and add a description to make it clearer.

return TestCategory.Flow;
case TestNamespace.Agent:
return TestCategory.Agent;
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should be careful about defaulting to one type or the other, we'll end up with hard-to-diagnose server-side errors if we send a malformed request

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a clarification: this method is not for building the request payload. Its purpose is to process the server's response.

I'm open to suggestions on improving its reliability.

const result = await asyncTestSrv.getAsyncTestResults(testQueueItems);

await asyncTestSrv.getAsyncTestResults(testQueueItems);
console.log(mockToolingQuery.calledTwice);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT: remove console

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants