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 ¶
- func OpenAITextTurn(model, text string, inTok, outTok int) string
- func OpenAIToolUseTurn(model, text, toolID, toolName, argsJSON string, inTok, outTok int) string
- func TextTurn(model, text string, inTok, outTok int) string
- func ToolUseTurn(model, text, toolID, toolName, inputJSON string, inTok, outTok int) string
- type OpenAIServer
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OpenAITextTurn ¶
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 ¶
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 ¶
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 ¶
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) 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 ¶
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 ¶
Auths returns the Authorization / x-api-key header values received, in order — used to assert the proxy forwarded real credentials upstream (§2.6).