Skip to content

feat(lint): rule-test coverage check + global testing.md codify (Bundle 137+138)#165

Merged
aloekun merged 2 commits into
masterfrom
bundle-137-138
May 19, 2026
Merged

feat(lint): rule-test coverage check + global testing.md codify (Bundle 137+138)#165
aloekun merged 2 commits into
masterfrom
bundle-137-138

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented May 19, 2026

Summary

Bundle 137 + 138 を実装。.claude/custom-lint-rules.toml の各 rule に対する test カバレッジを TOML meta field + cargo test で機械強制する 2 層構成を導入。命名規約に依存しない明示的 mapping を採用 (案 b) し、AI 生成の test 命名揺らぎを構造的に抑止する。

由来: PR #163 post-merge-feedback T1-#1 + T3-#1 採用 (Frequency High = PR #110/#151/#152/#155 の 4 PR 累積観測)。

変更内容

順位 137: Rule-Test Coverage Check Cargo test (Tier 1, M)

  • CustomRuletest_coverage: Option<CustomRuleTestCoverage> field 追加 (src/hooks-post-tool-linter/src/main.rs)
  • rule_test_coverage_check cargo test 新規実装 (50 行制限のため 4 helper 関数に分割)
    • load_deployed_custom_rules — deploy 済 TOML 読込 + false-green guard
    • extract_existing_test_fn_names — main.rs から fn 名を regex 抽出 + 自己存在 guard
    • classify_rule_extensions — 主要 (rs/toml/yaml/yml) vs 非主要に分類
    • check_main_ext_coverage / check_other_ext_coverage / check_main_ext_keys_sanity — 検証ロジック
  • 全 10 rule に [rules.test_coverage] meta field 宣言 (.claude/custom-lint-rules.toml)

Test gap 補填 (+7 tests, 121 → 128)

  • rule② no-personal-paths (元 0 tests — 配布後初の検証):
    • no_personal_paths_detects_windows_user_path_in_md
    • no_personal_paths_detects_unix_home_path_in_txt
    • no_personal_paths_skips_placeholder_paths
  • rule⑥ no-ephemeral-todo-reference yaml/yml (主要拡張子 gap):
    • no_ephemeral_todo_detects_yaml_ephemeral_reference
    • no_ephemeral_todo_yaml_skips_permanent_adr_reference
    • no_ephemeral_todo_detects_yml_ephemeral_reference

順位 138: Global testing.md codify (Tier 3, XS)

  • ~/.claude/rules/common/testing.md に新 section "Custom Lint Rule Test Coverage" 追加 (グローバル設定、派生プロジェクト = techbook-ledger / auto-review-fix-vc へ自動波及)
  • 原則 / 必須カバレッジ scope / 機械強制レイヤ / 命名規約 vs TOML meta field の trade-off と採用根拠 (案 b) を canonical 文書化

順位 137 + 138 entry 削除

設計判断

案 a (命名規約方式) vs 案 b (TOML meta field 方式) — 案 b 採用

ユーザー指示「コーディングエージェントによる揺らぎの余地を減らす意図」に従い、明示的 mapping を採用。

観点 案 a (命名規約) 案 b (TOML meta field)
TOML schema 拡張 不要 あり (本 PR で導入)
既存 test 命名の不整合 ps_empty_catch_* / md_mutable_anchor_* 等の混在で adapt 困難 任意命名に対応
AI 生成揺らぎ抑止 規約遵守に依存 rule 著者が明示宣言を強制
Typo / orphan mapping 検出 不可 (規約外として silent pass) cargo test で fail

必須カバレッジ scope

主要拡張子 (rs / toml / yaml / yml) × 全 rule に 1+ test を必須化。非主要拡張子は rule あたり 1+ positive test で代替 (test 関数爆発を抑制)。

Verification

Negative-case sanity check (load-bearing 証明)

no_write_result_discard_TYPO_NONEXISTENT を rule⑩ の meta field に注入 → rule_test_coverage_check が以下メッセージで fail:

rule test coverage gaps detected (1 issue(s)):
  - rule `no-write-result-discard` declares test `no_write_result_discard_TYPO_NONEXISTENT` for ext `rs` but no such function exists in main.rs

restore 後は green に戻ることを確認済。

