Skip to content

Conversation

@Bertk
Copy link
Collaborator

@Bertk Bertk commented Dec 6, 2025

This pull request introduces several infrastructure and configuration improvements to the project, focusing on modernizing dependencies, enhancing CI/CD workflows, and enforcing code quality standards.

Key update: New coverlet.MTP package for Microsoft Testing Platform support

Continuous Integration and Automation:

  • Added a new .github/workflows/dotnet.yml GitHub Actions workflow to automate building, testing (with coverage), and reporting for .NET projects across Ubuntu, Windows, and macOS. This workflow includes steps for restoring dependencies, building, running tests with coverage, generating reports, and publishing test results and coverage summaries to PRs.
  • Introduced .github/dependabot.yml to enable automated dependency updates with Dependabot, scheduled weekly.

Dependency and Package Management:

  • Upgraded multiple dependencies in Directory.Packages.props, including Microsoft.CodeAnalysis (to 4.13.0), Microsoft.NET.Test.Sdk (to 18.0.1), xunit.v3 (to 3.2.1), and others. Added new packages for Microsoft Testing Platform, banned API analyzers, and updated several system and test libraries to their latest versions.
  • Updated the default CoverletVersion to 8.0.0 in Directory.Build.props and improved test logger and output configuration for better compatibility with new test platforms and CI environments.

Solution Structure:

  • Added new projects for MTP integration and testing (coverlet.MTP, coverlet.MTP.validation.tests, coverlet.MTP.unit.tests) to the solution file, including their build and folder organization.

Most important changes:

1. Solution and API Governance

  • Added new projects for Microsoft Testing Platform integration and corresponding tests to the solution file.

2. Documentation

  • Created documentation on Coverlet MTP integration (Documentation/Coverlet.MTP.Integration.md).

@Bertk Bertk added feature PR label for new features breaking-change Issue or PR that represents a breaking change in features or functional. labels Dec 9, 2025
@Bertk
Copy link
Collaborator Author

Bertk commented Dec 9, 2025

The code coverage dropped and shall be fixed before merge.

main branch: line 90% branch 87%
this branch: line 74% branch 71%

@Bertk Bertk added the * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons) label Dec 9, 2025
@Bertk Bertk force-pushed the coverlet-MTP branch 2 times, most recently from 592ff6a to 010a409 Compare December 15, 2025 09:47
@Bertk Bertk marked this pull request as ready for review December 24, 2025 12:55
Copilot AI review requested due to automatic review settings December 24, 2025 12:55
- Updated target frameworks to net472 in coverlet.core and coverlet.msbuild.tasks projects
- Adjusted CoverletToolsPath for multi-targeting support in buildMultiTargeting props and targets
- Created unit tests for Coverlet.MTP command line options validation
- Added documentation for Coverlet.MTP integration
- Added CoverletExtensionCollector to handle test session lifecycle for coverage collection.
- Introduced CoverletExtensionCommandLineProvider for command line options.
- Created CoverletExtensionConfiguration to manage configuration settings.
- Developed CoverletLoggerAdapter for logging integration with Microsoft Testing Platform.
- Implemented CoverletExtensionEnvironmentVariableProvider for environment variable management.
- Added CoverletExtensionProvider to register the Coverlet extension with the testing platform.
- Created TestingPlatformBuilderHook to facilitate extension registration.
- Updated project files to include necessary dependencies and configurations for Coverlet.
- Added support for multiple target frameworks (net8.0 and net9.0).
- Included build and packaging configurations for Coverlet.MTP.
- Implemented command line options for coverage report formats and exclusions.
- Established logging mechanisms for better traceability during coverage collection.
…ationString for consistency and lowercase output
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request introduces Microsoft Testing Platform (MTP) support to coverlet through a new coverlet.MTP package, enabling code coverage collection for projects using the modern Microsoft Testing Platform instead of VSTest.

Key Changes:

  • New coverlet.MTP package with full MTP extension implementation
  • Core infrastructure updates to support managed instrumentation restore control
  • Comprehensive test projects for validation and unit testing
  • CI/CD workflow additions including GitHub Actions
  • Dependency upgrades to support .NET 8/9 and MTP v2.x
  • Documentation for MTP integration

Reviewed changes

