refactor(cli-push-runner): config.rs + stages/lint_screen.rs を 800 行以下に module 分割 (PR-W4) - #231
Conversation
…下に module 分割 (PR-W4)
📝 WalkthroughWalkthroughcli-push-runner の設定読み込み(config.rs)とlint-screenステージ(stages/lint_screen.rs)がそれぞれ複数のサブモジュール(config/mod.rs, config/lint_screen.rs, config/pr_size_check.rs, config/scratch_file_warning.rs / stages/lint_screen/mod.rs, classifier.rs, diff_filter.rs, report.rs)へ分割された。合わせて計画ドキュメントとTODOドキュメントが更新された。 Changescli-push-runner モジュール分割とドキュメント更新
Estimated code review effort: 4 (Complex) | ~60 minutes Possibly related PRs
Poem
🚥 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/cli-push-runner/src/stages/lint_screen/classifier.rs`:
- Around line 46-67: In classifier.rs, the current spawn/order in the stage
logic can deadlock because stdin.write_all() runs before stdout/stderr draining
starts. Reorder the flow around spawn_classifier, drain_pipe_capped, and
wait_with_timeout_basic so the stdout/stderr drain threads are started before
writing diff to child.stdin, or move the stdin write onto a separate thread with
timeout protection. Keep the existing exit handling and error mapping intact
while ensuring large diffs cannot block the push pipeline.
🪄 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: d04afcde-094a-4042-ba0b-17807496412a
📒 Files selected for processing (13)
docs/file-length-enforcement-plan.mddocs/todo-summary.mddocs/todo13.mdsrc/cli-push-runner/src/config.rssrc/cli-push-runner/src/config/lint_screen.rssrc/cli-push-runner/src/config/mod.rssrc/cli-push-runner/src/config/pr_size_check.rssrc/cli-push-runner/src/config/scratch_file_warning.rssrc/cli-push-runner/src/stages/lint_screen.rssrc/cli-push-runner/src/stages/lint_screen/classifier.rssrc/cli-push-runner/src/stages/lint_screen/diff_filter.rssrc/cli-push-runner/src/stages/lint_screen/mod.rssrc/cli-push-runner/src/stages/lint_screen/report.rs
💤 Files with no reviewable changes (2)
- src/cli-push-runner/src/stages/lint_screen.rs
- src/cli-push-runner/src/config.rs
…ied-files batch mode + [file_length_gate] opt-in (#234) * docs(todo): PR #232 post-merge-feedback 採用 1 件を登録 (順位 246) * feat(hooks): PR-W5 file-length Stop gate — comment-lint --check-modified-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> * fix(review): CodeRabbit #234-1 fail-closed 対応 + 削除 file skip 補正 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> --------- Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…k を解消 (順位242) (#241) * fix(cli-push-runner): invoke_classifier を drain-first 化し pipe deadlock を解消 (順位242) PR #231 で CodeRabbit が Major 指摘した pre-existing 欠陥の修正。 stdin.write_all(diff) を完了してから stdout/stderr の drain thread を spawn していたため、大きな diff で子プロセス (cli-finding-classifier) が stdin 読込前に大量出力するとパイプバッファ (~64KB) 満杯で親子相互 ブロックの deadlock になり push pipeline がハングした。 - pipe orchestration を pump_child_io として抽出し、drain thread を stdin write より前に spawn する drain-first に修正 (run_cmd_capture / Safe Subprocess Stdout Pattern と同型) - エラー経路 (stdin 書込失敗 / wait 失敗) で子プロセス kill + wait + drain join を行う abort_child を追加 (孤児プロセス残留防止) - regression test: stdin 読込前に ~256KB の stdout を吐く子プロセスに ~1MB の stdin を流して完走を検証 (#[ignore]、push gate の --ignored step で毎 push 実行)。修正前の順序では本テストが write_all でハング することを実測確認済み (78 分継続、自然回復なし) - 正常系 / 非 0 終了 / stdout 空の pump_child_io 単体テスト 3 件追加 - todo13.md 順位242 エントリ削除 + todo-summary.md 行削除 - 順位254 登録: pr_size_check がローカル master 遅延で誤計測する問題 (本 push で 1604 行と誤 block された実観測、base を remote tracking ref にする改修 task) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * WIP: PR #241 レビュー待ち * fix(review): apply CodeRabbit fixes for #241 Resolved findings: - [Major] src/cli-push-runner/src/stages/lint_screen/classifier.rs:186 タイムアウト分岐のテストが存在しない --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
概要
file-length-enforcement-plan の PR-W4:
cli-push-runnerの 800 行超 2 ファイルを module 分割。mechanical refactor / behavior 不変 / test count 不変 (168 tests、baseline から変化なし)。
分割内容
config.rs(946 行)config/{mod,lint_screen,pr_size_check,scratch_file_warning}.rsstages/lint_screen.rs(982 行)stages/lint_screen/{mod,classifier,diff_filter,report}.rs全ファイル ≤ 800 行を達成。
config/の分割方針mod.rs:Config集約構造体 +config_path/load_config/validate_config+ 共通定数 + 再エクスポートlint_screen.rs:LintScreenConfig+LINT_SCREEN_ENABLEDenv override 解釈pr_size_check.rs:PrSizeCheckConfig+ 順位 151 定数scratch_file_warning.rs:ScratchFileWarningConfigstages/lint_screen/の分割方針mod.rs: orchestration (run_lint_screen+ params 解決 + diff 読み込み)classifier.rs: cli-finding-classifier.exe の subprocess 起動report.rs: classifier 出力 (JSON) の markdown 整形 + 書き出しdiff_filter.rs: LLM 入力前の diff 前処理 (対象外拡張子除外 + metadata strip)制約遵守 (Phase 1 共通)
config_path→exe_adjacent_config_path分割で意図を表現)invoke_classifierからspawn_classifierを抽出pub(crate)/pub(super)検証
cargo test -p cli-push-runner: 168 passed (baseline 不変)cargo clippy --workspace -- -D warnings: cleancargo fmt: cleancargo test --workspace: regression なし同梱の docs コミット (mechanical refactor とは別コミット)
イテレーションコスト低減のため、前セッションのフィードバック由来 docs 変更を本 PR に同梱 (コミットは分離):
docs(plan): PR-W3 land 済 (refactor(cli-merge-pipeline): feedback.rs + main.rs を 800 行以下に module 分割 (PR-W3) #230) 更新docs(todo): PR refactor(cli-merge-pipeline): feedback.rs + main.rs を 800 行以下に module 分割 (PR-W3) #230 post-merge-feedback 採用 4 件登録 (順位 238-241)docs(plan): PR-W4 分割に伴う lint_screen.rs / config.rs のリンクを module ディレクトリに更新PR size
~8900 行の diff (削除 + 追加) だが mechanical な file 移動が主体。
PR_SIZE_CHECK_OVERRIDE=1で pre-push の pr_size_check を意図的バイパス (順位 151 の override 想定 use case)。Summary by CodeRabbit
New Features
Bug Fixes
Documentation