Skip to content

Finish RC-CRATES-G: 4 remaining integration tests against mock-anthropic-service - #22

Merged
nuniesmith merged 1 commit into
mainfrom
claude/rc-crates-g-mock-tests-2026-05-19
May 20, 2026
Merged

Finish RC-CRATES-G: 4 remaining integration tests against mock-anthropic-service#22
nuniesmith merged 1 commit into
mainfrom
claude/rc-crates-g-mock-tests-2026-05-19

Conversation

@nuniesmith

@nuniesmith nuniesmith commented May 20, 2026

Copy link
Copy Markdown
Owner

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:

  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 x-api-key header propagation.
  2. 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). Asserts api::OpenAiCompatClient normalises the response into a MessageResponse, and verifies POST /chat/completions plus 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.

tests/test_grok_integration.rs — one new test:

  1. test_model_router_two_tier_claude_routing_planner_vs_executor — with anthropic_enabled=true, asserts ArchitecturalReason / CodeReview / Unknown route to ClaudeTier::Planner + claude-opus-4-7, and ScaffoldStub / TodoTagging / TreeSummary / SymbolExtraction / RepoQuestion route to ClaudeTier::Executor + claude-sonnet-4-6.

Drive-by fix

crates/rusty-claude-cli/src/app/streaming.rs:442MessageStopEvent was simplified to an empty struct upstream but the inline unit test still constructed it with { index: 0 }, which was blocking cargo test -p rusty-claude-cli. One-character fix.

Test plan

  • cargo test -p rusty-claude-cli --test api_integration3 passed; 0 failed; 0 ignored
  • cargo check -p rusty-claude-cli --tests → clean
  • cargo check -p api → clean
  • cargo test --features integration --test test_grok_integration (blocked locally by the ort-sys CDN sandbox restriction; CI should verify the new G-2d case)

https://claude.ai/code/session_014DMg4gxA8VZv1MucmM7PV9


Generated by Claude Code

Summary by CodeRabbit

  • Tests

    • Expanded integration test suite for Claude and Grok paths with comprehensive coverage including round-trip messaging, routing assertions, and fallback scenarios.
    • Added new integration tests validating multi-tier routing behavior and prompt caching functionality.
    • Fixed existing integration tests to align with current API implementation.
  • Chores

    • Updated test tracking documentation to reflect completed test suite additions.

Review Change Stack

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
@coderabbitai

coderabbitai Bot commented May 20, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: dddd23e4-82dd-4b64-8c57-f220305f2cb9

📥 Commits

Reviewing files that changed from the base of the PR and between 246baa7 and bb2909a.

📒 Files selected for processing (4)
  • TODO.md
  • crates/rusty-claude-cli/src/app/streaming.rs
  • crates/rusty-claude-cli/tests/api_integration.rs
  • tests/test_grok_integration.rs

📝 Walkthrough

Walkthrough

This 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.

Changes

Integration Tests for API Crate and Model Router

Layer / File(s) Summary
Test Infrastructure: Config Setup, HTTP Mock, and Helpers
crates/rusty-claude-cli/tests/api_integration.rs
Test helpers to extract text and build requests, per-process CLAUDE_CONFIG_HOME setup via OnceLock with ConfigHomeGuard cleanup, and a SimpleHttpMock TCP-based HTTP/1.1 server that parses requests (method/path/headers/body with Content-Length handling) and returns canned JSON responses.
AnthropicClient Round-Trip Test
crates/rusty-claude-cli/tests/api_integration.rs
Integration test exercising MockAnthropicService, validating AnthropicClient::send_message response text, and asserting the mock captured exactly one request with the expected scenario and x-api-key header.
OpenAiCompatClient with HTTP Mock Server Test
crates/rusty-claude-cli/tests/api_integration.rs
Integration test spinning up inline TCP HTTP server serving OpenAI/xAI-shaped chat completion, verifying OpenAiCompatClient::send_message produces normalized assistant text, and checking captured HTTP method, /chat/completions path, Bearer authorization header, and request body model/prompt.
PromptCache Short-Circuiting Test
crates/rusty-claude-cli/tests/api_integration.rs
Integration test configuring per-process PromptCache session, performing two identical AnthropicClient::send_message calls, asserting both responses match and are non-empty, verifying the mock captured only one network request, and checking cache hit/miss/write counters.
Model Router Two-Tier Claude Routing Test
tests/test_grok_integration.rs
Gated integration test asserting ModelRouter two-tier Claude routing: planner-tier TaskKinds route to Planner tier with claude-opus-4-7; executor-tier TaskKinds route to Executor tier with claude-sonnet-4-6.
Documentation Update and Compilation Fix
TODO.md, crates/rusty-claude-cli/src/app/streaming.rs
RC-CRATES-G checklist entry updated to enumerate integration tests and follow-up fixes; MessageStopEvent test construction changed from { index: 0 } to {} to repair compilation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • nuniesmith/rustcode#1: Introduced Claude two-tier routing and PromptCache wiring that these new integration tests directly exercise via ModelRouter assertions and AnthropicClient round-trip/cache-hit validation.

Poem

🐰 Hop skip through tests, mock servers dance,
AnthropicClient finds its chance,
PromptCache whispers "hit!" with glee,
Two-tier routing flows so free,
Integration blooms in fresh sunlight! 🌿

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/rc-crates-g-mock-tests-2026-05-19

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.

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.

2 participants