Documentation
¶
Overview ¶
Package modeltest checks an HTTP-backed agent.Model against the streaming contract the agent loop relies on:
- The adapter releases its response when the consumer stops early. An adapter that reads a streamed response in its own goroutine and sends each event on an unbuffered channel blocks forever once nobody is receiving, holding the response body and its connection. Breaking out of Stream.Events, or cancelling the context passed to Model.Stream, must close the response body.
- A response that ends before the provider's end-of-turn marker is an error. A connection closed partway through a turn must never read as a complete message, which the agent would journal as the model's answer.
Index ¶
- func CheckSSEPrefix(t testing.TB, streamSSE func(body io.ReadCloser, send func(agent.Emit) bool), ...)
- func Run(t *testing.T, newModel func(baseURL string, client *http.Client) agent.Model, ...)
- func ToolConfig(t *testing.T, newModel func(baseURL string, client *http.Client) agent.Model)
- type SSEResult
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckSSEPrefix ¶ added in v0.7.0
func CheckSSEPrefix(t testing.TB, streamSSE func(body io.ReadCloser, send func(agent.Emit) bool), body []byte, cut int)
CheckSSEPrefix checks, on top of ReadSSE's properties for body and for its first cut bytes, that a response cut short is never a success that differs from the whole response's success: a connection that closes partway must not turn a truncated answer into a complete one. A fuzz target for an adapter's SSE reader calls it with arbitrary bytes and an arbitrary cut.
func Run ¶
func Run(t *testing.T, newModel func(baseURL string, client *http.Client) agent.Model, event func(i int) string)
Run runs the checks. newModel returns the adapter under test pointed at baseURL and using client for its requests. event returns the i-th server-sent event of an endless text response, in the provider's wire format and including its trailing blank line; it must not end the turn. The test server sends one every few milliseconds until the client goes away, as a long model response does, or, for the truncation check, stops after two.
func ToolConfig ¶ added in v0.7.0
ToolConfig checks that the adapter refuses a tool setup every provider rejects with agent.ErrConfig, before it sends anything: a tool name outside [a-zA-Z0-9_-] or longer than 64 characters, two tools with one name, and a tool choice that cannot be met (an unknown mode; "required" or "tool" with no tools declared; "tool" naming no tool or one not declared). A name every provider accepts, and "auto" or "none" with no tools, must reach the provider.
Types ¶
type SSEResult ¶ added in v0.7.0
SSEResult is what an adapter's SSE reader made of one response body: every Emit it sent, in order, and the message, usage, and error a consumer reading them gets.
func ReadSSE ¶ added in v0.7.0
func ReadSSE(t testing.TB, streamSSE func(body io.ReadCloser, send func(agent.Emit) bool), body []byte) SSEResult
ReadSSE runs an adapter's SSE reader (streamSSE, which reads body and sends each event through send) over body and checks the properties every response must keep, whatever its bytes:
- the reader sends at most one Finish, and nothing after it (the adapter ends the turn once; agent.Stream would otherwise report agent.ErrStreamProtocol);
- every error it sends is its last Emit;
- a failed response fails with an agent.ErrModel (or agent.ErrTruncatedToolArgs, which the message assembly reports for tool arguments that are not complete JSON).