Skip to main content

Module test_utils

Module test_utils 

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

Test utilities for the classic runtime and its provider-facing acceptance 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.
ConformanceToolError
Error used by the deterministic conformance tools.
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.
MockContextProbeTool
A mock tool that records whatever it observed in its per-call ToolContext, so tests can assert the context reached tool execution.
MockControlledTool
A mock tool that notifies when started and waits for an explicit finish signal.
MockDeniedTool
A tool that refuses execution, distinct from a framework policy skip.
MockEmbeddingModel
A deterministic EmbeddingModel that returns a fixed vector for each input document.
MockExampleTool
A mock tool named example_tool that returns "Example answer".
MockFailingTool
A tool that always fails with a configured ToolErrorKind. 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 failure with separate operator and model-visible feedback.
MockImageGeneratorTool
A mock tool named generate_test_image that returns a 1x1 red PNG image payload.
MockImageOutputTool
A mock tool that returns explicit image content.
MockMetadataTool
A tool whose success carries a MockRequestId in its result metadata. 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
Cloneable metadata a MockMetadataTool attaches to its result, used to verify that result metadata reaches 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.
ScenarioReport
Summary emitted by a portable model-conformance scenario.
SequencedHttpClient
An HttpClientExt implementation that records unary requests and returns one scripted response per request.
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 ToolContext.

Enums§

MockError
Scripted error returned by MockCompletionModel.
MockHttpResponse
Response scripted for RecordingHttpClient.
MockStreamEvent
Scripted streaming event yielded by MockCompletionModel.
ScenarioError
Typed failure from a portable model-conformance scenario.

Functions§

buffered_streaming_text_parity
Runs the same deterministic text request through buffered and raw streaming completion surfaces and validates equivalent visible content and usage.
cancellation_and_max_turns
Exercises post-execution cancellation and max-turn diagnostics through the public agent driver using real model-emitted calls.
complex_tool_arguments
Runs a nested, escaped, Unicode-bearing argument payload through typed tool deserialization and validates the exact semantic value received by the tool.
decode_structured_output
Decode a structured-output response with a typed conformance failure that retains the scenario name and raw response.
hook_rewrites_and_request_patch
Exercises chained argument/result rewrites and a first-turn-only request patch. Completion proves tool_choice=Required did not leak to turn two.
invalid_tool_recovery
Uses one real model turn to exercise fail-fast, retry exhaustion, repair, rejected repair, and skip handling without executing a disallowed call.
mock_math_toolset
Create a ToolSet containing MockAddTool and MockSubtractTool.
optional_argument
Runs the portable optional-argument tool scenario.
parallel_tools
Runs two independent calls in one assistant turn and validates canonical call/result history correlation.
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.
sequential_tools
Runs a portable two-tool sequential arithmetic scenario.
streaming_structured_after_tool
Runs a streamed real-tool turn followed by Rig’s synthetic output tool.
streaming_tool
Runs a tool through Rig’s multi-turn streaming agent driver.
structured_after_tool
Runs a normal tool followed by Rig’s synthetic structured-output tool.
structured_extraction
Runs Rig’s structured extractor and validates both the extracted semantic fields and accumulated usage.
tool_choice_modes
Runs all portable tool-choice modes directly against a completion model.
tool_output_serialization
Runs string- and JSON-returning tools and validates that neither output is double encoded.
validate_cancelled_failure
Validate cancellation diagnostics, including the exact reason and retained assistant tool-call history.
validate_extraction_fields
Validate a provider-neutral person extraction and its usage accounting.
validate_max_turns_failure
Validate max-turn diagnostics, including the exact configured budget and a retained pending prompt.
validate_protocol_hygiene
Validate that model-family control markers are absent from user-visible output and persisted history.
validate_result_redaction
Validate that a sensitive raw tool result was produced but did not reach the model’s user-visible response after result hooks ran.
validate_rewritten_arguments
Validate that every observed tool invocation contains the expected rewritten argument fields while allowing unrelated original fields to remain.
validate_unknown_tool_failure
Validate the portable diagnostics carried by an unknown or disallowed tool call failure.
zero_argument_tool
Runs a zero-argument tool and validates verbatim string-result handling.