Skip to content

docs: update CLAUDE.md with NAudio testability pattern and Copilot review rule#36

Merged
MiguelTVMS merged 1 commit intodevelopfrom
fix/update-claude-md
Mar 19, 2026
Merged

docs: update CLAUDE.md with NAudio testability pattern and Copilot review rule#36
MiguelTVMS merged 1 commit intodevelopfrom
fix/update-claude-md

Conversation

@KrennicMS
Copy link
Copy Markdown
Collaborator

What

Updates CLAUDE.md to document the lessons learned from recent PR review cycles.

Changes

NAudio COM testability

  • MMDevice and MMDeviceEnumerator are sealed COM classes — explicitly documented as unmockable
  • Added the delegate injection + generic type pattern showing how to make logic testable without COM
  • Shows both the production call site and the string-stub test pattern
  • Explicitly warns against null! null-forgiveness workarounds (they mask the real problem)

[Fact] vs [WindowsFact] clarification

  • Added a row: [Fact] is correct when the test exercises pure logic only (no Windows/COM/NAudio type references)
  • Updated the VolumeWatcherServiceTests.cs table row: now accurately described as mixed (some [Fact], most [WindowsFact])

PR Process section

  • Documents that Copilot review is mandatory before merging
  • Steps: check reviews endpoint, check inline comments, act on all comments, then merge

Why

Several recent CI failures and iterative review cycles stemmed from the absence of this guidance:

  1. Tests used null! stubs for MMDevice, causing NullReferenceException until the generic-delegate pattern was applied
  2. Copilot reviewed PRs after the fact, requiring multiple follow-up commits

…view rule

- Document that MMDevice/MMDeviceEnumerator are sealed COM classes and cannot
  be mocked; explain the delegate injection + generic type pattern to make
  such code unit-testable without COM
- Clarify [Fact] vs [WindowsFact] guidance: pure-logic tests using string
  stubs use [Fact]; tests that reference NAudio COM types use [WindowsFact]
- Update VolumeWatcherServiceTests row: now mixed ([Fact] for
  ResolveMonitoredDevice string-stub tests, [WindowsFact] for the rest)
- Add PR process section: Copilot review is mandatory before merging;
  steps to check reviews and inline comments before squash-merging
@MiguelTVMS MiguelTVMS requested a review from Copilot March 19, 2026 10:36
@MiguelTVMS MiguelTVMS merged commit 90c7447 into develop Mar 19, 2026
5 checks passed
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates CLAUDE.md to capture team learnings around Windows/NAudio testability and the expected PR workflow, helping prevent recurring CI/test issues and standardize review practices.

Changes:

  • Clarifies when to use [Fact] vs [WindowsFact] (including the “pure logic only” case).
  • Documents a delegate-injection + generic-type pattern for unit-testing logic that would otherwise depend on sealed NAudio COM types.
  • Adds a “Pull Request Process” section requiring Copilot review before merge and outlining recommended checks.

Comment thread CLAUDE.md
Comment on lines +311 to +312
id => (MMDevice?)_enumerator.GetDevice(id),
() => (MMDevice?)_enumerator.GetDefaultAudioEndpoint(...),
Comment thread CLAUDE.md
When a method needs to be unit-tested without COM, extract the logic into a `static` (or standalone) method that accepts delegates returning a generic `TDevice` instead of `MMDevice`, plus a `getName` delegate to get the device name:

```csharp
internal static TDevice? ResolveSomething<TDevice>(
Comment thread CLAUDE.md
Func<string, TDevice?> getDevice,
Func<TDevice?> getDefault,
Func<TDevice, string?> getName,
Action<COMException, string> logWarning,
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