check

package
v1.261006.2 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2026 License: MPL-2.0 Imports: 6 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package check holds the protocol-neutral, reusable check logic for the vmodel benchmark: the RoundTripResult view of a single gateway round trip and the named Assertion library that operates on it.

It carries no test-framework dependency (no *testing.T), so it can be imported in-process by any *test package or by an external Go project. Its only non-stdlib dependency is internal/protocol for APIType — and vmodel/* already imports internal/protocol, so this introduces no import cycle.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FinalResponsesBody added in v0.260924.1

func FinalResponsesBody(r *RoundTripResult) (map[string]any, error)

FinalResponsesBody returns the terminal Responses API response body of a round trip: RawBody parsed directly when the trip was not streaming, or the "response" payload of the terminal response.completed / response.incomplete SSE event when it was. Shared by this package's own assertions and by harness test cases that need the same body (e.g. internal/protocoltest/content_shapes.go), so the terminal-event scan is implemented once.

Types

type Assertion

type Assertion struct {
	Name  string
	Check func(r *RoundTripResult) error
}

Assertion is a named check applied to a RoundTripResult.

func AssertContentContains

func AssertContentContains(substring string) Assertion

AssertContentContains returns an Assertion that the response content contains substring.

func AssertContentEquals

func AssertContentEquals(expected string) Assertion

AssertContentEquals returns an Assertion that the response content equals expected.

func AssertContentNonEmpty

func AssertContentNonEmpty() Assertion

AssertContentNonEmpty returns an Assertion that the response carries some payload — either text content or at least one tool call. Useful as an upstream-independent structural check when the exact response text is not controlled by the test (e.g. vmodel or real upstreams).

func AssertErrorMessageContains

func AssertErrorMessageContains(substring string) Assertion

AssertErrorMessageContains returns an Assertion that the raw response body contains the given substring. Useful for validating error responses where the semantic fields (Content, Role, etc.) are not populated.

func AssertFinishReason

func AssertFinishReason(expected string) Assertion

AssertFinishReason returns an Assertion that the finish_reason equals expected.

func AssertFinishReasonNonEmpty added in v0.260716.1

func AssertFinishReasonNonEmpty() Assertion

AssertFinishReasonNonEmpty returns an Assertion that a finish/stop reason was extracted at all — upstream-independent, unlike AssertFinishReason which pins an exact value.

func AssertFinishReasonOneOf

func AssertFinishReasonOneOf(accepted ...string) Assertion

AssertFinishReasonOneOf returns an Assertion that the finish_reason matches any of the accepted values. Useful for scenarios where the expected finish reason varies by source protocol (e.g. "length" for Chat, "max_tokens" for Anthropic, "incomplete" for Responses).

func AssertHTTPStatus

func AssertHTTPStatus(expected int) Assertion

AssertHTTPStatus returns an Assertion that the HTTP status code equals expected.

func AssertHTTPStatusAtLeast

func AssertHTTPStatusAtLeast(min int) Assertion

AssertHTTPStatusAtLeast returns an Assertion that the HTTP status code is >= min.

func AssertHasThinking

func AssertHasThinking() Assertion

AssertHasThinking returns an Assertion that thinking content is non-empty.

func AssertHasToolCalls

func AssertHasToolCalls(count int) Assertion

AssertHasToolCalls returns an Assertion that exactly count tool calls are present.

func AssertModelContains

func AssertModelContains(substring string) Assertion

AssertModelContains returns an Assertion that the model name contains substring.

func AssertNoThinking

func AssertNoThinking() Assertion

AssertNoThinking returns an Assertion that no thinking content is present.

func AssertResponsesItemIDsCanonical added in v0.260924.1

func AssertResponsesItemIDsCanonical() Assertion

AssertResponsesItemIDsCanonical returns an Assertion that a Responses response synthesized by the gateway (source Responses, target not Responses) carries canonical ids: the response id and every output item id have the type prefix and 32-hex shape OpenAI validates on replay, ids are unique within the response, a function_call's call_id is set and distinct from its item id, and in streaming the same item id appears in output_item.added, output_item.done and the final response output.

It is a no-op for other pairs: on a Responses passthrough the ids come from the upstream, and a non-Responses source never sees these ids.

func AssertRoleEquals

func AssertRoleEquals(expected string) Assertion

AssertRoleEquals returns an Assertion that the response role equals expected.

func AssertStreamError added in v0.260723.1

func AssertStreamError() Assertion

AssertStreamError returns an Assertion that a streaming client explicitly observed an error after the response had started.

func AssertStreamEventCount

func AssertStreamEventCount(min int) Assertion

AssertStreamEventCount returns an Assertion that at least min SSE events were received.

func AssertStreamEventsContain added in v0.260716.1

func AssertStreamEventsContain(markers ...string) Assertion

AssertStreamEventsContain returns an Assertion that every marker appears somewhere in the raw SSE event lines. Use it to pin a streaming response's event shape (e.g. the Anthropic message_start…message_stop frame sequence) independently of its content.

func AssertStreamNotCompleted added in v0.260723.1

func AssertStreamNotCompleted() Assertion

AssertStreamNotCompleted returns an Assertion that no normal completion marker was observed. Error events and a clean terminal event are deliberately separate states: a truncated turn must never be presented as completed.

func AssertToolCallArgs

func AssertToolCallArgs(index int, key, value string) Assertion

AssertToolCallArgs returns an Assertion that tool call at index has key=value in its JSON args.

func AssertToolCallName

func AssertToolCallName(index int, name string) Assertion

AssertToolCallName returns an Assertion that the tool call at index has the given name.

func AssertUsageNonZero

func AssertUsageNonZero() Assertion

AssertUsageNonZero returns an Assertion that at least one token count > 0. For streaming responses, usage extraction is protocol-dependent and may not be available, so this assertion is skipped in streaming mode.

func AssertUsagePropagated added in v0.260716.1

func AssertUsagePropagated() Assertion

AssertUsagePropagated returns an Assertion that token usage was extracted with both input and output counts > 0 — including for streaming responses, where usage rides the terminal frames (e.g. Anthropic message_delta). Use it when the pipeline under test must propagate usage end-to-end; AssertUsageNonZero is the softer variant that skips streaming.

type RoundTripResult

type RoundTripResult struct {
	// Source and target context
	SourceProtocol protocol.APIType
	TargetProtocol protocol.APIType
	ScenarioName   string
	IsStreaming    bool

	// HTTP layer
	HTTPStatus   int
	RawBody      []byte
	StreamEvents []string // raw SSE event lines (streaming only)
	// StreamError records a failure reported after streaming had already
	// started. It is distinct from an HTTP/API error: headers may already have
	// committed a 200 response while the turn still failed to complete.
	StreamError     string
	StreamCompleted bool // true only when a normal completion marker was observed

	// Extracted semantics (populated by the framework after parsing)
	Content         string
	Role            string
	Model           string
	FinishReason    string
	ToolCalls       []ToolCallResult
	ThinkingContent string
	Usage           *TokenUsage
}

RoundTripResult captures the full result of a round-trip request through the gateway.

type TokenUsage

type TokenUsage struct {
	InputTokens  int
	OutputTokens int
}

TokenUsage holds token counts extracted from a provider response.

type ToolCallResult

type ToolCallResult struct {
	ID        string
	Name      string
	Arguments string // raw JSON string
}

ToolCallResult holds a single tool/function call extracted from a response.

Jump to

Keyboard shortcuts

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