Skip to main content

Module test_utils

Module test_utils 

Source
Available on crate feature test-utils only.
Expand description

Test utilities for deterministic completion-model tests.

Structs§

AppendFailingMemory
Memory backend that loads empty history and always fails on append.
BarrierMockToolIndex
A vector index that waits at a barrier before returning one tool ID.
CapturedHttpRequest
Request data captured by RecordingHttpClient.
CountingMemory
Memory backend that records load and append calls while delegating storage to InMemoryConversationMemory.
FailingMemory
Memory backend that always fails on load and no-ops append and clear.
HttpErrorStreamingClient
An HttpClientExt implementation whose send_streaming fails immediately with a non-success HTTP status and response body.
MockAddTool
A mock tool that adds x and y.
MockBarrierTool
A mock tool that waits at a barrier before returning "done".
MockCompletionModel
A cloneable scripted CompletionModel for tests.
MockControlledTool
A mock tool that notifies when started and waits for an explicit finish signal.
MockDeniedTool
A tool that declares the call denied from inside the tool (via ToolReturn::denied), producing a ToolOutcome::Denied outcome — as opposed to a hook Flow::Skip, which is Skipped. Registered under the name guarded.
MockEmbeddingModel
A deterministic EmbeddingModel that returns a fixed vector for each input document.
MockExampleTool
A mock tool named example_tool that returns "Example answer".
MockExtensionsProbeTool
A mock tool that records whatever it observed in its per-call ToolCallExtensions, so tests can assert the context reached tool execution.
MockFailingTool
A tool that always fails, classifying its error as a configured ToolFailureKind via Tool::classify_error. Used to exercise structured tool-failure surfacing (timeout, not-found, rate-limited, …) without a live provider. Registered under the name flaky_tool.
MockFailure
Error type for MockFailingTool, carrying a fixed message.
MockHandledFailureTool
A tool that reports a handled failure via ToolReturn: the Rust call succeeds, but the returned outcome is a classified ToolFailure while the model still receives useful output. Registered under the name lookup.
MockImageGeneratorTool
A mock tool named generate_test_image that returns a 1x1 red PNG image payload.
MockImageOutputTool
A mock tool that returns image JSON as a string.
MockMetadataTool
A tool whose success carries a MockRequestId in its result extensions. Registered under the name with_meta.
MockModelLister
A ModelLister that returns a preconfigured list of models.
MockMultiTextDocument
A test document that contributes multiple text fragments to an embedding request.
MockObjectOutputTool
A mock tool that returns a JSON object.
MockOperationArgs
Arguments for arithmetic mock tools.
MockRequestId
A cloneable extension value a MockMetadataTool attaches to its result, to verify result extensions reach hooks without being sent to the model.
MockResponse
Raw mock response used by completion and streaming test utilities.
MockStreamingClient
A mock HTTP client that returns pre-built SSE bytes from send_streaming.
MockStringOutputTool
A mock tool that returns a multiline string.
MockSubtractTool
A mock tool that subtracts y from x.
MockTextDocument
A test document that contributes one text fragment to an embedding request.
MockToolError
Shared error type for mock tools.
MockToolIndex
A vector index that returns a predefined list of tool IDs from top_n_ids.
MockTurn
A scripted non-streaming mock completion turn.
RecordingHttpClient
An HttpClientExt implementation that records unary requests and returns a fixed response.
SequencedStreamingHttpClient
An HttpClientExt implementation that returns one scripted stream of byte chunks from send_streaming.
SessionId
A caller-injected context value, like a session id or auth token carried in a ToolCallExtensions.

Enums§

MockError
Scripted error returned by MockCompletionModel.
MockHttpResponse
Response scripted for RecordingHttpClient.
MockStreamEvent
Scripted streaming event yielded by MockCompletionModel.

Functions§

mock_math_toolset
Create a ToolSet containing MockAddTool and MockSubtractTool.
scoped_tracing_subscriber_guard
Serializes tests that install scoped tracing subscribers (tracing::subscriber::set_default / with_default).
scoped_tracing_subscriber_guard_blocking
Blocking variant of scoped_tracing_subscriber_guard for synchronous tests.