testutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConcurrencyTestMu sync.Mutex

ConcurrencyTestMu protects concurrent access to global concurrency settings during benchmark tests to prevent race conditions.

Functions

func BenchmarkAccuracyMetric

func BenchmarkAccuracyMetric(expected, actual map[string]interface{}) float64

BenchmarkAccuracyMetric provides a standard accuracy metric for benchmarking.

func BenchmarkDatasetFromExamples

func BenchmarkDatasetFromExamples(examples []core.Example) core.Dataset

BenchmarkDatasetFromExamples converts examples to a dataset interface.

func CreateBenchmarkDatasets

func CreateBenchmarkDatasets() map[string]BenchmarkDataset

CreateBenchmarkDatasets creates standardized datasets for benchmarking optimizers.

func CreateBenchmarkProgram

func CreateBenchmarkProgram(predictor core.Module) core.Program

CreateBenchmarkProgram creates a standard program for benchmarking optimizers. The predictor parameter should be a modules.Predict instance to avoid import cycles.

func LogBenchmarkResult

func LogBenchmarkResult(result BenchmarkResult)

LogBenchmarkResult logs benchmark results in a structured format.

func StandardBenchmarkConfigs

func StandardBenchmarkConfigs() map[string]BenchmarkConfig

StandardBenchmarkConfigs provides predefined benchmark configurations.

Types

type BenchmarkConfig

type BenchmarkConfig struct {
	DatasetSize int
	Breadth     int
	Depth       int
	MaxSteps    int
	BatchSize   int
	NumTrials   int
	Temperature float64
	Timeout     int // seconds
}

BenchmarkConfig represents common benchmark configuration.

type BenchmarkDataset

type BenchmarkDataset struct {
	Name     string
	Size     int
	Examples []core.Example
}

BenchmarkDataset represents different dataset sizes for benchmarking.

type BenchmarkMetrics

type BenchmarkMetrics struct {
	CompilationTime float64
	AverageScore    float64
	TotalExamples   int
	TokensUsed      int
}

BenchmarkMetrics tracks performance metrics during benchmarking.

type BenchmarkResult

type BenchmarkResult struct {
	OptimizerName   string
	Config          BenchmarkConfig
	CompilationTime float64 // seconds
	AverageScore    float64
	TotalExamples   int
	Success         bool
	Error           string
}

BenchmarkResult captures the results of a benchmark run.

type MockCoreTool

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

Copied from pkg/tools/registry_test.go.

func NewMockCoreTool

func NewMockCoreTool(name, description string, executeFunc func(ctx context.Context, args map[string]interface{}) (core.ToolResult, error)) *MockCoreTool

NewMockCoreTool creates a new MockCoreTool instance.

func (*MockCoreTool) CanHandle

func (m *MockCoreTool) CanHandle(ctx context.Context, intent string) bool

func (*MockCoreTool) Description

func (m *MockCoreTool) Description() string

func (*MockCoreTool) Execute

func (m *MockCoreTool) Execute(ctx context.Context, args map[string]interface{}) (core.ToolResult, error)

func (*MockCoreTool) InputSchema

func (m *MockCoreTool) InputSchema() models.InputSchema

func (*MockCoreTool) Metadata

func (m *MockCoreTool) Metadata() *core.ToolMetadata

func (*MockCoreTool) Name

func (m *MockCoreTool) Name() string

func (*MockCoreTool) Validate

func (m *MockCoreTool) Validate(params map[string]interface{}) error

type MockDataset

type MockDataset struct {
	mock.Mock
	Examples []core.Example
	Index    int
	// contains filtered or unexported fields
}

MockDataset is a mock implementation of core.Dataset.

func NewMockDataset

func NewMockDataset(examples []core.Example) *MockDataset

NewMockDataset creates a new MockDataset with the given examples.

func (*MockDataset) Next

func (m *MockDataset) Next() (core.Example, bool)

func (*MockDataset) Reset

func (m *MockDataset) Reset()

Reset resets the dataset iterator.

type MockLLM

type MockLLM struct {
	mock.Mock
}

MockLLM is a mock implementation of core.LLM.

func (*MockLLM) Capabilities

func (m *MockLLM) Capabilities() []core.Capability

func (*MockLLM) CreateEmbedding

func (m *MockLLM) CreateEmbedding(ctx context.Context, input string, options ...core.EmbeddingOption) (*core.EmbeddingResult, error)

CreateEmbedding mocks the single embedding creation following the same pattern as Generate.

func (*MockLLM) CreateEmbeddings

func (m *MockLLM) CreateEmbeddings(ctx context.Context, inputs []string, options ...core.EmbeddingOption) (*core.BatchEmbeddingResult, error)

CreateEmbeddings mocks the batch embedding creation.

func (*MockLLM) Generate

func (m *MockLLM) Generate(ctx context.Context, prompt string, opts ...core.GenerateOption) (*core.LLMResponse, error)

