testkit

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package testkit provides shared test doubles for harness and server integration tests.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ContentTokenEstimate

func ContentTokenEstimate(msgs []*tacklr.Message) int

ContentTokenEstimate is a shared length-based token stand-in for pressure tests.

func HTTPModel added in v0.4.0

func HTTPModel(tb testing.TB, respond func(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool, ch chan<- tacklr.LLMResponseChunk)) tacklr.InferenceStrategy

HTTPModel is the real OpenAI-compatible client pointed at a local server. respond sees the conversation the client sent and writes chunks. An error chunk becomes the HTTP error the client classifies. Anything else is SSE.

func TextHTTPModel added in v0.4.0

func TextHTTPModel(tb testing.TB, respond func(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool, ch chan<- tacklr.LLMResponseChunk)) tacklr.InferenceStrategy

TextHTTPModel is HTTPModel on a model id that accepts text only.

Types

type RecordedError

type RecordedError struct {
	ID  json.RawMessage
	Err error
}

RecordedError is one WriteError call.

type RecordedResult

type RecordedResult struct {
	ID     json.RawMessage
	Result any
}

RecordedResult is one WriteResult call.

type RecordingWriter

type RecordingWriter struct {
	Results []RecordedResult
	Errors  []RecordedError
	Frames  [][]byte
	// contains filtered or unexported fields
}

RecordingWriter captures MessageWriter traffic for protocol tests.

func (*RecordingWriter) FrameCount

func (r *RecordingWriter) FrameCount() int

FrameCount returns the number of recorded frames (safe for concurrent poll).

func (*RecordingWriter) FramesAsMaps

func (r *RecordingWriter) FramesAsMaps(t *testing.T) []map[string]any

FramesAsMaps decodes recorded frames as JSON objects.

func (*RecordingWriter) SnapshotFrames

func (r *RecordingWriter) SnapshotFrames() [][]byte

SnapshotFrames returns a copy of recorded frames (safe for concurrent poll).

func (*RecordingWriter) WriteError

func (r *RecordingWriter) WriteError(id json.RawMessage, err error) error

func (*RecordingWriter) WriteFrame

func (r *RecordingWriter) WriteFrame(data []byte) error

func (*RecordingWriter) WriteResult

func (r *RecordingWriter) WriteResult(id json.RawMessage, result any) error

type ScriptedModel

type ScriptedModel struct {
	InvokeFn       func(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool, ch chan<- tacklr.LLMResponseChunk)
	InvokeErr      error
	InvokeErrFn    func(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool) error
	CountTokensFn  func(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool) (int, error)
	SupportsMIMEFn func(string) bool

	CallNum atomic.Int64

	SystemPrompts   []string
	LastInvokeMsgs  []*tacklr.Message
	LastInvokeTools []*tacklr.Tool
	// contains filtered or unexported fields
}

ScriptedModel is a cancel-aware InferenceStrategy for tests. Default CountTokens is sum of message content lengths (not zero), so window-pressure paths can fire when MaxWindowSize is small. Override CountTokensFn to customize.

func (*ScriptedModel) CountTokens

func (m *ScriptedModel) CountTokens(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool) (int, error)

func (*ScriptedModel) Invoke

func (m *ScriptedModel) Invoke(ctx context.Context, msgs []*tacklr.Message, tools []*tacklr.Tool, systemPrompt string) (chan tacklr.LLMResponseChunk, error)

func (*ScriptedModel) LastSystemPrompt added in v0.3.4

func (m *ScriptedModel) LastSystemPrompt() string

LastSystemPrompt is the most recent non-empty system prompt passed to Invoke.

func (*ScriptedModel) MaxContextWindow

func (m *ScriptedModel) MaxContextWindow() (int, error)

func (*ScriptedModel) ModelTelemetryIdentity added in v0.3.4

func (m *ScriptedModel) ModelTelemetryIdentity() telemetry.ModelIdentity

func (*ScriptedModel) SupportsMIME

func (m *ScriptedModel) SupportsMIME(mimeType string) bool

Jump to

Keyboard shortcuts

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