Skip to main content

Module testing

Module testing 

Source
Expand description

Test fixtures for code built on strands.

MockModel is a scripted model: give it assistant turns as content blocks, raw stream events or errors, and it streams them back while recording every ModelRequest it receives. test_agent builds an agent on one. tool_context builds the context to run a tool on its own, invoke_model_context and execute_tool_context the contexts of middleware handlers, injection_context the context an injection callback receives, and HookRecorder records the hook events that fire.

Structs§

HookRecorder
Records the hook events that fire, by event type name, in order.
MockModel
A scripted model for tests.
MockTurn
One scripted model response for MockModel.

Functions§

execute_tool_context
An ExecuteToolContext for calling a tool-stage handler’s logic on its own: the mock-agent view of tool_context, no registered tool and a cancel signal that never fires. Interrupts work as in an agent, with ids middleware:executeTool:<toolUseId>:<name>.
injection_context
An InjectionContext for messages on a mock agent (id mock-agent, empty app state), to test an injection render callback or predicate on its own.
invoke_model_context
An InvokeModelContext for calling a model-stage handler’s logic on its own: the mock-agent view and a MockModel as in tool_context, messages, and no system prompt, tools or tool choice. Set the public fields for anything else.
test_agent
An Agent on model, with the printer off and no tools. Keep a clone of the model to inspect the requests it received.
tool_context
A ToolContext for running a tool on its own.