Repository navigation
Conditional test filtering framework for PR builds - #55166
Conversation
Introduces a framework for conditionally running tests on PR builds based on what source files changed, reducing Helix compute consumption. - Design document (documentation/project-docs/pr-test-filtering.md) - C# evaluation script (scripts/EvaluateConditionalTestScopes.cs) - Central config (test/ConditionalTests.props) with TemplateEngine scope - MSBuild + pipeline integration - Agent instructions update Co-authored-by: Copilot App <[email protected]>
nagilson
left a comment
There was a problem hiding this comment.
Overall, I'm in favor of the proposal.
However, I want to poke on two points:
- How will we define
TriggerPaths?
I think this should be more than the folder containing relevant source code for that repo - e.g.dotnet-watchproject should not be conditioned on justdotnet-watchbut also include theProjectReference(s) such as..\..\Cli\Microsoft.DotNet.Cli.Definitions\Microsoft.DotNet.Cli.Definitions.csproj. Changes toPackageReference(s) such asMicrosoft.Build.Locator"may also result in a break.
dotnetup already uses conditional test filtering to a degree but we've seen more breaks than expected when running all of the tests. So, there is a risk involved in disabling these tests though on average I think it's the right approach. We should try to minimize that risk.
There have been times where we caught product bugs (e.g. system command line, roslyn, and others) because tests in other areas started failing even when roslyn's tests were all passing. But we shouldn't rely on test coverage of others like that.
- When can we ignore 'CoditionalTests' - I think we should be able to ignore that. We can still get a lot of the time saving on codeflow or certain dev PRs... but I think for example in dotnet/dotnet flow we will still want to run all of the tests so we get full filtering.
I'd propose to have the conditional tests condition test runs out on code flow for specific repos - e.g. a change to dotnet/templating code flow shouldn't need to run the watch tests. If we are all encompassing on dependencies with 1 then maybe we can be looser on that?
- Added 'Choosing trigger paths' subsection covering dependency awareness - Moved dependency flow RunAlways future inline with the metadata description - Consistent with how class/method-level futures are described inline Co-authored-by: Copilot App <[email protected]>
|
@noahfalk, thanks for the insightful feedback.
You are correct that defining just the src path for the affected area is often not sufficient. I did not elaborate on this in the documentation but should call it out in order to help devs and AI make better decisions when defining new test scopes.
Yes this is in ways a big hammer so it must be used correctly. Having good documentation calling these gotchas is imperative.
I do see it valuable to be able to specify a I updated the doc in d518adb in response to this feedback. |
Simplifies the evaluation script by requiring the caller to pass the props file path explicitly. Removes the FindPropsFile fallback. The pipeline YAML now passes the full path via Build.SourcesDirectory. Co-authored-by: Copilot App <[email protected]>
- Added one-third minimum goal for scope coverage - Clarified 'initial candidates' framing for example scopes - Added 'Choosing trigger paths' section covering dependency awareness - Inlined dependency flow RunAlways future with metadata description Co-authored-by: Copilot App <[email protected]>
Notes AI-based test selection and incremental build improvements as aspirational alternatives, framing PR velocity as the primary driver for the current pragmatic approach. Co-authored-by: Copilot App <[email protected]>
The script: task runs via cmd.exe on Windows where relative paths like .dotnet/dotnet don't resolve. Use Build.SourcesDirectory for the full path. Also update display name to purple dot convention. Co-authored-by: Copilot App <[email protected]>
When no scopes match, the script now outputs '__none__' instead of an empty string. This distinguishes 'script ran, nothing active' (remove scoped tests) from 'variable never set' (safe fallback, run all tests). Co-authored-by: Copilot App <[email protected]>
Logs build reason, target branch, changed file count (with file list for small diffs), and per-scope active/inactive decisions with reasons. Makes CI failures diagnosable from the step log. Co-authored-by: Copilot App <[email protected]>
Changes to shared test infrastructure (Microsoft.NET.TestFramework, TestFramework.MSTest, evaluation script) now force all conditional scopes to run, since these are dependencies of all test projects. GlobalTriggerPaths is defined in ConditionalTests.props as a PropertyGroup and checked before per-scope evaluation. Co-authored-by: Copilot App <[email protected]>
…tting - Invert variable semantics: list scopes to skip instead of scopes that are active - Rename ActiveConditionalTestScopes -> SkippedTestScopes (clearer intent) - Use __all__ sentinel when all scopes should be skipped - Global triggers now simply don't set the variable (natural safe default) - Restructure ConditionalTests.props with section headers for clarity - Use if/else chain in evaluation script instead of repeated !shouldRun guards - Update documentation decision flow and safe defaults Co-authored-by: Copilot App <[email protected]>
Include test/TestAssets/TestPackages/TemplateEngine/** so changes to template engine test packages also trigger the TemplateEngine scope. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
90f3554 to
35b65d6
Compare
Validates that all TriggerPaths and GlobalTriggerPaths in ConditionalTests.props reference directories that actually exist in the repo. Catches stale paths after folder renames or refactors. Co-authored-by: Copilot App <[email protected]>
@MichaelSimons Perhaps ambitious, but as a starting point would we want to consider a one-time build of the msbuild project dependency graph - and rebuild it whenever the project file changes? This would give us a better idea of what other |
d8c0efc to
25bf3eb
Compare
@nagilson - Dependency graph resolution is an interesting idea. For now though, I'd like to get a few scopes defined and validate the realized filtering gains before investing in additional infrastructure. It's also worth keeping in mind that this doesn't have to be 100% perfect — these tests still run on every CI build. We're only filtering on PR validation. If we start seeing that PR validation is frequently missing things that CI catches, that's the signal to adjust/invest in more tooling. But I don't think we need that up front. |
25bf3eb to
4b56d28
Compare
Move path validation into EvaluateConditionalTestScopes.cs which runs in the pipeline with full repo access. Emits ##[warning] for stale paths. Remove the Microsoft.NET.Infra.Tests project since Helix payloads don't include the source tree needed for directory existence checks. Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Matt Thalman <[email protected]>
…imons-conditionalize-illinker-tests
Co-authored-by: Copilot App <[email protected]>
Validation failures now emit ##[error] and return exit code 1. With continueOnError: true, the step shows as failed/orange but the pipeline continues with all tests running (safe default). Co-authored-by: Copilot App <[email protected]>
Ensures the variable always exists even if the evaluation step fails, preventing AzDO from passing literal unsubstituted text to MSBuild. Co-authored-by: Copilot App <[email protected]>
Use String.Replace to prepend RepoRoot to each entry after splitting, so test/Foo/**;test/Bar/** becomes C:\repo\test/Foo/**;C:\repo\test/Bar/** and MSBuild resolves each glob independently. Co-authored-by: Copilot App <[email protected]>
…aths By default, git enables rename detection (diff.renames=true since git 2.9). With rename detection, --name-only only shows the destination path, which means renaming a file OUT of a trigger path wouldn't trigger the associated tests. Using --no-renames ensures both the old and new paths appear in the diff output, so trigger paths match correctly in all rename scenarios. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4b54c4d1-6f40-4b47-9736-a7cf279126ff
The previous implementation converted ** to .* but left the literal / after it, requiring at least one directory separator. Patterns like src/**/*.cs would fail to match src/Foo.cs (zero intermediate segments). Fix by handling **/ as a unit, converting it to (.+/)? which optionally matches one-or-more chars ending in /. Trailing ** (e.g. src/**) still uses .* and works as before. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4b54c4d1-6f40-4b47-9736-a7cf279126ff
test/AGENTS.md: - Add SdkTest, SdkTestContext, and test asset placement to Conventions - Add Helix deployment section for TestExecutionDirectoryFiles and when to validate in a simulated Helix layout .github/copilot-instructions.md: - Add Target framework properties table to Coding Style covering SdkTargetFramework, .NET Framework multi-targeting, and CurrentTargetFramework for test assets Learnings from PR #55166 where tests were initially written without Helix compatibility. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 76a86ef3-d73c-451c-8f6e-cef56bf3509c
8ddd077 to
3177691
Compare
Add Microsoft.NET.Infrastructure.Tests project with end-to-end tests for both the EvaluateConditionalTestScopes script and the RemoveSkippedConditionalTestProjects MSBuild target. Tests cover: scope evaluation logic, glob matching, CI/dependency-flow detection, global trigger paths, __all__/__none__ semantics, branch filtering, and validation of required metadata (TriggerPaths, TestProjects, base directory existence). Uses .NET 11 Process.RunAndCaptureTextAsync API for clean subprocess invocation with surgical env var removal (MSBUILD_EXE_PATH, MSBuildSDKsPath, MSBuildExtensionsPath) to avoid test framework interference. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4b54c4d1-6f40-4b47-9736-a7cf279126ff
a6b1fbd to
eec0218
Compare
The test project must be in the solution so the initial build (without RuntimeIdentifier) produces the DLL at the non-RID output path. The Helix test infrastructure's CreateHelixTestWorkItems task reads the DLL via GetTargetPath (which does not pass RuntimeIdentifier) to extract method metadata for partitioning. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4b54c4d1-6f40-4b47-9736-a7cf279126ff
Replace custom temp directory creation in TestEnvironment with the existing TestAssetsManager.CreateTestDirectory() infrastructure. The directory is named after the test class for easier traceability, and uses the framework's standard test execution directory layout. Co-authored-by: Copilot App <[email protected]> Copilot-Session: 4b54c4d1-6f40-4b47-9736-a7cf279126ff
Summary
Introduces a framework for conditionally running tests on PR builds based on what source files changed. Tests that are unrelated to the PR's changes can be skipped, reducing Helix compute consumption and improving PR validation times. All tests continue to run unconditionally on CI builds (
main, release branches).This is posted as a draft to seek feedback on the approach. The implementation is included to illustrate the direction — it is intentionally simple and small despite addressing a complex problem.Received positive feedback on the approach — proceeding with the full implementation of conditional test filtering.
Design
See
documentation/project-docs/pr-test-filtering.mdfor the full motivation, mechanisms, and instructions for adding new scopes.What's included
ConditionalTests.props) with TemplateEngine as the first scopeMicrosoft.NET.Infrastructure.Tests) validating both the evaluation script and the MSBuild removal target — covers scope evaluation logic, glob matching, CI/dependency-flow detection, global trigger paths, branch filtering, and configuration validationRelated to #55203