Skip to main content

ChatBotHarness

Struct ChatBotHarness 

Source
pub struct ChatBotHarness { /* private fields */ }
Expand description

Runs the real chat stack — real MindsetOperator, real system prompt, real tool loop with argument validation — against an in-RAM memory and a scriptable adapter.

The point is that a test exercises production code paths. Anything the harness reimplemented would be a second implementation free to drift from the one that ships.

let harness = ChatBotHarness::builder(Arc::new(MyMindset))
    .tools(OrderTools::register_tools(&container))
    .container(container)
    .build();

harness.adapter().call_tool("read_order", json!({ "id": 7 }));
harness.adapter().reply("It shipped yesterday.");

let turn = harness.send("where is order 7?").await.unwrap();
assert_eq!(turn.text(), "It shipped yesterday.");
assert!(turn.called("read_order"));

Implementations§

Source§

impl ChatBotHarness

Source

pub fn new(mindset: Arc<dyn Mindset>) -> Self

A harness with a mock adapter, an in-RAM memory and no tools.

Source

pub fn builder(mindset: Arc<dyn Mindset>) -> ChatBotHarnessBuilder

Source

pub fn adapter(&self) -> &Arc<MockChatAdapter>

The scripted adapter — queue turns and assert on requests.

Source

pub fn operator(&self) -> &Arc<MindsetOperator>

The operator the bot uses, for asserting on the real prompt and tool schema.

Source

pub async fn send( &self, message: impl IntoChatMessage, ) -> Result<ChatTurn, ChatBotError>

Send a human message and collect what the bot did.

Source

pub async fn call_tool( &self, name: &str, arguments: impl ToArguments, ) -> Result<String, ToolError>

Run one tool directly — real validation, real dispatch — without scripting a conversation around it. Returns the string the model would have received.

Source

pub async fn system_prompt(&self) -> String

The real system prompt this mindset produces.

Source

pub fn tools(&self) -> Result<Vec<MindsetTool>, ToolError>

The real tool schema the model would be given.

Source

pub fn history(&self) -> Vec<ChatItem>

Everything recorded across every turn.

Source

pub fn memory(&self) -> &Arc<TestChatMemory>

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more