Add MockProvider for integration testing

Adds a configurable mock LLM provider that can simulate various behaviors:
- Text-only responses (single or multi-chunk streaming)
- Native tool calls
- JSON tool calls in text
- Truncated responses (max_tokens)
- Multi-turn conversations

Features:
- Builder pattern for easy test setup
- Request tracking for verification
- Preset scenarios for common patterns
- Full LLMProvider trait implementation

Also adds integration tests that use MockProvider to test the
stream_completion_with_tools code path, including:
- test_butler_bug_scenario: reproduces the exact bug where text-only
  responses were not saved to context, causing consecutive user messages

This enables testing complex streaming behaviors without real API calls.
This commit is contained in:
Dhanji R. Prasanna
2026-01-19 13:59:31 +05:30
parent 349230d0b7
commit 292a3aa48d
3 changed files with 827 additions and 0 deletions

View File

@@ -1,4 +1,7 @@
mod streaming;
pub mod mock;
pub use mock::{MockProvider, MockResponse, MockChunk};
pub use streaming::{decode_utf8_streaming, is_incomplete_json_error, make_final_chunk, make_text_chunk, make_tool_chunk};
use anyhow::Result;