faux

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package faux is a deterministic provider that replays a scripted sequence of assistant turns.

It ships as exported, supported API in the same place as the real providers, not as test-only code inside the module. That placement is deliberate, not a convenience: consumers use it to test their own tool handlers, middleware and interceptors, and an SDK whose double is internal forces every consumer to write one against their own guesses about the loop.

It is also the EXECUTABLE SPECIFICATION of the streaming protocol. The event order it emits is normative — a real provider that disagrees with it is the one that is wrong — so its golden test is the protocol's conformance test.

It is a functional double for the loop only. It does not substitute for wire-level differential testing.

Index

Constants

View Source
const API core.API = "faux"

API is the wire API id faux registers under.

Variables

This section is empty.

Functions

func EventNames

func EventNames(events []core.Event) string

EventNames renders an event sequence as a comma-separated list of type names. It exists so a golden test of the protocol reads as a sentence rather than as a struct dump.

func FauxText

func FauxText(s string) core.ContentBlock

FauxText scripts a text block.

func FauxThinking

func FauxThinking(thinking, signature string) core.ContentBlock

FauxThinking scripts a thinking block. A signature is required for the block to survive transcript repair on replay, which demotes an unsigned thinking block to plain text; passing "" is the deliberate way to script the residue of an aborted stream.

func FauxToolCall

func FauxToolCall(id, name, args string) core.ContentBlock

FauxToolCall scripts a tool call. args must be a JSON object; it panics otherwise, because a malformed script is a test bug and surfacing it at the call site is more useful than a confusing failure three layers down.

func Model

func Model() *core.Model

Model returns a model descriptor pointing at this provider.

Types

type Provider

type Provider struct {

	// ChunkSize splits text and tool arguments into deltas of this many bytes.
	// Zero means one delta per block. Setting it small is how a test exercises
	// a consumer's delta accumulator.
	ChunkSize int
	// ModelID is stamped on every message as the model that answered. Empty
	// leaves it to the consumer, which knows what it asked for.
	ModelID string
	// contains filtered or unexported fields
}

Provider is a scripted provider. The zero value is usable and answers every request with an empty "stop" turn.

func New

func New(turns ...Turn) *Provider

New returns a provider that replays turns in order. Once the script is exhausted every further request answers with an empty "stop" turn, so a test that under-scripts fails on its assertion rather than by deadlocking.

func (*Provider) Calls

func (p *Provider) Calls() int

Calls reports how many requests were made.

func (*Provider) Requests

func (p *Provider) Requests() []core.Request

Requests returns the requests the provider was asked to complete, in order. Tests use it to assert what the loop actually sent, and when.

func (*Provider) Stream

func (p *Provider) Stream(ctx context.Context, req core.Request) (<-chan core.StreamEvent, error)

Stream implements core.ProviderClient. A context already done is refused before the request counts as made.

type Turn

type Turn struct {
	Blocks     []core.ContentBlock
	StopReason core.StopReason
	// RawStopReason is the provider's own finish string. Scripting it lets a
	// test reproduce a STOP-family canonical reason arriving alongside tool
	// calls.
	RawStopReason string
	ErrorMessage  string
	Usage         core.Usage
	// Err, when set, ends the stream with an error after emitting whatever
	// blocks were produced — the half-a-message-then-fail case, which must be
	// representable in one value.
	Err error
	// Delay is inserted before the turn is produced, for tests that need a
	// window in which to Steer, Abort or observe a Phase.
	Delay time.Duration
}

Turn is one scripted assistant response.

func FauxAssistantMessage

func FauxAssistantMessage(reason core.StopReason, blocks ...core.ContentBlock) Turn

FauxAssistantMessage builds a whole turn in one call.

func Text

func Text(s string) Turn

Text scripts a turn that answers with s and ends: one text block with the stop reason "stop". A turn of several blocks takes FauxAssistantMessage.

func ToolCall

func ToolCall(id, name, args string) Turn

ToolCall scripts a turn that calls one tool: the block FauxToolCall builds, with the tool_use stop reason. Empty or whitespace args mean {}, as in core.NewToolUse. It panics, as FauxToolCall does, when args is not a JSON object.

Jump to

Keyboard shortcuts

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