全体テスト + ビルド

  • cargo test -p hooks-post-tool-linter: 128 passed; 0 failed
  • cargo build --workspace: clean (dead_code warning は #[allow(dead_code)] で抑制、test 専用 field のため)
  • pnpm build:all: 全 7 exe ビルド + .claude/ への配布完了

Backward Compatibility

#[serde(default)] + Option<CustomRuleTestCoverage> により、派生プロジェクト (techbook-ledger / auto-review-fix-vc) で 古い TOML (meta field 不在) を持つ deploy 先でも production hook は壊れないcargo test 実行時のみ "meta field 不在" として fail する設計で、production と test の責務を分離。

Commit 構成 (2 commits)

  1. feat(lint): rule-test coverage check cargo test + global testing.md codify (c5b5ad7) — 実装 + ドキュメント codify (TOML + main.rs)
  2. docs(todo): 順位 137 + 138 完了に伴い削除 (4f7e021) — todo entries cleanup

memory rule git-workflow.md § jj 環境完了タスク削除手順 に従い、本作業と todo 削除を別 commit に分離。

Test plan

  • cargo test -p hooks-post-tool-linter で 128 tests green
  • negative case (typo 注入) で actionable error message を確認
  • cargo build --workspace で warning なし
  • pnpm build:all で全 exe ビルド成功
  • CI (GitHub Actions) green
  • CodeRabbit review でブロッカーなし

🤖 Generated with Claude Code

Summary by CodeRabbit

リリースノート

  • Tests

    • カスタムリントルールのテストカバレッジ検証機能を強化しました。宣言されたテスト関数の存在確認と、各拡張子ごとの最小テスト要件の自動検証が可能になります。
  • Chores

    • ドキュメントを整理し、完了済みのタスク記述を削除しました。

Review Change Stack

aloekun added 2 commits May 19, 2026 14:39
…odify (Bundle 137+138, TOML meta field 方式)

- src/hooks-post-tool-linter/src/main.rs:
  - CustomRule に test_coverage: Option<CustomRuleTestCoverage> field 追加
  - rule_test_coverage_check cargo test 新規 (helper 4 関数に分割)
    - load_deployed_custom_rules / extract_existing_test_fn_names
    - classify_rule_extensions / check_main_ext_coverage / check_other_ext_coverage / check_main_ext_keys_sanity
    - collect_rule_coverage_gaps
  - test gap 補填 (合計 +7 tests, 121 → 128):
    - rule② (no-personal-paths): positive×2 + negative×1 (元 0 tests, 配布後初の検証)
    - rule⑥ (no-ephemeral-todo-reference) yaml: positive×1 + negative×1
    - rule⑥ (no-ephemeral-todo-reference) yml: positive×1

- .claude/custom-lint-rules.toml:
  - 全 10 rule に [rules.test_coverage] meta field を宣言
  - 主要拡張子 (rs/toml/yaml/yml) を targets する rule は main_ext_tests.<ext> で各 ext に 1+ test を明示
  - 非主要専用 rule は other_ext_tests でカバレッジ宣言

- ~/.claude/rules/common/testing.md (グローバル):
  - 新 section 'Custom Lint Rule Test Coverage' を追加
  - 命名規約 vs TOML meta field の trade-off と採用根拠 (案 b) を codify
  - 派生プロジェクト (techbook-ledger / auto-review-fix-vc) へ自動波及

順位 137 + 138 (PR #163 post-merge-feedback T1-#1 + T3-#1 採用)。命名規約に依存しない明示的 mapping を採用したのは AI 生成の揺らぎを構造的に抑止する意図 (ユーザー指示)。
- docs/todo-summary.md: 行 137 + 138 を削除 (table)
- docs/todo8.md: 順位 137/138 entry block を削除 (合計 90 行 -)

PR 本作業 (@-: feat(lint) commit) で実装 + ドキュメント codify が land したため、todo entries を片付け。
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 91c730e0-63ed-4898-97dd-d92a525fb133

📥 Commits

Reviewing files that changed from the base of the PR and between a1e979b and 4f7e021.

📒 Files selected for processing (4)
  • .claude/custom-lint-rules.toml
  • docs/todo-summary.md
  • docs/todo8.md
  • src/hooks-post-tool-linter/src/main.rs
💤 Files with no reviewable changes (2)
  • docs/todo-summary.md
  • docs/todo8.md

📝 Walkthrough

Walkthrough

このプルリクエストでは、カスタムリント規則に対するテストカバレッジメタデータシステムを導入します。TOML 設定ファイルに各規則が満たすべきテスト関数名を宣言し、Rust 実装側でそれらが実装に存在すること、かつ拡張子ごとの要件を満たすことを自動検証します。

Changes

テストカバレッジメタデータシステムの導入

Layer / File(s) Summary
メタデータスキーマと構造体定義
src/hooks-post-tool-linter/src/main.rs
CustomRuletest_coverage フィールドを追加し、CustomRuleTestCoverage 構造体で主要拡張子・非主要拡張子向けテスト関数リストを定義します。テスト生成ヘルパも対応。
TOML 設定ファイルへのテストカバレッジ宣言
.claude/custom-lint-rules.toml
10 個すべてのカスタムリール(①〜⑩)に対して、rules.test_coverage フィールドで対応するテスト関数識別子を other_ext_tests または main_ext_tests に分類して列挙。
個別規則のテストケース拡張
src/hooks-post-tool-linter/src/main.rs
no-personal-paths の Windows/Unix パス検出テストと、no-ephemeral-todo-reference の YAML/YML 拡張子向け positive/negative テストを追加。
テストカバレッジ検証ロジック
src/hooks-post-tool-linter/src/main.rs
rule_test_coverage_check テストとヘルパー関数群を実装し、デプロイ済み TOML から読み込んだ規則のテスト宣言が main.rs の実装と対応・充足しているかを検証。
ドキュメント整理
docs/todo-summary.md, docs/todo8.md
完了したタスク行(PR #163 関連)と実装済みの todo エントリ(Rule-Test Coverage Check, Rule Extension Test Pattern)を削除し、ドキュメント構成をシンプル化。

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly Related PRs

  • aloekun/claude-code-hook-test#141: 本 PR が追加する no-ephemeral-todo-reference の YAML/YML 自己除外テストと、retrieved PR の同規則に関する自己除外回帰テストが直接オーバーラップします。
  • aloekun/claude-code-hook-test#76: 本 PR が no-personal-paths ルール向けに追加するテストケース(Windows/Unix パス検出)は、retrieved PR が .claude/custom-lint-rules.toml で追加したルール定義と直に連動しています。
  • aloekun/claude-code-hook-test#159: 本 PR の test_coverage メタデータ・rule_test_coverage_check テストの追加は、retrieved PR が追加したルール⑩ no-write-result-discard の設定・テスト実装と同じファイル領域で直に連動しています。
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed プルリクエストのタイトルは、Bundle 137 と 138 の実装内容(ルール・テストカバレッジチェック機能の追加とグローバルテストドキュメント化)を簡潔に要約しており、チェンジセット全体の主要な変更を明確に反映している。
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@aloekun aloekun merged commit 04559e7 into master May 19, 2026
1 check passed
@aloekun aloekun deleted the bundle-137-138 branch May 19, 2026 08:21
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