Skip to content

Expand MSTest analyzer and code-fix test coverage - #12256

Merged
Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/analyzer-code-coverage
Nov 9, 2026
Merged

Amaury Levé (Evangelink) merged 2 commits into
mainfrom
dev/amauryleve/analyzer-code-coverage

Conversation

@Evangelink

Copy link
Copy Markdown
Member

Pull request

Summary

Expand the safety net for previously uncovered MSTest analyzer and code-fix behavior: framework/signature boundaries, metadata-only attributes, stale diagnostics, full fixed-source output, custom fix-all, and linked Roslyn/compatibility helpers.

Production code, dependencies, coverage configuration/exclusions, and test scheduling are unchanged. This is progress toward, not a claim of, 100% coverage.

Design and decision record

This is a test-only change, so no separate feature design record is needed. It reuses the established source-built MSTest/Roslyn verifiers and per-test workspaces rather than changing shipping APIs, adding dependencies, or excluding difficult code from coverage.

Helper tests use real Roslyn symbols/operations, including the pinned implementation's parenthesized operation, without implementing reserved Roslyn interfaces. Process-lifetime checks own their child process and use a ready/release handshake with bounded cleanup. Existing expression-bodied-fixture and invalid/stale-input limitations are characterized, not repaired, in this PR.

Demonstration

N/A for screenshots: no product output or UI changes. The measured coverage and execution tables below provide the relevant text evidence.

Validation and regression proof

Validated source: df9b675dd7b49b6bbd18775d013e05bc5af8a89a plus the test-only patch preserved unchanged in commit 3fce8f9b306c19fdabeb710263dd2809233b4eaa. All 30 delivered C# files were checked against the tested SHA-256 snapshot and retain UTF-8 BOM.

The pinned repository SDK was bootstrapped through the build scripts. The final clean Release build used the repository-local SDK, with no incremental compilation and warnings treated as errors: exit 0, 0 warnings, 0 errors.

Executed from the repository root ($a denotes the task-owned local artifact directory):

$env:DOTNET_ROOT = Join-Path $PWD.Path '.dotnet'
$env:DOTNET_MULTILEVEL_LOOKUP = '0'
$p = Join-Path $PWD.Path 'test\UnitTests\MSTest.Analyzers.UnitTests\MSTest.Analyzers.UnitTests.csproj'

.\.dotnet\dotnet.exe build $p -c Release --no-incremental -p:SkipUapTargetFramework=true -warnaserror "-bl:$a\pr-final-build-{}.binlog"

foreach ($tfm in @('net10.0', 'net11.0', 'net472')) {
    .\.dotnet\dotnet.exe test --project $p -c Release -f $tfm -p:SkipUapTargetFramework=true "-bl:$a\pr-verified-$tfm-tests-{}.binlog" --report-trx --report-trx-filename "final-$tfm.trx" --results-directory "$a\pr-verified" --show-test-results failed --no-ansi --progress off
    if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE }
}

Each final unfiltered invocation exited 0 on Windows. The net472 host ran on .NET Framework 4.8.1. Method-level/CPU-count scheduling within each assembly was preserved.

Target Total Passed Failed Skipped
net10.0 3062 3061 0 1
net11.0 3062 3061 0 1
net472 2997 2996 0 1
Total 9121 9118 0 3

This adds 726 discovered cases per target framework, across 207 new methods and 3 extended existing methods. The only skip is the unchanged Unix-only MissingOutputPathWithInheritedCrashDumpSettingsDoesNotProduceDump, once per target.

An earlier combined all-TFM invocation hit the pre-existing GlobalConfigGeneratorContinuationTests.ConflictingDuplicateRuleFailsWithoutPartialConfigurations temporary-DLL cleanup UnauthorizedAccessException on net11.0 (also observed during the unchanged baseline). No new test failed in that run. It is retained as a validation limitation, not erased by the final clean, separate per-target invocations.

