fix(engine): apply --treenode-filter to --list-tests#6334
Merged
Conversation
Discovery requests (--list-tests, IDE Test Explorer) flow through TestDiscoveryService.DiscoverTests with isForExecution=false, which skipped the filter entirely and listed every test. The isForExecution gate exists for side-effecting work (argument registration / fixture creation #6151, dependency closure expansion), but filtering itself is pure (MatchesTest only compares the test path/properties), so it was always safe to run during discovery. Now apply the filter during discovery when a real filter is present. Bare --list-tests and IDE discovery send null/NopFilter and keep listing everything (including [Explicit] tests, which FilterTests would otherwise strip). When a filter is present, reuse FilterTests so the listing mirrors what a run would execute. No fixture leaks: RegisterTestsAsync is still called with isForExecution=false. Adds ListTestsFilterTests covering reflection + source-generated modes.
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 7 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
Contributor
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. Summary: The fix correctly widens filtering in
🤖 Generated with Claude Code |
1 task
This was referenced Jun 30, 2026
Closed
This was referenced Jul 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--list-testsignored--treenode-filterand listed every test in the assembly. Users expectapp --list-tests --treenode-filter Xto list only the tests filterXselects — the same set a real run would execute.Root cause
MTP routes
--list-teststo aDiscoverTestExecutionRequest, which flows throughTestDiscoveryService.DiscoverTestswithisForExecution: false. The filter was applied only whenisForExecutionwas true:isForExecutionlegitimately gates side-effecting work — argument registration / fixture creation (#6151) and dependency-closure expansion. But filtering itself is pure (MatchesTestonly compares the test's path/properties against the filter), so running it during discovery was always safe; it just was never wired up. Filtering got conflated with the side-effect gate.Fix
Apply the filter during discovery too, but only when a real filter is present:
--list-tests, IDE Test Explorer) →null/NopFilter→ returns all tests unchanged, including[Explicit]ones (whichFilterTestswould otherwise strip). No behavior change.FilterTests, so the listing mirrors exactly what a run with that filter would execute.RegisterTestsAsyncis still called withisForExecution: false, soRegisterTestArgumentsAsyncstays skipped.isForExecution.Engine-runtime only; works identically in reflection and source-generated modes since both flow through
TestDiscoveryService. No snapshot/source-gen output changes.Tests
Adds
ListTestsFilterTests(reflection + source-generated modes):--list-testsstill lists everything (guards the no-filter path).Manually verified against
TUnit.TestProject:[Category=Pass]filterPass*, 0Fail*Pass1+Fail1present