Add preflight checks for locked/unresolvable assemblies - #1967
Merged
Merged
Conversation
Introduce Instrumenter.Preflight() to skip locked or unresolvable assemblies before instrumentation. Update Coverage.cs to use preflight results and log warnings. Add unit tests for preflight logic. Improve Moq and ILogger mocking guidance in documentation. Minor test stability improvement.
Add TryWithNetFrameworkRuntimeResolver to enhance assembly resolution on .NET Framework by probing the runtime directory as a fallback. Update ReachabilityHelper to suppress excessive unresolved method reference warnings after 25 occurrences, logging further instances only at the verbose level.
Update TestPreflight_LockedModule_ReturnsLocked to use a mocked FileSystem that throws IOException, simulating a locked file scenario. This removes direct file locking and ensures the test uses the file system abstraction as required.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a preflight step to Coverlet’s instrumentation flow to proactively skip assemblies that are locked or have unresolvable dependencies, improving reliability and reducing hard failures during coverage runs (notably for the scenario described in #1965).
Changes:
- Introduces
Instrumenter.Preflight()plusInstrumentationPreflightStatus/InstrumentationPreflightResultto detect locked/unresolvable modules before instrumentation. - Updates
Coverage.PrepareModules()to call preflight afterCanInstrument()and skip/log modules that fail preflight. - Adds/updates tests and documentation, including guidance for mocking different
ILoggerinterfaces and a minor xUnit theory stability tweak.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs | Adds unit tests for the new preflight logic and adjusts a theory attribute for stability. |
| src/coverlet.core/Instrumentation/ReachabilityHelper.cs | Suppresses excessive unresolved method reference warnings after a threshold (with optional verbose logging). |
| src/coverlet.core/Instrumentation/Instrumenter.cs | Adds the preflight status/result types and implements Preflight() dependency/lock checks. |
| src/coverlet.core/Instrumentation/CecilAssemblyResolver.cs | Adds a .NET Framework runtime-directory fallback resolver path. |
| src/coverlet.core/Coverage.cs | Integrates preflight into module preparation, skipping and warning on failures. |
| .github/copilot-instructions.md | Expands/clarifies Moq + ILogger mocking guidance and adds issue-specific preflight guidance. |
Corrected log messages in ReachabilityHelper.cs to include "it" for clarity. Updated copilot-instructions.md to clarify that Moq cannot verify logger extension methods directly and provided the correct approach for verifying underlying Log method calls.
- add PR 1967 - remove issue 1934 (ReportGenerator.MTP is not released)
This was referenced Sep 27, 2026
This was referenced Oct 4, 2026
Open
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.
Introduce Instrumenter.Preflight() to skip locked or unresolvable assemblies before instrumentation. Update Coverage.cs to use preflight results and log warnings. Add unit tests for preflight logic. Improve Moq and ILogger mocking guidance in documentation. Minor test stability improvement.
This pull request introduces a preflight check mechanism to the instrumentation process, ensuring that problematic assemblies (such as locked files or those with unresolvable dependencies) are identified and skipped before attempting instrumentation. This proactive approach improves reliability and error messaging during coverage runs. Additionally, the documentation has been updated to clarify mocking strategies for different
ILoggerinterfaces, and new tests have been added to verify the preflight logic.#1965
Instrumentation improvements:
InstrumentationPreflightStatusandInstrumentationPreflightResulttypes, and implemented aPreflight()method inInstrumenterto check if a module is locked or has unresolvable dependencies before instrumentation. This method attempts to open the file for writing and resolves all assembly references, returning a status and reason if preflight fails. (src/coverlet.core/Instrumentation/Instrumenter.cs)Coverage.PrepareModules()to callinstrumenter.Preflight()afterCanInstrument(), skipping modules that fail preflight and logging a warning with the reason. (src/coverlet.core/Coverage.cs)Testing enhancements:
Instrumenter.Preflight()to verify correct handling of locked modules and unresolvable dependencies, ensuring the new logic is robust. (test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs)test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs)Documentation updates:
.github/copilot-instructions.mdwith clearer examples and guidance for mockingILoggerinterfaces, including the distinction between Microsoft.Extensions.Logging.ILogger and Microsoft.Testing.Platform.Logging.ILogger, and added guidelines for handling issue coverlet.MTP does not collect coverage on the .NET Framework portion of a large project #1965 and assembly-level preflight checks.These changes make the instrumentation step safer and more transparent, improve developer guidance, and ensure new logic is well-tested.