Conversation
これまで「テスト不能」として `scripts/coverage.sh` の COVERAGE_IGNORE に 逃がしていた薄い IO ラッパ群を、依存注入(DI)でテスト可能にしてカバレッジ 計測(行・関数 100%)の対象に含める。 実 IO(標準入出力・サブプロセス・端末・スレッド)を引数やジェネリックで注入し、 本物の IO は合成ルート(src/main.rs、計測対象外)で束ねる。これにより presentation/CLI のオーケストレーションがユニットテストで 100% を満たせる。 - ジェネリック関数は非 test ビルド(統合テスト用 lib)で単相化されず、 test ビルドのユニットテストだけで計測対象になる(具象 IO の二重計上を回避)。 - cli/agent_phase.rs … フック payload を `impl Read` で注入(stdin をブロックしない) - cli/mcp.rs … `Box<dyn AgentBackend>` と `impl BufRead`/`impl Write` を注入。 実 IO の CliAgentBackend は main.rs へ移設 - cli/clean.rs … detached spawn を関数注入。実 spawn_detached は main.rs へ移設 - cli/hop.rs / cli/run.rs … TUI/gallery 起動を注入 - tui/splash|welcome|new|gallery/mod.rs … event_loop をモックに差し替え(use エイリアス) - tui/echo.rs … EchoGuard に fd を注入し PTY で echo クリア/復元を検証 - 既存の session 補完フォールバック(`session create/list <x>`)のテストを追加し home/command/builtins.rs を 100% に。 - COVERAGE_IGNORE は「テスト可能なロジックを抜いた後に残る実 IO 層」だけに限定。 残置理由を scripts/coverage.sh に明記。 - document/06-conventions.md に DI でテスト可能化する方針を追記。 残りの除外ファイル(llm_mcp / pty / release / term_reader / app / home / terminal_pane / terminal_pool / open / config / provisioning / main)は、 タイムアウトループのクロック注入・PtySession 抽象化・live TTY 注入など、 より大きな DI リファクタが必要なため後続で対応する。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`cli/llm_mcp.rs` を mcp.rs と同型でリファクタ: - `run` を `Box<dyn LlmBackend>` + `impl BufRead`/`impl Write` を取るジェネリック 関数にし、実 serve でユニットテスト(空入力の EOF と local_llm_ask の往復)。 - 実 IO(ollama サブプロセス起動・タイムアウト監視・出力キャップ)を担う OllamaBackend / read_capped / wait_with_timeout と関連定数を、計測対象外の 合成ルート src/main.rs へ移設。 - ジェネリック化で非 test ビルドに具象インスタンスが残らず、行・関数 100% を達成。 COVERAGE_IGNORE から cli/llm_mcp.rs を削除。CI 同条件の enforce が exit 0。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
📊 Test Coverage
🎉✨ パーフェクト!全ファイル Lines カバレッジ 100% を達成しました 🏆🐰 |
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.
目的
これまで「テスト不能」として
scripts/coverage.shのCOVERAGE_IGNOREに逃がしていた薄い IO ラッパ群を、依存注入(DI)でテスト可能にしてカバレッジ計測(行・関数 100%)の対象に戻す。「ignore をやめる」ための第一弾。方針 — テスト不能部分を DI で対処する
実 IO(標準入出力・サブプロセス・端末・スレッド)を引数やジェネリックで注入し、本物の IO は合成ルート
src/main.rs(計測対象外)で束ねる。これで presentation/CLI のオーケストレーションがユニットテストだけで 100% を満たせる。変更内容
計測対象に追加した 10 ファイル(いずれも行・関数 100%):
cli/agent_phase.rsimpl Readで注入(実 stdin をブロックしない)cli/mcp.rsBox<dyn AgentBackend>とimpl BufRead/impl Writeを注入。実 IO のCliAgentBackendはmain.rsへ移設cli/clean.rsspawn_detachedはmain.rsへ移設。usagi_binフォールバックを純粋関数へ抽出cli/hop.rs/cli/run.rstui/splash|welcome|new|gallery/mod.rsevent_loopを#[cfg(test)]のuseエイリアスでモックに差し替えtui/echo.rsEchoGuardに fd を注入し、PTY で echo クリア/復元を検証補助:
session create/list <x>補完フォールバックのテストを追加しhome/command/builtins.rsを 100% に(既存の未カバー行を解消)。COVERAGE_IGNOREを「テスト可能なロジックを抜いた後に残る実 IO 層」だけに限定し、残置理由をscripts/coverage.shに明記。document/06-conventions.mdに DI でテスト可能化する方針を追記。テスト・確認方法
ローカル(macOS)で全テスト緑・カバレッジ 100%(行・関数)・enforce exit 0 を確認。
残作業(後続 PR)
次の除外ファイルは、より大きな DI リファクタが必要なため別 PR で対応する:
infrastructure/release.rs・cli/llm_mcp.rs(std::process::ExitStatusが構築不能なため、ポーリング結果を独自 enum に分離して sleep/timeout 分岐をテスト可能化)infrastructure/pty.rs(実シェルを PTY に起動する統合テスト + reap ループの注入)tui/term_reader.rs(raw キー源・readiness・raw mode を注入。select/pollは fd 注入で直接テスト)tui/app/mod.rs・tui/home/mod.rs・home/terminal_pane.rs・home/terminal_pool.rs・tui/open/mod.rs・tui/config/mod.rs・tui/config/provisioning.rs(PtySessionの抽象化とスクリプト駆動が必要)src/main.rsは合成ルート(実 IO の注入先)として計測対象外を維持。🤖 Generated with Claude Code