How environment mapping works
An environment groups runs within one TestPerch project. For example, a team might want a reliability baseline for code already on main, while using AI to select tests for changes proposed for main. Two environments let the team treat those runs differently, even though both involve the same branch name.
How a run gets its label
Section titled “How a run gets its label”| Reported run | How TestPerch finds its environment |
|---|---|
| Pull request | Try Pull requests rules against the reported stack base or, if absent, the PR’s immediate target. If none matches, try Branches rules against the source branch. |
| Other CI run | Try Branches rules against the run’s branch. |
| Local run | Show Local. Local runs stay separate from CI environment rules. |
For a GitHub stacked pull request, TestPerch uses the base branch of the whole stack when the reporter supplies it. For example, if checkout-ui targets checkout-api and the stack lands on canary, both PRs match a pull-request rule for ^canary$. Runs recorded without a stack base use their immediate PR target, including when you change the rules and TestPerch remaps existing runs.
Within each rule type, lower priority numbers are checked first. The first environment with any matching pattern wins. A CI run with no match is labeled Unmapped. Its results are still available under Runs.
For example, suppose the project has a pull-request rule for ^main$ and a branch rule for ^release/.*$. A PR from release/2.1 into main gets the pull-request environment. The same source branch in a PR into develop gets the release environment, because there is no matching target rule. A push to release/2.1 also gets the release environment.
When to create another environment
Section titled “When to create another environment”- Compare reliability. Separate staging and production if CI runs them from distinguishable branches. Choose which environments contribute to the combined success rate.
- Apply a different test policy. Keep full-suite runs on a long-lived branch and enable AI test selection for PRs targeting it.
- Find a useful group of runs. One pattern can cover a family such as
release/2.1andrelease/2.2. A separate rule for every short-lived feature branch is rarely necessary.
The inputs are the run type and branch metadata. Two jobs that report identical branch and PR metadata will map the same way, even if they deploy to different regions or GitHub Actions environments.
Set up branch and pull-request environments for a worked configuration.