Skip to content

refactor(lib): drain_pipe を 3 variant で lib-subprocess に extract (順位 173c) - #207

Merged
aloekun merged 3 commits into
masterfrom
173c-drain-pipe-extract
Jun 14, 2026
Merged

refactor(lib): drain_pipe を 3 variant で lib-subprocess に extract (順位 173c)#207
aloekun merged 3 commits into
masterfrom
173c-drain-pipe-extract

Conversation

@aloekun

@aloekun aloekun commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Summary

3 variant の意味

variant semantics callsite
drain_pipe_unlimited read_to_string 全読み cli-pr-monitor (runner.rs 内部 2 + stages/push_jj_bookmark.rs 2 = 計 4 callsites) — check-ci-coderabbit の JSON 全量パース用
drain_pipe_capped(pipe, max_lines) read_until 行毎読込、max_lines 超過は silent truncate (パイプは継続排出) cli-push-runner (runner.rs 2 + stages/{scratch_file_warning, push_jj_bookmark, pr_size_check, lint_screen, bookmark_check}.rs 10 = 計 12) + cli-push-pipeline 2 + hooks-stop-quality 2 = 計 16 callsites
drain_pipe_capped_reporting(pipe, max_lines) 上記 + 末尾に "... (N lines truncated)" 付与 cli-merge-pipeline 2 = 計 2 callsites (MAX_LINES=200、merge log は truncate されたか reviewer に明示する設計)

MAX_LINES 定数の扱い

各 crate に const MAX_LINES: usize = N; を保持し、callsite で parameter として渡す形に変更:

crate MAX_LINES 意図
cli-pr-monitor (なし、unlimited variant) JSON 全量パース
cli-push-runner 40 ログ表示用
cli-push-pipeline 40 ログ表示用
hooks-stop-quality 20 Stop hook 出力の短さ
cli-merge-pipeline 200 メモリ保護しつつログは多めに残す

cli-push-runner の MAX_LINESpub(crate) const 化して 5 stage file から crate::runner::MAX_LINES 参照可能にした (runner-internal const がワークスペース内 stage から参照される非標準的な visibility shape だが、定数の意味は「cli-push-runner の出力 truncate ポリシー」で 1 箇所維持が適切。将来 config.rs 等への移動余地あり)。

内訳 (15 files changed, +219 / -179)

