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 ¶
- func FinalResponsesBody(r *RoundTripResult) (map[string]any, error)
- type Assertion
- func AssertContentContains(substring string) Assertion
- func AssertContentEquals(expected string) Assertion
- func AssertContentNonEmpty() Assertion
- func AssertErrorMessageContains(substring string) Assertion
- func AssertFinishReason(expected string) Assertion
- func AssertFinishReasonNonEmpty() Assertion
- func AssertFinishReasonOneOf(accepted ...string) Assertion
- func AssertHTTPStatus(expected int) Assertion
- func AssertHTTPStatusAtLeast(min int) Assertion
- func AssertHasThinking() Assertion
- func AssertHasToolCalls(count int) Assertion
- func AssertModelContains(substring string) Assertion
- func AssertNoThinking() Assertion
- func AssertResponsesItemIDsCanonical() Assertion
- func AssertRoleEquals(expected string) Assertion
- func AssertStreamError() Assertion
- func AssertStreamEventCount(min int) Assertion
- func AssertStreamEventsContain(markers ...string) Assertion
- func AssertStreamNotCompleted() Assertion
- func AssertToolCallArgs(index int, key, value string) Assertion
- func AssertToolCallName(index int, name string) Assertion
- func AssertUsageNonZero() Assertion
- func AssertUsagePropagated() Assertion
- type RoundTripResult
- type TokenUsage
- type ToolCallResult
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 ¶
AssertContentContains returns an Assertion that the response content contains substring.
func AssertContentEquals ¶
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 ¶
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 ¶
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 ¶
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 ¶
AssertHTTPStatus returns an Assertion that the HTTP status code equals expected.
func AssertHTTPStatusAtLeast ¶
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 ¶
AssertHasToolCalls returns an Assertion that exactly count tool calls are present.
func AssertModelContains ¶
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 ¶
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 ¶
AssertStreamEventCount returns an Assertion that at least min SSE events were received.
func AssertStreamEventsContain ¶ added in v0.260716.1
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 ¶
AssertToolCallArgs returns an Assertion that tool call at index has key=value in its JSON args.
func AssertToolCallName ¶
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 ¶
TokenUsage holds token counts extracted from a provider response.
type ToolCallResult ¶
ToolCallResult holds a single tool/function call extracted from a response.