Copilot reviewed 100 out of 105 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
src/coverlet.MTP/* New MTP extension package with command-line providers, collectors, and configuration
src/coverlet.core/Helpers/InstrumentationHelper.cs Added DisableManagedInstrumentationRestore parameter to control backup/restore behavior
src/coverlet.core/Coverage.cs Added parameter support for instrumentation restore control
src/coverlet.collector/* Extended collector settings with DisableManagedInstrumentationRestore flag
test/coverlet.MTP.unit.tests/* Unit tests for MTP extension components
test/coverlet.MTP.validation.tests/* Integration validation tests with sample projects
test/coverlet.tests.utils/TestUtils.cs Added GetBuildConfigurationString() helper for cross-platform path handling
Directory.Packages.props Upgraded dependencies including Microsoft.Testing.Platform v2.0.2, xunit v3.2.1
.github/workflows/dotnet.yml New GitHub Actions workflow for cross-platform CI/CD
Documentation/Coverlet.MTP.Integration.md Comprehensive MTP integration guide with examples
global.json Updated SDK version to 9.0.308
eng/.yml, eng/.sh Updated build and test scripts for MTP projects

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Bertk added 11 commits December 24, 2025 14:02
- Updated target frameworks to net472 in coverlet.core and coverlet.msbuild.tasks projects
- Adjusted CoverletToolsPath for multi-targeting support in buildMultiTargeting props and targets
- Created unit tests for Coverlet.MTP command line options validation
- Added documentation for Coverlet.MTP integration
- Added CoverletExtensionCollector to handle test session lifecycle for coverage collection.
- Introduced CoverletExtensionCommandLineProvider for command line options.
- Created CoverletExtensionConfiguration to manage configuration settings.
- Developed CoverletLoggerAdapter for logging integration with Microsoft Testing Platform.
- Implemented CoverletExtensionEnvironmentVariableProvider for environment variable management.
- Added CoverletExtensionProvider to register the Coverlet extension with the testing platform.
- Created TestingPlatformBuilderHook to facilitate extension registration.
- Updated project files to include necessary dependencies and configurations for Coverlet.
- Added support for multiple target frameworks (net8.0 and net9.0).
- Included build and packaging configurations for Coverlet.MTP.
- Implemented command line options for coverage report formats and exclusions.
- Established logging mechanisms for better traceability during coverage collection.
…ment for consistency across environments"

This reverts commit 06a684c.
- Expanded MTP integration docs and added usage ToDo
- Enabled package generation in coverlet.MTP.csproj
- Added strong name signing for validation tests
- Updated validation test project: new dependencies, utility refs, and test project copying
- Updated InternalsVisibleTo for new test assemblies
Introduce a comprehensive validation test suite for the Coverlet Microsoft Testing Platform (MTP) extension, including new integration and CLI option tests. Add isolated test infrastructure with sample projects and custom MSBuild props/targets to ensure tests run in a pure MTP environment. Update packaging logic in coverlet.MTP to improve dependency handling and NuGet layout, and adjust build system to better support MTP scenarios. Also includes minor bug fixes and ensures correct local package versioning in tests.
    - Enhance test output with detailed diagnostics and error context
    - Use robust assertions with informative failure messages
    - Create temp test projects under artifacts/tmp for isolation
    - Add retries and file attribute handling to test dir cleanup
    - Check for test executable and coverlet.MTP.dll before running
    - Refactor HelpCommandTests for consistent path handling
    - Fix sample class naming mismatch in test project
    - Add condition to MSBuild import for props file robustness
    - Update NuGet config and project file handling for clarity
Renamed the constant sutName to SutName in HelpCommandTests
to follow .NET PascalCase naming conventions for constants.
Updated all references to use the new name for consistency.
Switch all test projects to xunit.v3.mtp-v2 for Microsoft Testing Platform (MTP) integration. Bump Microsoft.Testing.Platform to 2.0.2 and manage Moq version via property. Make Coverlet MTP extension opt-in by default and register as TestingPlatformExtension. Minor formatting and encoding adjustments included.
Bertk added 11 commits December 24, 2025 14:07
- Rename --coverage to --coverlet-coverage and update all related option names for consistency and clarity (e.g., --formats, --exclude, --include).
- Introduce CoverletOptionNames static class to centralize option name constants.
- Update command-line providers to use new option names and improve descriptions.
- Add validation for output formats; deprecate/comment out output path option.
- Ensure help output always shows options; only collect coverage if --coverlet-coverage is set.
- Update tests to use new flags and add help output verification.
- Remove redundant code and improve comments for maintainability.
- Update csproj to clean up package references and add local NuGet restore source.
Refactor CoverletExtensionCollector to use ITestHostProcessLifetimeHandler, moving instrumentation and report generation to new lifecycle methods. Modernize configuration handling and command-line parsing. Move InternalsVisibleTo attributes to AssemblyInfo.cs. Update tests for new APIs and improved diagnostics. Clean up obsolete code and improve maintainability.
- Allow multiple --formats options (ArgumentArity.OneOrMore) instead of comma-separated values
- Enforce single, supported format per --formats argument
- Update tests to use repeated --formats options
- Expand and clarify process exit code to error message mapping
- Add BasicNoCoverage_CollectsDataForCoveredLines test to verify test execution without coverage collection.
- Enhance Assert.True error messages to include process ErrorText for better debugging.
- Update generated test project to reference TrxReport and explicitly include Tests.cs.
- Refactor BranchTests to use explicit string type for result variables.
- Minor code style and message consistency improvements.
Add detailed diagnostic logging and debugger attach support via environment variables. Enhance test module path resolution and configuration logging. Refactor DI container creation and introduce MtpProcessExitHandler for in/out-of-process execution. Add default exclude filter, improve report output handling, and expand command line parsing. Integrate Microsoft.Extensions.Configuration and update test project output path for consistency.
Introduce InstrumentationDiagnostics.cs to provide centralized, async diagnostic logging for code instrumentation and coverage collection. Logs instrumented modules, excluded modules, coverage result generation, and errors using ILogger, improving transparency and troubleshooting for Coverlet users. No changes to existing code; this is a new utility class.
Refactor to introduce CoverletCommandLineOptionDefinitions as the single source of truth for all command-line options, eliminating duplication and inconsistencies. Remove CoverletCommandLineOptionsProvider and update CoverletExtensionCommandLineProvider to use the centralized definitions and validation. Rename and clean up option constants in CoverletOptionNames. Update CoverageConfiguration and related logging for new source mapping file handling. Adjust tests and namespaces for consistency with new option names and structure.
- Refactor InstrumentationHelper backup/restore logic:
  - Skip and log if a module or symbol file is already in the backup list instead of throwing.
  - Check for backup existence before restore; log warnings or verbose messages as needed.
  - Add IsCurrentlyRunningAssembly to avoid restoring the running assembly.
  - Log the number of modules to restore and skip missing or running assemblies.
- Update CoverletMTPCommandLineTests to match the current set of supported options.
- Update HelpCommandTests to reflect new, clearer option descriptions.
Refactor build pipeline to use dotnet test for coverlet.MTP.unit.tests with MSBuild-based code coverage collection and opencover output. Increase minimum required line coverage from 70% to 90%. Update coverlet.MTP.unit.tests.csproj to include necessary imports and package references for coverage integration. Add comments for alternative coverage approaches and modernize test execution paths.
- Add support for reading Coverlet settings from appsettings.json or any Microsoft.Extensions.Configuration source.
- Introduce CoverletMTPSettings, CoverletMTPConstants, and CoverletMTPSettingsParser for strongly-typed configuration and parsing.
- Add CoverletConfigurationExtensions for easy registration with MTP.
- Implement CoverletTestSessionHandler to use parsed configuration.
- Rename all command line options from coverage-* to coverlet-* for consistency.
- Enable and test the SourceMappingFile option.
- Update and expand tests to cover configuration parsing, defaults, and new option names.
- Update build/test pipeline and project files to support new config and cross-platform test execution.
- Add detailed Coverlet.MTP integration documentation and usage guide
- Refactor CoverletExtensionCollector for clarity, logging, and env var handling
- Overhaul test infra: generate SUT + test projects in solution, robust cleanup, and real-world structure
- Improve coverage validation: assert on actual data, not just file presence
- Add/configure .mcp.json for NuGet MCP server
- Minor fixes: exit code handling, error messages, and CoverletTestSessionHandler interface compliance
Explicitly use ./ and .\ prefixes for test executables in build.yml scripts to ensure correct execution on all platforms. This improves reliability of unit test runs by avoiding path resolution issues on different operating systems.
- Add comprehensive CoverageConfigurationTests.cs for all config options using Moq
- Fix devcontainer.json syntax and ensure GitHub Actions extension is included
- Enable Dependabot for GitHub Actions and NuGet with custom schedule
- Improve Coverlet.MTP.Integration.md: typo fix, clarify usage, update sample project and coverage command
- Simplify build.yml by unifying test execution to cross-platform dotnet exec
- Make CoverletDataCollector version dynamic from assembly
- Remove default CoverletMTPEnabled property and make props import conditional
- Set IsTestingPlatformApplication to false in csproj and tidy formatting
@Bertk Bertk changed the title Coverlet MTP extension (experiment) Coverlet MTP extension Dec 24, 2025
return defaultFormats;
}

public string GetOutputDirectory()

Choose a reason for hiding this comment

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

Where is this method called? I haven't cloned the repo with your branch yet but I'm not able to see where it's called from the GitHub browser diff (except for LogConfigurationSummary which is logging-only).

_ => $"coverage.{format}"
};

string fullPath = fileName;

Choose a reason for hiding this comment

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

This is not correct.
This should use Path.Combine(serviceProvider.GetConfiguration().GetTestResultDirectory(), fileName)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks. I missed to fix this line.

/// Data collector for Coverlet code coverage.
/// Compatible with Microsoft.Testing.Platform V2.0.2
/// </summary>
internal sealed class CoverletDataCollector : IDataProducer, ITestSessionLifetimeHandler

Choose a reason for hiding this comment

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

Is this extension registered? I don't see where the usage is.

- Eliminate --coverlet-output and --coverlet-source-mapping-file options from Coverlet.MTP integration, code, and docs.
- Coverage output directory now determined by Microsoft Testing Platform's test result directory.
- Update documentation and help output to reflect new behavior and remove obsolete references.
- Remove CoverletDataCollector class; rely on CoverletExtensionCollector and MTP extension model.
- Update build script and test projects for new output handling and configuration.
- Improve documentation examples for merging and reporting coverage.
- Refine table formatting and minor test project settings.
Introduce CoverletExtensionCollectorTests to comprehensively verify construction, option parsing, environment variable handling, and integration with Microsoft Testing Platform extension interfaces. Tests cover normal and edge cases, ensuring correct behavior without modifying production code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change Issue or PR that represents a breaking change in features or functional. feature PR label for new features * NO MERGE * The PR is not ready for merge yet (see discussion for detailed reasons)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants