Documentation
¶
Index ¶
- func AssertTokenInvariant(t testing.TB, accountant *accounting.TokenAccountant, out sleipnir.RunOutput)
- func ByType[T sleipnir.Event](c *EventCollector) []T
- func MultiToolCallResponse(calls ...anyllm.ToolCall) *anyllm.ChatCompletion
- func StaticTool(name, result string) sleipnir.Tool
- func TextResponse(text string) *anyllm.ChatCompletion
- func ToolCallResponse(toolName, toolCallID string, args json.RawMessage) *anyllm.ChatCompletion
- type EventCollector
- func (c *EventCollector) ByAgent(name string) []sleipnir.Event
- func (c *EventCollector) CheckCompleted() error
- func (c *EventCollector) Events() []sleipnir.Event
- func (c *EventCollector) Send(e sleipnir.Event)
- func (c *EventCollector) TokensFor(agentName string) sleipnir.Usage
- func (c *EventCollector) ToolCalls() []sleipnir.ToolCallEvent
- type FakeMCPServer
- type StubProvider
- func (s *StubProvider) Completion(_ context.Context, params anyllm.CompletionParams) (*anyllm.ChatCompletion, error)
- func (s *StubProvider) CompletionStream(_ context.Context, _ anyllm.CompletionParams) (<-chan anyllm.ChatCompletionChunk, <-chan error)
- func (s *StubProvider) Name() string
- func (s *StubProvider) WhenMessageMatches(pattern *regexp.Regexp, resp *anyllm.ChatCompletion) *StubProvider
- type StubTool
- type StubToolInvocation
- type TodoCollector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertTokenInvariant ¶
func AssertTokenInvariant(t testing.TB, accountant *accounting.TokenAccountant, out sleipnir.RunOutput)
AssertTokenInvariant verifies that TokenAccountant.Total().TotalTokens equals RunOutput.Usage.TotalTokens. Call immediately after Run returns.
func ByType ¶
func ByType[T sleipnir.Event](c *EventCollector) []T
ByType returns all events in c that are of type T.
func MultiToolCallResponse ¶
func MultiToolCallResponse(calls ...anyllm.ToolCall) *anyllm.ChatCompletion
MultiToolCallResponse returns a *ChatCompletion scripted to call multiple tools in a single turn.
func StaticTool ¶
StaticTool returns a Tool with the given name that always returns result. Useful for registering tools with duplicate names to trigger ErrToolNameCollision.
func TextResponse ¶
func TextResponse(text string) *anyllm.ChatCompletion
TextResponse returns a *ChatCompletion containing only assistant text and no tool calls. Covers the most common scripted scenario in harness tests.
func ToolCallResponse ¶
func ToolCallResponse(toolName, toolCallID string, args json.RawMessage) *anyllm.ChatCompletion
ToolCallResponse returns a *ChatCompletion scripted to call one tool.
Types ¶
type EventCollector ¶
type EventCollector struct {
// contains filtered or unexported fields
}
EventCollector implements Sink and accumulates all sent events. Safe for concurrent use.
func NewEventCollector ¶
func NewEventCollector() *EventCollector
func (*EventCollector) ByAgent ¶
func (c *EventCollector) ByAgent(name string) []sleipnir.Event
ByAgent returns all events where the AgentName field equals name. Uses reflection so it works across all event types.
func (*EventCollector) CheckCompleted ¶
func (c *EventCollector) CheckCompleted() error
CheckCompleted returns an error if no AgentEndEvent with StopDone was received.
func (*EventCollector) Events ¶
func (c *EventCollector) Events() []sleipnir.Event
Events returns a snapshot of all collected events.
func (*EventCollector) Send ¶
func (c *EventCollector) Send(e sleipnir.Event)
func (*EventCollector) TokensFor ¶
func (c *EventCollector) TokensFor(agentName string) sleipnir.Usage
TokensFor returns the Usage from the AgentEndEvent for the named agent. Returns zero Usage if no AgentEndEvent was received for that agent.
func (*EventCollector) ToolCalls ¶
func (c *EventCollector) ToolCalls() []sleipnir.ToolCallEvent
ToolCalls returns all ToolCallEvents collected.
type FakeMCPServer ¶
type FakeMCPServer struct {
// contains filtered or unexported fields
}
FakeMCPServer is an in-process MCP server for testing. Register tools with AddTool, then call Start to connect a client. After Start returns, Client() provides a connected *mcp.ClientSession.
func NewFakeMCPServer ¶
func NewFakeMCPServer(t *testing.T) *FakeMCPServer
NewFakeMCPServer creates a FakeMCPServer. Call AddTool to register tools, then call Start to connect. Cleanup is registered with t.Cleanup.
func (*FakeMCPServer) AddRawTool ¶
func (f *FakeMCPServer) AddRawTool(name, description string, fn func(ctx context.Context, args map[string]any) (*mcp.CallToolResult, error))
AddRawTool registers a tool whose handler returns a raw *mcp.CallToolResult. Use this when you need to return multiple content items or non-text content. Must be called before Start.
func (*FakeMCPServer) AddTool ¶
func (f *FakeMCPServer) AddTool(name, description string, fn func(ctx context.Context, args map[string]any) (string, error))
AddTool registers a low-level tool on the server. fn receives the raw arguments as a map[string]any and returns a text result. Must be called before Start.
func (*FakeMCPServer) Client ¶
func (f *FakeMCPServer) Client() *mcp.ClientSession
Client returns the connected MCP client session. Panics if Start has not been called.
func (*FakeMCPServer) Start ¶
func (f *FakeMCPServer) Start()
Start connects the server and client in-process and registers cleanup. Must be called before Client().
type StubProvider ¶
type StubProvider struct {
// contains filtered or unexported fields
}
func NewStubProvider ¶
func NewStubProvider(t *testing.T, responses ...*anyllm.ChatCompletion) *StubProvider
func (*StubProvider) Completion ¶
func (s *StubProvider) Completion(_ context.Context, params anyllm.CompletionParams) (*anyllm.ChatCompletion, error)
Completion implements anyllm.Provider
func (*StubProvider) CompletionStream ¶
func (s *StubProvider) CompletionStream(_ context.Context, _ anyllm.CompletionParams) (<-chan anyllm.ChatCompletionChunk, <-chan error)
CompletionStream implements anyllm.Provider - not used in tests; panics with "not implemented"
func (*StubProvider) Name ¶
func (s *StubProvider) Name() string
func (*StubProvider) WhenMessageMatches ¶
func (s *StubProvider) WhenMessageMatches(pattern *regexp.Regexp, resp *anyllm.ChatCompletion) *StubProvider
WhenMessageMatches registers a response for calls where the last user message content matches pattern. Checked before the scripted sequence. Returns the receiver for chaining.
type StubTool ¶
type StubTool struct {
// contains filtered or unexported fields
}
StubTool is a Tool for use in tests. It records every invocation.
func NewStubTool ¶
func (*StubTool) Definition ¶
func (s *StubTool) Definition() sleipnir.ToolDefinition
func (*StubTool) Invocations ¶
func (s *StubTool) Invocations() []StubToolInvocation
func (*StubTool) Invoke ¶
func (s *StubTool) Invoke(ctx context.Context, args json.RawMessage) (sleipnir.ToolResult, error)
func (*StubTool) InvokeCount ¶
type StubToolInvocation ¶
type StubToolInvocation struct {
Args json.RawMessage
Result sleipnir.ToolResult
Err error
}
type TodoCollector ¶
type TodoCollector struct {
// contains filtered or unexported fields
}
TodoCollector implements Sink and accumulates TodoEvents. After a run, ByToolCallID returns the final todo list for each invocation.
func NewTodoCollector ¶
func NewTodoCollector() *TodoCollector
func (*TodoCollector) ByToolCallID ¶
func (c *TodoCollector) ByToolCallID(id string) []sleipnir.TodoItem
func (*TodoCollector) Send ¶
func (c *TodoCollector) Send(e sleipnir.Event)