Skip to main content
AI test selection reads a git diff and runs a focused set of Momentic tests that covers the changed behavior. Use it in pull request CI when running every test would take too long.

Run selected tests

Run selection from the root of your git repository:
In supported CI providers, Momentic detects the pull request base ref. Use --ai-select-base when you need to set it explicitly:
Test files changed directly in the diff are included. Changes to shared modules do not force every consuming test to run; selection chooses representative coverage for the affected behavior. If Momentic cannot build a safe selection, it runs the full in-scope test set instead.

How selection works

Momentic combines these sources of evidence:
  1. The git diff identifies the code and behavior that changed.
  2. A local code index traces imports and downstream consumers in your repository.
The test budget is a soft cap. Momentic can exceed it when more tests are needed to cover distinct changed behavior.

Guide selection with a prompt

Use --prompt to add repository-specific selection guidance that Momentic cannot infer from the diff or code index:
The prompt augments Momentic’s built-in selection instructions. It does not replace them. Repeat the flag to provide multiple instructions; Momentic appends the values in command-line order. When you omit --prompt, the standard selection prompt is unchanged apart from applicable knowledge-base rules. The standalone command accepts the same flag:
For persistent guidance, create an Agent rule in the knowledge base and choose Test selection. Selection uses relevant organization-wide rules and rules for the environment passed via --env, but ignores test-scoped rules.

Use the code index in GitHub Actions

Check out full git history and install the code-index parsers before running the command:
See the complete GitHub Actions example for setup, code-index caching, standalone selection output, test execution, and result uploads.

Preview a selection

Use --ai-select-dry-run to compare a selection with the full test run before using it to gate pull requests. Momentic still runs every in-scope test and records which ones selection would have skipped.
To inspect a selection without running tests, use momentic ai select:
The JSON result contains selectedTests for an explicit handoff and sets fallbackToRunAll when Momentic cannot produce a safe selection.

Limit selection time

AI test selection runs for up to 180 seconds by default and reserves time to finalize gathered evidence before the deadline. If Momentic cannot recover a selection, it falls back to running every in-scope test. Slow billing or telemetry does not discard a completed selection. Use --timeout to change the limit, in seconds, for the standalone command. The minimum is 60 seconds:
In JSON output, an unrecoverable timeout returns an empty selectedTests array and sets fallbackToRunAll to true. Treat this as a run-all outcome rather than a zero-test selection.

Build a dynamic CI matrix

Run standalone selection once in a planning job, convert the selected test paths into your CI system’s matrix format, and pass each shard’s paths to momentic run. This lets a small selection use one runner while larger selections create more shards. Your planner should handle three outcomes:
  1. Run the paths in selectedTests.
  2. Run every in-scope test when fallbackToRunAll is true.
  3. Skip the execution job for a valid selection with no tests.
The dynamic GitHub Actions example shows the complete workflow. Its matrix builder is a small Node.js script you can adapt to another CI provider or shard size. Use momentic run --ai-select when you do not need to customize the handoff; it performs selection and execution in one command.

When selection chooses zero tests

A selection that picks no tests is a normal outcome for non-behavioral changes. The run group still uploads with the selection plan, and the GitHub pull request comment explains why nothing ran. When onboarding to AI test selection, set your CI up so zero-test selections reach Momentic:
  • Always run momentic results upload. Do not gate the upload step on the runs directory existing or on tests having run; a zero-test run group uploads its metadata, which is what powers the pull request comment.
  • When you merge sharded results before uploading, pass --allow-empty to momentic results merge so shards without runs keep their selection plans in the merged archive.
  • momentic results check treats a zero-test results directory as clean, so a check step needs no special casing.
The AI test selection example workflows follow this setup, including a zero-selection reporting job for the dynamic matrix pattern where an empty selection skips the execution jobs entirely.

Benchmark

We benchmarked Momentic on QAWorkflowSelect, our custom benchmark. It uses real code changes across frontend, backend, CLI, shared libraries, configuration, and non-behavioral scenarios. Standalone baselines select from code changes and candidate test files without Momentic’s selection process. Cross-functional recall uses the harder cases that span product boundaries. Metrics are macro averages across cases. Momentic’s updated results and the standalone-agent baseline results come from separate benchmark runs. Cost savings compare the estimates shown above. Momentic’s estimate includes reported cached-token usage; baseline estimates use standard uncached API rates. These are estimated model costs, not customer prices, and exclude test execution. Actual costs vary with caching and provider agreements. Model output varies between runs, so these results measure the evaluated code changes rather than guarantee a particular selection. We can share the raw results and reproduction harness on request.

Notes

  • The command needs enough git history to resolve the base ref. Use fetch-depth: 0 with actions/checkout.
  • The code index currently analyzes TypeScript and JavaScript imports.
  • A budget limits selection size, not safety behavior. Selection can fall back to running all tests.