Documentation
¶
Overview ¶
Package mocks provides test doubles for the agent package.
Package mocks provides test doubles for the agent package.
Index ¶
- type AutoToolMockChatModel
- func (m *AutoToolMockChatModel) Generate(_ context.Context, messages []*schema.Message, _ ...model.Option) (*schema.Message, error)
- func (m *AutoToolMockChatModel) Stream(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
- func (m *AutoToolMockChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type MockChatModel
- func (m *MockChatModel) BoundTools() []*schema.ToolInfo
- func (m *MockChatModel) CallCount() int64
- func (m *MockChatModel) Generate(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.Message, error)
- func (m *MockChatModel) SetResponses(responses ...string)
- func (m *MockChatModel) SetTokenUsage(usage *schema.TokenUsage)
- func (m *MockChatModel) SetToolCallSequence(calls [][]ToolCallSpec)
- func (m *MockChatModel) Stream(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
- func (m *MockChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
- type StatisticsStore
- func (_m *StatisticsStore) EXPECT() *StatisticsStore_Expecter
- func (_m *StatisticsStore) RecordIntentStat(ctx context.Context, stat *store.IntentStat) error
- func (_m *StatisticsStore) RecordLLMStat(ctx context.Context, stat *store.LLMStat) error
- func (_m *StatisticsStore) RecordTokenUsage(ctx context.Context, stat *store.TokenStat) error
- func (_m *StatisticsStore) RecordToolStat(ctx context.Context, stat *store.ToolStat) error
- type StatisticsStore_Expecter
- func (_e *StatisticsStore_Expecter) RecordIntentStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordIntentStat_Call
- func (_e *StatisticsStore_Expecter) RecordLLMStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordLLMStat_Call
- func (_e *StatisticsStore_Expecter) RecordTokenUsage(ctx interface{}, stat interface{}) *StatisticsStore_RecordTokenUsage_Call
- func (_e *StatisticsStore_Expecter) RecordToolStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordToolStat_Call
- type StatisticsStore_RecordIntentStat_Call
- func (_c *StatisticsStore_RecordIntentStat_Call) Return(_a0 error) *StatisticsStore_RecordIntentStat_Call
- func (_c *StatisticsStore_RecordIntentStat_Call) Run(run func(ctx context.Context, stat *store.IntentStat)) *StatisticsStore_RecordIntentStat_Call
- func (_c *StatisticsStore_RecordIntentStat_Call) RunAndReturn(run func(context.Context, *store.IntentStat) error) *StatisticsStore_RecordIntentStat_Call
- type StatisticsStore_RecordLLMStat_Call
- func (_c *StatisticsStore_RecordLLMStat_Call) Return(_a0 error) *StatisticsStore_RecordLLMStat_Call
- func (_c *StatisticsStore_RecordLLMStat_Call) Run(run func(ctx context.Context, stat *store.LLMStat)) *StatisticsStore_RecordLLMStat_Call
- func (_c *StatisticsStore_RecordLLMStat_Call) RunAndReturn(run func(context.Context, *store.LLMStat) error) *StatisticsStore_RecordLLMStat_Call
- type StatisticsStore_RecordTokenUsage_Call
- func (_c *StatisticsStore_RecordTokenUsage_Call) Return(_a0 error) *StatisticsStore_RecordTokenUsage_Call
- func (_c *StatisticsStore_RecordTokenUsage_Call) Run(run func(ctx context.Context, stat *store.TokenStat)) *StatisticsStore_RecordTokenUsage_Call
- func (_c *StatisticsStore_RecordTokenUsage_Call) RunAndReturn(run func(context.Context, *store.TokenStat) error) *StatisticsStore_RecordTokenUsage_Call
- type StatisticsStore_RecordToolStat_Call
- func (_c *StatisticsStore_RecordToolStat_Call) Return(_a0 error) *StatisticsStore_RecordToolStat_Call
- func (_c *StatisticsStore_RecordToolStat_Call) Run(run func(ctx context.Context, stat *store.ToolStat)) *StatisticsStore_RecordToolStat_Call
- func (_c *StatisticsStore_RecordToolStat_Call) RunAndReturn(run func(context.Context, *store.ToolStat) error) *StatisticsStore_RecordToolStat_Call
- type ToolCallSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AutoToolMockChatModel ¶
type AutoToolMockChatModel struct {
// contains filtered or unexported fields
}
AutoToolMockChatModel is a mock ChatModel that automatically exercises the capability tools (request_capabilities + call_capability) in the standard Sequify agent loop.
Behaviour per Generate call:
- No tool results in messages → return a request_capabilities tool call.
- Tool result from request_capabilities present → parse capability names and parameter definitions from the Markdown response, then return call_capability tool calls for each discovered capability.
- Tool results from call_capability present → return a text summary that echoes the tool results and the user's original message so that keyword-based test assertions (e.g. error messages, capability outputs) pass without a real LLM.
Parameter values are derived from the user's original message so that keyword-based test assertions pass (e.g. "settings" in a navigate_to URL).
This mock is designed for integration/E2E tests that run with SEQUIFY_LLM__PROVIDER=mock and need the agent to exercise the full tool-calling loop without a real LLM.
AutoToolMockChatModel is safe for concurrent use.
func NewAutoToolMockChatModel ¶
func NewAutoToolMockChatModel() *AutoToolMockChatModel
NewAutoToolMockChatModel creates an AutoToolMockChatModel.
func (*AutoToolMockChatModel) Generate ¶
func (m *AutoToolMockChatModel) Generate(_ context.Context, messages []*schema.Message, _ ...model.Option) (*schema.Message, error)
Generate examines the conversation history and returns the appropriate mock response for the current stage of the tool-calling loop.
func (*AutoToolMockChatModel) Stream ¶
func (m *AutoToolMockChatModel) Stream(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
Stream delegates to Generate and wraps the result in a StreamReader.
func (*AutoToolMockChatModel) WithTools ¶
func (m *AutoToolMockChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
WithTools binds the given tools to the mock and returns the same instance.
type MockChatModel ¶
type MockChatModel struct {
testifymock.Mock
// contains filtered or unexported fields
}
MockChatModel implements model.ToolCallingChatModel for testing.
It supports two usage modes:
Expectation-based (testify/mock): use On("Generate").Return(...) or On("Generate").RunAndReturn(...) to configure per-call behaviour.
Configuration-based: use the factory functions (NewSimpleMockChatModel, NewToolCallingMockChatModel) or set fields directly (Responses, ToolCallSequence, TokenUsage) for quick setup without expectations.
When an expectation is registered via On(), it takes precedence over the configuration fields. This allows mixing both modes in the same test.
MockChatModel is safe for concurrent use.
func NewMockChatModel ¶
func NewMockChatModel() *MockChatModel
NewMockChatModel creates an empty MockChatModel. Configure it via expectation-based On() calls or by calling helper methods such as SetResponses and SetToolCallSequence.
func NewSimpleMockChatModel ¶
func NewSimpleMockChatModel(responses ...string) *MockChatModel
NewSimpleMockChatModel creates a MockChatModel that cycles through the given text responses. Each call to Generate returns the next response (wrapping around). Token usage is set to 10 prompt + 20 completion tokens.
func NewToolCallingMockChatModel ¶
func NewToolCallingMockChatModel(toolCalls [][]ToolCallSpec, finalResponses ...string) *MockChatModel
NewToolCallingMockChatModel creates a MockChatModel that returns the specified tool calls on the first N Generate calls (where N = len(toolCalls)), then cycles through finalResponses for subsequent calls.
This is useful for testing ReAct agent loops: the agent receives tool calls, executes them, sends tool results back, and eventually gets a text response.
Example:
m := NewToolCallingMockChatModel(
[][]ToolCallSpec{
{{Name: "search", Arguments: `{"q":"weather"}`}},
},
"The weather is sunny.",
)
func (*MockChatModel) BoundTools ¶
func (m *MockChatModel) BoundTools() []*schema.ToolInfo
BoundTools returns the tools most recently bound via WithTools.
func (*MockChatModel) CallCount ¶
func (m *MockChatModel) CallCount() int64
CallCount returns the total number of Generate calls made so far.
func (*MockChatModel) Generate ¶
func (m *MockChatModel) Generate(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.Message, error)
Generate returns a mock response based on the current configuration.
Resolution order:
- If a testify expectation is registered (via On("Generate")), use it.
- If the call index falls within toolCallSequence, return those tool calls.
- Otherwise, return the next text response (cycling through responses).
func (*MockChatModel) SetResponses ¶
func (m *MockChatModel) SetResponses(responses ...string)
SetResponses configures the predefined text responses to cycle through.
func (*MockChatModel) SetTokenUsage ¶
func (m *MockChatModel) SetTokenUsage(usage *schema.TokenUsage)
SetTokenUsage configures the token usage reported in every response.
func (*MockChatModel) SetToolCallSequence ¶
func (m *MockChatModel) SetToolCallSequence(calls [][]ToolCallSpec)
SetToolCallSequence configures the tool calls to return before falling back to text responses.
func (*MockChatModel) Stream ¶
func (m *MockChatModel) Stream(ctx context.Context, messages []*schema.Message, opts ...model.Option) (*schema.StreamReader[*schema.Message], error)
Stream returns a StreamReader that yields a single mock message. It delegates to Generate internally.
If a testify expectation is registered for "Stream", it takes precedence.
func (*MockChatModel) WithTools ¶
func (m *MockChatModel) WithTools(tools []*schema.ToolInfo) (model.ToolCallingChatModel, error)
WithTools binds the given tools to the mock and returns the same instance. This matches the behaviour of other test mocks in the codebase: the mock is mutated in place rather than returning a copy, which is acceptable for single-goroutine test scenarios.
type StatisticsStore ¶
StatisticsStore is an autogenerated mock type for the StatisticsStore type
func NewStatisticsStore ¶
func NewStatisticsStore(t interface {
mock.TestingT
Cleanup(func())
}) *StatisticsStore
NewStatisticsStore creates a new instance of StatisticsStore. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. The first argument is typically a *testing.T value.
func (*StatisticsStore) EXPECT ¶
func (_m *StatisticsStore) EXPECT() *StatisticsStore_Expecter
func (*StatisticsStore) RecordIntentStat ¶
func (_m *StatisticsStore) RecordIntentStat(ctx context.Context, stat *store.IntentStat) error
RecordIntentStat provides a mock function with given fields: ctx, stat
func (*StatisticsStore) RecordLLMStat ¶
RecordLLMStat provides a mock function with given fields: ctx, stat
func (*StatisticsStore) RecordTokenUsage ¶
RecordTokenUsage provides a mock function with given fields: ctx, stat
func (*StatisticsStore) RecordToolStat ¶
RecordToolStat provides a mock function with given fields: ctx, stat
type StatisticsStore_Expecter ¶
type StatisticsStore_Expecter struct {
// contains filtered or unexported fields
}
func (*StatisticsStore_Expecter) RecordIntentStat ¶
func (_e *StatisticsStore_Expecter) RecordIntentStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordIntentStat_Call
RecordIntentStat is a helper method to define mock.On call
- ctx context.Context
- stat *store.IntentStat
func (*StatisticsStore_Expecter) RecordLLMStat ¶
func (_e *StatisticsStore_Expecter) RecordLLMStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordLLMStat_Call
RecordLLMStat is a helper method to define mock.On call
- ctx context.Context
- stat *store.LLMStat
func (*StatisticsStore_Expecter) RecordTokenUsage ¶
func (_e *StatisticsStore_Expecter) RecordTokenUsage(ctx interface{}, stat interface{}) *StatisticsStore_RecordTokenUsage_Call
RecordTokenUsage is a helper method to define mock.On call
- ctx context.Context
- stat *store.TokenStat
func (*StatisticsStore_Expecter) RecordToolStat ¶
func (_e *StatisticsStore_Expecter) RecordToolStat(ctx interface{}, stat interface{}) *StatisticsStore_RecordToolStat_Call
RecordToolStat is a helper method to define mock.On call
- ctx context.Context
- stat *store.ToolStat
type StatisticsStore_RecordIntentStat_Call ¶
StatisticsStore_RecordIntentStat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordIntentStat'
func (*StatisticsStore_RecordIntentStat_Call) Return ¶
func (_c *StatisticsStore_RecordIntentStat_Call) Return(_a0 error) *StatisticsStore_RecordIntentStat_Call
func (*StatisticsStore_RecordIntentStat_Call) Run ¶
func (_c *StatisticsStore_RecordIntentStat_Call) Run(run func(ctx context.Context, stat *store.IntentStat)) *StatisticsStore_RecordIntentStat_Call
func (*StatisticsStore_RecordIntentStat_Call) RunAndReturn ¶
func (_c *StatisticsStore_RecordIntentStat_Call) RunAndReturn(run func(context.Context, *store.IntentStat) error) *StatisticsStore_RecordIntentStat_Call
type StatisticsStore_RecordLLMStat_Call ¶
StatisticsStore_RecordLLMStat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordLLMStat'
func (*StatisticsStore_RecordLLMStat_Call) Return ¶
func (_c *StatisticsStore_RecordLLMStat_Call) Return(_a0 error) *StatisticsStore_RecordLLMStat_Call
func (*StatisticsStore_RecordLLMStat_Call) Run ¶
func (_c *StatisticsStore_RecordLLMStat_Call) Run(run func(ctx context.Context, stat *store.LLMStat)) *StatisticsStore_RecordLLMStat_Call
func (*StatisticsStore_RecordLLMStat_Call) RunAndReturn ¶
func (_c *StatisticsStore_RecordLLMStat_Call) RunAndReturn(run func(context.Context, *store.LLMStat) error) *StatisticsStore_RecordLLMStat_Call
type StatisticsStore_RecordTokenUsage_Call ¶
StatisticsStore_RecordTokenUsage_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordTokenUsage'
func (*StatisticsStore_RecordTokenUsage_Call) Return ¶
func (_c *StatisticsStore_RecordTokenUsage_Call) Return(_a0 error) *StatisticsStore_RecordTokenUsage_Call
func (*StatisticsStore_RecordTokenUsage_Call) Run ¶
func (_c *StatisticsStore_RecordTokenUsage_Call) Run(run func(ctx context.Context, stat *store.TokenStat)) *StatisticsStore_RecordTokenUsage_Call
func (*StatisticsStore_RecordTokenUsage_Call) RunAndReturn ¶
func (_c *StatisticsStore_RecordTokenUsage_Call) RunAndReturn(run func(context.Context, *store.TokenStat) error) *StatisticsStore_RecordTokenUsage_Call
type StatisticsStore_RecordToolStat_Call ¶
StatisticsStore_RecordToolStat_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'RecordToolStat'
func (*StatisticsStore_RecordToolStat_Call) Return ¶
func (_c *StatisticsStore_RecordToolStat_Call) Return(_a0 error) *StatisticsStore_RecordToolStat_Call
func (*StatisticsStore_RecordToolStat_Call) Run ¶
func (_c *StatisticsStore_RecordToolStat_Call) Run(run func(ctx context.Context, stat *store.ToolStat)) *StatisticsStore_RecordToolStat_Call
func (*StatisticsStore_RecordToolStat_Call) RunAndReturn ¶
func (_c *StatisticsStore_RecordToolStat_Call) RunAndReturn(run func(context.Context, *store.ToolStat) error) *StatisticsStore_RecordToolStat_Call
type ToolCallSpec ¶
type ToolCallSpec struct {
// ID is the unique tool call identifier. Auto-generated if empty.
ID string
// Name is the tool function name.
Name string
// Arguments is the JSON-encoded arguments string.
Arguments string
}
ToolCallSpec specifies a tool call to include in a mock response.