systemonetest

package
v1.2.9 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package systemonetest provides a scriptable fake System One server that emulates Ollama 0.35 and Jev-compatible remote gateways. It is used by Go tests and by the WebUI Playwright run.

Index

Constants

View Source
const (
	DuplicateChargeP          = 0.9760968387170561
	DuplicateChargeConfidence = 0.9145015492062412
)

Recorded probability values of DuplicateChargeResponseJSON.

View Source
const DuplicateChargeResponseJSON = `` /* 274-byte string literal not displayed */

DuplicateChargeResponseJSON is the recorded /v1/systemone answer for a billing-intent question.

View Source
const OllamaShowTev1JSON = `` /* 158-byte string literal not displayed */

OllamaShowTev1JSON is the /api/show body for tev1:0.8b.

View Source
const OllamaTagsJSON = `` /* 845-byte string literal not displayed */

OllamaTagsJSON is the /api/tags body used by NewOllama035.

View Source
const OllamaVersionJSON = `{"version":"0.35.0"}`

OllamaVersionJSON is the /api/version body.

View Source
const OpenRouterModelsJSON = `{"data":[{"id":"openai/gpt-5"},{"id":"typesafe/jev-1.13"},{"id":"~typesafe/jev-latest"}]}`

OpenRouterModelsJSON is an OpenAI-style mixed catalogue.

View Source
const TypeSafeModelsJSON = `{"models":["jev-latest","jev-1.13"]}`

TypeSafeModelsJSON is the {"models":[...]} shape.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mode

type Mode int

Mode selects which backend is emulated.

const (
	ModeOllama Mode = iota
	ModeRemote
)

type Option

type Option func(*Server)

Option customises a Server.

func WithAPIKey

func WithAPIKey(k string) Option

WithAPIKey requires "Authorization: Bearer <key>" on every request.

func WithAcceptedModels

func WithAcceptedModels(ids ...string) Option

WithAcceptedModels restricts the model ids accepted by /v1/systemone.

func WithMode

func WithMode(m Mode) Option

WithMode sets the emulated backend.

func WithModelsJSON

func WithModelsJSON(j string) Option

WithModelsJSON sets the /v1/models body (remote mode) and the set of ids accepted by /v1/systemone.

func WithModelsStatus

func WithModelsStatus(code int) Option

WithModelsStatus makes /v1/models answer with the given status (e.g. 404).

func WithShowJSON

func WithShowJSON(j string) Option

WithShowJSON overrides the /api/show body (Ollama mode).

func WithTagsJSON

func WithTagsJSON(j string) Option

WithTagsJSON overrides the /api/tags body (Ollama mode).

func WithVersion

func WithVersion(v string) Option

WithVersion overrides the /api/version value (Ollama mode).

type Recorded

type Recorded struct {
	Method string
	Path   string
	Header http.Header
	Body   []byte
}

Recorded is one request seen by the server.

type Server

type Server struct {
	*httptest.Server
	// contains filtered or unexported fields
}

Server is the fake backend.

func New

func New(t testing.TB, opts ...Option) *Server

New starts a fake server (Ollama 0.35 by default) closed by t.Cleanup.

func NewOllama035

func NewOllama035(t testing.TB, opts ...Option) *Server

NewOllama035 starts a server serving the recorded Ollama 0.35.0 fixtures.

func NewRemote

func NewRemote(t testing.TB, opts ...Option) *Server

NewRemote starts a remote Jev-compatible gateway emulation.

func (*Server) BaseURL

func (s *Server) BaseURL() string

BaseURL is the server root (same as the embedded URL).

func (*Server) Count

func (s *Server) Count(path string) int

Count returns how many requests hit path.

func (*Server) Delay

func (s *Server) Delay(d time.Duration)

Delay makes every request sleep d before answering.

func (*Server) FailNext

func (s *Server) FailNext(status int)

FailNext queues an error status for the next request (any path). Several calls queue several failures, consumed in order.

func (*Server) Requests

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

Requests returns a copy of the request log.

func (*Server) Reset

func (s *Server) Reset()

Reset clears the request log and scripted failures.

func (*Server) SetCost

func (s *Server) SetCost(c float64)

SetCost makes responses carry usage.cost.

func (*Server) SetDecision

func (s *Server) SetDecision(choice string, probs map[string]float64)

SetDecision scripts the answer returned for every choice question. A nil probs map gives probability 1 to choice.

func (*Server) SetQuestionDecision

func (s *Server) SetQuestionDecision(question, choice string, probs map[string]float64)

SetQuestionDecision scripts the answer for one named question, overriding SetDecision for that question only.

func (*Server) SetRawResponse

func (s *Server) SetRawResponse(body string)

SetRawResponse scripts a verbatim 200 body for /v1/systemone.

Jump to

Keyboard shortcuts

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