fakeapi

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package fakeapi is a test-only fake Anthropic Messages server used by integration tests. Implemented in M1 (CLAUDE.md §13).

Package fakeapi is a test-only fake Anthropic Messages server. It speaks real server-sent events so the full record loop — scripted client -> proxy -> this server — runs in CI with zero network and zero credentials (CLAUDE.md §13).

It is a normal (non _test.go) package so tests in other packages can import it; it has no place in a production build.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OpenAITextTurn

func OpenAITextTurn(model, text string, inTok, outTok int) string

OpenAITextTurn builds an SSE stream for an assistant turn that is a single text block, with the given token usage and finish_reason "stop". Usage rides a trailing chunk (as OpenAI does with stream_options.include_usage).

func OpenAIToolUseTurn

func OpenAIToolUseTurn(model, text, toolID, toolName, argsJSON string, inTok, outTok int) string

OpenAIToolUseTurn builds an SSE stream for an assistant turn that emits a short text block followed by a tool_call whose arguments stream across chunks by index, with finish_reason "tool_calls".

func TextTurn

func TextTurn(model, text string, inTok, outTok int) string

TextTurn builds an SSE stream for an assistant turn that is a single text block, with the given token usage and stop_reason "end_turn".

func ToolUseTurn

func ToolUseTurn(model, text, toolID, toolName, inputJSON string, inTok, outTok int) string

ToolUseTurn builds an SSE stream for an assistant turn that emits a short text block followed by a tool_use block whose input JSON is streamed, with stop_reason "tool_use".

Types

type OpenAIServer

type OpenAIServer struct {
	// contains filtered or unexported fields
}

OpenAIServer is a fake OpenAI Chat Completions endpoint (POST /v1/chat/completions) that replays a scripted sequence of SSE responses, one per request, and records what it received. It mirrors Server (the fake Anthropic endpoint) so the OpenAI record->replay loop runs in CI with zero network and zero credentials (CLAUDE.md §13) — the credential-free proof that the second protocol lens records and replays through rung 1.

func NewOpenAI

func NewOpenAI(turns ...string) *OpenAIServer

NewOpenAI starts a fake server that replies to the k-th POST /v1/chat/completions with turns[k]. Requests past the script get a minimal stop stream. Close it with Close.

func (*OpenAIServer) Auths

func (s *OpenAIServer) Auths() []string

Auths returns the Authorization header values received, in order — used to assert the proxy forwarded real credentials upstream (§2.6).

func (*OpenAIServer) Close

func (s *OpenAIServer) Close()

Close shuts the server down.

func (*OpenAIServer) Requests

func (s *OpenAIServer) Requests() [][]byte

Requests returns the raw request bodies received, in order.

func (*OpenAIServer) URL

func (s *OpenAIServer) URL() string

URL is the base URL to point a proxy's upstream at.

type Server

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

Server is a fake Anthropic Messages endpoint that replays a scripted sequence of SSE responses, one per POST /v1/messages request, and records what it received so tests can assert on it.

func New

func New(turns ...string) *Server

New starts a fake server that replies to the k-th POST /v1/messages with turns[k]. Requests past the script get an empty message_stop stream. Close it with Close.

func (*Server) Auths

func (s *Server) Auths() []string

Auths returns the Authorization / x-api-key header values received, in order — used to assert the proxy forwarded real credentials upstream (§2.6).

func (*Server) Close

func (s *Server) Close()

Close shuts the server down.

func (*Server) Requests

func (s *Server) Requests() [][]byte

Requests returns the raw request bodies received, in order.

func (*Server) URL

func (s *Server) URL() string

URL is the base URL to point a proxy's upstream at.

Jump to

Keyboard shortcuts

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