testspec

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package testspec defines the current protocol-neutral authored test contract. It has no transport, persistence, or application dependencies.

Index

Constants

View Source
const MaxDocumentBytes = 4 << 20
View Source
const MaxFileInputBytes = 1 << 20

Variables

View Source
var ErrFileInputsUnsupported = errors.New(
	"file inputs require an admitted asset resolver; file execution is unsupported",
)

Functions

func RequiresRandom

func RequiresRandom(spec Spec) bool

Types

type Artifact

type Artifact struct {
	Kind string `json:"kind"`
	URL  string `json:"url"`
}

type Assertion

type Assertion struct {
	ID           string          `json:"id"`
	Source       string          `json:"source,omitempty"`
	Pointer      string          `json:"pointer,omitempty"`
	Operator     string          `json:"operator,omitempty"`
	Value        json.RawMessage `json:"value,omitempty"`
	All          []Assertion     `json:"all,omitempty"`
	Any          []Assertion     `json:"any,omitempty"`
	Each         []Assertion     `json:"each,omitempty"`
	EachMode     string          `json:"each_mode,omitempty"`
	Transform    string          `json:"transform,omitempty"`
	ExpectedFrom *Reference      `json:"expected_from,omitempty"`
}

type AssertionResult

type AssertionResult struct {
	ID       string            `json:"id"`
	Source   string            `json:"source,omitempty"`
	Pointer  string            `json:"pointer,omitempty"`
	Operator string            `json:"operator,omitempty"`
	Expected json.RawMessage   `json:"expected,omitempty"`
	Actual   json.RawMessage   `json:"actual,omitempty"`
	Status   VerdictStatus     `json:"status"`
	Reason   string            `json:"reason,omitempty"`
	Children []AssertionResult `json:"children,omitempty"`
}

type Exchange

type Exchange struct {
	Step            string             `json:"step"`
	Method          string             `json:"method"`
	Path            string             `json:"path"`
	RequestBody     json.RawMessage    `json:"request_body,omitempty"`
	HTTPStatus      *int               `json:"http_status,omitempty"`
	Response        json.RawMessage    `json:"response,omitempty"`
	Events          []json.RawMessage  `json:"events,omitempty"`
	ElapsedMS       float64            `json:"elapsed_ms"`
	Metrics         map[string]float64 `json:"metrics,omitempty"`
	StreamCompleted *bool              `json:"stream_completed,omitempty"`
}

type FileBinding

type FileBinding struct {
	AssetRef string `json:"asset_ref"`
}

FileBinding identifies owned content logically; it never names a local path.

func (*FileBinding) UnmarshalJSON

func (binding *FileBinding) UnmarshalJSON(raw []byte) error

type FileInput

type FileInput struct {
	Encoding   string   `json:"encoding"`
	MediaTypes []string `json:"media_types"`
	MaxBytes   int64    `json:"max_bytes"`
}

func (*FileInput) UnmarshalJSON

func (file *FileInput) UnmarshalJSON(raw []byte) error

func (FileInput) Validate

func (file FileInput) Validate() error

type FileOccurrence

type FileOccurrence struct {
	InputName string
	Pointer   string
	AssetRef  string
	File      FileInput
}

type Input

type Input struct {
	Type        string            `json:"type"`
	Description string            `json:"description,omitempty"`
	Unit        string            `json:"unit,omitempty"`
	Default     json.RawMessage   `json:"default,omitempty"`
	Required    bool              `json:"required,omitempty"`
	Minimum     *float64          `json:"minimum,omitempty"`
	Maximum     *float64          `json:"maximum,omitempty"`
	Enum        []json.RawMessage `json:"enum,omitempty"`
	File        *FileInput        `json:"file,omitempty"`
}

func (Input) Clone

func (input Input) Clone() Input

func (*Input) UnmarshalJSON

func (input *Input) UnmarshalJSON(raw []byte) error

func (Input) Validate

func (input Input) Validate() error

type Issue

type Issue struct {
	Stage string `json:"stage"`
	Code  string `json:"code"`
}

type Metric

type Metric struct {
	ID          string `json:"id"`
	Label       string `json:"label"`
	Unit        string `json:"unit"`
	Scope       string `json:"scope"`
	Aggregation string `json:"aggregation"`
}

type Observation

