Skip to content

test: strengthen existing rule regression coverage (#8) - #21

Merged
mao2009 merged 2 commits into
mainfrom
feature/issue-8-regression-coverage
Sep 3, 2026
Merged

test: strengthen existing rule regression coverage (#8)#21
mao2009 merged 2 commits into
mainfrom
feature/issue-8-regression-coverage

Conversation

@mao2009

@mao2009 mao2009 commented Sep 3, 2026

Copy link
Copy Markdown
Owner

Issue #8: Strengthen existing rule regression coverage

Refs #8

既存 RT/LVP/FIF Analyzer の現在の挙動を v1.0 まで壊さないための回帰テストを体系化します。テスト数 56 → 101

⚠️ Base branch: この PR は main ではなく feature/issue-7-diagnostic-ssot をベースにしています。理由は「Issue #7 への依存」を参照してください。PR #20 の merge 後、base は自動的に main に切り替わります。

Changes

DiagnosticContractTests.cs(33 tests)

docs/DIAGNOSTICS.md の SSOT を機械的に固定します。

  • 全 7 Diagnostic の ID / category / default severity / 既定有効 を検証
  • SupportedDiagnostics が公開契約と厳密に一致することを検証(追加・削除の双方を検出。新規 Diagnostic は SSOT とこのリストを同時に更新しないと通りません)
  • ID 命名規則(PREFIX + 4桁)を検証
  • category 方針(Naming は既定 Error にしない)を検証
  • 各 descriptor の title / message / description が解決可能かつ非空であることを検証
  • title / description が Diagnostic 間で共有されていないことを検証

message 文言そのものは公開契約対象外のため値は固定していません。代わりに「descriptor が自分自身の ID の resource key を参照していること」を検証します。

RegressionBoundaryTests.cs(11 tests)

既存テストが扱っていなかった境界を固定します。

対象 内容
RT0001 instance field は対象外 / 同一アクセスが重複報告されないことを件数で固定
RT0002 stringConvert など既知純粋型は許可 / user type の instance method は検出 / [PureMethod] なしは解析対象外
RT0003 呼び出しではなく property 参照経路Console.Out)を固定
LVP0001 var 宣言 / nested block / 二重アンダースコア / 読み取りのみは検出しない

AnalyzerProbe.cs

Analyzer を直接実行して報告 Diagnostic をそのまま取得するヘルパー。Microsoft.CodeAnalysis.Testing の markup 形式では重複報告の有無を表現しづらいため、件数と位置を直接検証したい境界テストで使用します。Issue #8 スコープの「Analyzer Test 共通パターンの整理」に該当します。

実装調査で判明した現在の挙動(テストで固定済み)

[PureMethod] メソッド内のローカル関数について:

  • 本体は外側メソッドとして解析されるため、static mutable field アクセスに RT0001 が報告される
  • 一方でローカル関数自体は [PureMethod] を持たないため、その呼び出しは RT0002(非純粋メソッド呼び出し)になる

この扱いが妥当かどうかは Issue #10(pure method contract / interprocedural analysis)の検討対象です。本 PR では挙動を変更せず、現状を固定するに留めています。

Issue #7 への依存(実測で確認)

Descriptor_DescriptionsAreNotSharedBetweenDiagnostics は、Issue #7 の LVP0003 descriptor 修正がない状態で実行すると

These diagnostics share an identical description, which means at least one
references another diagnostic's resource key: LVP0003, FIF0001

として実際に失敗することを実測で確認しました。推測ではなく CONFIRMED な依存です。

Merge order: PR #20#7)→ この PR。

Verification

  • Build: PASS (0 error)
  • Tests: 101/101 PASS(baseline 56 から +45)
  • git diff --check: PASS

Issue #8 完了条件

  • 全公開 Diagnostic に positive/negative テストがある
  • 主要な境界ケースがテストされている
  • 既存挙動を変更する PR で回帰テストが必須になる(contract test が descriptor 変更を検出)
  • Release 前に全 Analyzer Tests が green である

Merge boundary

技術検証を通過しても MERGE CANDIDATE にとどまります。merge には Merge Skill による検証と、この PR / HEAD に対する新しい明示的 human approval が必要です。

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added regression coverage for analyzer behavior involving field access, pure and non-pure methods, I/O properties, variable reassignment, nested blocks, and read-only access.
    • Added contract tests validating diagnostic IDs, categories, severities, enablement, naming, descriptions, titles, and documented policies.
    • Added test infrastructure for compiling source code and collecting analyzer diagnostics asynchronously.

Issue #8 に対応し、既存 RT/LVP/FIF Analyzer の現在の挙動を v1.0 まで
壊さないための回帰テストを体系化する。テスト数 56 -> 101。

追加: DiagnosticContractTests.cs (33 tests)
docs/DIAGNOSTICS.md の SSOT を機械的に固定する。
- 全 7 Diagnostic の ID / category / default severity / 既定有効を検証
- SupportedDiagnostics が公開契約と厳密に一致することを検証
  (追加・削除の双方を検出する。新規 Diagnostic は SSOT とこのリストを
   同時に更新しなければ通らない)
- ID 命名規則 (PREFIX + 4桁) を検証
- category 方針 (Naming は既定 Error にしない) を検証
- 文書化済み category 以外を使っていないことを検証
- 各 descriptor の title / message / description が解決可能かつ非空で
  あることを検証
- title / description が Diagnostic 間で共有されていないことを検証

message 文言そのものは公開契約対象外のため値は固定していない。代わりに
「descriptor が自分自身の ID の resource key を参照していること」を
検証している。

追加: RegressionBoundaryTests.cs (11 tests)
既存テストが扱っていなかった境界を固定する。
- RT0001: instance field は対象外
- RT0001: 同一フィールドアクセスが重複報告されないことを件数で固定
- RT0002: string / Convert など既知純粋型の呼び出しは許可
- RT0002: user type の instance method 呼び出しは検出
- RT0002: [PureMethod] のないメソッドは解析対象外
- RT0003: 呼び出しではなく property 参照経路 (Console.Out) を固定
- LVP0001: var 宣言 / nested block / 二重アンダースコア
- LVP0001: 読み取りのみは検出しない

追加: AnalyzerProbe.cs
Analyzer を直接実行して報告 Diagnostic をそのまま取得するヘルパー。
Microsoft.CodeAnalysis.Testing の markup 形式では重複報告の有無を
表現しづらいため、件数と位置を直接検証したい境界テストで使用する。
Issue #8 スコープの「Analyzer Test 共通パターンの整理」に該当する。

実装調査で判明した現在の挙動 (テストで固定済み):
[PureMethod] メソッド内のローカル関数について、本体は外側メソッドとして
解析されるため static mutable field アクセスに RT0001 が報告される。
一方でローカル関数自体は [PureMethod] を持たないため、その呼び出しは
RT0002 (非純粋メソッド呼び出し) になる。この扱いが妥当かどうかは
Issue #10 (pure method contract / interprocedural analysis) の検討対象で
あり、本 Issue では挙動の変更を行わず現状を固定するに留めた。

Issue #7 への依存 (実測で確認):
DiagnosticContractTests の
Descriptor_DescriptionsAreNotSharedBetweenDiagnostics は、Issue #7 の
LVP0003 descriptor 修正がない状態では
"LVP0003, FIF0001" として失敗することを実測で確認した。
したがって本 PR は Issue #7 の後に merge する必要がある。

検証結果:
- dotnet build: PASS (0 error)
- dotnet test --no-build: PASS (101/101、baseline 56 から +45)
- git diff --check: PASS

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XB2mDSE67ZDQS9mk5KfAdZ
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: fe5ccefb-e3c5-4c98-9f41-6c1e7c2cb12c

📥 Commits

Reviewing files that changed from the base of the PR and between 285f852 and 052fb57.

📒 Files selected for processing (3)
  • src/PureSharp.Analyzers.Tests/AnalyzerProbe.cs
  • src/PureSharp.Analyzers.Tests/DiagnosticContractTests.cs
  • src/PureSharp.Analyzers.Tests/RegressionBoundaryTests.cs

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The test project adds a Roslyn analyzer execution helper, a diagnostic contract suite, and regression tests for RT0001–RT0003 and LVP0001 boundary behavior.

Changes

Analyzer testing

Layer / File(s) Summary
Analyzer execution probe
src/PureSharp.Analyzers.Tests/AnalyzerProbe.cs
Adds asynchronous compilation and analyzer execution with automatic metadata-reference discovery and load-failure handling.
Diagnostic contract validation
src/PureSharp.Analyzers.Tests/DiagnosticContractTests.cs
Adds checks for diagnostic coverage, IDs, categories, severities, enablement, naming, descriptor text, uniqueness, and category policies.
Analyzer boundary regressions
src/PureSharp.Analyzers.Tests/RegressionBoundaryTests.cs
Adds regression cases for RT0001, RT0002, RT0003, and LVP0001 analyzer behavior.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to 052fb

This adds analyzer contract and boundary regression coverage without changing analyzer production behavior. The expanded test suite is reported passing, with no current merge-blocking risk identified.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 27 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the primary change: stronger regression coverage for the existing analyzers. It is concise and related to the added regression and diagnostic contract tests.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/issue-8-regression-coverage

Comment @coderabbitai help to get the list of available commands.

PR #20 (Issue #7) が main にマージされたため、PR #21 のスタック元
feature/issue-7-diagnostic-ssot は不要になった。PR #21 を main 直接の
PR に付け替えるにあたり、ブランチ内容を現在の main 基準に更新する。

方式として rebase ではなく merge を選択した理由:
- merge-skill SKILL.md の固定安全ポリシーが force push を禁じており、
  rebase は履歴書き換えのため force push が必須になる
- PR #22 が本ブランチを base にスタックしているため、force push は
  #22 の merge-base を破壊し diff ノイズを生む
- merge であれば fast-forward push で済み、#22 の diff は #9 変更のみの
  ままクリーンに保たれる
- 履歴とトレーサビリティが完全に保存される

取り込んだ main の変更:
- 285f852 Merge pull request #20 (Issue #7 diagnostic SSOT)
- 44bc400 docs: READMEのDiagnostic titleを実装の値に一致させる

Issue #8 の変更範囲 (test-only) には影響しない。main...HEAD の
三点diff は Issue #8 のテスト3ファイルのみである。

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HbycDX129cVZTorjE2s4W9
@mao2009
mao2009 changed the base branch from feature/issue-7-diagnostic-ssot to main September 3, 2026 03:26
@mao2009 mao2009 closed this Sep 3, 2026
@mao2009 mao2009 reopened this Sep 3, 2026
@mao2009

mao2009 commented Sep 3, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@mao2009
mao2009 merged commit b38403d into main Sep 3, 2026
2 checks passed
@mao2009
mao2009 deleted the feature/issue-8-regression-coverage branch September 8, 2026 01:18
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