testkit/openaifake
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.
type Call struct { ID, Name, Arguments string}Call is a tool call in a reply. Arguments is the JSON object as text.
Server
Section titled “Server”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.
func New(turns ...Turn) *ServerNew returns a server that replies with turns, in order.
Server.Bodies
Section titled “Server.Bodies”func (s *Server) Bodies() [][]byteBodies returns the bodies of the requests served so far, in order.
Server.ServeHTTP
Section titled “Server.ServeHTTP”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.
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
Section titled “Reported”func Reported(id, text string) TurnReported 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
Section titled “Summary”func Summary(summary string) TurnSummary is a turn that answers a compaction call with summary between the <summary> tags the call asks for.