TRX, CTRF and JUnit were parsed and reconciled for every target. Coverage exports used exactly the three successful final root .coverage files, not failed runs or duplicate merged inputs:

$inputs = @(Get-ChildItem -LiteralPath "$a\pr-verified" -Filter '*.coverage' -File | Sort-Object Name | Select-Object -ExpandProperty FullName)
.\.dotnet\dotnet.exe coverage merge $inputs --output "$a\pr-verified\coverage.cobertura.xml" --output-format cobertura
.\.dotnet\dotnet.exe coverage merge $inputs --output "$a\pr-verified\coverage.native.xml" --output-format xml

Both exports exited 0. Complete production image identities and denominators match the baseline; no exclusion, suppression, source deletion or denominator reduction was used.

Complete assembly Final touched lines (Cobertura) Final fully covered lines (native)
MSTest.Analyzers 8383 / 8412 (99.66%) 9286 / 9693 (95.80%)
MSTest.Analyzers.CodeFixes 3027 / 3068 (98.66%) 3102 / 3233 (95.95%)

For the directly comparable net10.0-only runs, touched-line coverage increased from 7764/8412 (92.30%) to 8382/8412 (99.64%) for analyzers and 2738/3068 (89.24%) to 3027/3068 (98.66%) for code fixes. The table above includes the union of all three targets.

Touched lines, native full/partial lines, and basic blocks are different metrics. The collector supplies no branch/condition denominator; its branch-rate=1 is not treated as measured 100% branch coverage. Remaining gaps include caller-invariant fallbacks, generated members, Release-elided DEBUG helpers and process-exit race paths; not every residual path is proved unreachable.

Local binlogs, parsed result records, both coverage formats and complete residual inventories are retained in the session artifacts, not uploaded as inaccessible local-path links. The exact commands, counts and measurements are included here for reproduction; CI verification of the published head is pending. Package/acceptance, Debug, Linux and macOS runs were not performed for this test-only change.

Test-value evidence

These are safety-net/characterization additions on unchanged production behavior, not a product bug fix or new feature. The existing suite was green before implementation. Assertion sensitivity has been reviewed statically; no deliberate production mutation or empirical mutation-kill result is claimed.

The unchanged net10.0 baseline executed 2336 cases: 2335 passed, 0 failed, 1 pre-existing skip. Final execution is reported above; compiler/fixture-development failures are not counted as behavioral red-phase proof.

Requirement Evidence
Analyzer diagnostics and invalid/metadata boundaries GenericArrayArguments_AllLegalElementTypes_AreInferredWithoutDiagnostic; DependencyTarget_UnresolvedType_DoesNotStackAnalyzerDiagnosticsOnTheErrorType; MetadataAttributes_DiagnosticsWithoutAttributeSyntax_FallBackToNoLocation.
Code-action output, stale diagnostics and fix-all CancellationToken_OutOfOrderNamedArguments_AppendsANamedTokenWithoutReordering; CancellationToken_FixAll_SkipsStaleLocationAndAddsOnlyOneContextProperty; ConditionalAccess_FixAll_SkipsStaleDiagnosticAndSharesTheNullGuard.
Shared reference/hash/process contracts ParenthesizedOperations_PreserveParameterIdentityThroughBuiltInConversions; Combine_AllArities_MatchSeededXxHash32; WaitForExit_ReleasedOrAlreadyExitedChild_PreservesTheExitCode.
Exact 100% target Not met. Both complete assembly totals and unmeasured branch coverage are stated explicitly; no rounded or file-selected 100% claim is made.

Add behavior-focused diagnostic, code-action, metadata, fix-all, and shared-helper cases while preserving production behavior and coverage denominators.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 17:35
@github-actions github-actions Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026

@github-actions github-actions Bot 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.

🧪 Test quality review — PR #12256

Compared merge base df9b675dd7b49b6bbd18775d013e05bc5af8a89a with head 3fce8f9b306c19fdabeb710263dd2809233b4eaa. Evidence applies to this head, not every intermediate commit.

Test-value evidence