区分 内容
lib-subprocess/src/lib.rs 3 variant + 6 test 追加 (各 variant の代表 case: short / long / over-cap / under-cap / reporting on / reporting off)
cli-pr-monitor/src/runner.rs drain_pipe impl + NOTE コメント削除、内部 2 callsite を drain_pipe_unlimited に置換
cli-pr-monitor/src/stages/push_jj_bookmark.rs 2 callsite を lib_subprocess::drain_pipe_unlimited
cli-push-runner/src/runner.rs drain_pipe impl 削除、MAX_LINESpub(crate) const 化、内部 2 callsite を drain_pipe_capped(pipe, MAX_LINES)
cli-push-runner/src/stages/*.rs 5 ファイル 10 callsite を lib_subprocess::drain_pipe_capped(..., crate::runner::MAX_LINES)
cli-push-pipeline/src/main.rs drain_pipe impl 削除、2 callsite を drain_pipe_capped(pipe, MAX_LINES) に (lib-subprocess は 173a で dep 追加済)
hooks-stop-quality/Cargo.toml lib-subprocess dep 追加 (本 PR で初追加)
hooks-stop-quality/src/main.rs drain_pipe impl 削除、2 callsite を drain_pipe_capped(pipe, MAX_LINES)
cli-merge-pipeline/src/main.rs drain_pipe impl 削除、2 callsite を drain_pipe_capped_reporting(pipe, MAX_LINES)
docs/todo11.md 173c の work plan 完了マーク + 22 callsites 移行詳細を inline 記述

Test plan

  • cargo build --workspace pass
  • cargo test --workspace pass (lib-subprocess 15 test + 6 影響 crate を含む workspace 全体 pass)
  • cargo clippy --workspace -- -D warnings clean (push-runner-config.toml の gate と同等)
  • pre-push review APPROVED (0 findings) (1 iteration, 4m 34s)

173a/b と異なり挙動差が test 観測可能

173b の _safe vs _basic は Err 経路の差で「unreachable」だったため test で variant 分岐を pin できなかったが、173c の 3 variant は inputs で直接観測可能な挙動差 (drain_pipe_unlimited は 500 行返却 / drain_pipe_capped は 3 行切り捨て / _reporting"... (2 lines truncated)" 付与) を持つため、test が variant 分岐を mechanically pin する。誤って variant を merge した場合 test が失敗する。

関連

Summary by CodeRabbit

Refactor

  • サブプロセス出力処理の標準化:各モジュールで個別だった出力回収を共通ライブラリに統合しました。最大行数での切り捨て(必要に応じて末尾に「切り捨て」情報を付与)を各所で一貫させ、タイムアウト/終了後の取り込みを安定させつつ、出力の肥大化を抑制します。

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

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: 31654322-11d6-4b79-8875-a7c0de84910b

📥 Commits

Reviewing files that changed from the base of the PR and between b2341e8 and 726074e.

📒 Files selected for processing (4)
  • docs/todo11.md
  • src/cli-push-runner/src/stages/bookmark_check.rs
  • src/cli-push-runner/src/stages/pr_size_check.rs
  • src/cli-push-runner/src/stages/push_jj_bookmark.rs
✅ Files skipped from review due to trivial changes (1)
  • docs/todo11.md

📝 Walkthrough

Walkthrough

lib-subprocessdrain_pipe_unlimiteddrain_pipe_cappeddrain_pipe_capped_reportingの3バリアント関数とそのユニットテストを追加した。各クレート(cli-merge-pipelinecli-pr-monitorcli-push-pipelinecli-push-runnerhooks-stop-quality)のローカルdrain_pipe実装を削除し、対応するライブラリ関数に置き換えた。docs/todo11.mdを完了状態に更新。

Changes

drain_pipe 3バリアント抽出とcallsite移行

Layer / File(s) Summary
lib-subprocessへのdrain_pipe 3バリアント追加とテスト
src/lib-subprocess/src/lib.rs
drain_pipe_unlimited(全量読み取り・末尾trim)、drain_pipe_capped(max_lines上限でサイレント切り捨て)、drain_pipe_capped_reporting(超過行数をサマリ付与)の3関数を追加し、Cursorを用いたユニットテストで各挙動を検証する。
cli-pr-monitorでのdrain_pipe_unlimited置換
src/cli-pr-monitor/src/runner.rs, src/cli-pr-monitor/src/stages/push_jj_bookmark.rs
ローカルdrain_pipeを削除しlib_subprocess::drain_pipe_unlimitedをimport。run_cmd_directrun_jjのドレイン呼び出しを置き換える。
cli-merge-pipelineでのdrain_pipe_capped_reporting置換
src/cli-merge-pipeline/src/main.rs
drain_pipe_capped_reportingをimportしてローカル実装を削除し、run_cmd内のstdout/stderr収集をdrain_pipe_capped_reporting(..., MAX_LINES)に切り替える。
cli-push-pipelineでのdrain_pipe_capped置換
src/cli-push-pipeline/src/main.rs
drain_pipe_cappedをimportしてローカル実装を削除し、run_cmdのstdout/stderr収集をdrain_pipe_capped(..., MAX_LINES)に置き換える。
cli-push-runner/src/runner.rsでのdrain_pipe_capped導入
src/cli-push-runner/src/runner.rs
MAX_LINESpub(crate)に変更しローカルdrain_pipeを削除。run_cmd内のstdout/stderr収集をdrain_pipe_capped(..., MAX_LINES)に置き換える。
*cli-push-runner/src/stages/でのdrain_pipe置換
src/cli-push-runner/src/stages/bookmark_check.rs, src/cli-push-runner/src/stages/lint_screen.rs, src/cli-push-runner/src/stages/pr_size_check.rs, src/cli-push-runner/src/stages/push_jj_bookmark.rs, src/cli-push-runner/src/stages/scratch_file_warning.rs
5つのstages(bookmark_check、lint_screen、pr_size_check、push_jj_bookmark、scratch_file_warning)で、ローカルdrain_pipeからlib_subprocessの対応バリアントに置き換え。lint_screenとscratch_file_warningはdrain_pipe_capped、その他3つはdrain_pipe_unlimitedを採用。
hooks-stop-qualityへのlib-subprocess依存追加とdrain_pipe_capped置換
src/hooks-stop-quality/Cargo.toml, src/hooks-stop-quality/src/main.rs
Cargo.tomlにlib-subprocess依存を追加し、main.rsでローカルdrain_pipedrain_pipe_capped(..., MAX_LINES)に置き換える。
todo11.md完了状態の更新
docs/todo11.md
173c「drain_pipe 3バリアント抽出」セクションを実装完了(2026-06-14)の記録に更新し、採用バリアント・callsite数・完了作業を反映する。

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • aloekun/claude-code-hook-test#2: hooks-stop-qualityrun_stepでdeadlock回避のためにローカルdrain_pipeを実装した元のコードが、本PRでlib_subprocess::drain_pipe_cappedへの置換対象となっている。
  • aloekun/claude-code-hook-test#206: cli-push-runnerのサブプロセス処理でwait_with_timeout_*をlib-subprocessに抽出した変更と対を成しており、本PRはdrain_pipe_*側の同様の抽出を行っている。
  • aloekun/claude-code-hook-test#144: src/cli-push-runner/src/stages/lint_screen.rsでclassifier stdout/stderr処理経路を扱っており、本PRのdrain_pipe_capped置換対象となったコードパスと重なっている。
🚥 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 タイトルは drain_pipe を 3 variant で lib-subprocess に extract したこと(173c)を正確に説明しており、PR の主要な変更内容と合致している。
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/pr_size_check.rs`:
- Around line 157-164: The problem is that drain_pipe_capped silently truncates
output that is critical for control flow decisions, causing incorrect behavior
when important information (like the summary line of jj diff --stat or bookmark
counts) exceeds the cap. In src/cli-push-runner/src/stages/pr_size_check.rs at
lines 157-164, replace drain_pipe_capped for stdout with drain_pipe_unlimited
since the jj diff --stat summary appears at the end and must not be truncated
for accurate size determination. In
src/cli-push-runner/src/stages/bookmark_check.rs at lines 83-90, replace
drain_pipe_capped with drain_pipe_unlimited for the stdout used in bookmark
existence determination to ensure accurate detection. In
src/cli-push-runner/src/stages/push_jj_bookmark.rs at lines 142-149, replace
drain_pipe_capped with drain_pipe_unlimited for stdout in the fallback bookmark
count judgment logic to prevent data loss that could cause incorrect moves or
skips. All three locations must switch from capped to unlimited draining since
they depend on complete, untruncated output for correctness.
🪄 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: fc73f969-8982-4148-85d7-b9b67e41bdff

📥 Commits

Reviewing files that changed from the base of the PR and between 4833a5a and b2341e8.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (14)
  • docs/todo11.md
  • src/cli-merge-pipeline/src/main.rs
  • src/cli-pr-monitor/src/runner.rs
  • src/cli-pr-monitor/src/stages/push_jj_bookmark.rs
  • src/cli-push-pipeline/src/main.rs
  • src/cli-push-runner/src/runner.rs
  • src/cli-push-runner/src/stages/bookmark_check.rs
  • src/cli-push-runner/src/stages/lint_screen.rs
  • src/cli-push-runner/src/stages/pr_size_check.rs
  • src/cli-push-runner/src/stages/push_jj_bookmark.rs
  • src/cli-push-runner/src/stages/scratch_file_warning.rs
  • src/hooks-stop-quality/Cargo.toml
  • src/hooks-stop-quality/src/main.rs
  • src/lib-subprocess/src/lib.rs

Comment thread src/cli-push-runner/src/stages/pr_size_check.rs Outdated
aloekun added 2 commits June 14, 2026 13:51
Resolved findings:
- [Major] src/cli-push-runner/src/stages/pr_size_check.rs:164 制御判定に使う stdout を silent truncate しており、分岐が誤判定されます。
@aloekun

aloekun commented Jun 14, 2026

Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 14, 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.

@aloekun
aloekun merged commit 46d2077 into master Jun 14, 2026
1 check passed
@aloekun
aloekun deleted the 173c-drain-pipe-extract branch June 14, 2026 07:24
aloekun added a commit that referenced this pull request Jun 14, 2026
…d) (#208)

* docs(todo): 順位 208 (drain_pipe_capped 境界値テスト) を追加 (PR #207 post-merge-feedback T2-1 採用)

* refactor(lib): run_cmd を lib-subprocess に extract (順位 173d)

* fix(review): apply CodeRabbit fixes for #208

Resolved findings:
- [Major] src/lib-subprocess/src/lib.rs:247 `try_wait` エラー時に子プロセスと reader スレッドを未回収のまま返却しています
aloekun added a commit that referenced this pull request Jun 16, 2026
PR #207 (順位 173c) で CR が 🟠 Major として発見した silent truncate 由来 silent
disable (fail-open、ADR-043 violation) の root cause = drain_pipe_capped が
MAX_LINES boundary で off-by-one regression を起こしうる構造を test レベルで pin する。

追加内容 (lib-subprocess/src/lib.rs):
- drain_pipe_capped: N-1 / N / N+1 行の 3 boundary test
- drain_pipe_capped_reporting: 同 3 boundary test (truncated 報告 on/off 含む)
- max_lines=5 で固定、各 case は独立 setup (feedback_test_dry_antipattern 準拠)

検証:
- cargo test -p lib-subprocess 全 27 test pass (既存 21 + 新規 6)
- cargo clippy -p lib-subprocess --tests -- -D warnings clean
- 手動 mutation check: `< max_lines` → `<= max_lines` で両 variant の
  n_plus_1 test が落ちることを確認 (off-by-one regression 検出構造)
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