fix: mutmut の clean test 失敗を修正(グローバル event loop 汚染の除去)#460
Merged
Conversation
mutmut 3.x は同一プロセスで pytest スイートを複数回実行する(stats 収集 → clean test 検証 → ミュータント実行)。tests/security/test_ssrf_github.py の _run() だけがグローバル asyncio event loop を set/get していたため、 test_llm_clients.py の asyncio.run() が残したグローバル loop の壊れ状態が 2 周目に持ち越され、get_event_loop() が "RuntimeError: There is no current event loop" を送出。これで `make mutation-backend` が clean test 失敗(Failed to run clean test)で exit(1) していた。 _run() を他 11 個の _run と同じ「ローカル loop を作って閉じるだけ」の分離 パターンに統一し、反復実行に対して冪等にする。再発防止として .claude/rules/backend/test.md のアンチパターンに追記。 - プロダクトコード(app/)は無変更。テストの意図(不正 username を HTTP 発行前に弾く)も不変。 - 検証: フルスイートを同一プロセスで 2 回実行し、修正前=2 回目 1 failed → 修正後=両方 667 passed を確認。ruff clean。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SsRavDhjAWMQby1g6gHVyR
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA test helper in test_ssrf_github.py was changed to create and close a local asyncio event loop instead of mutating the global event loop. The backend test guidelines document was updated to document this pattern as the recommended anti-pattern avoidance for mutmut-repeated test runs. ChangesEvent Loop Isolation Fix
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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 |
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.
変更概要
make mutation-backend(mutmut run)がミューテーション本体に入る前の clean test フェーズでRuntimeError: There is no current event loopにより落ち、Failed to run clean test→exit(1)していた問題を修正する。原因はtests/security/test_ssrf_github.pyの_run()だけがグローバル asyncio event loop を操作していたこと。他 11 個の_runと同じ「ローカル loop を作って閉じるだけ」の分離パターンに統一し、mutmut の同一プロセス反復実行に対して冪等にする。原因(詳細)
mutmut 3.x は 同一 Python プロセス内で pytest スイートを複数回実行する(stats 収集 → clean test 検証 → ミュータント実行)。
test_llm_clients.pyのasyncio.run()が終了時にグローバル loop をNoneへ戻す(_set_called=Trueのまま)ため、その壊れた状態が 2 周目のスイート実行に持ち越される。2 周目に SSRF テストの_run()がasyncio.get_event_loop()を呼ぶとRuntimeError: There is no current event loopを送出し、with pytest.raises(NonRetryableError)の外へ抜けてtest_fetch_repos_raw_rejects_bad_username_without_httpが失敗していた。_runヘルパのうち、グローバル loop を触るのは本ファイルの 1 つのみ(唯一の汚染源かつ被害者)。.claude/rules/backend/test.mdのアンチパターンに「テストでグローバル event loop を触らない」を追記。セルフレビューチェックリスト
必須確認
make ci相当を確認(※本セッション環境に nix が無いため公式makeは未実行。同等の venv で ruff clean / フルスイート 667 passed / 同一プロセス 2 回実行で修正前=2 回目 1 failed→修正後=両方 667 passed を確認。実環境ではmake ci/make mutation-backendでの最終確認を推奨)条件付き確認
app/schemas/またはapp/routers/の変更: N/A(テストとルール文書のみ、OpenAPI へ影響なし)web/src/の日本語メッセージ: N/A(web 変更なし)破壊的変更
app/無変更。テストの意図・API 契約・DB スキーマに変更なし)ADR
検証
🤖 Generated with Claude Code
Generated by Claude Code
Summary by CodeRabbit
Bug Fixes
Documentation