Contract Evidence Status
30 test-only files (7,449 added lines, 0 source files changed) adding residual coverage for analyzers, code fixes, and helpers The diff only adds tests, so it should pass on both revisions. Nothing was built or executed, and no paired execution records were accessible. Unverified (static only)

The scope is too large for a full per-test review within this run's budget, so the contracts were not individually assessed.

🧵 Parallel safety

PARALLEL-SAFETY RESULT
STATUS: PARTIAL

The specialist analysis was not completed. This is not a clean result. 12 parallelization-configuration candidates were in scope, including the new [assembly: Parallelize(Scope = ExecutionScope.MethodLevel)] snippet text in AnalyzerResidualCoverageTests.cs. That text appears inside test source strings, so it is not an assembly attribute.

Per-test assessment

Pseudo-mutation evidence would consist of static predictions, not executed mutation results.

Result Quality Test Notes How to improve
Uncertain — mod AnalyzerHashingTests.* and the other new test classes Only a sample was read (Combine_AllArities_MatchSeededXxHash32 compares against an independent XxHash32). Full per-test grading was not completed. Re-run /review-tests on a narrower scope for per-test grades.

No inline comments were published because no verified, actionable finding reached the publication gate. Existing-thread deduplication was not needed for that reason.

<sub>This advisory review is heuristic and non-blocking.

Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.</sub>

🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · ~27 AIC · ⌖ ~1 AIC · ⊞ 8K

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026

@github-actions github-actions Bot 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.

Note

🤖 Automated review by GitHub Copilot. Generated by the Expert Code Review workflow. To request a follow-up action, reply by tagging @copilot directly.

Scope: 30 test-only files (~7.4k added lines) in MSTest.Analyzers.UnitTests. No production code, public API, resources or IPC changes.

Coverage limits: The diff payload could not be parsed in this run because shell access to it was denied. I reviewed the changed content through the PR commit checkout and a targeted pattern scan. This was not a line-by-line pass through all 7.4k lines, so it is not an all-clear. I did not compile or run the tests.

Finding (1 inline): The tests depend on reflection over Roslyn and analyzer internals (ProductReflection). These are maintainability and brittleness risks, not correctness defects.

Other observations (no action required):

  • Only analyzer and code-fix tests were added, all in C# with no VB snippets, which matches the repo policy.
  • The Thread.Sleep, Task.Delay, Environment.SetEnvironmentVariable and Process.Start hits are all inside analyzer-input source strings, not executed by the tests.
  • Test-value evidence: Not assessed. These are coverage additions and no behavior change is claimed, so green-before/green-after runs on the exact revision are still expected from CI.

@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@github-actions github-actions Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 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.

🟡 Changes recommended

The tests can pass without exercising metadata and stale-location guards, while unbounded waits in the cancellation test can hang the suite instead of detecting a regression.

3 open issues
What changed in this PR

This test-only PR expands the safety net for MSTest analyzers, code fixes, and shared helpers without changing shipping behavior, dependencies, or coverage exclusions.

Changes:

  • Adds framework, signature, metadata, and unsupported-input boundary cases.
  • Extends complete fixed-source, stale-diagnostic, and custom fix-all checks.
  • Adds direct coverage for Roslyn helpers, hashing, compatibility APIs, and process lifetime handling.

Test-value evidence: The description reports successful Windows Release runs for the tested patch preserved in 3fce8f9b306c19fdabeb710263dd2809233b4eaa. This review used static inspection; execution artifacts were not independently verified, and empirical mutation sensitivity remains unproven.

All paths below are relative to test/UnitTests/MSTest.Analyzers.UnitTests/.

