# testkit/openaifake

> Package openaifake is a scripted Chat Completions server for tests of zelk as a whole: the zero-config entry point and the CLI run against it over real HTTP, as they would against an OpenAI-compatible API.

<!-- Generated from the Go source of github.com/barevoidco/zelk/core/testkit/openaifake (cmd/zelk/internal/reference TestReferenceGoAPI). Don't edit: change the code, then run make reference. -->

```go
import "github.com/barevoidco/zelk/core/testkit/openaifake"
```

Package openaifake is a scripted Chat Completions server for tests of zelk as a whole: the zero-config entry point and the CLI run against it over real HTTP, as they would against an OpenAI-compatible API. It speaks the streaming wire format the openaicompat adapter reads, from turns written as plain data.


## Call

```go
type Call struct {
	ID, Name, Arguments string
}
```

Call is a tool call in a reply. Arguments is the JSON object as text.


## Server

```go
type Server struct {
	// contains filtered or unexported fields
}
```

Server answers each Chat Completions request with the next turn, as a stream. Requests past the script fail with status 400. It is safe for concurrent use.


### New

```go
func New(turns ...Turn) *Server
```

New returns a server that replies with turns, in order.


### Server.Bodies

```go
func (s *Server) Bodies() [][]byte
```

Bodies returns the bodies of the requests served so far, in order.


### Server.ServeHTTP

```go
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)
```

ServeHTTP serves POST /…/chat/completions. Any other request, such as a host listing models, is not found and takes no turn of the script.


## Turn

```go
type Turn struct {
	Text  string
	Calls []Call
	// Check, if set, inspects the request's body and fails the request
	// with its error.
	Check func(body []byte) error
	// CachedTokens is how many of the reply's 100 prompt tokens the
	// server reports as read from its cache.
	CachedTokens int
}
```

Turn is one scripted model reply: text, tool calls, or both.


### Reported

```go
func Reported(id, text string) Turn
```

Reported is a turn that answers with text and ends the run with zelk's ReportOutcome step, reporting the goal met with text as its summary and the request as its one requirement, confirmed by a check. id must be unique within the session.


### Summary

```go
func Summary(summary string) Turn
```

Summary is a turn that answers a compaction call with summary between the \<summary> tags the call asks for.
