Skip to content

fix(rollback): Protect directives during roll back process - #3817

Merged
rouke-broersma merged 6 commits into
masterfrom
improve_handling_of_directives
Sep 14, 2026
Merged

rouke-broersma merged 6 commits into
masterfrom
improve_handling_of_directives

Conversation

@dupdob

@dupdob dupdob commented Sep 3, 2026

Copy link
Copy Markdown
Member

Improve statement/block mutations rollback logic to protect existing directives
Fixes #3799

Copilot AI lite review requested due to automatic review settings September 3, 2026 05:09

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 updated trivia-preservation logic and test refactor contain correctness/reliability issues (directive trivia can still be stripped in some block shapes, and a helper compilation test can be order-dependent/flaky).

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR improves Stryker.NET’s C# rollback behavior so that rolling back statement/block mutations preserves directive trivia (notably #pragma warning), preventing “restored” code from failing to compile after a rollback.

Changes:

  • Adjust rollback/instrumentation handling to better preserve trivia by wrapping/unwrapping blocks and carrying trivia through revert paths.
  • Add a HasSignificantTrivia Roslyn helper and centralize helper SyntaxTree creation for injection with consistent parse options.
  • Extend/refactor unit tests to cover directive preservation during rollback and helper compilation across newer C# language versions.
File summaries
File Description
src/Stryker.Core/Stryker.Core/Mutants/CsharpNodeOrchestrators/BaseFunctionOrchestrator.cs Unwraps nested single-statement blocks during instrumentation removal to better restore original shapes/trivia.
src/Stryker.Core/Stryker.Core/Instrumentation/IfInstrumentationEngine.cs Adds block annotation + updated block handling intended to preserve trivia through inject/revert.
src/Stryker.Core/Stryker.Core/InjectedHelpers/CodeInjection.cs Introduces a helper to produce helper SyntaxTrees with consistent encoding/options.
src/Stryker.Core/Stryker.Core/Initialisation/CsharpProjectComponentsBuilder.cs Uses the new CodeInjection helper to inject helper syntax trees.
src/Stryker.Core/Stryker.Core/Helpers/RoslynHelper.cs Adds HasSignificantTrivia to detect directive/comment trivia.
src/Stryker.Core/Stryker.Core.UnitTest/Mutants/CsharpMutantOrchestratorTests.cs Adds a directive preservation regression test that compiles, triggers rollback, then asserts compilation succeeds.
src/Stryker.Core/Stryker.Core.UnitTest/InjectedHelpers/InjectedHelperTests.cs Refactors helper compilation tests and expands language-version coverage.
src/Stryker.Core/Stryker.Core.UnitTest/Compiling/CSharpRollbackProcessTests.cs Updates test references to align with memory-mapped-file helper usage.
src/Stryker.Core/Stryker.Core.UnitTest/AssertExtensions.cs Improves syntax tree assertion output and removes an unused file assertion helper.
Review details
  • Files reviewed: 9/9 changed files
  • Comments generated: 3
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@dupdob
dupdob force-pushed the improve_handling_of_directives branch from dff8454 to 79b2b6e Compare September 4, 2026 06:48
@dupdob
dupdob force-pushed the improve_handling_of_directives branch from 79b2b6e to 2a927f6 Compare September 4, 2026 08:48
@rouke-broersma rouke-broersma changed the title Protect directives during roll back process fix(rollback): Protect directives during roll back process Sep 14, 2026
@rouke-broersma
rouke-broersma enabled auto-merge (squash) September 14, 2026 12:11
@sonarqubecloud

Copy link
Copy Markdown

This was referenced Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CSharpRollbackProcess drops #pragma warning directives, so restored code can stop compiling

3 participants