Documentation
¶
Index ¶
- type MockProvider
- func (m *MockProvider) AuthHeader() string
- func (m *MockProvider) BaseURL() string
- func (m *MockProvider) BridgedRoutes() []string
- func (m *MockProvider) CircuitBreakerConfig() *config.CircuitBreaker
- func (m *MockProvider) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (intercept.Interceptor, error)
- func (m *MockProvider) InjectAuthHeader(h *http.Header)
- func (m *MockProvider) Name() string
- func (m *MockProvider) PassthroughRoutes() []string
- func (m *MockProvider) RoutePrefix() string
- type MockRecorder
- func (m *MockRecorder) RecordInterception(ctx context.Context, req *recorder.InterceptionRecord) error
- func (m *MockRecorder) RecordInterceptionEnded(ctx context.Context, req *recorder.InterceptionRecordEnded) error
- func (m *MockRecorder) RecordPromptUsage(ctx context.Context, req *recorder.PromptUsageRecord) error
- func (m *MockRecorder) RecordTokenUsage(ctx context.Context, req *recorder.TokenUsageRecord) error
- func (m *MockRecorder) RecordToolUsage(ctx context.Context, req *recorder.ToolUsageRecord) error
- func (m *MockRecorder) RecordedInterceptions() []*recorder.InterceptionRecord
- func (m *MockRecorder) RecordedPromptUsages() []*recorder.PromptUsageRecord
- func (m *MockRecorder) RecordedTokenUsages() []*recorder.TokenUsageRecord
- func (m *MockRecorder) RecordedToolUsages() []*recorder.ToolUsageRecord
- func (m *MockRecorder) ToolUsages() []*recorder.ToolUsageRecord
- func (m *MockRecorder) VerifyAllInterceptionsEnded(t *testing.T)
- type MockUpstream
- type ReceivedRequest
- type UpstreamResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MockProvider ¶ added in v1.0.1
type MockProvider struct {
Name_ string
URL string
Bridged []string
Passthrough []string
InterceptorFunc func(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (intercept.Interceptor, error)
}
func (*MockProvider) AuthHeader ¶ added in v1.0.1
func (m *MockProvider) AuthHeader() string
func (*MockProvider) BaseURL ¶ added in v1.0.1
func (m *MockProvider) BaseURL() string
func (*MockProvider) BridgedRoutes ¶ added in v1.0.1
func (m *MockProvider) BridgedRoutes() []string
func (*MockProvider) CircuitBreakerConfig ¶ added in v1.0.1
func (m *MockProvider) CircuitBreakerConfig() *config.CircuitBreaker
func (*MockProvider) CreateInterceptor ¶ added in v1.0.1
func (m *MockProvider) CreateInterceptor(w http.ResponseWriter, r *http.Request, tracer trace.Tracer) (intercept.Interceptor, error)
func (*MockProvider) InjectAuthHeader ¶ added in v1.0.1
func (m *MockProvider) InjectAuthHeader(h *http.Header)
func (*MockProvider) Name ¶ added in v1.0.1
func (m *MockProvider) Name() string
func (*MockProvider) PassthroughRoutes ¶ added in v1.0.1
func (m *MockProvider) PassthroughRoutes() []string
func (*MockProvider) RoutePrefix ¶ added in v1.0.3
func (m *MockProvider) RoutePrefix() string
type MockRecorder ¶
type MockRecorder struct {
// contains filtered or unexported fields
}
MockRecorder is a test implementation of aibridge.Recorder that captures all recording calls for test assertions.
func (*MockRecorder) RecordInterception ¶
func (m *MockRecorder) RecordInterception(ctx context.Context, req *recorder.InterceptionRecord) error
func (*MockRecorder) RecordInterceptionEnded ¶
func (m *MockRecorder) RecordInterceptionEnded(ctx context.Context, req *recorder.InterceptionRecordEnded) error
func (*MockRecorder) RecordPromptUsage ¶
func (m *MockRecorder) RecordPromptUsage(ctx context.Context, req *recorder.PromptUsageRecord) error
func (*MockRecorder) RecordTokenUsage ¶
func (m *MockRecorder) RecordTokenUsage(ctx context.Context, req *recorder.TokenUsageRecord) error
func (*MockRecorder) RecordToolUsage ¶
func (m *MockRecorder) RecordToolUsage(ctx context.Context, req *recorder.ToolUsageRecord) error
func (*MockRecorder) RecordedInterceptions ¶
func (m *MockRecorder) RecordedInterceptions() []*recorder.InterceptionRecord
RecordedInterceptions returns a copy of recorded interceptions in a thread-safe manner. Note: This is a shallow clone (see RecordedTokenUsages for details).
func (*MockRecorder) RecordedPromptUsages ¶
func (m *MockRecorder) RecordedPromptUsages() []*recorder.PromptUsageRecord
RecordedPromptUsages returns a copy of recorded prompt usages in a thread-safe manner. Note: This is a shallow clone (see RecordedTokenUsages for details).
func (*MockRecorder) RecordedTokenUsages ¶
func (m *MockRecorder) RecordedTokenUsages() []*recorder.TokenUsageRecord
RecordedTokenUsages returns a copy of recorded token usages in a thread-safe manner. Note: This is a shallow clone - the slice is copied but the pointers reference the same underlying records. This is sufficient for our test assertions which only read the data and don't modify the records.
func (*MockRecorder) RecordedToolUsages ¶
func (m *MockRecorder) RecordedToolUsages() []*recorder.ToolUsageRecord
RecordedToolUsages returns a copy of recorded tool usages in a thread-safe manner. Note: This is a shallow clone (see RecordedTokenUsages for details).
func (*MockRecorder) ToolUsages ¶
func (m *MockRecorder) ToolUsages() []*recorder.ToolUsageRecord
ToolUsages returns the raw toolUsages slice for direct field access in tests. Use RecordedToolUsages() for thread-safe access when assertions don't need direct field access.
func (*MockRecorder) VerifyAllInterceptionsEnded ¶
func (m *MockRecorder) VerifyAllInterceptionsEnded(t *testing.T)
VerifyAllInterceptionsEnded verifies all recorded interceptions have been marked as completed.
type MockUpstream ¶ added in v1.0.7
type MockUpstream struct {
*httptest.Server
// Calls is incremented atomically on every request.
Calls atomic.Uint32
// StatusCode overrides the HTTP status for non-streaming responses.
// Zero means 200.
StatusCode int
// AllowOverflow disables the strict call-count check. When true,
// requests beyond the last response repeat that response, and the
// cleanup assertion only verifies that at least len(responses)
// requests were made. This is useful for error-response tests where
// the bridge may retry.
AllowOverflow bool
// contains filtered or unexported fields
}
MockUpstream replays txtar fixture responses, validates incoming request bodies, and counts calls. It stands in for a real AI provider API (Anthropic, OpenAI) during integration tests.
func NewMockUpstream ¶ added in v1.0.7
func NewMockUpstream(t *testing.T, ctx context.Context, responses ...UpstreamResponse) *MockUpstream
NewMockUpstream creates a started httptest.Server that replays fixture responses. Responses are returned in order: first call → first response. The test fails if the number of requests doesn't match the number of responses (when AllowOverflow is not set, default).
srv := testutil.NewMockUpstream(t, ctx, testutil.NewFixtureResponse(fix)) // simple srv := testutil.NewMockUpstream(t, ctx, testutil.NewFixtureResponse(fix), testutil.NewFixtureToolResponse(fix)) // multi-turn
func (*MockUpstream) ReceivedRequests ¶ added in v1.0.7
func (ms *MockUpstream) ReceivedRequests() []ReceivedRequest
ReceivedRequests returns a copy of all requests received so far.
type ReceivedRequest ¶ added in v1.0.7
ReceivedRequest captures the details of a single request handled by MockUpstream.
type UpstreamResponse ¶ added in v1.0.7
type UpstreamResponse struct {
Streaming []byte // returned when the request has "stream": true.
Blocking []byte // returned for non-streaming requests.
// OnRequest, if non-nil, is called with the incoming request and body
// before the response is sent. Use it for per-request assertions.
OnRequest func(r *http.Request, body []byte)
}
UpstreamResponse defines a single response that MockUpstream will replay for one incoming request. Use NewFixtureResponse or NewFixtureToolResponse to construct one from a parsed txtar archive.
func NewFixtureResponse ¶ added in v1.0.7
func NewFixtureResponse(fix fixtures.Fixture) UpstreamResponse
NewFixtureResponse creates an UpstreamResponse from a parsed fixture archive. It reads whichever of 'streaming' and 'non-streaming' sections exist; not every fixture has both (e.g. error fixtures may only define one).
func NewFixtureToolResponse ¶ added in v1.0.7
func NewFixtureToolResponse(fix fixtures.Fixture) UpstreamResponse
NewFixtureToolResponse creates an UpstreamResponse from the tool-call fixture files. It reads whichever of 'streaming/tool-call' and 'non-streaming/tool-call' sections exist.