pub struct MockTurn { /* private fields */ }test-utils only.Expand description
A scripted non-streaming mock completion turn.
Implementations§
Source§impl MockTurn
impl MockTurn
Sourcepub fn tool_call(
id: impl Into<String>,
name: impl Into<String>,
arguments: Value,
) -> MockTurn
pub fn tool_call( id: impl Into<String>, name: impl Into<String>, arguments: Value, ) -> MockTurn
Create a tool-call response turn.
Sourcepub fn provider_response_error(
status: StatusCode,
body: impl Into<String>,
request_id: impl Into<String>,
) -> MockTurn
pub fn provider_response_error( status: StatusCode, body: impl Into<String>, request_id: impl Into<String>, ) -> MockTurn
Create a provider-response error turn carrying a transport request id (rig#2314): the scripted failure a test uses to assert error-identity attribution.
Sourcepub fn request_error(message: impl Into<String>) -> MockTurn
pub fn request_error(message: impl Into<String>) -> MockTurn
Create a request-error response turn.
Sourcepub fn from_content(content: AssistantContent) -> MockTurn
pub fn from_content(content: AssistantContent) -> MockTurn
Create a response turn from one assistant content item.
Sourcepub fn from_contents(
content: impl IntoIterator<Item = AssistantContent>,
) -> MockTurn
pub fn from_contents( content: impl IntoIterator<Item = AssistantContent>, ) -> MockTurn
Create a response turn from assistant content items.
Infallible now that content is a Vec: an empty turn is a shape a
provider can genuinely return, so it is a value to build, not an error.
Sourcepub fn with_call_id(self, call_id: impl Into<String>) -> MockTurn
pub fn with_call_id(self, call_id: impl Into<String>) -> MockTurn
Attach a provider-specific call ID to a tool-call response turn.
Sourcepub fn with_usage(self, usage: Usage) -> MockTurn
pub fn with_usage(self, usage: Usage) -> MockTurn
Override usage for this turn.
Sourcepub fn with_message_id(self, message_id: impl Into<String>) -> MockTurn
pub fn with_message_id(self, message_id: impl Into<String>) -> MockTurn
Set a provider-assigned assistant message ID for this turn.
Sourcepub fn with_response_id(self, response_id: impl Into<String>) -> MockTurn
pub fn with_response_id(self, response_id: impl Into<String>) -> MockTurn
Set a provider-assigned response-scoped ID for this turn.
Sourcepub fn with_provider_request_id(self, request_id: impl Into<String>) -> MockTurn
pub fn with_provider_request_id(self, request_id: impl Into<String>) -> MockTurn
Set a provider transport request id for this turn.
Sourcepub fn with_finish_reason(self, finish_reason: FinishReason) -> MockTurn
pub fn with_finish_reason(self, finish_reason: FinishReason) -> MockTurn
Set the terminal finish reason for this turn.
Without this, a mocked blocking turn always reports None, which
leaves the whole blocking half of the truncation contract (rig#2322)
unexercisable — the streamed mock could script a reason and the
blocking one could not.
Sourcepub fn with_raw(self, raw: Value) -> MockTurn
pub fn with_raw(self, raw: Value) -> MockTurn
Script the provider’s own response for this turn — what a real seam
would serialize from its raw type. Attached to the response as-is, so
agent tests can prove the payload reaches every observer of the turn
without a live provider. A turn without a scripted payload reports
raw: Value::Null, so a non-null raw in a test means the scripted
value arrived, never that the mock invented one.