Finish RC-CRATES-G: 4 remaining integration tests against mock-anthropic-service - #22
Conversation
Closes the four pending RC-CRATES-G test scenarios:
1. anthropic_client_round_trips_through_mock_service — sends a non-streaming
request through api::AnthropicClient against MockAnthropicService and asserts
the canned scenario response plus header propagation (x-api-key).
2. openai_compat_client_consumes_openai_shaped_response — spawns a tiny inline
TCP mock that returns an xAI-shaped chat completion and asserts
api::OpenAiCompatClient correctly normalises it into a MessageResponse, plus
verifies POST /chat/completions and Bearer auth on the outgoing request.
3. prompt_cache_short_circuits_second_identical_request — attaches a PromptCache
to AnthropicClient, sends the same request twice, and asserts the mock only
observes one captured request (second served from disk cache). Uses a unique
CLAUDE_CONFIG_HOME temp dir per test binary via a OnceLock guard.
4. test_model_router_two_tier_claude_routing_planner_vs_executor (added to
tests/test_grok_integration.rs) — with anthropic_enabled=true, asserts
ArchitecturalReason / CodeReview / Unknown route to ClaudeTier::Planner with
claude-opus-4-7, and ScaffoldStub / TodoTagging / TreeSummary /
SymbolExtraction / RepoQuestion route to ClaudeTier::Executor with
claude-sonnet-4-6.
Drive-by: fixed a pre-existing compile break in
crates/rusty-claude-cli/src/app/streaming.rs — MessageStopEvent was simplified
to an empty struct but the inline test still constructed it with { index: 0 },
which was blocking cargo test on the whole cli crate.
All three new mock tests pass: cargo test -p rusty-claude-cli
--test api_integration → 3 passed; 0 failed.
https://claude.ai/code/session_014DMg4gxA8VZv1MucmM7PV9
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughThis PR adds comprehensive integration tests for the API crate, covering AnthropicClient round-trip communication, OpenAiCompatClient fallback via HTTP mock, PromptCache short-circuiting behavior, and model router two-tier Claude routing assertions. A new test file and supporting infrastructure (TCP HTTP mock, config home setup) enable these tests, with documentation and compilation fixes included. ChangesIntegration Tests for API Crate and Model Router
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
✨ 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 |
Summary
Closes the four pending tasks under RC-CRATES-G, taking it from partial to done.
What's new
crates/rusty-claude-cli/tests/api_integration.rs— three live-mock tests:anthropic_client_round_trips_through_mock_service— sends a non-streaming request throughapi::AnthropicClientagainstMockAnthropicServiceand asserts the canned scenario response plusx-api-keyheader propagation.openai_compat_client_consumes_openai_shaped_response— spawns a tiny inline TCP mock that returns an xAI-shaped chat completion (the workspace mock is Anthropic-shaped, so it can't serve OpenAI/xAI traffic). Assertsapi::OpenAiCompatClientnormalises the response into aMessageResponse, and verifiesPOST /chat/completionsplusBearerauth on the outgoing request.prompt_cache_short_circuits_second_identical_request— attaches aPromptCachetoAnthropicClient, sends the same request twice, and asserts the mock only observes one captured request (second served from disk cache). Uses a uniqueCLAUDE_CONFIG_HOMEtemp dir per test binary via aOnceLockguard.tests/test_grok_integration.rs— one new test:test_model_router_two_tier_claude_routing_planner_vs_executor— withanthropic_enabled=true, assertsArchitecturalReason/CodeReview/Unknownroute toClaudeTier::Planner+claude-opus-4-7, andScaffoldStub/TodoTagging/TreeSummary/SymbolExtraction/RepoQuestionroute toClaudeTier::Executor+claude-sonnet-4-6.Drive-by fix
crates/rusty-claude-cli/src/app/streaming.rs:442—MessageStopEventwas simplified to an empty struct upstream but the inline unit test still constructed it with{ index: 0 }, which was blockingcargo test -p rusty-claude-cli. One-character fix.Test plan
cargo test -p rusty-claude-cli --test api_integration→3 passed; 0 failed; 0 ignoredcargo check -p rusty-claude-cli --tests→ cleancargo check -p api→ cleancargo test --features integration --test test_grok_integration(blocked locally by theort-sysCDN sandbox restriction; CI should verify the new G-2d case)https://claude.ai/code/session_014DMg4gxA8VZv1MucmM7PV9
Generated by Claude Code
Summary by CodeRabbit
Tests
Chores