pub struct Fake { /* private fields */ }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
impl Fake
Sourcepub fn agentcat(
&self,
project_id: impl Into<String>,
options: Options,
) -> AgentCat
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.
Sourcepub async fn events(&self) -> Vec<Event>
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.
Sourcepub async fn assert_tracked(&self, tool_name: &str)
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.
Sourcepub async fn assert_tracked_count(&self, count: usize)
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.
Sourcepub async fn assert_nothing_tracked(&self)
pub async fn assert_nothing_tracked(&self)
Sourcepub async fn assert_custom_event_published(&self, resource_name: &str)
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.