mocks

package
v0.0.0-...-5ed4770 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package mocks provides test doubles for the agent package.

Package mocks provides test doubles for the agent package.

Index

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:

  1. No tool results in messages → return a request_capabilities tool call.
  2. 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.
  3. 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

Stream delegates to Generate and wraps the result in a StreamReader.

func (*AutoToolMockChatModel) WithTools

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:

  1. Expectation-based (testify/mock): use On("Generate").Return(...) or On("Generate").RunAndReturn(...) to configure per-call behaviour.

  2. 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:

  1. If a testify expectation is registered (via On("Generate")), use it.
  2. If the call index falls within toolCallSequence, return those tool calls.
  3. 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

type StatisticsStore struct {
	mock.Mock
}

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 (*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

func (_m *StatisticsStore) RecordLLMStat(ctx context.Context, stat *store.LLMStat) error

RecordLLMStat provides a mock function with given fields: ctx, stat

func (*StatisticsStore) RecordTokenUsage

func (_m *StatisticsStore) RecordTokenUsage(ctx context.Context, stat *store.TokenStat) error

RecordTokenUsage provides a mock function with given fields: ctx, stat

func (*StatisticsStore) RecordToolStat

func (_m *StatisticsStore) RecordToolStat(ctx context.Context, stat *store.ToolStat) error

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

type StatisticsStore_RecordIntentStat_Call struct {
	*mock.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 (*StatisticsStore_RecordIntentStat_Call) Run

func (*StatisticsStore_RecordIntentStat_Call) RunAndReturn

type StatisticsStore_RecordLLMStat_Call

type StatisticsStore_RecordLLMStat_Call struct {
	*mock.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 (*StatisticsStore_RecordLLMStat_Call) Run

func (*StatisticsStore_RecordLLMStat_Call) RunAndReturn

type StatisticsStore_RecordTokenUsage_Call

type StatisticsStore_RecordTokenUsage_Call struct {
	*mock.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 (*StatisticsStore_RecordTokenUsage_Call) Run

func (*StatisticsStore_RecordTokenUsage_Call) RunAndReturn

type StatisticsStore_RecordToolStat_Call

type StatisticsStore_RecordToolStat_Call struct {
	*mock.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 (*StatisticsStore_RecordToolStat_Call) Run

func (*StatisticsStore_RecordToolStat_Call) RunAndReturn

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL