testutil

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2026 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package testutil provides shared test helpers for the goagent module.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MockEmbedder

type MockEmbedder struct {
	Dim int // vector dimension; defaults to 16 when zero
}

MockEmbedder generates deterministic embeddings via an LCG seeded with the FNV-32a hash of the text content. Makes no API calls. The same text always produces the same normalized vector. Use in unit tests that need similarity search without external services.

func (*MockEmbedder) Embed

func (m *MockEmbedder) Embed(_ context.Context, blocks []goagent.ContentBlock) ([]float32, error)

Embed returns a deterministic unit-length vector for the text content of blocks. Returns vector.ErrNoEmbeddeableContent when blocks contain no text.

type MockLongTermMemory

type MockLongTermMemory struct {
	// contains filtered or unexported fields
}

MockLongTermMemory is a thread-safe LongTermMemory implementation for tests.

func NewMockLongTermMemory

func NewMockLongTermMemory() *MockLongTermMemory

NewMockLongTermMemory creates a MockLongTermMemory that stores all messages and returns an empty slice from Retrieve by default.

func NewMockLongTermMemoryWithErrors

func NewMockLongTermMemoryWithErrors(storeErr, retrieveErr error) *MockLongTermMemory

NewMockLongTermMemoryWithErrors creates a MockLongTermMemory that returns the given errors from Store and Retrieve respectively.

func NewMockLongTermMemoryWithRetrieve

func NewMockLongTermMemoryWithRetrieve(retrieved ...goagent.Message) *MockLongTermMemory

NewMockLongTermMemoryWithRetrieve creates a MockLongTermMemory that returns the given messages (with Score 0.0) as the fixed response to every Retrieve call.

func (*MockLongTermMemory) AllStored

func (m *MockLongTermMemory) AllStored() []goagent.Message

AllStored returns all messages passed to Store as a defensive copy.

func (*MockLongTermMemory) Retrieve

Retrieve returns the fixed retrieved slice. Returns retrieveErr if configured.

func (*MockLongTermMemory) Store

func (m *MockLongTermMemory) Store(_ context.Context, msgs ...goagent.Message) error

Store records msgs. Returns storeErr if configured.

type MockMemory

type MockMemory struct {
	// contains filtered or unexported fields
}

MockMemory is a thread-safe ShortTermMemory implementation for tests. It records all Append calls and can be configured to return errors.

func NewMockMemory

func NewMockMemory() *MockMemory

NewMockMemory creates a MockMemory with no pre-loaded history and no errors.

func NewMockMemoryWithErrors

func NewMockMemoryWithErrors(appendErr, messagesErr error) *MockMemory

NewMockMemoryWithErrors creates a MockMemory that returns the given errors from Append and Messages respectively. Pass nil to not error on that method.

func NewMockMemoryWithHistory

func NewMockMemoryWithHistory(msgs ...goagent.Message) *MockMemory

NewMockMemoryWithHistory creates a MockMemory pre-loaded with the given messages.

func (*MockMemory) All

func (m *MockMemory) All() []goagent.Message

All returns all stored messages as a defensive copy.

func (*MockMemory) Append

func (m *MockMemory) Append(_ context.Context, msgs ...goagent.Message) error

Append records the messages. Returns appendErr if configured.

func (*MockMemory) Messages

func (m *MockMemory) Messages(_ context.Context) ([]goagent.Message, error)

Messages returns the stored messages. Returns messagesErr if configured.

type MockProvider

type MockProvider struct {
	// contains filtered or unexported fields
}

MockProvider is a thread-safe Provider that returns pre-configured responses in FIFO order. Use it in unit tests to avoid requiring a live LLM.

func NewMockProvider

func NewMockProvider(responses ...goagent.CompletionResponse) *MockProvider

NewMockProvider creates a MockProvider that will return the given responses in order. If Complete is called more times than there are responses, it returns an error.

func (*MockProvider) Calls

func (m *MockProvider) Calls() []goagent.CompletionRequest

Calls returns all requests received so far, in order. Safe to call after the test has finished.

func (*MockProvider) Complete

Complete returns the next queued response. It is safe for concurrent use.

type MockStream added in v0.7.0

type MockStream struct {
	Events []goagent.StreamEvent
	// contains filtered or unexported fields
}

MockStream is an exported Stream backed by a fixed slice of events. Use it when a test needs fine-grained control over stream contents.

func (*MockStream) Close added in v0.7.0

func (s *MockStream) Close() error

func (*MockStream) Err added in v0.7.0

func (s *MockStream) Err() error

func (*MockStream) Event added in v0.7.0

func (s *MockStream) Event() goagent.StreamEvent

func (*MockStream) Next added in v0.7.0

func (s *MockStream) Next(_ context.Context) bool

type MockStreamingProvider added in v0.7.0

type MockStreamingProvider struct {
	*MockProvider
	// contains filtered or unexported fields
}

MockStreamingProvider is a Provider that also implements goagent.StreamingProvider. It embeds MockProvider for the non-streaming Complete path.

func NewMockStreamingProvider added in v0.7.0

func NewMockStreamingProvider(
	events []goagent.StreamEvent,
	responses ...goagent.CompletionResponse,
) *MockStreamingProvider

NewMockStreamingProvider creates a MockStreamingProvider. events are returned by CompleteStream; responses are returned by Complete.

func (*MockStreamingProvider) CompleteStream added in v0.7.0

CompleteStream implements goagent.StreamingProvider.

func (*MockStreamingProvider) WithStreamError added in v0.7.0

func (m *MockStreamingProvider) WithStreamError(err error)

WithStreamError configures CompleteStream to return err instead of a stream.

type MockTool

type MockTool struct {
	// contains filtered or unexported fields
}

MockTool is a Tool implementation for use in tests.

func NewMockTool

func NewMockTool(name, description, result string) *MockTool

NewMockTool creates a tool that always returns result as a text block with no error.

func NewMockToolWithError

func NewMockToolWithError(name, description string, err error) *MockTool

NewMockToolWithError creates a tool that always returns the given error.

func (*MockTool) Definition

func (m *MockTool) Definition() goagent.ToolDefinition

func (*MockTool) Execute

func (m *MockTool) Execute(_ context.Context, _ map[string]any) ([]goagent.ContentBlock, error)

Jump to

Keyboard shortcuts

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