fake

package
v1.16.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fake provides a VCR-based proxy for replaying recorded AI API responses. This is useful for E2E testing without making real API calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APIKeyHeaderUpdater added in v1.15.2

func APIKeyHeaderUpdater(host string, req *http.Request)

APIKeyHeaderUpdater injects API keys from environment variables into request headers. This is used when recording API interactions to ensure real API calls succeed.

func CustomMatcher

func CustomMatcher(onError func(err error)) recorder.MatcherFunc

CustomMatcher creates a matcher that normalizes tool call IDs for consistent matching. The onError callback is called if reading the request body fails (nil logs and returns false).

func Handle

func Handle(transport http.RoundTripper, headerUpdater func(host string, req *http.Request)) echo.HandlerFunc

Handle creates an echo handler that proxies requests through the VCR transport. The headerUpdater is called with the host and request to update headers (e.g., for adding API keys).

func IsStreamResponse

func IsStreamResponse(resp *http.Response) bool

IsStreamResponse checks if the response should be streamed.

func RemoveHeadersHook

func RemoveHeadersHook(i *cassette.Interaction) error

RemoveHeadersHook strips headers from recorded interactions for security.

func StartProxy

func StartProxy(cassettePath string) (string, func() error, error)

StartProxy starts an internal HTTP proxy that replays cassette responses. It returns the proxy URL and a cleanup function that should be called when done.

func StartProxyWithOptions

func StartProxyWithOptions(
	cassettePath string,
	mode recorder.Mode,
	matcher recorder.MatcherFunc,
	headerUpdater func(host string, req *http.Request),
) (string, func() error, error)

StartProxyWithOptions starts an internal HTTP proxy with configurable options. - mode: recorder mode (ModeReplayOnly, ModeRecordOnce, etc.) - matcher: custom matcher function (nil uses default CustomMatcher) - headerUpdater: optional function to update request headers (for recording with real API keys)

func StartRecordingProxy added in v1.15.2

func StartRecordingProxy(cassettePath string) (string, func() error, error)

StartRecordingProxy starts a proxy that records AI API interactions to a cassette file. It injects API keys from environment variables for the actual API calls. The recorded cassette can later be replayed using StartProxy.

func StreamCopy

func StreamCopy(c echo.Context, resp *http.Response) error

StreamCopy copies a streaming response to the client.

func TargetURLForHost

func TargetURLForHost(host string) func(req *http.Request) string

TargetURLForHost returns the target URL builder for a given forwarding host. Returns nil if the host is not recognized.

Types

This section is empty.

Jump to

Keyboard shortcuts

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