type Observation struct {
	Model           string             `json:"model"`
	Protocol        string             `json:"protocol"`
	HTTPStatus      *int               `json:"http_status,omitempty"`
	Response        json.RawMessage    `json:"response,omitempty"`
	Text            *string            `json:"text,omitempty"`
	StreamCompleted *bool              `json:"stream_completed,omitempty"`
	Metrics         map[string]float64 `json:"metrics"`
	Usage           json.RawMessage    `json:"usage,omitempty"`
	Task            *Task              `json:"task,omitempty"`
	Artifacts       []Artifact         `json:"artifacts"`
	Exchanges       []Exchange         `json:"exchanges"`
	Issues          []Issue            `json:"issues"`
}

type RandomContext

type RandomContext struct {
	Seed            uint64 `json:"seed"`
	ExecutionItemID string `json:"execution_item_id"`
	MemberID        string `json:"member_id"`
	Iteration       uint64 `json:"iteration"`
}

type Reference

type Reference struct {
	Source    string `json:"source"`
	Pointer   string `json:"pointer,omitempty"`
	Transform string `json:"transform,omitempty"`
}

type RenderInput

type RenderInput struct {
	Request      Request
	Declarations map[string]Input
	Values       ResolvedInputs
	Random       RandomContext
	Responses    map[string]json.RawMessage
}

type RenderedRequest

type RenderedRequest struct {
	Body  json.RawMessage
	Files []FileOccurrence
}

RenderedRequest contains unresolved file slots, never file bytes. Each file's JSON value is null until the protocol boundary prepares its owned wire body.

func Generate

func Generate(spec Spec, values map[string]json.RawMessage, random RandomContext) (RenderedRequest, error)

func Render

func Render(input RenderInput) (RenderedRequest, error)

Render evaluates explicit template nodes. Strings never undergo interpolation.

func (RenderedRequest) Clone

func (request RenderedRequest) Clone() RenderedRequest

func (RenderedRequest) Validate

func (request RenderedRequest) Validate() error

type Request

type Request struct {
	Body json.RawMessage `json:"body"`
}

type ResolvedInputs

type ResolvedInputs struct {
	JSONValues map[string]json.RawMessage
	Files      map[string]FileBinding
}

ResolvedInputs keeps file bindings out of ordinary JSON template values.

func ValidateInputs

func ValidateInputs(declarations map[string]Input, supplied map[string]json.RawMessage) (ResolvedInputs, error)

ValidateInputs resolves declared defaults and rejects undeclared assignments. It validates authoring parameters, not the provider's request-body contract.

func (ResolvedInputs) SnapshotValues

func (inputs ResolvedInputs) SnapshotValues() map[string]json.RawMessage

SnapshotValues projects the current logical values into the snapshot's single Parameters/CaseInputs representation. It does not resolve or read content.

type Result

type Result struct {
	Observation Observation `json:"observation"`
	Verdict     Verdict     `json:"verdict"`
}

type RunSettings

type RunSettings struct {
	TimeoutMS      uint64 `json:"timeout_ms,omitempty"`
	PollIntervalMS uint64 `json:"poll_interval_ms,omitempty"`
	TaskTimeoutMS  uint64 `json:"task_timeout_ms,omitempty"`
}

func (RunSettings) Validate

func (settings RunSettings) Validate() error

type Spec

type Spec struct {
	Operation  string           `json:"operation,omitempty"`
	Inputs     map[string]Input `json:"inputs"`
	Request    Request          `json:"request"`
	Assertions []Assertion      `json:"assertions"`
	Workflow   *Workflow        `json:"workflow,omitempty"`
}

func Decode

func Decode(raw json.RawMessage) (Spec, error)

func (Spec) HasFileInputs

func (spec Spec) HasFileInputs() bool

func (Spec) Validate

func (spec Spec) Validate() error

type Step

type Step struct {
	ID      string  `json:"id"`
	Request Request `json:"request"`
}

Steps contain complete request body templates. $response nodes reference an earlier step's response through a JSON Pointer; request order is explicit.

type Task

type Task struct {
	ID       string `json:"id"`
	Status   string `json:"status"`
	Terminal bool   `json:"terminal"`
}

type Verdict

type Verdict struct {
	Status     VerdictStatus     `json:"status"`
	Assertions []AssertionResult `json:"assertions"`
}

func Evaluate

func Evaluate(assertions []Assertion, observation Observation) Verdict

type VerdictStatus

type VerdictStatus string
const (
	VerdictPassed        VerdictStatus = "passed"
	VerdictFailed        VerdictStatus = "failed"
	VerdictNotApplicable VerdictStatus = "not_applicable"
	VerdictIndeterminate VerdictStatus = "indeterminate"
)

type Workflow

type Workflow struct {
	Mode  string `json:"mode"`
	Steps []Step `json:"steps,omitempty"`
}

Workflow specifies protocol execution behavior, never expected outcomes.

Jump to

Keyboard shortcuts

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