anthropictest

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: AGPL-3.0 Imports: 4 Imported by: 0

Documentation

Overview

Package anthropictest is a fake Anthropic API for tests: the Messages API, token counting and List Workspaces, answering as the test sets it up and recording what it was sent. Serve it with httptest.NewServer and point models.Deps.AnthropicURL at it.

Index

Constants

View Source
const WorkspaceNeeded = "This API key is not scoped to a workspace, so this request must include the anthropic-workspace-id header " +
	"with the ID of the workspace to use. Add the header, or use an API key that is scoped to a workspace."

WorkspaceNeeded is Anthropic's refusal of a request that names no workspace, made with a key that covers a whole organisation (as the daemon logged it on 2026-10-07, MAI-57).

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Workspaces     []Workspace // what List Workspaces lists
	ListStatus     int         // non-zero: List Workspaces is refused with this status
	ProbeStatus    int         // non-zero: count_tokens is refused with this status; 400 = for want of a workspace
	NeedsWorkspace bool        // a message that names no workspace is refused with WorkspaceNeeded
	Answer         string      // the tool input every message answers with; empty = {}
}

Config is how the fake answers.

type Seen

type Seen struct {
	Lists, Probes     int
	ListQuery         string   // the query of the last List Workspaces call
	MessageWorkspaces []string // the anthropic-workspace-id of every message, in order; "" = none
	APIKeys           []string // the x-api-key of every request
}

Seen is what the fake was sent.

type Server

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

Server is the fake, an http.Handler.

func New

func New(cfg Config) *Server

New returns a fake that answers as cfg says.

func (*Server) Seen

func (s *Server) Seen() Seen

Seen returns what the fake was sent so far.

func (*Server) ServeHTTP

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

func (*Server) Set

func (s *Server) Set(cfg Config)

Set changes how the fake answers from the next request on.

type Workspace

type Workspace struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

Workspace is one workspace List Workspaces answers.

Jump to

Keyboard shortcuts

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