Sitelet https://github.com/coverlet-coverage/coverlet/pull/1967
Skip to content

Add preflight checks for locked/unresolvable assemblies - #1967

Merged
Bertk merged 5 commits into
coverlet-coverage:masterfrom
Bertk:fix-1965
Jun 18, 2026
Merged

Bertk merged 5 commits into
coverlet-coverage:masterfrom
Bertk:fix-1965

Conversation

@Bertk

@Bertk Bertk commented Jun 12, 2026 •

Copy link
Copy Markdown
Collaborator

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 ILogger interfaces, and new tests have been added to verify the preflight logic.
#1965

Instrumentation improvements:

  • Added InstrumentationPreflightStatus and InstrumentationPreflightResult types, and implemented a Preflight() method in Instrumenter to 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)
  • Updated Coverage.PrepareModules() to call instrumenter.Preflight() after CanInstrument(), skipping modules that fail preflight and logging a warning with the reason. (src/coverlet.core/Coverage.cs)

Testing enhancements:

  • Added unit tests for 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)
  • Minor test attribute update: disabled discovery enumeration for a theory test to improve test suite reliability. (test/coverlet.core.tests/Instrumentation/InstrumenterTests.cs)

Documentation updates:

These changes make the instrumentation step safer and more transparent, improve developer guidance, and ensure new logic is well-tested.

Bertk added 2 commits June 12, 2026 16:11
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.
@Bertk Bertk added bug Something isn't working coverlet-core labels Jun 12, 2026
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.
@Bertk
Bertk marked this pull request as ready for review June 12, 2026 15:47
Copilot AI review requested due to automatic review settings June 12, 2026 15:47

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 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() plus InstrumentationPreflightStatus/InstrumentationPreflightResult to detect locked/unresolvable modules before instrumentation.
  • Updates Coverage.PrepareModules() to call preflight after CanInstrument() and skip/log modules that fail preflight.
  • Adds/updates tests and documentation, including guidance for mocking different ILogger interfaces 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.

Comment thread src/coverlet.core/Instrumentation/Instrumenter.cs
Comment thread .github/copilot-instructions.md Outdated
Comment thread src/coverlet.core/Instrumentation/ReachabilityHelper.cs Outdated
Comment thread src/coverlet.core/Instrumentation/ReachabilityHelper.cs Outdated
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.
@Bertk Bertk added enhancement General enhancement request and removed bug Something isn't working labels Jun 18, 2026
- add PR 1967
- remove issue 1934 (ReportGenerator.MTP is not released)
@Bertk
Bertk merged commit c962ca2 into coverlet-coverage:master Jun 18, 2026
12 checks passed
@Bertk
Bertk deleted the fix-1965 branch June 18, 2026 06:47
This was referenced Oct 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverlet-core enhancement General enhancement request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

coverlet.MTP does not collect coverage on the .NET Framework portion of a large project

2 participants