Skip to content

Add a local fuzz harness for analyzers and code fixes - #4350

Merged
AArnott merged 2 commits into
masterfrom
add-fuzz-harness
Oct 19, 2026
Merged

AArnott merged 2 commits into
masterfrom
add-fuzz-harness

Conversation

@AArnott

@AArnott AArnott commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Closes #4338

Adds a local, deterministic harness that mutates C# and runs every StyleCop analyzer and code fix in a worker process. It is intentionally not in StyleCopAnalyzers.slnx and has no workflow job. The same seed, corpus, and iteration count replay the same candidates, so a required mutate check would be unstable. A new seed or more iterations can surface different bugs, but only by sampling.

Also adds .agents/skills/fuzz-analyzers/SKILL.md and a row in AGENTS.md. A later agent can use that skill to run another campaign and turn a confirmed crash, or a code fix that breaks valid code, into a test-first fix. Campaign output stays outside the repo.

No analyzer or code-fix behavior changes. The tool's self-test passes locally. CI will not build this project.

Left out, on purpose:

  • coverage-guided fuzzing
  • automatic issue filing
  • a CI or scheduled mutate/repro job

repro of a signature directory now restores the saved filename and settings from input.json, replays edits to input.cs, and does not analyze fixed.cs. Ordinary seeds and their settings sidecars are unchanged. Covered by the harness self-test.

Keep the campaign tool out of the solution and CI. Document how to rerun it and how to turn a confirmed finding into a test-first fix.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7b84c03c-f9e3-4447-96f6-caff454f3096
@AArnott
AArnott requested a balanced review from Copilot October 19, 2026 14:37
@AArnott
AArnott marked this pull request as ready for review October 19, 2026 14:40

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Saved-directory replay loses original filenames and settings and incorrectly analyzes fixed-output artifacts.

1 open issue
What changed in this PR

Adds a local deterministic fuzz harness for StyleCop analyzers and code fixes, supporting #4338 without changing shipping behavior or adding CI integration.

Changes:

  • Adds corpus extraction, mutation, worker isolation, and saved findings.
  • Includes seed inputs and self-tests.
  • Documents campaign execution and manual triage.
File Description
tools/​StyleCop.Analyzers.Fuzz/​StyleCop.Analyzers.Fuzz.csproj Defines the standalone tool.
tools/​StyleCop.Analyzers.Fuzz/​SelfTests.cs Checks defect detection.
tools/​StyleCop.Analyzers.Fuzz/​Seeds/​Trivia.cs Exercises comment placement.
tools/​StyleCop.Analyzers.Fuzz/​Seeds/​Spacing.cs Exercises spacing rules.
tools/​StyleCop.Analyzers.Fuzz/​Seeds/​Modern.cs Exercises modern syntax.
tools/​StyleCop.Analyzers.Fuzz/​Seeds/​Documentation.cs Exercises documentation rules.
tools/​StyleCop.Analyzers.Fuzz/​Seeds/​Directives.cs Exercises preprocessor directives.
tools/​StyleCop.Analyzers.Fuzz/​Result.cs Models execution results.
tools/​StyleCop.Analyzers.Fuzz/​Program.cs Runs campaigns and manages workers.
tools/​StyleCop.Analyzers.Fuzz/​Input.cs Models source and settings.
tools/​StyleCop.Analyzers.Fuzz/​Finding.cs Models detected findings.
tools/​StyleCop.Analyzers.Fuzz/​Corpus.cs Loads, extracts, and mutates seeds.
tools/​StyleCop.Analyzers.Fuzz/​AnalysisEngine.cs Executes analyzers and validates fixes.
AGENTS.md Links the fuzzing skill.
.agents/​skills/​fuzz-analyzers/​SKILL.md Documents campaigns and triage.

Review effort: Balanced

Comment thread tools/StyleCop.Analyzers.Fuzz/Corpus.cs Resolved
@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.65%. Comparing base (4371321) to head (e945fd6).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4350   +/-   ##
=======================================
  Coverage   97.65%   97.65%           
=======================================
  Files        1334     1334           
  Lines      148794   148794           
  Branches     5052     5052           
=======================================
  Hits       145299   145299           
  Misses       2215     2215           
  Partials     1280     1280           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

A signature directory was loaded as ordinary seeds, so input.json was treated as stylecop.json and fixed.cs was analyzed. Replay the minimized input.cs with the saved envelope instead.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7b84c03c-f9e3-4447-96f6-caff454f3096
Copilot AI balanced review requested due to automatic review settings October 19, 2026 14:48
@AArnott
AArnott marked this pull request as draft October 19, 2026 14:48

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Broken worker pipes can abort campaigns, and exception-signature collisions can discard independent reproducers.

No open issues 🎉

2 previously missed issues

In code that hasn't changed since last review

Medium severity Include stack traces to distinguish exception throw sites

tools/​StyleCop.Analyzers.Fuzz/​Program.cs:147

Using only the first exception line gives different NullReferenceException throw sites in the same analyzer or fix action identical signatures. Analyzer exceptions also leave Rule and Action empty. The shortest-input replacement then retains only one reproducer, hiding an independent failure. Include stack-trace information in exception signatures, and add a regression case with identical exception messages from different throw sites.

Medium severity Handle broken-pipe I/O failures without aborting the campaign

tools/​StyleCop.Analyzers.Fuzz/​Program.cs:192

If the worker exits before or while reading the request, this write throws an IOException (broken pipe), rather than reaching the null-output crash handling below. Only TimeoutException is caught, so the entire campaign aborts without saving this input or restarting the worker. Catch pipe I/O failures and return a Crash finding after disposing the worker so subsequent inputs can still run.

1 resolved since last review

Review effort: Balanced

@AArnott
AArnott marked this pull request as ready for review October 19, 2026 15:06
@AArnott
AArnott merged commit 8b9ceee into master Oct 19, 2026
30 checks passed
@AArnott
AArnott deleted the add-fuzz-harness branch October 19, 2026 15:06
This was referenced Nov 22, 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.

Add fuzzing of the library and its code fixers

2 participants