File Description
UseOSConditionAttributeInsteadOfRuntimeCheckAnalyzerTests.cs Covers additional platforms and version-specific guards.
UseExecuteAsyncOverrideFixerTests.cs Checks qualified signatures and nested delegate preservation.
UseExecutableConditionAttributeInsteadOfProcessCheckAnalyzerTests.cs Tests equivalent comparisons and unsupported executable checks.
UseCIConditionAttributeInsteadOfEnvironmentCheckAnalyzerTests.cs Rejects value-sensitive environment checks.
UndeclaredProcessGlobalStateMutationAnalyzerTests.cs Covers nested bodies and older frameworks.
TestMethodShouldBeValidAnalyzerTests.cs Checks uninferable generic parameters.
TestContextShouldBeValidAnalyzerTests.cs Covers throwing read-only context getters.
TestClassConstructorShouldBeValidAnalyzerTests.cs Tests referenced host-injection metadata.
OSPlatformAttributesShouldBeConsistentAnalyzerTests.cs Covers unmappable platform attributes.
MemberConditionShouldBeValidAnalyzerTests.cs Tests null contracts and unsupported members.
InheritedMemberFromDifferentMSTestVersionAnalyzerTests.cs Extends recursive generic signature comparisons.
Helpers/​ProductReflection.cs Adds reflection utilities for internal helper tests.
Helpers/​FixtureRegistrationTests.cs Checks registration prerequisites and supplied symbols.
Helpers/​AnalyzerRoslynHelperTests.cs Tests symbol, type, diagnostic, and attribute helpers.
Helpers/​AnalyzerResidualHelperTests.cs Extends operation identity and helper boundary coverage.
Helpers/​AnalyzerProcessCompatibilityTests.cs Tests waits using owned child processes.
Helpers/​AnalyzerHashingTests.cs Covers hashing, pooling, and rotation boundaries.
Helpers/​AnalyzerCompatibilityTests.cs Tests compatibility APIs and cancellation behavior.
DynamicDataShouldBeValidAnalyzerTests.cs Covers invalid sources and ambiguous display-name members.
DataRowShouldBeValidAnalyzerTests.cs Extends generic array inference coverage.
CultureMutationUnderParallelizationAnalyzerTests.cs Tests resource locks and older-framework diagnostics.
CodeFixResidualHelperTests.cs Exercises internal rewrite helpers and invalid-input boundaries.
CodeFixRegistrationContinuationTests.cs Adds stale-syntax and invalid-metadata registration cases.
CodeFixContinuationTests.cs Extends exact rewrites and custom fix-all coverage.
AvoidThreadSleepAndTaskWaitInTestsAnalyzerTests.cs Tests nested test scopes and field initializers.
AssemblyFixtureProviderNotSupportedWithNativeAotAnalyzerTests.cs Covers older frameworks without fixture-provider attributes.
AnalyzerResidualMetadataTests.cs Tests metadata-only attributes, modules, and legacy inheritance.
AnalyzerDiagnosticContinuationTests.cs Extends suppressor, missing-framework, and diagnostic boundary cases.

Review effort: Balanced

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added state/needs-review Awaiting review from the team. and removed state/needs-review Awaiting review from the team. labels Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 2026
Use native integer aliases, isolate registration guard assertions from opt-outs, and bound cancellation checks with owned child-process cleanup.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 6, 2026 18:41
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/approved Proposal approved; ready for implementation. labels Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 2026
@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 2026

@github-actions github-actions Bot 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.

🧪 Test quality review — PR #12256

Compared merge base df9b675dd7b49b6bbd18775d013e05bc5af8a89a with head 8e84c3118db0b9399815e8ad48056ec159963064. Evidence applies to this head, not every intermediate commit.

Test-value evidence

Contract Evidence Status
Test-only safety net for analyzers, code fixes and helpers (30 files, 0 source files changed) Behavior-preserving additions are expected to pass on both revisions. The PR body reports Windows Release runs on net10.0, net11.0 and net472, but no paired execution records for this head were accessible here. Unverified (static only)
Head commit 8e84c3118 tightens earlier weak spots: the fixture-signature CannotFix opt-out is tested separately, and guard-fixer invalid-metadata tests now first assert that one action is registered for a valid diagnostic and then assert none for the invalid one. It also moves the child-process handshake to a bounded WaitForCompletionAsync. Static reading of the delta: the valid-then-invalid pairing means an always-empty result would now fail the first assertion, and the waits are bounded. Static prediction: protective

