Documentation
¶
Overview ¶
Package test has a registry and a HTTP server of its API, for tests
Index ¶
- Constants
- func NewRegistry(t *testing.T, providers []llm.Provider, opts ...registry.Opt) *registry.Registry
- func NewToolkit(t *testing.T) *toolkit.Toolkit
- type AgentStore
- func (m *AgentStore) Create(_ context.Context, meta schema.AgentMeta) (schema.Agent, error)
- func (m *AgentStore) Delete(_ context.Context, name string, serial uint64) error
- func (m *AgentStore) Get(_ context.Context, name string) (schema.Agent, error)
- func (m *AgentStore) List(_ context.Context, req schema.AgentListRequest) (schema.AgentList, error)
- func (m *AgentStore) Put(_ context.Context, agent schema.Agent) (schema.Agent, error)
- type EventStore
- func (m *EventStore) Create(_ context.Context, meta schema.EventMeta) (schema.Event, error)
- func (m *EventStore) Delete(_ context.Context, id uuid.UUID, serial uint64) error
- func (m *EventStore) Get(_ context.Context, id uuid.UUID) (schema.Event, error)
- func (m *EventStore) List(_ context.Context, req schema.EventListRequest) (schema.EventList, error)
- func (m *EventStore) Put(_ context.Context, event schema.Event) (schema.Event, error)
- type Exchange
- type Server
- func (s *Server) Do(t *testing.T, method, path string, body any) (int, []byte)
- func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)
- func (s *Server) Exchanges() []Exchange
- func (s *Server) JSON(t *testing.T, method, path string, body, v any) int
- func (s *Server) Reset()
- func (s *Server) Spec() *openapi.Spec
- func (s *Server) Verify() []error
- type SessionStore
- func (m *SessionStore) Changed(event eventschema.Change) int
- func (m *SessionStore) Create(_ context.Context, id uuid.UUID, meta schema.SessionMeta) (schema.Session, error)
- func (m *SessionStore) Delete(_ context.Context, id uuid.UUID, serial uint64) error
- func (m *SessionStore) Get(_ context.Context, id uuid.UUID) (schema.Session, error)
- func (m *SessionStore) Len() int
- func (m *SessionStore) List(_ context.Context, req schema.SessionListRequest) (schema.SessionList, error)
- func (m *SessionStore) Put(_ context.Context, session schema.Session) (schema.Session, error)
- func (m *SessionStore) Watch(ctx context.Context, ch chan<- eventschema.Change) (<-chan error, error)
Constants ¶
const Prefix = "/api"
Prefix is the path prefix for the API routes
Variables ¶
This section is empty.
Functions ¶
func NewRegistry ¶
NewRegistry returns a registry, with the options, and the providers, each by its own name, such as its type, or fails the test. As the registry isn't stored, each test has a registry of its own.
Types ¶
type AgentStore ¶ added in v0.6.0
type AgentStore struct {
// contains filtered or unexported fields
}
AgentStore is a store of agents in memory, by their names, which it lists in order of their names, for tests, whose serials are of the store, rather than of each agent, so an agent which is deleted, and created again, doesn't have a serial it had
func NewAgentStore ¶ added in v0.6.0
func NewAgentStore() *AgentStore
NewAgentStore returns a store of agents in memory, which has none
func (*AgentStore) List ¶ added in v0.6.0
func (m *AgentStore) List(_ context.Context, req schema.AgentListRequest) (schema.AgentList, error)
type EventStore ¶ added in v1.2.0
type EventStore struct {
// contains filtered or unexported fields
}
EventStore is a store of the outcomes of events in memory, for tests, which lists them the most recently created first
func NewEventStore ¶ added in v1.2.0
func NewEventStore() *EventStore
NewEventStore returns a store of events in memory, which has none
func (*EventStore) List ¶ added in v1.2.0
func (m *EventStore) List(_ context.Context, req schema.EventListRequest) (schema.EventList, error)
type Exchange ¶
type Exchange struct {
Method string
Path string
// Pattern is the route pattern which matched the request, such as
// "/api/llm/provider", or empty if no route matched
Pattern string
RequestHeader http.Header
RequestBody []byte
Status int
ResponseHeader http.Header
ResponseBody []byte
}
Exchange is a recorded request and response
type Server ¶
Server is a HTTP test server serving the llm registry API. Every request and response is recorded, and checked against the OpenAPI specification when the test ends.
func NewServer ¶
NewServer starts a HTTP test server serving the llm registry API for the registry, and its broadcaster's API, which streams its events. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.
func NewServerFunc ¶
NewServerFunc starts a HTTP test server serving the API registered by the function. When the test ends the server is closed, and every recorded exchange is checked against the OpenAPI specification.
func (*Server) Do ¶
Do sends a request to the API with a JSON body, and returns the status code and response body. The path is relative to the API prefix, and may include a query string. A body which is a string or []byte is sent as-is, nil sends no body, and any other value is encoded as JSON.
func (*Server) DoWithContentType ¶
func (s *Server) DoWithContentType(t *testing.T, method, path, contentType string, body any) (int, []byte)
DoWithContentType sends a request with the body as the content type, which is used as-is for a string or []byte body, and otherwise encoded as JSON. Returns the status code and the response body.
func (*Server) JSON ¶
JSON sends a request to the API as Do does, and decodes a successful response body into v. Returns the status code.
type SessionStore ¶ added in v0.6.0
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore is a store of sessions in memory, whose identifiers are version 7 UUIDs, which are in the order the sessions are created, for tests. Its watchers are sent the events which Changed is called with, as changes which others made.
func NewSessionStore ¶ added in v0.6.0
func NewSessionStore() *SessionStore
NewSessionStore returns a store of sessions in memory, which has none
func (*SessionStore) Changed ¶ added in v0.6.0
func (m *SessionStore) Changed(event eventschema.Change) int
Changed sends the event to the watchers, as a change which others made, such as another server, and returns how many it was sent to
func (*SessionStore) Create ¶ added in v0.6.0
func (m *SessionStore) Create(_ context.Context, id uuid.UUID, meta schema.SessionMeta) (schema.Session, error)
func (*SessionStore) Len ¶ added in v0.6.0
func (m *SessionStore) Len() int
Len returns how many sessions there are
func (*SessionStore) List ¶ added in v0.6.0
func (m *SessionStore) List(_ context.Context, req schema.SessionListRequest) (schema.SessionList, error)
func (*SessionStore) Watch ¶ added in v0.6.0
func (m *SessionStore) Watch(ctx context.Context, ch chan<- eventschema.Change) (<-chan error, error)
Watch sends the events which Changed is called with to the channel, until the context is cancelled, when the returned channel is sent nil