Closes #440
This PR introduces a mock HTTP client system to enable integration tests without making real HTTP requests to external services like LLM providers.
Dual-mode operation: Real mode (actual requests) or Mock mode (cached responses)
Transparent API: Implements the same interface as reqwest::Client
Automatic response caching in Real mode
Configurable cache directory
Support for updating cached responses
Offline mode support for skipping tests without available mocks
# Real mode (requires API keys) cargo test
Mock mode (uses cached responses)
USE_MOCK_PROVIDER=true cargo test
Offline mode (skips tests without mocks)
USE_MOCK_PROVIDER=true OFFLINE_MODE=true cargo test
# For integration tests export OPENROUTER_API_KEY=your_api_key cargo run --bin record_integration_test_mocks
For general usage
cargo run –bin record_mocks cargo run –bin update_mocks
Variable | Description |
---|---|
USE_MOCK_PROVIDER | Use cached responses instead of real requests |
UPDATE_MOCK_CACHE | Update existing mock cache files |
OFFLINE_MODE | Skip tests if no mock data is available |
OPENROUTER_API_KEY | API key for making real requests (used during recording) |
Stored in tests/fixtures/llm_mocks/
JSON files named using a hash of the request
Each file includes method, URL, headers, request body, response status, headers, and body
get_test_client()
: Returns a client based on current environment
is_offline_mode()
: Detects if offline mode is active
skip_if_offline_without_mock()
: Skips test if mock is missing in offline mode
Faster test runs
No API rate limits or external dependencies
Reduced testing cost
Supports offline development and CI environments
Deterministic test behavior
Luffy
@luffy-orf
Tailcall Inc.
@tailcallhq