testutil

package
v0.76.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 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 added in v0.41.0

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

BenchmarkAccuracyMetric provides a standard accuracy metric for benchmarking.

func BenchmarkDatasetFromExamples added in v0.41.0

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

BenchmarkDatasetFromExamples converts examples to a dataset interface.

func CreateBenchmarkDatasets added in v0.41.0

func CreateBenchmarkDatasets() map[string]BenchmarkDataset

CreateBenchmarkDatasets creates standardized datasets for benchmarking optimizers.

func CreateBenchmarkProgram added in v0.41.0

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 added in v0.41.0

func LogBenchmarkResult(result BenchmarkResult)

LogBenchmarkResult logs benchmark results in a structured format.

func StandardBenchmarkConfigs added in v0.41.0

func StandardBenchmarkConfigs() map[string]BenchmarkConfig

StandardBenchmarkConfigs provides predefined benchmark configurations.

Types

type BenchmarkConfig added in v0.41.0

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 added in v0.41.0

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

BenchmarkDataset represents different dataset sizes for benchmarking.

type BenchmarkMetrics added in v0.41.0

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

BenchmarkMetrics tracks performance metrics during benchmarking.

type BenchmarkResult added in v0.41.0

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 added in v0.27.0

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

Copied from pkg/tools/registry_test.go.

func NewMockCoreTool added in v0.27.0

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 added in v0.27.0

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

func (*MockCoreTool) Description added in v0.27.0

func (m *MockCoreTool) Description() string

func (*MockCoreTool) Execute added in v0.27.0

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

func (*MockCoreTool) InputSchema added in v0.27.0

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

func (*MockCoreTool) Metadata added in v0.27.0

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

func (*MockCoreTool) Name added in v0.27.0

func (m *MockCoreTool) Name() string

func (*MockCoreTool) Validate added in v0.27.0

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 added in v0.14.0

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

func (*MockLLM) CreateEmbedding added in v0.16.1

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 added in v0.16.1

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 added in v0.38.0

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

func (*MockLLM) GenerateWithFunctions added in v0.20.0

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 added in v0.14.0

func (m *MockLLM) ModelID() string

ModelID mocks the GetModelID method from the LLM interface.

func (*MockLLM) ProviderName added in v0.14.0

func (m *MockLLM) ProviderName() string

GetProviderName mocks the GetProviderName method from the LLM interface.

func (*MockLLM) StreamGenerate added in v0.23.0

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

func (*MockLLM) StreamGenerateWithContent added in v0.38.0

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

type MockMCPClient added in v0.27.0

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 added in v0.27.0

func NewMockMCPClientWithTools() *MockMCPClient

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

func (*MockMCPClient) CallTool added in v0.27.0

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 added in v0.27.0

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

ListTools calls the underlying ListToolsFunc.

type MockModule added in v0.46.0

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

MockModule is a mock implementation of core.Module.

func NewMockModule added in v0.46.0

func NewMockModule(instruction string) *MockModule

NewMockModule creates a new MockModule with the given instruction.

func (*MockModule) Clone added in v0.46.0

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

func (*MockModule) GetDisplayName added in v0.46.0

func (m *MockModule) GetDisplayName() string

func (*MockModule) GetModuleType added in v0.46.0

func (m *MockModule) GetModuleType() string

func (*MockModule) GetSignature added in v0.46.0

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

func (*MockModule) Process added in v0.46.0

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

func (*MockModule) SetLLM added in v0.46.0

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

func (*MockModule) SetSignature added in v0.46.0

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

func (*MockModule) UpdateInstruction added in v0.46.0

func (m *MockModule) UpdateInstruction(instruction string)

type MockStreamConfig added in v0.23.0

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 added in v0.18.0

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

func NewMockTool added in v0.18.0

func NewMockTool(name string) *MockTool

NewMockTool creates a new mock tool with default metadata.

func (*MockTool) CanHandle added in v0.18.0

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

CanHandle implements the Tool interface.

func (*MockTool) Description added in v0.24.0

func (m *MockTool) Description() string

func (*MockTool) Execute added in v0.18.0

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

Execute implements the Tool interface.

func (*MockTool) InputSchema added in v0.24.0

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

func (*MockTool) Metadata added in v0.18.0

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

Metadata implements the Tool interface.

func (*MockTool) Name added in v0.24.0

func (m *MockTool) Name() string

func (*MockTool) Validate added in v0.18.0

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