providertest

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package providertest provides a test contract kit for model provider implementations. It defines a Script type that describes expected provider behavior and a Run function that validates a provider against those specifications.

The kit is provider-agnostic: adapters supply format-specific bodies through Script fields, while Run validates the contract invariants (retry behavior, token mapping, usage consistency).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(t *testing.T, mk func(baseURL string) runtime.ModelProvider, script Script)

Run executes a provider contract test suite against a provider factory. mk is a function that creates a ModelProvider given a base URL. It runs 6 subtests validating Complete_Text, Stream, Usage_Mapping, Stream_Assembly, ToolCall_Roundtrip, Retry429, and ContextCancel.

Types

type Script

type Script struct {
	// CompleteResponse is the JSON body the fake server returns for non-streaming Complete calls.
	// Must be a valid model.Response JSON.
	CompleteResponse string

	// StreamChunks is a slice of SSE data lines for streaming tests.
	// Each string is the "data: " payload for an SSE event (SSE framing is added by Run).
	StreamChunks []string

	// ExpectedModel is the model identifier the adapter must send in the request.
	ExpectedModel string

	// ExpectedTools controls whether to verify tools are present in the adapter's request.
	ExpectedTools bool

	// ToolCallResponse is the JSON response for a tool call test.
	// If non-empty, enables the tool-call roundtrip subtest.
	ToolCallResponse string

	// ToolResultFinalResponse is the JSON response the server returns after receiving
	// a tool result. Used in the tool-call roundtrip subtest, step (c).
	ToolResultFinalResponse string

	// UsageInputTokens is the expected InputTokens count in the response.
	UsageInputTokens int

	// UsageOutputTokens is the expected OutputTokens count in the response.
	UsageOutputTokens int

	// Validate is an optional hook called for each HTTP request with (request, body bytes).
	// Return an error to fail the request; returning nil allows it to proceed.
	Validate func(*http.Request, []byte) error

	// Handler is an optional custom HTTP handler that replaces the default behavior.
	// If set, Validate is ignored and Handler receives all requests.
	Handler http.Handler
}

Script describes the expected behavior of a model provider for a test roundtrip. Adapters fill in format-specific request/response bodies; Run validates invariants.

Jump to

Keyboard shortcuts

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