Skip to content

test(analyzer): exercise using insertion in NE0010 code fix - #230

Merged
samtrion merged 1 commit into
mainfrom
fix/stryker-codefix-usings-insertion-untested
Oct 29, 2026
Merged

samtrion merged 1 commit into
mainfrom
fix/stryker-codefix-usings-insertion-untested

Conversation

@samtrion

@samtrion samtrion commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Mutation report for Usage/RequireCancellationTokenParameterCodeFixProvider.cs, lines 236-312 (EnsureSystemThreadingUsing, InsertAlphabetically, RemoveLeadingBlankLines): 11 NoCoverage and 13 Survived mutants (29 Killed, 23 Survived, 11 NoCoverage in the file, excluding CompileError and Ignored). The tests NoParameters_AppendsTokenAndAddsUsing, FileScopedNamespace_UsingInsertedAtNamespaceLevel and BlockScopedNamespaceWithExistingUsings_UsingInsertedAtNamespaceLevel claim to test using insertion.

Root cause

All three tests have using System.Threading; already in their input, so the fix returns at if (hasUsing) return root and never runs the insertion code. The only real insertion tests reach just the append-at-end branch.

Change

  • Remove using System.Threading; from the input of the three tests and fully qualify System.Threading.CancellationToken in the helper (input and expected output). The using is now inserted at compilation-unit, file-scoped and block-scoped namespace level, before an existing using System.Threading.Tasks; (insert-before branch, leading-blank-line removal).
  • Add BlockScopedNamespaceNewUsingSortsAfterAllExisting_AppendedWithIndentation: the new using sorts last inside an indented block namespace, covering the append branch that copies the first using's leading trivia.

Test-only change; no product code touched.

Before / After

Measured with the mutation workflow dispatched on this branch: https://github.com/dailydevops/analyzer/actions/runs/40815375432 (before: latest successful run on main, 2026-10-27). The per-file score is not printed in the log, so the comparison is on whole-run totals.

metric before after
mutation score 59.95 % 60.63 %
mutants created 2110 2110
compile errors 474 474
NoCoverage 42 33
Ignored (block already covered) n/a in summary 300
Killed 793 801
Survived 491 491
Timeout 5 6
duration 25:15 24:23

Result: 9 NoCoverage mutants are now covered and 8 more are killed, but the Survived count did not change. The gain (+0.68 points) is below the estimated 1.0-1.4 points; the 13 survivors in lines 236-301 (trailing-trivia fallback, existingUsing logic) are not affected by these tests.

Risk / what this does not change

No product code changes. Not addressed: line 270 (dead ternary, Usings.Count is always 0 there, equivalent mutants) and lines 246-247 (CRLF versus LF trailing trivia fallback, would need brittle CRLF input). Realistic expectation is roughly 14-19 fewer survivors/NoCoverage, not the full 24.

The NE0010 code-fix tests named AddsUsing / UsingInsertedAtNamespaceLevel
already contained 'using System.Threading;' in their input, so the fix
returned early and never ran EnsureSystemThreadingUsing's insertion
branches (11 NoCoverage and 13 Survived mutants in the mutation report).

Drop the directive from the input of those three tests (the helper now
uses the fully qualified CancellationToken) so the using is really
inserted at compilation-unit, file-scoped and block-scoped namespace
level, before an existing using. Add a block-scoped case where the new
using sorts last, covering the indentation carried over from the first
existing using.
@codecov

codecov Bot commented Oct 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.54%. Comparing base (8c86c2b) to head (bf60594).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #230      +/-   ##
==========================================
+ 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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@samtrion
samtrion merged commit cb39b55 into main Oct 29, 2026
9 checks passed
@samtrion
samtrion deleted the fix/stryker-codefix-usings-insertion-untested branch October 29, 2026 15:43
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.

1 participant