Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Agent: clean-up assertion of telemetry events within integration tests #5455

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

akalia25
Copy link
Contributor

@akalia25 akalia25 commented Sep 4, 2024

Previously, the assertion of telemetry events for agent integration tests was happening within an afterEach, and this was not the cleanest approach, as the error messages would not point to the relevant code causing the error. In addition, this PR also adds parameters as a property that gets sent with the testing telemetry events.

Now, we manually add the assertion at the end of test cases where we want to assert what events got exported. As @olafurpg mentioned, the benefits of this approach are:

The benefit of this approach is that you get clearer error messages pointing to a relevant line of code in the tests. With the afterEach() approach, you need to hunt down the test name and reason about this currentClient logic. Also, this afterEach() block is only available in index.test.ts, it's not straightforward how to reuse this logic in other test files.

Addresses feedback here

Test plan

CI, specifically pnpm run test src/index.test.ts

Changelog

@akalia25 akalia25 changed the title Agent: improve assertion of exported telemetry events within integration tests Agent: clean-up assertion of telemetry events within integration tests Sep 6, 2024
@akalia25 akalia25 marked this pull request as ready for review September 6, 2024 14:52
Copy link
Member

@olafurpg olafurpg left a comment

Choose a reason for hiding this comment

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

I'm sorry, I had published pending comments a long time ago but forgot to "comment" the reviwe.

This is a nice cleanup! Only one blocking comment, otherwise LGTM

@@ -30,6 +30,28 @@ const workspace = new TestWorkspace(path.join(__dirname, '__tests__', 'example-t
const mayRecord =
process.env.CODY_RECORDING_MODE === 'record' || process.env.CODY_RECORD_IF_MISSING === 'true'

async function returnTelemetryEvents(currentClient: TestClient) {
Copy link
Member

Choose a reason for hiding this comment

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

The returnTelemetryEvents name is a bit unusual, also the return type is missing

Suggested change
async function returnTelemetryEvents(currentClient: TestClient) {
async function exportedTelemetryEvents(currentClient: TestClient): string[] {

// telemetry assertion, to validate the expected events fired during the test run
// Do not remove this assertion, and instead update the expectedEvents list above
expect(await returnTelemetryEvents(client)).toEqual(
expect.arrayContaining(client.expectedEvents)
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 remove the mutable TestClient.expectedEvents property and inline the values into the assertions instead. This is the only blocking comment for the PR

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.

2 participants