Documentation
¶
Overview ¶
Package testspec defines the current protocol-neutral authored test contract. It has no transport, persistence, or application dependencies.
Index ¶
- Constants
- Variables
- func RequiresRandom(spec Spec) bool
- type Artifact
- type Assertion
- type AssertionResult
- type Exchange
- type FileBinding
- type FileInput
- type FileOccurrence
- type Input
- type Issue
- type Metric
- type Observation
- type RandomContext
- type Reference
- type RenderInput
- type RenderedRequest
- type Request
- type ResolvedInputs
- type Result
- type RunSettings
- type Spec
- type Step
- type Task
- type Verdict
- type VerdictStatus
- type Workflow
Constants ¶
const MaxDocumentBytes = 4 << 20
const MaxFileInputBytes = 1 << 20
Variables ¶
var ErrFileInputsUnsupported = errors.New(
"file inputs require an admitted asset resolver; file execution is unsupported",
)
Functions ¶
func RequiresRandom ¶
Types ¶
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 ¶
type FileOccurrence ¶
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) UnmarshalJSON ¶
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 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 (Spec) HasFileInputs ¶
type Step ¶
Steps contain complete request body templates. $response nodes reference an earlier step's response through a JSON Pointer; request order is explicit.
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" )