Skip to content

feat(hooks): Phase D D-5 — comment-lint test 拡充 + MAX cap break scope test#151

Merged
aloekun merged 2 commits into
masterfrom
d5-comment-lint-test-expansion
May 13, 2026
Merged

feat(hooks): Phase D D-5 — comment-lint test 拡充 + MAX cap break scope test#151
aloekun merged 2 commits into
masterfrom
d5-comment-lint-test-expansion

Conversation

@aloekun
Copy link
Copy Markdown
Owner

@aloekun aloekun commented May 13, 2026

Summary

Phase D Round 2 の D-5 (順位 56 + 119 bundle) 実装 + dogfood 観測。

コード変更 (commit 5cbed3c)

  • hooks-post-tool-comment-lint-rust: UTF-8 multi-byte test 5 パターン + block comment boundary test 6 パターン + direct unit test 1 件追加 (計 12 tests)
  • hooks-post-tool-linter: MAX_CUSTOM_VIOLATIONS outer/inner loop break scope explicit test 2 件追加
  • 副産物 production bug fix: byte_offset_to_line の char-boundary panic を解消 (UTF-8 multi-byte 文字で終わる needle で panic していた production bug)

Test

  • comment-lint-rust: 85 passed / linter: 111 passed = 全 196 tests pass

Phase D D-5 dogfood 観測 (3 push events で 3 data points)

  • Push 1 (Rust diff 649 行): auto_fix + 1 FP (file 混同型 hallucinate)
  • Push 2 (docs-only 67 行): auto_fix + 1 FP (同 FP 再現 = mistral:7b が diff 外 hook source を見ている根拠)
  • Push 3 (docs-only 50 行): auto_fix + 1 FP (file 名を hallucinate、reviewer が "the report documents its own FP" と評価)
  • 累積 6 data points / 3 PR で ADR-038 採用条件先行充足、fallback 0/5 = 0%

詳細は docs/local-llm-offload-analysis.md の D-5 outcome 節を参照。

Test plan

  • cargo test 全 pass (196 tests)
  • cargo fmt / clippy clean
  • pre-push-review APPROVE (3 push events 全て 1-iter 収束)
  • lint_screen dogfood 観測完了 (3 data points)
  • CodeRabbit review (post-PR)

Summary by CodeRabbit

リリースノート

  • ドキュメント

    • 分析進捗と実装データを更新
    • タスク管理・推奨実行順序を最新状況に反映
  • テスト

    • 多言語・特殊文字に対応したテストカバレッジを拡充
    • カスタムルール動作の検証テストを追加
  • 機能拡張

    • TOML ファイルに対応する規則を追加

Review Change Stack

aloekun added 2 commits May 13, 2026 15:15
…NS outer/inner break test (順位 56 + 119)

## D-5 実装 (順位 56 + 119 bundle)

### 順位 56: comment-lint hook test 拡充 (PR #104 T2-1+T2-2 bundle)

`src/hooks-post-tool-comment-lint-rust/src/main.rs`:
- UTF-8 multi-byte test 5 パターン追加: 漢字 + ASCII 混合 / 漢字単独 / emoji / BMP 外
  文字 (𝕊) / 結合文字 (e + U+0301)
- Block comment boundary test 6 パターン追加: 複数行 (start/end/middle 被覆) + 単行
  block comment (exact / starts-at / ends-at) で `span_overlaps_ranges` の
  inclusive-bounds 区間交差判定を体系化
- 既存 1 パターンずつのテストは保持 (regression 防止)

### 副産物: `byte_offset_to_line` char-boundary panic fix

UTF-8 漢字単独パターン test 着手時に発見した production bug を修正:

- 旧: `source[..clamped].bytes()` は `clamped` が char boundary でない場合 panic
- 新: `source.as_bytes()[..clamped].iter()` で byte slice 経由に変更 (char boundary 不要)
- 影響: needle 末尾が multi-byte 文字の場合 (例: 「漢字のみのコメント」を Edit/Write の
  new_string として渡す現実シナリオ) で hook が panic していたのを修正
- direct unit test `byte_offset_to_line_handles_mid_multibyte_offset` を追加して bug
  location を pinpoint

### 順位 119: MAX_CUSTOM_VIOLATIONS outer/inner loop break scope explicit test

`src/hooks-post-tool-linter/src/main.rs`:
- `run_custom_rules_outer_break_skips_subsequent_rules`: rule_a 単独で 21 件 →
  cap で 20 件、rule_b は呼ばれない (全 violation が "RULE_A") を assert
- `run_custom_rules_inner_cap_after_partial_first_rule`: rule_a 19 件 + rule_b 1 件 =
  20 件 (rule_b の inner break が mid-rule で発火) を type 分布で検証
- PR #148 で発見した `run_custom_rules` refactor の outer/inner loop break scope を
  test net で固定化

## test 結果

- hooks-post-tool-comment-lint-rust: 85 passed (前 84 + 新 1 direct unit + 11 integration)
- hooks-post-tool-linter: 111 passed (前 109 + 新 2)
- 合計 196 tests pass

## docs 整理

- docs/todo7.md: 順位 56 entry 削除
- docs/todo8.md: 順位 119 entry 削除
- docs/todo-summary.md: 順位 56 / 119 行削除
- docs/local-llm-offload-analysis.md: D-5 row を ✅ 着手済 に更新、bug fix を副産物として明記

## 並行: PR #150 post-merge-feedback 登録 (本セッション前から @ に含まれていた変更)

- docs/todo8.md: 順位 120 (rule comment + ADR-007 case study) / 順位 121 (4 fields
  個別 fixture test) / 順位 122 (development-workflow.md Step 0 stale entry 確認 step) 登録
- docs/todo-summary.md: 3 行追加

## Phase D 累積状況

D-3 (PR #148) + D-4 (PR #150) + D-5 (本 PR) = 3 PR 完了、Phase E 着手要件 (5 PR 累積)
まであと 2 PR (D-6 + D-7)。本 PR の dogfood は push 時に `LINT_SCREEN_ENABLED=true`
で opt-in 観測予定。
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 13, 2026

📝 Walkthrough

Walkthrough

PR #151 は Phase D Round 2 の lint_screen 実測結果をドキュメントに記録し、D-5 で発見された UTF-8/byte_offset のバグを Comment Lint Rust hook で修正・テスト拡張、Linter hook で MAX_CUSTOM_VIOLATIONS キャップのテストカバレッジを強化し、no-ephemeral-todo-reference rule を toml ファイルへ拡張する変更をまとめたもの。

Changes

Phase D Round 2 進捗とUTF-8バグ修正

Layer / File(s) Summary
Phase D Round 2 進捗ドキュメント更新
docs/local-llm-offload-analysis.md, docs/todo-summary.md, docs/todo7.md, docs/todo8.md
local-llm-offload-analysis.md に Phase D Round 2 の state セクション、D-4(PR #150 merged)の dogfood outcome(2 回の push による informational/auto_fix のスクリーンショット結果)、D-5 の dogfood outcome(両方 auto_fix、false positive 再現、production bug fix 副産物)を追記。todo-summary.md・todo7.md から comment-lint hook テスト拡充タスク削除、todo8.md に PR #150 関連の 3 つの新規タスク(takt-workflow-persona コメント拡張+ADR-007 case study、permission_mode doc 修正+fixture テスト、development-workflow Step 0 チェック)を追加。
Comment Lint Rust の UTF-8/Multibyte バグ修正とテスト拡張
src/hooks-post-tool-comment-lint-rust/src/main.rs
D-5 で観測された byte_offset/UTF-8 境界バグを修正。byte_offset_to_lineas_bytes() スライスベースの実装に再構築し multibyte 文字の正確な行計算を実現。function_metriccollect_all_violations をリフォーマット。新たに 4 つのテストグループを追加:mixed ASCII+Kanji・emoji・combining characters での locate_string_line_ranges 検証、mid-multibyte offset での byte_offset_to_line 検証、multiline/inline block comment の range overlap(start/middle/end only 等)での find_violations 検証。

Linter ルール拡張とテストカバレッジ

Layer / File(s) Summary
MAX_CUSTOM_VIOLATIONS 上限キャップのテスト
src/hooks-post-tool-linter/src/main.rs
複数ルール間での MAX_CUSTOM_VIOLATIONS キャップ動作の 2 つの新規テストを追加。Outer break テストで最初のルール実行後のキャップ使い尽くしと後続ルール実行ブロック、inner cap テストで最初のルール部分消費後の次ルール実行を検証。
Linter ルール拡張とコード整形
src/hooks-post-tool-linter/src/main.rs
compile_paths_glob エラーマッピングをシングルライン化、build_violation_json の関数シグネチャと JSON 構築をマルチラインチェーン形式に再整形。複数の test helper 呼び出し(make_test_rulewrite_file)を整形。no-ephemeral-todo-reference rule の extensions"toml" を追加して toml ファイルへのマッチング対象を拡張。deployed custom rules テストを可読性向上のため再整形。

推奨される関連PR

  • aloekun/claude-code-hook-test#104: comment-lint-rust の byte_offset_to_line/find_violations range-filter リファクタリング・UTF-8/offset テスト拡張が PR #104 で導入された line_filter 仕組みの上に直接構築。
  • aloekun/claude-code-hook-test#148: Linter hook の compile_paths_glob/build_violation_json 変更が PR #148 の paths-filter 整備の直後に追加実装。
  • aloekun/claude-code-hook-test#141: no-ephemeral-todo-reference rule の extensions"toml" 追加と PR #141 の同ルール self-exclusion 回帰テスト(deployed TOML が自分自身で発火しない)が相互補完。

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 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 PRタイトルは「feat(hooks): Phase D D-5 — comment-lint test 拡充 + MAX cap break scope test」で、PR目標に完全に一致し、変更内容の主要部分(comment-lint テスト拡充と MAX_CUSTOM_VIOLATIONS の break scope テスト追加)を正確に反映している。
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.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/hooks-post-tool-linter/src/main.rs (1)

1917-1918: ⚡ Quick win

toml 追加に対する正方向の検出テストを1本追加しておくと堅いです。

extensions"toml" を追加したので、config.toml で実際に違反が検出されるケースも明示しておくと、この拡張の回帰検知がより確実になります。

📌 追加例(テスト)
+    #[test]
+    fn no_ephemeral_todo_detects_concrete_digit_reference_in_toml() {
+        let dir = tempfile::tempdir().unwrap();
+        let file = write_file(
+            dir.path(),
+            "config.toml",
+            "note = \"see docs/todo3.md\"\n",
+        );
+        let rules = compile_test_rules(vec![no_ephemeral_todo_reference_rule()]);
+        let violations = run_custom_rules(file.to_str().unwrap(), &rules);
+        assert_eq!(violations.len(), 1);
+    }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks-post-tool-linter/src/main.rs` around lines 1917 - 1918, extensions
配列に "toml" を追加したので、対応する正方向の検出テストを追加してください: 新しいユニット/統合テストを作り、config.toml を入力として
linter 実行(関数/バイナリ呼び出しを担当するテストヘルパー)し、期待通り違反が検出されることをアサートします。該当コード箇所は extensions
配列("rs","toml",...)と linter 実行を行うテストヘルパー(既存のテストで使っている run_lint/execute_tool
相当の関数名)を使って、config.toml に違反となるサンプルを書き込み、違反メッセージが返ることを検証するように実装してください。
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/hooks-post-tool-linter/src/main.rs`:
- Around line 1917-1918: extensions 配列に "toml" を追加したので、対応する正方向の検出テストを追加してください:
新しいユニット/統合テストを作り、config.toml を入力として linter
実行(関数/バイナリ呼び出しを担当するテストヘルパー)し、期待通り違反が検出されることをアサートします。該当コード箇所は extensions
配列("rs","toml",...)と linter 実行を行うテストヘルパー(既存のテストで使っている run_lint/execute_tool
相当の関数名)を使って、config.toml に違反となるサンプルを書き込み、違反メッセージが返ることを検証するように実装してください。

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7413deb6-f185-4dbc-b287-34a6902d592b

📥 Commits

Reviewing files that changed from the base of the PR and between 39ae2cd and 1a69cc6.

📒 Files selected for processing (6)
  • docs/local-llm-offload-analysis.md
  • docs/todo-summary.md
  • docs/todo7.md
  • docs/todo8.md
  • src/hooks-post-tool-comment-lint-rust/src/main.rs
  • src/hooks-post-tool-linter/src/main.rs
💤 Files with no reviewable changes (1)
  • docs/todo7.md

@aloekun aloekun merged commit 6cfa8b2 into master May 13, 2026
1 check passed
@aloekun aloekun deleted the d5-comment-lint-test-expansion branch May 13, 2026 08:50
aloekun added a commit that referenced this pull request May 13, 2026
…ions + Bundle k post-merge-feedback (#152)

* docs(todo): PR #151 post-merge-feedback ★ Bundle k — 5 件採用 (順位 123-127)

## 採用 5 件 (Tier 1 #1+#2 / Tier 2 #1 / Tier 3 #1+#2)

### Tier 1 (決定論的防止層)
- 順位 123 (Bundle k コア): lint-screen の Markdown ファイル除外フィルター追加 (M, Frequency High)
  - D-3/D-4/D-5 で 3 PR・4 push 一貫観測の mistral:7b による .md → Rust hallucinate FP を構造的に解消
- 順位 124: no-ephemeral-todo-reference rule の TOML positive test 追加 (S, Frequency Medium)

### Tier 2 (横展開)
- 順位 125: UTF-8 マルチバイト boundary test を他の string-processing hooks に横展開 (M, Frequency Medium)
  - PR #151 で発見した byte_offset_to_line char-boundary panic bug の systemic 防御

### Tier 3 (docs/comment 明文化)
- 順位 126 (順位 123 と同 PR 推奨): ADR-038 に mistral:7b 「diff 外 context hallucinate」failure mode を追記 (XS, Frequency High)
- 順位 127 (順位 124 と同 PR 推奨): extensions 拡張時の test 追加 pattern をコード comment で明文化 (XS, Frequency Medium)

## Sub-PR 構成推奨

- k-1: 順位 123 + 126 (実装 + ADR codify、コア層)
- k-2: 順位 124 + 127 (TOML test + extensions code comment、test gap 補強層)
- k-3: 順位 125 (UTF-8 boundary 横展開、独立)

## 却下 (4 件) / 様子見 (3 件)

却下: UTF-8 lint rule (FP リスク + AST 必須) / byte_offset_to_line 強化 (既対応) /
UTF-8 guideline + extensions checklist (feedback_no_unenforced_rules.md 適用)
様子見: lint-screen dogfood CI step (L + takt infra 依存) / test→bug pattern を ADR-007 (1 PR 観測) /
multi-rule fixture pattern を test comment (Low × Low)

## 含意

Phase D dogfood 観測 (docs/local-llm-offload-analysis.md L334-340 の docs-only FP failure mode 記述) が
直接 actionable な決定論的防止層 (順位 123) に結実。Phase E 採否判定前に systemic FP root cause が
解消される構造的進展。

* feat(takt-facet): D-6 — refresh .takt/review-diff.txt between fix and review iterations (順位 51)
aloekun added a commit that referenced this pull request May 18, 2026
…時 test 追加 reminder comment (順位 124 + 127) (#163)

## 順位 124 (Tier 1): TOML positive + negative test 追加

PR #151 T1-#1 採用、PR #152 で再観測 (Frequency Medium)。
既存 `no_ephemeral_todo_self_exclusion_invariant_holds_on_deployed_toml` は
self-exclusion 不変条件のみ確認、TOML での検出力 test が不在だった gap を
構造的に塞ぐ:

- `no_ephemeral_todo_detects_toml_ephemeral_reference`: TOML + ephemeral 参照
  → 1 violation 検出 (positive)
- `no_ephemeral_todo_toml_skips_permanent_adr_reference`: TOML + ADR 参照
  → 0 violation (negative、pattern 正確性も seal)

self-trigger 回避: fixture content は既存 `build_concrete_digit_fixture(3)`
(format! interpolation) を再利用。

## 順位 127 (Tier 3): extensions 拡張時 test 追加義務の comment 明文化

PR #151 T3-#2 採用、PR #152 で再観測。
`.claude/custom-lint-rules.toml` の `no-ephemeral-todo-reference` rule 上に
9 行のコメントブロックを追加: extensions 変更時は同 PR で positive/negative
test を追加することを次回 rule 編集者の目に入る位置に置く。

`feedback_no_unenforced_rules.md` 例外 = 既存実践の明文化 + guide 効果
(機械強制ではなく point-of-edit reminder)。

## 検証

- cargo test -p hooks-post-tool-linter: 121 passed / 0 failed
- 新規 2 test (positive / negative) を含む 8 tests (no_ephemeral_todo 系列) 全通過

## Net 差分

- `.claude/custom-lint-rules.toml`: +9 lines (reminder comment)
- `docs/todo-summary.md`: -2 lines (順位 124 + 127 削除)
- `docs/todo8.md`: -44 lines (詳細 entries 削除)
- `src/hooks-post-tool-linter/src/main.rs`: +41 lines (2 test + doc comment)

production code path 変更なし。exe rebuild 不要。
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