Add Mock HTTP Client for Integration Tests

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.

Features

  • 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

Usage

Running Integration Tests

# 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

Recording Mock Data

# 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

Environment Variables

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)

Mock File Format

  • 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

Helper Utilities

  • 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

Benefits

  • Faster test runs

  • No API rate limits or external dependencies

  • Reduced testing cost

  • Supports offline development and CI environments

  • Deterministic test behavior

/claim #440

Claim

Total prize pool $120
Total paid $0
Status Pending
Submitted April 12, 2025
Last updated April 12, 2025

Contributors

LU

Luffy

@luffy-orf

100%

Sponsors

TA

Tailcall Inc.

@tailcallhq

$120