glean/testing/provider

Types

A scripted response the test provider should return.

pub type ScriptedResponse {
  TextResponse(text: String)
  ToolCallResponse(calls: List(ScriptedToolCall))
  ErrorResponse(error: error.GleanError)
}

Constructors

  • TextResponse(text: String)

    Return a successful text response

  • ToolCallResponse(calls: List(ScriptedToolCall))

    Return a response containing tool calls

  • ErrorResponse(error: error.GleanError)

    Return a provider error

A tool call to include in a scripted response.

pub type ScriptedToolCall {
  ScriptedToolCall(id: String, name: String, arguments: String)
}

Constructors

  • ScriptedToolCall(id: String, name: String, arguments: String)

Values

pub fn test_provider(
  responses: List(ScriptedResponse),
) -> provider.Provider

Create a test provider that returns scripted responses in order.

Each call to generate consumes the next response from the list. Uses a closure over a mutable index — the one controlled escape hatch for stateful test providers, hidden behind the Provider interface.

Example

let provider = test_provider([
  ToolCallResponse([ScriptedToolCall("c1", "calc", "{\"a\":1}")]),
  TextResponse("The answer is 1"),
])
pub fn text_result(text: String) -> provider.GenerateResult

Create a simple text response GenerateResult (for building custom test flows).

pub fn tool_call_result(
  calls: List(#(String, String, String)),
) -> provider.GenerateResult

Create a tool call response GenerateResult.

✨ Search Document