zoobzio December 13, 2025 Edit this page

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

MethodDescription
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() stringReturn JSON string
BuildBytes() []byteReturn JSON bytes

SequencedProvider

Returns responses in order. After exhaustion, repeats the last response.

func NewSequencedProvider(responses ...string) *SequencedProvider

Methods

MethodDescription
Call(ctx, messages, temperature)Return next response in sequence
Name() stringReturns "sequenced-mock"
CallCount() intNumber 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

MethodDescription
WithSuccessResponse(string)Set response after failures exhaust
WithFailError(string)Set failure error message
Call(ctx, messages, temperature)Fail until count reached, then succeed
Name() stringReturns "failing-mock"
CallCount() intNumber of calls made
Reset()Reset call counter

CallRecorder

Wraps a provider and records all calls for inspection.

func NewCallRecorder(provider zyn.Provider) *CallRecorder

Methods

MethodDescription
Call(ctx, messages, temperature)Delegate and record
Name() stringWrapped provider's name
Calls() []RecordedCallCopy of all recorded calls
CallCount() intNumber of calls recorded
LastCall() *RecordedCallMost 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

MethodDescription
Call(ctx, messages, temperature)Delay then delegate
Name() stringWrapped provider's name

UsageAccumulator

Tracks total token usage across multiple calls.

func NewUsageAccumulator() *UsageAccumulator

Methods

MethodDescription
Add(session)Accumulate from session's last usage
AddUsage(usage)Accumulate directly
PromptTokens() intTotal prompt tokens
CompletionTokens() intTotal completion tokens
TotalTokens() intTotal tokens
CallCount() intNumber of calls accumulated
Reset()Clear all values

StreamRecorder

Records chunks delivered during streaming.

func NewStreamRecorder() *StreamRecorder

Methods

MethodDescription
Callback() StreamCallbackReturns callback that records chunks
Chunks() []stringCopy of all recorded chunks
Combined() stringAll chunks joined
ChunkCount() intNumber of chunks
Reset()Clear recorded chunks

StreamEventRecorder

Records typed stream events.

func NewStreamEventRecorder() *StreamEventRecorder

Methods

MethodDescription
Callback() StreamEventCallbackReturns callback that records events
Events() []StreamEventCopy of all recorded events
EventCount() intNumber of events
TextEvents() []StreamEventOnly text events
ToolStartEvents() []StreamEventOnly tool_start events
Reset()Clear recorded events