feat(hooks): PR-W5 file-length Stop gate — comment-lint --check-modified-files batch mode + [file_length_gate] opt-in - #234
Conversation
…ied-files batch mode + [file_length_gate] opt-in Phase 1 (PR-W1〜W4、#220/#224/#230/#231) で 800 行以下に整えた clean state を恒久維持する 強制層。hooks-post-tool-comment-lint-rust に --check-modified-files batch mode を追加し、 Stop hook quality_gate の 1 step として PR 範囲 (base..@) の .rs file 行数を検査。 800 行超が 1 件でもあれば exit 1 で Stop を block する (Option C-2)。 実装: - src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs (新規、17 tests) - main.rs に --check-modified-files dispatch 追加、Cargo.toml に toml 依存追加 - .claude/hooks-config.toml に file-length step + [file_length_gate] section mechanical refactor、behavior 不変。既存 lint (comment/function/file_length/metrics) は不変。 ## ADR-039 3 点セット (experimental feature 標準パターン) - Config opt-in (default OFF): gate_enabled() が unwrap_or(false)。本 repo のみ dogfood で enabled=true - Kill-switch: 下表 - Bounded lifetime: file-length-enforcement-plan.md 削除条件 3 (override 未使用で 1-2 セッション通過) ## Kill-switch table | 起動経路 | 停止コマンド | 影響範囲 | |---|---|---| | .claude/hooks-config.toml の [file_length_gate] enabled=true + file-length step | enabled=false (恒久) | Stop hook の file-length 判定のみ (他 step 不変) | | Stop hook 発火時に file-length step 実行 | env FILE_LENGTH_CHECK_OVERRIDE=1 (緊急、truthy 値) | 当該 Stop の判定を skip | ## 設計判断 - jj 変更検出は base branch を config 引数化 (default master、ADR-021 § Revset Composability) - cmd path は cmd.exe の forward-slash 非対応のため backslash TOML literal string - jj 失敗時は fail-closed で block (ADR-043、stop_hook_active retry-skip が永続 lock を防止) - templates (TS/Python) は Rust 非対象のため未追加 ## 検証 - cargo test -p hooks-post-tool-comment-lint-rust: 116 pass / clippy clean / fmt clean - cargo test --workspace: regression なし / cargo clippy --workspace clean - dogfood (deploy 済 exe): clean=exit0 / 850行file=block / OVERRIDE(=1,=true)=bypass / enabled=false=no-op / self-host=exit0 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
👮 Files not reviewed due to content moderation or server errors (1)
📝 Walkthrough🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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.
Inline comments:
In `@src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs`:
- Around line 176-185: collect_oversize_files currently treats every
read_to_string failure as a skipped file via .ok()?; update it to fail-closed
for existing .rs files by distinguishing missing-file cases from other read
errors. Keep skipping only genuinely deleted/missing paths, and propagate
permission/encoding/race read failures as Err so run_check_modified_files() can
exit 1; use collect_oversize_files and its caller in run_check_modified_files()
to locate the change.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 211e17d5-9c8b-44b6-9ac3-bb3b92cac857
⛔ Files ignored due to path filters (1)
Cargo.lockis excluded by!**/*.lock
📒 Files selected for processing (7)
.claude/hooks-config.tomldocs/file-length-enforcement-plan.mddocs/todo-summary.mddocs/todo13.mdsrc/hooks-post-tool-comment-lint-rust/Cargo.tomlsrc/hooks-post-tool-comment-lint-rust/src/main.rssrc/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs
Resolved findings: - [Major] src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs:185 読み取り不能な既存 `.rs` は fail-closed にしてください。
CodeRabbit Major #234-1 (読み取り不能な既存 .rs は fail-closed に) を適用: collect_oversize_files を Result 化し、存在するのに読めない .rs は Err → exit 1 (block)。 さらに削除 file 誤検知を補正: jj diff --name-only は削除 file も列挙する (実測確認) ため、 Path::exists() で存在確認し削除 file (非存在) は skip する。これがないと file split refactor (元 file 削除を伴う、本 plan が促進する作業そのもの) を gate が誤 block する。 CodeRabbit の指摘文言も「*既存* .rs」であり削除 file は対象外。 - collect_oversize_files: filter(Path::exists) + Result<Vec, String> - fail-closed 診断を run_check_modified_files で block 表示 (ADR-043 § 原則1) - tests: skips_deleted_file (skip) + errors_on_present_but_unreadable (Err) で両分岐を assert Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
275591c to
5cc827d
Compare
|
@coderabbitai review |
✅ Action performedReview finished.
|
概要
file-length-enforcement-plan.md の PR-W5 (Phase 2 / Stop hook gate C)。Phase 1 (PR-W1〜W4、#220/#224/#230/#231) で 800 行以下に整えた clean state を恒久維持する強制層を追加する。
hooks-post-tool-comment-lint-rustに--check-modified-filesbatch mode を追加し、Stop hook quality_gate の 1 step として PR 範囲 (base..@) の.rsfile 行数を検査。800 行超が 1 件でもあれば exit 1 で Stop を block する (Option C-2)。mechanical な feature 追加、behavior 不変。既存 lint (comment/function/file_length/metrics) は不変。
実装
src/hooks-post-tool-comment-lint-rust/src/modified_files_check.rs(新規、17 tests)main.rsに--check-modified-filesdispatch 追加、Cargo.tomlにtoml依存追加.claude/hooks-config.tomlに file-length step +[file_length_gate]section (dogfood のため enabled=true)docs/file-length-enforcement-plan.mdPR-W5 実績反映なお本 PR には前セッションの feedback docs コミット (順位 246、todo-summary/todo13) を 別コミットとして bundle している。
ADR-039 3 点セット
gate_enabled()がunwrap_or(false)。本 repo のみ dogfood で enabled=trueKill-switch table
[file_length_gate] enabled=true+ file-length stepenabled=false(恒久)FILE_LENGTH_CHECK_OVERRIDE=1(緊急、truthy)設計判断
検証
cargo test -p hooks-post-tool-comment-lint-rust: 116 pass / clippy clean / fmt cleancargo test --workspace: regression なし /cargo clippy --workspaceclean🤖 Generated with Claude Code
Summary by CodeRabbit
New Features
Documentation