func (*MockLLM) GenerateWithContent

func (m *MockLLM) GenerateWithContent(ctx context.Context, content []core.ContentBlock, options ...core.GenerateOption) (*core.LLMResponse, error)

func (*MockLLM) GenerateWithFunctions

func (m *MockLLM) GenerateWithFunctions(ctx context.Context, prompt string, functions []map[string]interface{}, options ...core.GenerateOption) (map[string]interface{}, error)

func (*MockLLM) GenerateWithJSON

func (m *MockLLM) GenerateWithJSON(ctx context.Context, prompt string, opts ...core.GenerateOption) (map[string]interface{}, error)

func (*MockLLM) ModelID

func (m *MockLLM) ModelID() string

ModelID mocks the GetModelID method from the LLM interface.

func (*MockLLM) ProviderName

func (m *MockLLM) ProviderName() string

GetProviderName mocks the GetProviderName method from the LLM interface.

func (*MockLLM) StreamGenerate

func (m *MockLLM) StreamGenerate(ctx context.Context, prompt string, opts ...core.GenerateOption) (*core.StreamResponse, error)

func (*MockLLM) StreamGenerateWithContent

func (m *MockLLM) StreamGenerateWithContent(ctx context.Context, content []core.ContentBlock, options ...core.GenerateOption) (*core.StreamResponse, error)

type MockMCPClient

type MockMCPClient struct {
	ListToolsFunc func(ctx context.Context, cursor *models.Cursor) (*models.ListToolsResult, error)
	// Corrected CallToolFunc signature again to match MCPClientInterface
	CallToolFunc func(ctx context.Context, toolName string, arguments map[string]interface{}) (*models.CallToolResult, error)
}

MockMCPClient provides a mock implementation of the MCPClient interface (or relevant parts).

func NewMockMCPClientWithTools

func NewMockMCPClientWithTools() *MockMCPClient

NewMockMCPClientWithTools creates a MockMCPClient pre-configured with standard mock tools.

func (*MockMCPClient) CallTool

func (m *MockMCPClient) CallTool(ctx context.Context, toolName string, arguments map[string]interface{}) (*models.CallToolResult, error)

Corrected CallTool signature again to match MCPClientInterface.

func (*MockMCPClient) ListTools

func (m *MockMCPClient) ListTools(ctx context.Context, cursor *models.Cursor) (*models.ListToolsResult, error)

ListTools calls the underlying ListToolsFunc.

type MockModule

type MockModule struct {
	mock.Mock
	// contains filtered or unexported fields
}

MockModule is a mock implementation of core.Module.

func NewMockModule

func NewMockModule(instruction string) *MockModule

NewMockModule creates a new MockModule with the given instruction.

func (*MockModule) Clone

func (m *MockModule) Clone() core.Module

func (*MockModule) GetDisplayName

func (m *MockModule) GetDisplayName() string

func (*MockModule) GetModuleType

func (m *MockModule) GetModuleType() string

func (*MockModule) GetSignature

func (m *MockModule) GetSignature() core.Signature

func (*MockModule) Process

func (m *MockModule) Process(ctx context.Context, inputs map[string]any, opts ...core.Option) (map[string]any, error)

func (*MockModule) SetLLM

func (m *MockModule) SetLLM(llm core.LLM)

func (*MockModule) SetSignature

func (m *MockModule) SetSignature(signature core.Signature)

func (*MockModule) UpdateInstruction

func (m *MockModule) UpdateInstruction(instruction string)

type MockStreamConfig

type MockStreamConfig struct {
	Content      string
	ChunkSize    int
	ChunkDelay   time.Duration
	Error        error
	ErrorAfter   int
	TokenCounts  *core.TokenInfo
	ShouldCancel bool
	mock.Mock
}

MockStreamConfig configures how the mock LLM will stream responses during tests.

type MockTool

type MockTool struct {
	mock.Mock
	// contains filtered or unexported fields
}

func NewMockTool

func NewMockTool(name string) *MockTool

NewMockTool creates a new mock tool with default metadata.

func (*MockTool) CanHandle

func (m *MockTool) CanHandle(ctx context.Context, intent string) bool

CanHandle implements the Tool interface.

func (*MockTool) Description

func (m *MockTool) Description() string

func (*MockTool) Execute

func (m *MockTool) Execute(ctx context.Context, params map[string]interface{}) (core.ToolResult, error)

Execute implements the Tool interface.

func (*MockTool) InputSchema

func (m *MockTool) InputSchema() models.InputSchema

func (*MockTool) Metadata

func (m *MockTool) Metadata() *core.ToolMetadata

Metadata implements the Tool interface.

func (*MockTool) Name

func (m *MockTool) Name() string

func (*MockTool) Validate

func (m *MockTool) Validate(params map[string]interface{}) error

Validate implements the Tool interface.

Jump to

Keyboard shortcuts

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