fix(cli-pr-monitor): 並列テスト flaky を tempfile 一意化と state path DI で構造的に解消 - #227
Merged
Conversation
…pfile + dir injection 順位 230。convert_body_to_file は temp file 名を PID+ミリ秒で生成しており、並列 cargo test で body_with_literal_newline_converted 等が稀に衝突して fail していた。tempfile::Builder::tempfile_in による O_EXCL+乱数の一意名生成へ移行し、生成先 dir を注入可能化。テストは各自 tempfile::tempdir() を渡して本番 namespace から分離。tempfile を dev-dependency から通常依存へ昇格し、自前 TempFile struct を TempPath に置換。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…obal (fixes parallel-test flaky) 順位 229。PR_MONITOR_STATE_FILE_OVERRIDE (process-global env var) を複数 test module の独立 static LOCK が奪い合い、finalize_park_siblings_have_symmetric_write_state_handling が並列実行で約 50% fail してゲートを高確率で落としていた。env var seam と state_file_path の env 分岐、write_state/read_state ラッパ、4 つの env_override_lock を全廃。state path を PollContext + 関数引数で全面注入し、各テストは自前 path を渡す。共有グローバル可変状態を根絶し並列競合を構造的に解消。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
順位 229 (env_override_lock / state path DI) と順位 230 (create_pr tempfile) を解決済みのため、todo13.md の詳細エントリと todo-summary.md の該当行を削除。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthrough
Changes明示的な state_path 注入リファクタリング
推定コードレビュー工数🎯 3 (Moderate) | ⏱️ ~25 minutes 関連する可能性のある PR
🚥 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-pr-monitor/src/stages/create_pr.rs`:
- Around line 207-208: `write_early_reset_state()` is still resolving
`state_file_path()` internally, so it can’t be isolated from the other state
operations in `run_create_pr`. Update `run_create_pr` to accept and pass a
`state_path: &Path` into `write_early_reset_state()`, and change that helper to
use the provided path when calling `write_state_to()`. This will let tests
inject a tempdir-backed state file and avoid sharing state across parallel or
repeated runs.
🪄 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: 7e1a4830-62bf-4b65-a0b1-f1222f228f38
📒 Files selected for processing (11)
docs/todo-summary.mddocs/todo13.mdsrc/cli-pr-monitor/Cargo.tomlsrc/cli-pr-monitor/src/stages/create_pr.rssrc/cli-pr-monitor/src/stages/monitor.rssrc/cli-pr-monitor/src/stages/poll/iteration.rssrc/cli-pr-monitor/src/stages/poll/mod.rssrc/cli-pr-monitor/src/stages/poll/rate_limit.rssrc/cli-pr-monitor/src/stages/poll/review_recheck.rssrc/cli-pr-monitor/src/stages/poll/review_recheck_signal.rssrc/cli-pr-monitor/src/state.rs
💤 Files with no reviewable changes (2)
- docs/todo13.md
- docs/todo-summary.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
cli-pr-monitorの並列テストで断続的に発生していた flaky test を構造的に解消する。原因は独立した 2 系統あり、それぞれ別コミットで修正した。加えて完了済みの todo エントリを整理する。変更内容
1. create_pr temp-file flaky の解消 (tempfile crate + dir injection)
convert_body_to_fileが--body-file用一時ファイルをpid + ms命名で生成していたため、並列cargo test(同一プロセス・同一 ms)で名前が衝突し flaky 化していた。tempfilecrate を導入しO_EXCL+ ランダム名 + 衝突時リトライで一意名を生成std::env::temp_dir()、テストは専用tempdir()を注入して本番 namespace から分離)TempFilestruct からtempfile::TempPathに置換2. parallel-test flaky の解消 (state path DI + env-var global 除去)
state ファイルパスを env-var 経由の ambient global で解決していたため、並列テスト間で競合していた。共有グローバルやロックではなく依存注入で根本解決する方針に沿う。
3. docs(todo) の整理
完了済みエントリ(順位 229・230)を
todo-summary.md/todo13.mdから削除。テスト
push pipeline の品質ゲート(clippy / cargo test / cargo test --ignored)で検証済み。
Summary by CodeRabbit
Bug Fixes
Chores