The three open threads from the earlier head (CannotFix opt-out masking, metadata guard bypassing registration, unbounded cancellation wait) appear addressed by this head. This review did not re-verify the threads' disposition. Contracts in the remaining files were not individually assessed within this run's budget.

🧵 Parallel safety

PARALLEL-SAFETY RESULT
STATUS: PARTIAL

The specialist analysis was not run in this pass, so this is not a clean result. The PR states that scheduling and parallelization configuration are unchanged. The 12 configuration candidates are test-source strings (for example [assembly: Parallelize(...)] snippets inside analyzer inputs), not assembly attributes. The process-lifetime tests own their child process and release or kill it in finally.

Per-test assessment

Pseudo-mutation evidence below consists of static predictions, not executed mutation results.

Result Quality Test Notes How to improve
Uncertain — mod CodeFixRegistrationContinuationTests.GuardFixers_InvalidMetadata_DoNotRegisterAnUnsafeAction The valid-diagnostic action is asserted first, then none for invalid metadata; only this delta was read. Run /review-tests on a narrower scope for a full grade.
Uncertain — new CodeFixRegistrationContinuationTests.FixtureSignatureFixers_CannotFixMarker_SuppressesOnlyMarkedDiagnostics It asserts one action unmarked and none for null/"true" markers; production body not traced. Run /review-tests on a narrower scope for a full grade.
Uncertain — mod AnalyzerProcessCompatibilityTests.WaitForExit_ReleasedOrAlreadyExitedChild_PreservesTheExitCode Waits are bounded via a 60s limit with a ready/release handshake; the rest was not graded. Run /review-tests on a narrower scope for a full grade.
Uncertain — the other new and modified tests in the 30 files Full per-test grading was not completed within budget. Re-run /review-tests on a narrower scope.

No inline comments were published: no verified, actionable finding reached the publication gate. That is not an all-clear for the unread portions.

<sub>This advisory review is heuristic and non-blocking.

Re-run the combined review with /review-tests, or only the parallel-safety specialist with /parallel-audit.</sub>

🤖 Automated content by GitHub Copilot. Generated by the Test Quality Review on PR (on open / sync) workflow. · copilot · auto · ~33 AIC · ⌖ ~1 AIC · ⊞ 8K

@microsoft-github-policy-service microsoft-github-policy-service Bot added the state/needs-review Awaiting review from the team. label Nov 6, 2026
@github-actions github-actions Bot added state/approved Proposal approved; ready for implementation. and removed state/needs-review Awaiting review from the team. state/approved Proposal approved; ready for implementation. labels Nov 6, 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.

🔵 Needs a closer look

The missing-framework tests leave disabled-by-default analyzers off, so their passing rows do not exercise the missing-symbol guards or detect regressions in them.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Enable disabled analyzers in missing-framework tests

test/​UnitTests/​MSTest.Analyzers.UnitTests/​AnalyzerDiagnosticContinuationTests.cs:196

The missing-framework matrix includes disabled-by-default analyzers such as PublicTypeShouldBeTestClassAnalyzer, but AnalyzeAsync leaves them disabled unless enableDisabledRules is set. Roslyn therefore skips those analyzers, so their rows pass without exercising the missing-symbol guards. For example, incorrectly registering the public-type analysis without a TestClassAttribute would still leave these rows green. Enable the rules here so the empty-diagnostics assertion actually protects that boundary.

3 resolved since last review

Review effort: Balanced

@Evangelink
Amaury Levé (Evangelink) merged commit 1f353a4 into main Nov 9, 2026
53 of 60 checks passed
@Evangelink
Amaury Levé (Evangelink) deleted the dev/amauryleve/analyzer-code-coverage branch November 9, 2026 09:39
@github-actions github-actions Bot removed the state/approved Proposal approved; ready for implementation. label Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants