pub struct MockTurn { /* private fields */ }test-utils only.Expand description
A scripted non-streaming mock completion turn.
A turn is data: a script serializes, so a scripted model can be written
to a fixture and read back (see MockCompletionModel::script).
Implementations§
Source§impl MockTurn
impl MockTurn
Sourcepub fn tool_call(
id: impl Into<String>,
name: impl Into<String>,
arguments: Value,
) -> Self
pub fn tool_call( id: impl Into<String>, name: impl Into<String>, arguments: Value, ) -> Self
Create a tool-call response turn. An empty name scripts a provider
error instead: no call can be built without a name.
Sourcepub fn provider_response_error(
status: StatusCode,
body: impl Into<String>,
request_id: impl Into<String>,
) -> Self
pub fn provider_response_error( status: StatusCode, body: impl Into<String>, request_id: impl Into<String>, ) -> Self
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>) -> Self
pub fn request_error(message: impl Into<String>) -> Self
Create a request-error response turn.
Sourcepub fn from_content(content: AssistantContent) -> Self
pub fn from_content(content: AssistantContent) -> Self
Create a response turn from one assistant content item.
Sourcepub fn from_contents(
content: impl IntoIterator<Item = AssistantContent>,
) -> Self
pub fn from_contents( content: impl IntoIterator<Item = AssistantContent>, ) -> Self
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>) -> Self
pub fn with_call_id(self, call_id: impl Into<String>) -> Self
Attach a provider-specific call ID to a tool-call response turn.
Sourcepub fn with_usage(self, usage: Usage) -> Self
pub fn with_usage(self, usage: Usage) -> Self
Override usage for this turn.
Sourcepub fn with_response_id(self, response_id: impl Into<String>) -> Self
pub fn with_response_id(self, response_id: impl Into<String>) -> Self
Set a provider-assigned response-scoped ID for this turn.
Sourcepub fn with_provider_request_id(self, request_id: impl Into<String>) -> Self
pub fn with_provider_request_id(self, request_id: impl Into<String>) -> Self
Set a provider transport request id for this turn.
Sourcepub fn with_finish_reason(self, finish_reason: FinishReason) -> Self
pub fn with_finish_reason(self, finish_reason: FinishReason) -> Self
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) -> Self
pub fn with_raw(self, raw: Value) -> Self
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 carries the scripted turn itself, serialized — the mock’s own document, the same capture every real adapter performs — so a scripted value in a test is distinguishable from the mock’s default by content.
Sourcepub fn raw(&self) -> Result<Value, ProviderError>
pub fn raw(&self) -> Result<Value, ProviderError>
The provider document the mock attaches to this turn’s response: the
scripted payload when one was supplied, otherwise the turn itself,
serialized. Public so a test can state the expected raw of a
recorded call without repeating the mock’s serialization. An error
turn has no document.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for MockTurn
impl<'de> Deserialize<'de> for MockTurn
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for MockTurn
Auto Trait Implementations§
impl Freeze for MockTurn
impl RefUnwindSafe for MockTurn
impl Send for MockTurn
impl Sync for MockTurn
impl Unpin for MockTurn
impl UnsafeUnpin for MockTurn
impl UnwindSafe for MockTurn
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more