Repository navigation
Conversation
The code-fix verifiers only compare the fixed source, never which action produced it. Stryker therefore reports the string mutants on every CodeAction title and equivalenceKey as survived (about 34 in 14 providers, plus the Fix All title of SequentialFixAllProvider). Add CodeActionProbe, which runs an analyzer plus code fix over a source file and returns the registered actions, and CodeActionMetadataTests, which pins Title and EquivalenceKey per provider, including both actions of NE0001, NE0009 and NE0014, the keyless ambiguous NE0012 actions and the pre-C# 9 title of NE0005. FixAllRunner gains a title accessor so the sequential Fix All action title is asserted as well.
Resolves S2479 in CodeActionMetadataTests by using explicit escape sequences instead of literal zero-width and BOM characters.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #233 +/- ##
==========================================
+ Coverage 94.72% 95.54% +0.82%
==========================================
Files 48 48
Lines 2557 2557
Branches 449 449
==========================================
+ Hits 2422 2443 +21
+ Misses 58 41 -17
+ Partials 77 73 -4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This branch has not been deployed
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.
Problem
The latest mutation run of this repo (analyzer 59.95%: 793 killed, 491 survived, 2110 created) reports string mutants on the registered
CodeActiontitles and equivalence keys of the code-fix providers as survived. Counting the individual lines (OneTypePerFile 64/66/84/86, AvoidInvisibleCharacters 88/90/99/101, RequireNumericLiteralSuffix 71/73/96, UseIsNotNull 49 x2/55, UseIsNull 50/52, UseIsNotNullOverIsObject 54/56, AvoidRedundantCollectionClear 43/45, NamespaceMatchesFolder 45/47, SingleNamespacePerFile 68/70, AvoidRegionDirectives 54/57, NativeTypeCref 68, UseLangword 57, RequireCancellationCheck 54/70, RequireCancellationTokenParameter 58/61, plus the Fix All title inSequentialFixAllProviderline 53) this is about 34 string mutants, roughly half titles and half keys. The log only gives per-file survivor totals, so the exact string-only count is an estimate.Root cause
The
CSharpCodeFixVerifierwrappers only assert the fixed source, never which action produced it. OnlyRequireCancellationCheckCodeFixVerifierpasses an equivalence key. Nothing asserts the lightbulb text (Title) or the Fix All grouping (EquivalenceKey). SettingCodeActionEquivalenceKeyin the verifier would only kill key mutants (Roslyn fails when no action has that key) and never touches titles, so a test that inspects the registered actions directly is the primary fix.Change
Tests only, no production code changes.
Verifiers/CodeActionProbe.cs: runs an analyzer plus code fix over a source file in anAdhocWorkspace, registers the fix for the first diagnostic of a given id and returnsTitle [EquivalenceKey]of every registered action.CodeActionMetadataTests.cs: 18 tests pinning exact title and key per provider (NE0001 to NE0012, NE0014, NE0015). Covers both actions of NE0001 (rename/move), NE0009 and NE0014 (rename/text span), the two titles of NE0005 (C# 9 and pre-C# 9), and the keyless per-suffix actions of NE0012. Interpolated titles are asserted against concrete expected strings.FixAllRunner.FixAllTitleAsyncplus one test inOneTypePerFileFixAllTestspin theSequentialFixAllProvidertitle (Fix all 'NE0001' occurrences).Not done: a
codeActionEquivalenceKeyparameter onCSharpCodeFixVerifier. The probe asserts the keys directly, so the overload (which would be ambiguous next to the existingint? codeActionIndexoverload) is not needed. NE0013 (UseNumericLiteralSuffixOverCast) is not in the finding and is not covered here.Local check:
dotnet test -f net10.0on the unit project passes (475 tests). Replacing the NE0004 title with an empty string makesNE0004_UseIsNullfail as expected.Before / After
Risk / what this does not change
Measured on https://github.com/dailydevops/analyzer/actions/runs/40816302143 (workflow_dispatch on this branch, success, about 27 min). The +38 killed mutants match the estimate of about 34 string mutants plus a few incidental ones. Which individual mutants died was not broken down further, since the report only lists per-file totals.