0
Fork 0
mirror of https://github.com/mastra-ai/mastra.git synced 2026-11-17 08:44:46 +00:00
mastra/.github/scripts/ci-routing.cjs
Ward Peeters 27340425d7
ci: select tests for dependency bumps and directory-scanning tests on… (#29725)
… PRs

PR test selection only follows source imports, so three PRs merged green
and broke the alpha cron's full suite: an OpenTelemetry lockfile bump
(#28581, otel-bridge), lockfile maintenance moving @ai-sdk/anthropic
(#29341, schema-compat e2e), and a new hook without a story (#29373,
storybook-coverage.test.ts reads the hooks folder rather than importing
it).

Prebuild now compares each workspace package's resolved dependency tree
between the base and head lockfiles and runs the tests of packages whose
tree or package.json changed. A root toolchain change, or a selection
over a quarter of the suite, runs the sharded full suite instead. Tests
that scan their package's directory run when a file there is added,
removed or renamed.

The selection logic also moves out of inline workflow script into
.github/scripts/select-affected-tests.cjs with unit tests, and keeps the
three-way split of large affected unit runs from #29143.

## Description

<!-- Required: Provide a brief description of the changes in this PR.
-->

## Related issue(s)

<!-- Required: Link to the issue(s) this PR addresses, e.g. with: Fixes
#123. PRs without linked issues will be closed. High-quality issues with
reproductions are preferred to vague pull requests. -->

## Type of change

- [ ] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [ ] Performance improvement
- [ ] Test update

## Checklist

- [ ] I have linked the related issue(s) in the description above
- [ ] I have made corresponding changes to the documentation (if
applicable)
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## ELI5

The test selector checks whether package dependencies changed and
whether tests search their package folders for files. It uses the PR’s
own lockfile changes to select relevant tests, so unrelated changes on
the base branch do not trigger extra test runs.

## What changed

- Added dependency-based test routing. It compares resolved dependency
trees in the merge-base and PR-head lockfiles, follows workspace links,
and selects tests for affected packages.
- Selects a package’s tests when its `package.json` changes.
- Selects directory-scanning tests when files in their package are
added, removed, or renamed.
- Requests the full suite when root dependencies change or
dependency-based selection exceeds 25% of the test files.
- Moved Prebuild test selection into
`.github/scripts/select-affected-tests.cjs`. The script combines
import-graph and dependency-based selections and routes tests to the
applicable suites.
- Added tests for dependency routing and suite selection. Added `yaml`
as a root development dependency.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: mastracode <284800079+mastra-platform[bot]@users.noreply.github.com>
2026-11-09 23:45:01 +01:00

213 lines
6.4 KiB