Skip to content

Implement dynamic exclusion filters for Coverlet.MTP assemblies - #1946

Merged
Bertk merged 6 commits into
coverlet-coverage:masterfrom
Bertk:dynamic-exclude
Jun 1, 2026
Merged

Bertk merged 6 commits into
coverlet-coverage:masterfrom
Bertk:dynamic-exclude

Conversation

@Bertk

@Bertk Bertk commented May 30, 2026 •

Copy link
Copy Markdown
Collaborator

This pull request introduces a dynamic mechanism for generating default assembly exclude filters in coverlet.MTP, replacing the previous static list with runtime discovery of loaded assemblies (#1934). This makes it easier to support new test frameworks without code changes and improves maintainability. The change is architected to ensure that dynamic filtering is only applied when no configuration file is present, preserving existing precedence rules. The implementation is modular and testable, with new abstractions and unit tests to support the new logic.

Dynamic Exclude Filter Generation:

  • Added IProcessAssemblyHelper interface and ProcessAssemblyHelper implementation to coverlet.core for discovering assemblies loaded in the current process at runtime. This enables the generation of exclude filters based on actual test infrastructure dependencies present during test execution.
  • Added a static helper method to convert assembly names to coverlet filter patterns (e.g., "xunit.core" → "[xunit.core]*").

Configuration and Precedence Changes:

  • Updated CoverageConfiguration in coverlet.MTP to:
    • Inject IProcessAssemblyHelper and the test assembly name.
    • Replace the static list of default exclude filters with a permanent baseline ("[coverlet.*]*") and generate additional filters dynamically at runtime.
    • Ensure dynamic defaults are only used if neither CLI nor config file exclusions are specified, maintaining existing precedence.
  • Updated CollectorExtension to pass the test assembly name to CoverageConfiguration, enabling the exclusion of the test assembly itself from the dynamic filters.

Constants and Maintenance:

  • Reduced the static exclude filter list in CoverletMTPConstants.cs to a single baseline entry, with all other framework assemblies discovered dynamically.

Documentation and Testing:

  • Added detailed documentation (DynamicExcludeFilters.md) describing the motivation, architecture, implementation steps, and benefits of the new dynamic exclude filter mechanism.
  • Added comprehensive unit and integration tests to validate the new dynamic filtering logic and ensure correct precedence and fallback behaviors.

These changes collectively automate the process of excluding test infrastructure assemblies from coverage reports, reducing manual maintenance and improving support for new or custom test frameworks.

Bertk added 2 commits May 30, 2026 10:12
Replace static exclude list with dynamic discovery of loaded assemblies at runtime. Introduce IProcessAssemblyHelper for testability and maintainability. Update CoverageConfiguration to use dynamic filters as defaults when no config file is present, keeping CLI/config file override logic. Reduce CoverletMTPConstants to a single baseline filter. Add tests for new dynamic behavior. This removes the need for manual updates when new test frameworks are used.
Refactor exclusion logic to dynamically discover and exclude loaded test framework assemblies at runtime using a new IProcessAssemblyHelper abstraction. Always include a permanent baseline filter for Coverlet assemblies. Update CoverageConfiguration to merge filters by CLI, config file, then dynamic defaults. Add comprehensive unit tests for dynamic exclusion, fallback, and deduplication. Update existing tests to match new behavior. Improves robustness and reduces hardcoded filter maintenance.
Copilot AI review requested due to automatic review settings May 30, 2026 09:02
@Bertk Bertk added enhancement General enhancement request driver-MTP Issue related to Microsoft Testing Platform driver labels May 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces dynamic default exclude filters for coverlet.MTP by discovering loaded assemblies at runtime instead of relying on a long static list. It adds a core helper abstraction, wires it into MTP configuration, and expands tests/documentation around precedence and fallback behavior.

Changes:

  • Adds IProcessAssemblyHelper / ProcessAssemblyHelper to enumerate loaded assembly names and convert them to coverlet exclude filters.
  • Updates CoverageConfiguration and CollectorExtension to use dynamic exclude defaults when no CLI/config-file exclusions are provided.
  • Adds tests and documentation for dynamic filtering, precedence, deduplication, and fallback behavior.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/coverlet.core/Abstractions/IProcessAssemblyHelper.cs Adds an internal abstraction for retrieving loaded assembly names.
src/coverlet.core/Helpers/ProcessAssemblyHelper.cs Implements loaded-assembly discovery and filter-pattern conversion.
src/coverlet.MTP/Configuration/CoverageConfiguration.cs Replaces static default exclude list with baseline + dynamic defaults.
src/coverlet.MTP/Collector/CollectorExtension.cs Passes the test assembly name into MTP coverage configuration.
test/coverlet.core.tests/Helpers/ProcessAssemblyHelperTests.cs Adds tests for assembly discovery and filter formatting.
test/coverlet.MTP.tests/Configuration/CoverageConfigurationDynamicExcludeTests.cs Adds tests for dynamic defaults, precedence, fallback, and deduplication.
test/coverlet.MTP.tests/Configuration/CoverageConfigurationTests.cs Updates existing exclude-filter assertions for the new baseline behavior.
Documentation/Plans/DynamicExcludeFilters.md Documents the design and intended behavior of dynamic exclude filters.

Comment thread src/coverlet.MTP/Collector/CollectorExtension.cs
Comment thread test/coverlet.core.tests/Helpers/ProcessAssemblyHelperTests.cs Outdated
Comment thread src/coverlet.MTP/Configuration/CoverageConfiguration.cs Outdated
Bertk added 4 commits May 30, 2026 14:10
Extend dynamic exclude-filter logic to merge assemblies from both the test module's deps.json and the controller process, improving infrastructure exclusion for coverage. Add GetDepsJsonAssemblyNames to IProcessAssemblyHelper and implement it. Update filter pattern logic to wildcard after the second segment for multi-part names and prune redundant filters. Refactor CoverageConfiguration to use testModulePath. Expand and update tests to cover new logic and edge cases. Apply minor code and style improvements.
Revise documentation to clarify default exclude filters, introduce dynamic runtime exclusions based on assembly naming, and specify that both static and dynamic exclusions are not applied when a configuration file is present. Update breaking change notice accordingly.
Updated CoverageConfigurationDynamicExcludeTests to expect additional default exclude filters: "[Microsoft.VisualStudio.TestPlatform.*]*" and "[testhost*]*", in addition to "[coverlet.*]*". This aligns test expectations with the new dynamic exclusion logic.
@Bertk
Bertk merged commit c502253 into coverlet-coverage:master Jun 1, 2026
12 checks passed
@Bertk
Bertk deleted the dynamic-exclude branch June 1, 2026 09:24
This was referenced Sep 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

driver-MTP Issue related to Microsoft Testing Platform driver enhancement General enhancement request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants