glean/testing/simulation
Types
Optional assertion function. Use no_assert for no assertion.
pub type AssertFn {
NoAssert
Assert(fn(SimulationState) -> Result(Nil, AssertionError))
}
Constructors
-
NoAssert -
Assert(fn(SimulationState) -> Result(Nil, AssertionError))
Error from a failed assertion.
pub type AssertionError {
AssertionError(step: Int, expected: String, got: String)
}
Constructors
-
AssertionError(step: Int, expected: String, got: String)
Describes a tool call and its expected result.
pub type ScriptedToolExecution {
ScriptedToolExecution(
call: provider.ScriptedToolCall,
result: ToolExecutionResult,
)
}
Constructors
-
ScriptedToolExecution( call: provider.ScriptedToolCall, result: ToolExecutionResult, )
A complete simulation scenario (opaque, built with builder pattern).
pub opaque type Simulation
Result of running a simulation.
pub type SimulationResult {
SimulationPassed(name: String, final_state: SimulationState)
SimulationFailed(
name: String,
step: Int,
error: AssertionError,
)
SimulationExceededMaxSteps(
name: String,
max_steps: Int,
state: SimulationState,
)
}
Constructors
-
SimulationPassed(name: String, final_state: SimulationState) -
SimulationFailed(name: String, step: Int, error: AssertionError) -
SimulationExceededMaxSteps( name: String, max_steps: Int, state: SimulationState, )
State accumulated during simulation.
pub type SimulationState {
SimulationState(
messages: List(message.Message),
step_count: Int,
total_usage: stream.Usage,
tool_calls_made: List(message.ToolResult),
errors_encountered: List(error.GleanError),
)
}
Constructors
-
SimulationState( messages: List(message.Message), step_count: Int, total_usage: stream.Usage, tool_calls_made: List(message.ToolResult), errors_encountered: List(error.GleanError), )
A step in a simulated agent workflow.
pub type SimulationStep {
ExpectText(text: String, then_assert: AssertFn)
ExpectToolCalls(
executions: List(ScriptedToolExecution),
then_assert: AssertFn,
)
ExpectError(error: error.GleanError, then_assert: AssertFn)
}
Constructors
-
ExpectText(text: String, then_assert: AssertFn)Provider returns text (agent loop should terminate)
-
ExpectToolCalls( executions: List(ScriptedToolExecution), then_assert: AssertFn, )Provider returns tool calls, tools execute, results fed back
-
ExpectError(error: error.GleanError, then_assert: AssertFn)Provider returns an error
What happens when a tool is executed.
pub type ToolExecutionResult {
ToolSuccess(content: String)
ToolFailure(error: String)
}
Constructors
-
ToolSuccess(content: String) -
ToolFailure(error: String)
Values
pub fn assert_finally(
sim: Simulation,
assertion: fn(SimulationState) -> Result(Nil, AssertionError),
) -> Simulation
Add a final assertion that runs after all steps complete.
pub fn assert_passed(result: SimulationResult) -> SimulationState
Assert that a simulation passed. Panics with descriptive message if not.
pub fn run(sim: Simulation) -> SimulationResult
Run the simulation. Pure function — all responses come from the script.
pub fn then_call_tools(
sim: Simulation,
executions: List(ScriptedToolExecution),
) -> Simulation
Add a step where the provider calls tools.
pub fn then_call_tools_and_assert(
sim: Simulation,
executions: List(ScriptedToolExecution),
assertion: fn(SimulationState) -> Result(Nil, AssertionError),
) -> Simulation
Add a tool call step with assertion.
pub fn then_provider_error(
sim: Simulation,
error: error.GleanError,
) -> Simulation
Add a step where the provider returns an error.
pub fn then_respond_text(
sim: Simulation,
text: String,
) -> Simulation
Add a step where the provider returns text.
pub fn then_respond_text_and_assert(
sim: Simulation,
text: String,
assertion: fn(SimulationState) -> Result(Nil, AssertionError),
) -> Simulation
Add a text step with assertion.
pub fn with_max_steps(sim: Simulation, max: Int) -> Simulation
Set max steps before the simulation is considered stuck.
pub fn with_system_prompt(
sim: Simulation,
prompt: String,
) -> Simulation
Set the system prompt.