Autofix Flaky Tests

Trunk can automatically investigate flaky tests in your codebase and raise fix pull requests with suggested solutions.

Prerequisites

To use the Autofix Flaky Tests feature, you'll need:

  1. Beta access via waitlist (reach out to us on Slackarrow-up-right)

  2. The "Investigate Flaky Tests" setting enabled in your workspace

  3. Active installation of the Trunk GitHub App

circle-info

The "Investigate Flaky Tests" setting can only be changed by organization admins.

Setting to enable Flaky Test investigation

Auto-Investigate Flaky Tests

Once enabled, any time that Trunk detects a flaky test, Trunk analyzes the failure patterns, failure output, and git history of the test to provide a number of insights.

Results of an automatic flaky tests analysis

Flaky tests can also be analyzed manually via the UI and via the MCP server.

Autofix with Cursor Automations

Whenever an investigation is completed, Trunk will emit a webhook for test_case.investigation_completed. Enable webhooks via Svix.

You can then set up a Cursor Automationarrow-up-right to trigger when webhooks are received.

Configuration for Cursor Automation

We recommend the following conventions:

  • Version your Automation names for more clarity.

  • Configure the Svix endpoint with the Cursor Bearer token.

  • Webhooks are configured for your entire organization, so you will need to use Svix transformationsarrow-up-right or filter out events that are not for your intended repository.

  • Be specific about conventions and antipatterns for your repository. You will need to refine the Automation prompt to suit your needs.

  • If your CI setup allows it, prompt Cursor to run the tests to verify them.

What's next?

  • Continue to monitor your tests to confirm the flaky test fixes are effective

  • Investigations can be triggered and applied via MCP

circle-info

Coming soon. Set up Claude Routines to autofix flaky tests

Last updated

Was this helpful?