Skip to main content

Fake

Struct Fake 

Source
pub struct Fake { /* private fields */ }
Available on crate feature test-util only.
Expand description

A test double for AgentCat: it builds handles whose events never leave the process and records every event that finishes the pipeline, telemetry-only events (an empty project ID) included. The identify, tag, property and redact_event hooks run as they do in production, so a recorded event is the one that would have been published.

A Fake is an instance, not a global: two fakes in one process see only their own handles. Clones share the record. Its handles are always on (they ignore AGENTCAT_ENABLED), never configure the process logger and use a publisher that never sends, so a test needs no network. The log destination is process-wide and the first handle that configures it decides it, so the handles of a fake write no ~/agentcat.log lines unless a handle built with AgentCat::new or AgentCat::from_env in the same process configured it: then their lines go there too.

A fake keeps a clone of each handle it built, so the last clone drops with the fake and the servers that hold one, and that drop drains as any handle does (see dropping the last handle): for up to 5 s, and under #[tokio::test], a current-thread runtime, an event that still needs a hook is dropped after that wait. The assertion methods flush first, so after them the drop has nothing left to wait for, unless a flush timed out: the events that flush left wait for the drop.

use agentcat_sdk::Options;
use agentcat_sdk::testing::Fake;

let fake = Fake::new();
let server = fake.agentcat("proj_123", Options::default()).track(MyServer);
// ... serve `server` and make calls against it ...
fake.assert_nothing_tracked().await;

The assertion methods panic with a message that lists the recorded events’ types and resource names, and says so when a handle did not finish delivering within the 5 s flush (a hook slower than that holds its event back).

Implementations§

Source§

impl Fake

Source

pub fn new() -> Self

A fake with no handles and no events.

Source

pub fn agentcat( &self, project_id: impl Into<String>, options: Options, ) -> AgentCat

A handle for project_id (empty means telemetry only) whose events this fake records and whose publisher never sends. Wrap a server with AgentCat::track.

Source

pub async fn events(&self) -> Vec<Event>

Flushes every handle this fake built, for up to 5 s each, then returns the recorded events in the order they finished. An event whose hooks take longer than that is not among them.

Source

pub async fn assert_tracked(&self, tool_name: &str)

Asserts that a tool call of the tool tool_name was tracked.

§Panics

When no recorded tool-call event has that resource name.

Source

pub async fn assert_tracked_count(&self, count: usize)

Asserts that exactly count tool calls were tracked (custom events do not count).

§Panics

When the number of recorded tool-call events differs.

Source

pub async fn assert_nothing_tracked(&self)

Asserts that no event of any kind was recorded.

§Panics

When any event was recorded.

Source

pub async fn assert_custom_event_published(&self, resource_name: &str)

Asserts that a custom event with the resource name resource_name was published.

§Panics

When no recorded custom event has that resource name.

Trait Implementations§

Source§

impl Clone for Fake

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Fake

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Fake

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Fake

§

impl RefUnwindSafe for Fake

§

impl Send for Fake

§

impl Sync for Fake

§

impl Unpin for Fake

§

impl UnsafeUnpin for Fake

§

impl UnwindSafe for Fake

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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<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