Documentation
¶
Overview ¶
Package testutil provides deterministic, dependency-free test doubles for building examples and tests against manglekit without external services or API keys:
- MockLLM: a scripted core.TextGenerator
- DeterministicEmbedder / NewLengthEmbedder / NewKeywordEmbedder: deterministic core.Embedder implementations
- InMemoryStateProvider: a core.StateProvider backed by a map
- WorkflowSessionStore: an in-memory ports.SessionStateStore
Everything here is deterministic and safe for concurrent use.
Index ¶
- type DeterministicEmbedder
- type InMemoryStateProvider
- func (p *InMemoryStateProvider) Close(_ context.Context) error
- func (p *InMemoryStateProvider) Delete(_ context.Context, sessionID string) error
- func (p *InMemoryStateProvider) Get(_ context.Context, sessionID string) (any, error)
- func (p *InMemoryStateProvider) Set(_ context.Context, sessionID string, state any) error
- func (p *InMemoryStateProvider) Size() int
- type MockLLM
- func (m *MockLLM) Calls() int
- func (m *MockLLM) Complete(_ context.Context, prompt string) (string, error)
- func (m *MockLLM) Generate(_ context.Context, prompt string, _ ...core.GenerateOption) (*core.LLMResponse, error)
- func (m *MockLLM) Prompts() []string
- func (m *MockLLM) Stream(ctx context.Context, prompt string) (<-chan core.StreamChunk, error)
- type WorkflowSessionStore
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeterministicEmbedder ¶
type DeterministicEmbedder struct {
// Dim is the vector dimension reported by Dimension().
Dim int
// VecFor maps text to its vector. It must be pure and deterministic.
VecFor func(text string) []float32
}
DeterministicEmbedder is a core.Embedder whose vectors are a pure function of the input text. Construct it with NewLengthEmbedder or NewKeywordEmbedder, or directly with a custom VecFor function.
func NewKeywordEmbedder ¶
func NewKeywordEmbedder(keywords map[string][]float32, fallback []float32) *DeterministicEmbedder
NewKeywordEmbedder returns an embedder that returns a fixed vector when the text contains any of the given keyword substrings, and fallback otherwise. keywords maps substring (matched via strings.Contains) to vector; all vectors must have the same dimension as fallback.
func NewLengthEmbedder ¶
func NewLengthEmbedder() *DeterministicEmbedder
NewLengthEmbedder returns a 2-dimensional embedder that derives vectors from text length — cheap, deterministic, and distinct for different lengths.
func (*DeterministicEmbedder) Dimension ¶
func (e *DeterministicEmbedder) Dimension() int
Dimension implements core.Embedder.
func (*DeterministicEmbedder) EmbedBatch ¶
func (e *DeterministicEmbedder) EmbedBatch(ctx context.Context, texts []string) ([][]float32, error)
EmbedBatch implements core.Embedder.
type InMemoryStateProvider ¶
type InMemoryStateProvider struct {
// contains filtered or unexported fields
}
InMemoryStateProvider implements core.StateProvider using a thread-safe map. Get marshals the stored state to JSON bytes (nil, nil when absent), Set accepts anything JSON-marshalable (plus *core.SessionState / []byte shortcuts), and Close resets the store. Suitable for tests and demos; use a Badger/Redis-backed provider in production.
func NewInMemoryStateProvider ¶
func NewInMemoryStateProvider() *InMemoryStateProvider
NewInMemoryStateProvider creates an empty in-memory state provider.
func (*InMemoryStateProvider) Close ¶
func (p *InMemoryStateProvider) Close(_ context.Context) error
Close implements core.StateProvider: it resets the store.
func (*InMemoryStateProvider) Delete ¶
func (p *InMemoryStateProvider) Delete(_ context.Context, sessionID string) error
Delete implements core.StateProvider.
func (*InMemoryStateProvider) Get ¶
Get implements core.StateProvider: it returns the JSON encoding of the session state, or (nil, nil) when the session does not exist.
func (*InMemoryStateProvider) Size ¶
func (p *InMemoryStateProvider) Size() int
Size returns the number of stored sessions (test helper).
type MockLLM ¶
type MockLLM struct {
// contains filtered or unexported fields
}
MockLLM is a deterministic, scripted implementation of core.TextGenerator. Responses are consumed in order (FIFO); once the script is exhausted the last response repeats, so a single-response MockLLM never runs dry.
llm := testutil.NewMockLLM("first answer", "second answer")
client.SetLLM(llm)
It also records every prompt it was given (see Prompts) so tests can assert on what the supervised action actually sent.
func NewMockLLM ¶
NewMockLLM builds a MockLLM that answers with the given responses in call order. With no responses it answers with the empty string.
func (*MockLLM) Generate ¶
func (m *MockLLM) Generate(_ context.Context, prompt string, _ ...core.GenerateOption) (*core.LLMResponse, error)
Generate implements core.TextGenerator.
type WorkflowSessionStore ¶
type WorkflowSessionStore = ports.InMemorySessionStore
WorkflowSessionStore is the thread-safe in-memory ports.SessionStateStore used by multiagent.HydratedWorkflowExecutor for workflow-instance checkpointing and resume. It re-exports ports.InMemorySessionStore so examples and tests need one import for all their test doubles.
func NewWorkflowSessionStore ¶
func NewWorkflowSessionStore() *WorkflowSessionStore
NewWorkflowSessionStore creates an empty in-memory workflow session store.