Testing Package
import zynt "github.com/zoobz-io/zyn/testing"
Test utilities for deterministic synapse testing.
ResponseBuilder
Fluent interface for constructing mock LLM responses.
func NewResponseBuilder() *ResponseBuilder
Methods
| Method | Description |
|---|---|
WithDecision(bool) | Set decision field (binary synapses) |
WithConfidence(float64) | Set confidence score |
WithReasoning(...string) | Set reasoning list |
WithPrimary(string) | Set primary label (classification) |
WithSecondary(string) | Set secondary label (classification) |
WithRanked(...string) | Set ranked items (ranking) |
WithOutput(string) | Set output text (transform) |
WithChanges(...string) | Set changes list (transform) |
WithOverall(string) | Set overall sentiment (sentiment) |
WithScores(positive, negative, neutral float64) | Set sentiment scores |
WithEmotions(...string) | Set detected emotions (sentiment) |
WithAspects(map[string]string) | Set aspect sentiments (sentiment) |
WithField(string, any) | Set an arbitrary field |
Build() string | Return JSON string |
BuildBytes() []byte | Return JSON bytes |
SequencedProvider
Returns responses in order. After exhaustion, repeats the last response.
func NewSequencedProvider(responses ...string) *SequencedProvider
Methods
| Method | Description |
|---|---|
Call(ctx, messages, temperature) | Return next response in sequence |
Name() string | Returns "sequenced-mock" |
CallCount() int | Number of calls made |
Reset() | Reset call counter |
FailingProvider
Fails a specified number of times before succeeding. Useful for testing retry behavior.
func NewFailingProvider(failCount int) *FailingProvider
Methods
| Method | Description |
|---|---|
WithSuccessResponse(string) | Set response after failures exhaust |
WithFailError(string) | Set failure error message |
Call(ctx, messages, temperature) | Fail until count reached, then succeed |
Name() string | Returns "failing-mock" |
CallCount() int | Number of calls made |
Reset() | Reset call counter |
CallRecorder
Wraps a provider and records all calls for inspection.
func NewCallRecorder(provider zyn.Provider) *CallRecorder
Methods
| Method | Description |
|---|---|
Call(ctx, messages, temperature) | Delegate and record |
Name() string | Wrapped provider's name |
Calls() []RecordedCall | Copy of all recorded calls |
CallCount() int | Number of calls recorded |
LastCall() *RecordedCall | Most recent call, or nil |
Reset() | Clear recorded calls |
RecordedCall
type RecordedCall struct {
Messages []zyn.Message
Temperature float32
}
LatencyProvider
Wraps a provider with artificial delay. Respects context cancellation.
func NewLatencyProvider(provider zyn.Provider, delay time.Duration) *LatencyProvider
Methods
| Method | Description |
|---|---|
Call(ctx, messages, temperature) | Delay then delegate |
Name() string | Wrapped provider's name |
UsageAccumulator
Tracks total token usage across multiple calls.
func NewUsageAccumulator() *UsageAccumulator
Methods
| Method | Description |
|---|---|
Add(session) | Accumulate from session's last usage |
AddUsage(usage) | Accumulate directly |
PromptTokens() int | Total prompt tokens |
CompletionTokens() int | Total completion tokens |
TotalTokens() int | Total tokens |
CallCount() int | Number of calls accumulated |
Reset() | Clear all values |
StreamRecorder
Records chunks delivered during streaming.
func NewStreamRecorder() *StreamRecorder
Methods
| Method | Description |
|---|---|
Callback() StreamCallback | Returns callback that records chunks |
Chunks() []string | Copy of all recorded chunks |
Combined() string | All chunks joined |
ChunkCount() int | Number of chunks |
Reset() | Clear recorded chunks |
StreamEventRecorder
Records typed stream events.
func NewStreamEventRecorder() *StreamEventRecorder
Methods
| Method | Description |
|---|---|
Callback() StreamEventCallback | Returns callback that records events |
Events() []StreamEvent | Copy of all recorded events |
EventCount() int | Number of events |
TextEvents() []StreamEvent | Only text events |
ToolStartEvents() []StreamEvent | Only tool_start events |
Reset() | Clear recorded events |