Help us shape the future of Go! Take the 2026 Go Developer Survey

jev

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package jev provides a partitioned TypeSafe Jev System One API with deterministic answers, failure modes and a per-partition request log.

A Jev policy appends /v1/systemone to its base URL, so a scenario points the policy at

http://testbench:3019/<partition>/<mode>

or, for a policy that requires HTTPS, at https://testbench:3020/<partition>/<mode>: the same service over TLS, sharing its partitions.

where <partition> is a scenario-unique name and <mode> selects the service's behaviour: ok, error, slow, ratelimit-once, overloaded-once, ratelimit-always, invalid-json or missing-answer.

Answers default to a low noul probability, a zero score and evenly spread choice options. A marker in the text Jev is asked about sets a question's answer:

jev:<key>=0.95                       a noul probability
jev:<key>=2@0.5                      a score and its confidence
jev:<key>=code@0.9                   a choice, the rest spread over the other options
jev:<key>=a:0.35,b:0.35,c:0.3        a choice distribution

Every request is recorded, including those answered with an error, and GET /<partition>/test/requests reports them with their count.

Index

Constants

View Source
const (
	EnvTLSCert = "TESTBENCH_JEV_TLS_CERT"
	EnvTLSKey  = "TESTBENCH_JEV_TLS_KEY"
)

EnvTLSCert and EnvTLSKey name the variables holding the PEM certificate and key the service serves HTTPS with on TLSPort. When both are unset only the plain HTTP port is served.

View Source
const (
	// DefaultNoul is the probability a noul question answers.
	DefaultNoul = 0.05
	// DefaultScore is the scale position a score question answers.
	DefaultScore = 0.0
	// DefaultConfidence is the confidence reported with every score and choice answer.
	DefaultConfidence = 0.9
)

Default answers for questions a request carries no marker for.

View Source
const (
	// ModeOK answers every question.
	ModeOK = "ok"
	// ModeError answers 500.
	ModeError = "error"
	// ModeSlow answers after the slow delay, so a short policy timeout expires first.
	ModeSlow = "slow"
	// ModeRateLimitOnce answers the partition's first request with 429 and every later one normally.
	ModeRateLimitOnce = "ratelimit-once"
	// ModeOverloadedOnce answers the partition's first request with 529 and every later one normally.
	ModeOverloadedOnce = "overloaded-once"
	// ModeRateLimitAlways answers every request with 429.
	ModeRateLimitAlways = "ratelimit-always"
	// ModeInvalidJSON answers 200 with a body that is not JSON.
	ModeInvalidJSON = "invalid-json"
	// ModeMissingAnswer answers every question except the first, in key order.
	ModeMissingAnswer = "missing-answer"
)

Modes, the path segment after the partition.

View Source
const APIKey = "test-jev-key"

APIKey is the only key the service accepts, as "Authorization: Bearer <APIKey>".

View Source
const Port = 3019

Port is the container port used by the testbench.

View Source
const StatusOverloaded = 529

StatusOverloaded is the status Jev uses when it is overloaded.

View Source
const SystemOnePath = "/v1/systemone"

SystemOnePath is the Jev endpoint the policies call, appended to their base URL.

View Source
const TLSPort = 3020

TLSPort is the port the same service answers on over HTTPS, for a policy that refuses a plain HTTP Jev endpoint on a host that is not loopback.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	Mode          string          `json:"mode"`
	Authorization string          `json:"authorization"`
	Model         string          `json:"model"`
	State         json.RawMessage `json:"state"`
	QuestionKeys  []string        `json:"questionKeys"`
	Questions     json.RawMessage `json:"questions"`
}

Request is one recorded call to the System One endpoint.

type Service

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

Service implements testbench.Service and testbench.Partitioned.

func New

func New() *Service

New returns a new Jev service.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the partitioned routes.

func (*Service) Name

func (s *Service) Name() string

Name returns the service registration name.

func (*Service) OverTLS

func (s *Service) OverTLS(certPEM, keyPEM []byte) (testbench.Service, error)

OverTLS returns the service served over HTTPS on TLSPort with the supplied PEM certificate and key. It shares this service's partitions, so a call made over HTTPS is read back from /test/requests on either port.

func (*Service) PartitionKey

func (s *Service) PartitionKey() string

PartitionKey returns the partitioning strategy used by this stateful service.

func (*Service) Port

func (s *Service) Port() int

Port returns the service's listening port.

func (*Service) Stateful

func (s *Service) Stateful() bool

Stateful reports that the service retains the requests it receives.

Jump to

Keyboard shortcuts

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