mcptests

package
v1.5.5 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MCP Server URLs from environment
	EnvMCPHTTPServerURL = "MCP_HTTP_URL"
	EnvMCPSSEServerURL  = "MCP_SSE_URL"
	EnvMCPHTTPHeaders   = "MCP_HTTP_HEADERS" // JSON string of headers, e.g. {"Authorization":"Bearer token"}
	EnvMCPSSEHeaders    = "MCP_SSE_HEADERS"  // JSON string of headers, e.g. {"Authorization":"Bearer token"}

	// Bifrost API configuration
	EnvBifrostAPIKey       = "OPENAI_API_KEY"
	EnvBifrostTestProvider = "BIFROST_TEST_PROVIDER"
	EnvBifrostTestModel    = "BIFROST_TEST_MODEL"

	// Default values
	DefaultTestProvider = "openai"
	DefaultTestModel    = "gpt-4o"
)

Variables

This section is empty.

Functions

func AssertAgentCompletedInTurns

func AssertAgentCompletedInTurns(t *testing.T, mocker *DynamicLLMMocker, expectedTurns int)

AssertAgentCompletedInTurns verifies the agent completed in expected number of LLM calls

func AssertAgentCompletedInTurnsResponses

func AssertAgentCompletedInTurnsResponses(t *testing.T, mocker *DynamicLLMMocker, expectedTurns int)

AssertAgentCompletedInTurnsResponses verifies the agent completed in expected number of turns (Responses API)

func AssertAgentCompletedSuccessfully

func AssertAgentCompletedSuccessfully(t *testing.T, resp *schemas.BifrostChatResponse, bifrostErr *schemas.BifrostError)

AssertAgentCompletedSuccessfully asserts that agent completed without errors

func AssertAgentError

func AssertAgentError(t *testing.T, bifrostErr *schemas.BifrostError, shouldContain string)

AssertAgentError verifies the agent returned an error

func AssertAgentFinalResponse

func AssertAgentFinalResponse(t *testing.T, response *schemas.BifrostChatResponse, expectedFinishReason string, shouldContainText string)

AssertAgentFinalResponse verifies the final agent response

func AssertAgentFinalResponseResponses

func AssertAgentFinalResponseResponses(t *testing.T, result *schemas.BifrostResponsesResponse, mustContainInContent string)

AssertAgentFinalResponseResponses verifies the final response (Responses API)

func AssertAgentMaxDepthReached

func AssertAgentMaxDepthReached(t *testing.T, mocker *DynamicLLMMocker, maxDepth int)

AssertAgentMaxDepthReached verifies the agent stopped due to max depth

func AssertAgentStoppedAtTurn

func AssertAgentStoppedAtTurn(t *testing.T, mocker *DynamicLLMMocker, expectedTurn int)

AssertAgentStoppedAtTurn verifies the agent stopped at a specific turn (e.g., due to non-auto tool)

func AssertAgentStoppedAtTurnResponses

func AssertAgentStoppedAtTurnResponses(t *testing.T, mocker *DynamicLLMMocker, expectedTurn int)

AssertAgentStoppedAtTurnResponses verifies the agent stopped at expected turn (Responses API)

func AssertAgentSuccess

func AssertAgentSuccess(t *testing.T, response *schemas.BifrostChatResponse, bifrostErr *schemas.BifrostError)

AssertAgentSuccess verifies the agent completed without errors

func AssertBifrostErrorContains

func AssertBifrostErrorContains(t *testing.T, bifrostErr *schemas.BifrostError, expectedMessage string)

AssertBifrostErrorContains asserts that bifrost error contains expected message

func AssertClientState

func AssertClientState(t *testing.T, clients []schemas.MCPClientState, clientID string, expectedState schemas.MCPConnectionState)

AssertClientState asserts that a client is in the expected state

func AssertCodeExecutionError

func AssertCodeExecutionError(t *testing.T, result *schemas.ChatMessage, expectedErrorContains string)

AssertCodeExecutionError asserts that code execution failed with an error Note: This checks if the return value contains an error field, not if ParseCodeModeResponse returned an error

func AssertCodeExecutionSuccess

func AssertCodeExecutionSuccess(t *testing.T, result *schemas.ChatMessage, expectedOutputContains string)

AssertCodeExecutionSuccess asserts that code execution completed successfully

func AssertExecutionTimeUnder

func AssertExecutionTimeUnder(t *testing.T, fn func(), maxDuration time.Duration, operationName string)

AssertExecutionTimeUnder asserts that execution completes within expected time

func AssertNoToolCalls

func AssertNoToolCalls(t *testing.T, response *schemas.BifrostChatResponse)

AssertNoToolCalls verifies there are no tool calls in the response

func AssertPluginCalled

func AssertPluginCalled(t *testing.T, plugin *TestLoggingPlugin, expectedCalls int)

AssertPluginCalled asserts that a plugin hook was called

func AssertRequestIDChanged

func AssertRequestIDChanged(t *testing.T, ctx1 *schemas.BifrostContext, ctx2 *schemas.BifrostContext)

AssertRequestIDChanged verifies request ID changed between turns

func AssertRequestIDPropagated

func AssertRequestIDPropagated(t *testing.T, ctx *schemas.BifrostContext)

AssertRequestIDPropagated verifies request ID is present in context

func AssertResponseHasToolCalls

func AssertResponseHasToolCalls(t *testing.T, resp *schemas.BifrostChatResponse, expectedCount int)

AssertResponseHasToolCalls asserts that response has tool calls

func AssertToolCallExtracted

func AssertToolCallExtracted(t *testing.T, code string, expectedServerName string, expectedToolName string)

AssertToolCallExtracted asserts that tool calls are correctly extracted from code

func AssertToolExecuted

func AssertToolExecuted(t *testing.T, resp *schemas.BifrostMCPResponse, err error)

AssertToolExecuted asserts that a tool was successfully executed

func AssertToolExecutedInTurn

func AssertToolExecutedInTurn(t *testing.T, mocker *DynamicLLMMocker, toolName string, turn int)

AssertToolExecutedInTurn verifies a tool was executed in a specific turn

func AssertToolNotExecuted

func AssertToolNotExecuted(t *testing.T, err error, expectedErrorSubstring string)

AssertToolNotExecuted asserts that a tool execution failed

func AssertToolNotExecutedInAnyTurn

func AssertToolNotExecutedInAnyTurn(t *testing.T, mocker *DynamicLLMMocker, toolName string)

AssertToolNotExecutedInAnyTurn verifies a tool was never executed

func AssertToolResponse

func AssertToolResponse(t *testing.T, resp *schemas.BifrostMCPResponse, expectedContent string)

AssertToolResponse asserts that a tool response is valid

func AssertToolResponseContains

func AssertToolResponseContains(t *testing.T, resp *schemas.BifrostMCPResponse, expectedText string)

AssertToolResponseContains asserts that tool response contains expected text

func AssertToolResultPresent

func AssertToolResultPresent(t *testing.T, mocker *DynamicLLMMocker, callID string, shouldContain string)

AssertToolResultPresent verifies a tool result is in the conversation history

func AssertToolsExecutedInParallel

func AssertToolsExecutedInParallel(t *testing.T, mocker *DynamicLLMMocker, toolNames []string, turn int)

AssertToolsExecutedInParallel verifies multiple tools were called in the same turn

func AssertToolsExecutedInParallelResponses

func AssertToolsExecutedInParallelResponses(t *testing.T, mocker *DynamicLLMMocker, expectedTools []string, turn int)

AssertToolsExecutedInParallelResponses verifies tools were executed in a specific turn (Responses API)

func CountToolCallsInChatHistory

func CountToolCallsInChatHistory(history []schemas.ChatMessage) int

CountToolCallsInChatHistory counts the number of tool calls in Chat history

func CountToolCallsInResponsesHistory

func CountToolCallsInResponsesHistory(history []schemas.ResponsesMessage) int

CountToolCallsInResponsesHistory counts the number of tool calls in Responses history

func CreateChatResponseWithText

func CreateChatResponseWithText(text string) *schemas.BifrostChatResponse

CreateChatResponseWithText creates a Chat response with text

func CreateChatResponseWithToolCalls

func CreateChatResponseWithToolCalls(toolCalls []schemas.ChatAssistantMessageToolCall) *schemas.BifrostChatResponse

CreateChatResponseWithToolCalls creates a Chat response with tool calls

func CreateExecuteToolCodeCall

func CreateExecuteToolCodeCall(callID string, code string) schemas.ChatAssistantMessageToolCall

CreateExecuteToolCodeCall creates executeToolCode tool call for testing

func CreateExecuteToolCodeCallResponses

func CreateExecuteToolCodeCallResponses(callID string, code string) schemas.ResponsesToolMessage

CreateExecuteToolCodeCallResponses creates executeToolCode tool call for Responses API

func CreateInProcessToolCall

func CreateInProcessToolCall(id, toolName string, args map[string]interface{}) schemas.ChatAssistantMessageToolCall

CreateInProcessToolCall creates a tool call for an in-process tool In-process tools are registered with "bifrostInternal-" prefix The tool name format is: bifrostInternal-{tool_name} (e.g., "bifrostInternal-echo")

func CreateResponsesResponseWithText

func CreateResponsesResponseWithText(text string) *schemas.BifrostResponsesResponse

CreateResponsesResponseWithText creates a Responses response with text

func CreateResponsesResponseWithToolCalls

func CreateResponsesResponseWithToolCalls(toolCalls []schemas.ResponsesToolMessage) *schemas.BifrostResponsesResponse

CreateResponsesResponseWithToolCalls creates a Responses response with tool calls

func CreateResponsesToolCallForExecution

func CreateResponsesToolCallForExecution(callID string, toolName string, args map[string]interface{}) schemas.ResponsesToolMessage

CreateResponsesToolCallForExecution creates a Responses API tool call with the proper client prefix for direct execution via ExecuteResponsesMCPTool. The tool name is automatically prefixed with "bifrostInternal-" to match how tools are stored in the MCP manager.

func CreateSTDIOToolCall

func CreateSTDIOToolCall(id, serverName, toolName string, args map[string]interface{}) schemas.ChatAssistantMessageToolCall

CreateSTDIOToolCall creates a tool call for a STDIO server tool (with server prefix) Note: serverName should be the client Name (e.g., "GoTestServer"), not the ID The tool name format is: {ServerName}-{tool_name} (e.g., "GoTestServer-uuid_generate")

func CreateTempTestFile

func CreateTempTestFile(t *testing.T, content string) string

CreateTempTestFile creates a temporary test file

func CreateTestContextWithCustomTimeout

func CreateTestContextWithCustomTimeout(timeout time.Duration) (*schemas.BifrostContext, context.CancelFunc)

CreateTestContextWithTimeout creates a test context with custom timeout

func CreateTestContextWithMCPFilter

func CreateTestContextWithMCPFilter(includeClients []string, includeTools []string) *schemas.BifrostContext

CreateTestContextWithMCPFilter creates a test context with MCP filtering

func CreateToolCall

func CreateToolCall(id, toolName string, args map[string]interface{}) schemas.ChatAssistantMessageToolCall

CreateToolCall is a convenience function for creating tool calls in tests

func CreateToolCallForExecution

func CreateToolCallForExecution(callID string, toolName string, args map[string]interface{}) schemas.ChatAssistantMessageToolCall

CreateToolCallForExecution creates a tool call with the proper client prefix for direct execution via ExecuteChatMCPTool. The tool name is automatically prefixed with "bifrostInternal-" to match how tools are stored in the MCP manager.

func GenerateInvalidCode

func GenerateInvalidCode(errorType string) string

GenerateInvalidCode generates invalid Starlark code for testing

func GenerateInvalidJSON

func GenerateInvalidJSON() []string

GenerateInvalidJSON returns various malformed JSON strings for testing

func GeneratePathTraversalAttempts

func GeneratePathTraversalAttempts() []string

GeneratePathTraversalAttempts generates various path traversal attack strings

func GenerateRandomToolName

func GenerateRandomToolName(prefix string) string

GenerateRandomToolName generates a random tool name for testing

func GenerateUnicodeStrings

func GenerateUnicodeStrings() []string

GenerateUnicodeStrings generates various unicode strings for testing

func GenerateValidCode

func GenerateValidCode(codeType string) string

GenerateValidCode generates valid TypeScript/JavaScript code for testing

func GetActualToolNameFromServer

func GetActualToolNameFromServer(t *testing.T, clientName string) string

GetActualToolNameFromServer gets the actual tool name from the HTTP server Returns the first tool available that matches the filter pattern

func GetActualToolNamesFromServer

func GetActualToolNamesFromServer(t *testing.T, count int) []string

GetActualToolNamesFromServer gets multiple actual tool names from the HTTP server

func GetAllToolResultsFromChatHistory

func GetAllToolResultsFromChatHistory(history []schemas.ChatMessage) map[string]string

GetAllToolResultsFromChatHistory extracts all tool results from Chat message history

func GetAllToolResultsFromResponsesHistory

func GetAllToolResultsFromResponsesHistory(history []schemas.ResponsesMessage) map[string]string

GetAllToolResultsFromResponsesHistory extracts all tool results from Responses message history

func GetBifrostRoot

func GetBifrostRoot(t *testing.T) string

GetBifrostRoot returns the bifrost root directory by walking up from the current directory

func GetEdgeCaseServerConfig

func GetEdgeCaseServerConfig(bifrostRoot string) schemas.MCPClientConfig

GetEdgeCaseServerConfig returns a STDIO client configuration for the edge-case-server located in examples/mcps/edge-case-server. Provides tools for testing edge cases like unicode, binary data, large payloads, nested structures, null values, and special characters. The server must be built first using: go build -o bin/edge-case-server

func GetErrorTestServerConfig

func GetErrorTestServerConfig(bifrostRoot string) schemas.MCPClientConfig

GetErrorTestServerConfig returns a STDIO client configuration for the error-test-server located in examples/mcps/error-test-server. Provides tools for testing error scenarios including timeouts, malformed JSON, various error types, intermittent failures, and memory intensive operations. The server must be built first using: go build -o bin/error-test-server

func GetGoTestServerConfig

func GetGoTestServerConfig(bifrostRoot string) schemas.MCPClientConfig

GetGoTestServerConfig returns a STDIO client configuration for the go-test-server located in examples/mcps/go-test-server. Provides tools for string manipulation, JSON validation, UUID generation, hashing, and encoding/decoding. The server must be built first using: go build -o bin/go-test-server

func GetLastUserMessageFromChatHistory

func GetLastUserMessageFromChatHistory(history []schemas.ChatMessage) (string, bool)

GetLastUserMessageFromChatHistory extracts the last user message from Chat history

func GetLastUserMessageFromResponsesHistory

func GetLastUserMessageFromResponsesHistory(history []schemas.ResponsesMessage) (string, bool)

GetLastUserMessageFromResponsesHistory extracts the last user message from Responses history

func GetParallelTestServerConfig

func GetParallelTestServerConfig(bifrostRoot string) schemas.MCPClientConfig

GetParallelTestServerConfig returns a STDIO client configuration for the parallel-test-server located in examples/mcps/parallel-test-server. Provides tools with different execution times for testing parallel execution and timing behavior (fast, medium, slow, very slow operations). The server must be built first using: go build -o bin/parallel-test-server

func GetSampleAssistantMessage

func GetSampleAssistantMessage(content string) schemas.ChatMessage

GetSampleAssistantMessage returns a sample assistant message

func GetSampleCalculatorTool

func GetSampleCalculatorTool() schemas.ChatTool

GetSampleCalculatorTool returns a sample calculator tool definition

func GetSampleCalculatorToolCall

func GetSampleCalculatorToolCall(id string, operation string, x, y float64) schemas.ChatAssistantMessageToolCall

GetSampleCalculatorToolCall returns a sample calculator tool call

func GetSampleCodeModeAgentClientConfig

func GetSampleCodeModeAgentClientConfig(t *testing.T, serverURL string) schemas.MCPClientConfig

GetSampleCodeModeAgentClientConfig returns code mode client configured for agent mode with headers applied from test config

func GetSampleCodeModeClientConfig

func GetSampleCodeModeClientConfig(t *testing.T, serverURL string) schemas.MCPClientConfig

GetSampleCodeModeClientConfig returns a sample code mode client configuration with headers applied from test config

func GetSampleDelayTool

func GetSampleDelayTool() schemas.ChatTool

GetSampleDelayTool returns a sample delay tool for timeout testing

func GetSampleDelayToolCall

func GetSampleDelayToolCall(id string, seconds float64) schemas.ChatAssistantMessageToolCall

GetSampleDelayToolCall returns a sample delay tool call

func GetSampleEchoTool

func GetSampleEchoTool() schemas.ChatTool

GetSampleEchoTool returns a sample echo tool definition

func GetSampleEchoToolCall

func GetSampleEchoToolCall(id string, message string) schemas.ChatAssistantMessageToolCall

GetSampleEchoToolCall returns a sample echo tool call

func GetSampleErrorTool

func GetSampleErrorTool() schemas.ChatTool

GetSampleErrorTool returns a sample error tool for error testing

func GetSampleHTTPClientConfig

func GetSampleHTTPClientConfig(serverURL string) schemas.MCPClientConfig

GetSampleHTTPClientConfig returns a sample HTTP client configuration

func GetSampleHTTPClientConfigNoSpaces

func GetSampleHTTPClientConfigNoSpaces(serverURL string) schemas.MCPClientConfig

GetSampleHTTPClientConfigNoSpaces returns HTTP client config without spaces in name (for agent tests)

func GetSampleInProcessClientConfig

func GetSampleInProcessClientConfig() schemas.MCPClientConfig

GetSampleInProcessClientConfig returns a sample InProcess client configuration

func GetSampleResponsesAssistantMessage

func GetSampleResponsesAssistantMessage(content string) schemas.ResponsesMessage

GetSampleResponsesAssistantMessage returns a sample Responses API assistant message

func GetSampleResponsesToolCallMessage

func GetSampleResponsesToolCallMessage(callID, toolName string, args map[string]interface{}) schemas.ResponsesMessage

GetSampleResponsesToolCallMessage returns a sample Responses API tool call

func GetSampleResponsesToolResultMessage

func GetSampleResponsesToolResultMessage(callID, output string) schemas.ResponsesMessage

GetSampleResponsesToolResultMessage returns a sample Responses API tool result

func GetSampleResponsesUserMessage

func GetSampleResponsesUserMessage(content string) schemas.ResponsesMessage

GetSampleResponsesUserMessage returns a sample Responses API user message

func GetSampleSSEClientConfig

func GetSampleSSEClientConfig(serverURL string) schemas.MCPClientConfig

GetSampleSSEClientConfig returns a sample SSE client configuration

func GetSampleSTDIOClientConfig

func GetSampleSTDIOClientConfig(command string, args []string) schemas.MCPClientConfig

GetSampleSTDIOClientConfig returns a sample STDIO client configuration

func GetSampleToolCallMessage

func GetSampleToolCallMessage(toolCalls []schemas.ChatAssistantMessageToolCall) schemas.ChatMessage

GetSampleToolCallMessage returns a sample message with tool calls

func GetSampleToolResultMessage

func GetSampleToolResultMessage(toolCallID, content string) schemas.ChatMessage

GetSampleToolResultMessage returns a sample tool result message

func GetSampleUserMessage

func GetSampleUserMessage(content string) schemas.ChatMessage

GetSampleUserMessage returns a sample user message

func GetSampleUserMessageResponses

func GetSampleUserMessageResponses(text string) schemas.ResponsesMessage

GetSampleUserMessageResponses is an alias for GetSampleResponsesUserMessage

func GetSampleWeatherTool

func GetSampleWeatherTool() schemas.ChatTool

GetSampleWeatherTool returns a sample weather tool definition

func GetSampleWeatherToolCall

func GetSampleWeatherToolCall(id string, location string, units string) schemas.ChatAssistantMessageToolCall

GetSampleWeatherToolCall returns a sample weather tool call

func GetTemperatureMCPClientConfig

func GetTemperatureMCPClientConfig(bifrostRoot string) schemas.MCPClientConfig

GetTemperatureMCPClientConfig returns a STDIO client configuration for the temperature MCP server located in examples/mcps/temperature. This requires the temperature server to be built first. The path is relative to the bifrost root directory.

func GetTestDataPath

func GetTestDataPath(t *testing.T, filename string) string

GetTestDataPath returns path to test data file

func GetToolResultFromChatHistory

func GetToolResultFromChatHistory(history []schemas.ChatMessage, callID string) (string, bool)

GetToolResultFromChatHistory extracts a tool result from Chat message history by call ID

func GetToolResultFromResponsesHistory

func GetToolResultFromResponsesHistory(history []schemas.ResponsesMessage, callID string) (string, bool)

GetToolResultFromResponsesHistory extracts a tool result from Responses message history by call ID

func HasToolCallInChatHistory

func HasToolCallInChatHistory(history []schemas.ChatMessage, toolName string) bool

HasToolCallInChatHistory checks if a specific tool was called in Chat history

func HasToolCallInResponsesHistory

func HasToolCallInResponsesHistory(history []schemas.ResponsesMessage, toolName string) bool

HasToolCallInResponsesHistory checks if a specific tool was called in Responses history Supports both prefixed (bifrostInternal-toolName) and unprefixed tool names

func InitMCPServerPaths

func InitMCPServerPaths(t *testing.T)

InitMCPServerPaths initializes the global MCP server paths Call this in tests that need STDIO MCP servers

func MeasureExecutionTime

func MeasureExecutionTime(t *testing.T, name string, fn func()) time.Duration

MeasureExecutionTime measures execution time of a function

func MustMarshalJSON

func MustMarshalJSON(t *testing.T, v interface{}) string

MustMarshalJSON marshals value to JSON or fails test

func MustUnmarshalJSON

func MustUnmarshalJSON(t *testing.T, data string, v interface{})

MustUnmarshalJSON unmarshals JSON to value or fails test

func ParseCodeModeResponse

func ParseCodeModeResponse(t *testing.T, responseText string) (returnValue interface{}, hasError bool, errorMsg string)

ParseCodeModeResponse parses the text response from executeToolCode and extracts the return value. The response format is:

[Console output: ...]
Execution completed successfully.
Return value: <JSON>
Environment: ...

OR for errors:

Execution runtime error:
<error message>
...

func RegisterCalculatorTool

func RegisterCalculatorTool(manager *mcp.MCPManager) error

RegisterCalculatorTool registers a calculator tool for testing

func RegisterDelayTool

func RegisterDelayTool(manager *mcp.MCPManager) error

RegisterDelayTool registers a delay tool that sleeps for specified seconds

func RegisterEchoTool

func RegisterEchoTool(manager *mcp.MCPManager) error

RegisterEchoTool registers a simple echo tool for testing

func RegisterGetTemperatureTool

func RegisterGetTemperatureTool(manager *mcp.MCPManager) error

RegisterGetTemperatureTool registers a mock temperature tool (same name as STDIO server for conflict testing)

func RegisterGetTimeTool

func RegisterGetTimeTool(manager *mcp.MCPManager) error

RegisterGetTimeTool registers a tool that returns current time info

func RegisterReadFileTool

func RegisterReadFileTool(manager *mcp.MCPManager) error

RegisterReadFileTool registers a mock file reading tool for testing

func RegisterSearchTool

func RegisterSearchTool(manager *mcp.MCPManager) error

RegisterSearchTool registers a mock search tool for testing

func RegisterThrowErrorTool

func RegisterThrowErrorTool(manager *mcp.MCPManager) error

RegisterThrowErrorTool registers a tool that always throws an error

func RegisterWeatherTool

func RegisterWeatherTool(manager *mcp.MCPManager) error

RegisterWeatherTool registers a mock weather tool for testing

func RunAgentScenario

func RunAgentScenario(t *testing.T, scenario AgentScenario)

RunAgentScenario executes a complete agent scenario with setup, turns, and assertions

func SetInternalClientAsCodeMode

func SetInternalClientAsCodeMode(manager *mcp.MCPManager, toolsToExecute []string) error

SetInternalClientAsCodeMode configures the internal Bifrost client as a CodeMode client

func SetInternalClientAutoExecute

func SetInternalClientAutoExecute(manager *mcp.MCPManager, toolNames []string) error

SetInternalClientAutoExecute configures which tools should be auto-executed for the internal Bifrost client

func SetupManagerWithAutoExecuteTools

func SetupManagerWithAutoExecuteTools(t *testing.T, tools []string, autoExecuteTools []string) *mcp.MCPManager

SetupManagerWithAutoExecuteTools creates a manager with specified tools set to auto-execute

func SetupManagerWithTools

func SetupManagerWithTools(t *testing.T, tools []string) *mcp.MCPManager

SetupManagerWithTools creates a manager with specified tools registered

func SimpleAgentTest

func SimpleAgentTest(t *testing.T, name string, config AgentTestConfig, responses []ChatResponseFunc, assertions func(*testing.T, *schemas.BifrostChatResponse, *schemas.BifrostError, *DynamicLLMMocker))

SimpleAgentTest runs a simple agent test with inline setup

Types

type AgentAssertion

type AgentAssertion struct {
	Type     string // "turn_count", "tool_executed", "final_text", etc.
	Expected interface{}
}

AgentAssertion represents an assertion to make after agent execution

type AgentScenario

type AgentScenario struct {
	Name        string
	Description string
	Setup       AgentTestConfig
	Turns       []AgentTurn
	Assertions  []AgentAssertion
}

AgentScenario represents a complete multi-turn agent test scenario

type AgentTestConfig

type AgentTestConfig struct {
	// Tool registration
	InProcessTools []string // InProcess tools to register (echo, calculator, weather, etc.)
	STDIOClients   []string // STDIO clients to add (temperature, go-test-server, etc.)
	HTTPClients    []string // HTTP client names (for future expansion)
	SSEClients     []string // SSE client names (for future expansion)

	// Auto-execute configuration
	AutoExecuteTools []string // Tools to set as auto-execute (supports "*", specific names)

	// Agent configuration
	MaxDepth int // Max agent depth (0 = use default)

	// Context filtering (runtime overrides)
	ClientFiltering []string // Context client filter (MCPContextKeyIncludeClients)
	ToolFiltering   []string // Context tool filter (MCPContextKeyIncludeTools)

	// Test expectations
	ExpectedCallCount   int    // Expected number of LLM calls
	ExpectedFinalReason string // Expected final finish reason
}

AgentTestConfig provides declarative configuration for agent mode tests

type AgentTurn

type AgentTurn struct {
	Description string
	Response    ChatResponseFunc
}

AgentTurn represents a single turn in an agent scenario

type AutoExecuteScenario

type AutoExecuteScenario struct {
	Name               string
	ToolsToExecute     []string
	ToolsToAutoExecute []string
	RequestedTool      string
	ShouldAllowExecute bool // Can execute at all
	ShouldAutoExecute  bool // Should auto-execute in agent mode
	ExpectedBehavior   string
}

AutoExecuteScenario represents a test scenario for auto-execute filtering

func GetAutoExecuteScenarios

func GetAutoExecuteScenarios() []AutoExecuteScenario

GetAutoExecuteScenarios returns comprehensive auto-execute test scenarios

type ChatResponseFunc

type ChatResponseFunc func(history []schemas.ChatMessage) (*schemas.BifrostChatResponse, *schemas.BifrostError)

ChatResponseFunc is a function that generates a Chat response based on message history

func CreateAgentTurnValidatingResult

func CreateAgentTurnValidatingResult(callID string, mustContain []string, nextToolCalls []schemas.ChatAssistantMessageToolCall, failText string) ChatResponseFunc

CreateAgentTurnValidatingResult creates a turn that validates tool result before responding

func CreateAgentTurnWithText

func CreateAgentTurnWithText(text string) ChatResponseFunc

CreateAgentTurnWithText creates a mock LLM response with text (agent stops)

func CreateAgentTurnWithToolCalls

func CreateAgentTurnWithToolCalls(toolCalls ...schemas.ChatAssistantMessageToolCall) ChatResponseFunc

CreateAgentTurnWithToolCalls creates a mock LLM response with tool calls for agent mode

func CreateConditionalChatResponse

func CreateConditionalChatResponse(condition func(history []schemas.ChatMessage) bool, trueResponse, falseResponse *schemas.BifrostChatResponse) ChatResponseFunc

CreateConditionalChatResponse creates a Chat response based on a condition function

func CreateDynamicChatResponse

func CreateDynamicChatResponse(fn func(history []schemas.ChatMessage) *schemas.BifrostChatResponse) ChatResponseFunc

CreateDynamicChatResponse is a convenience function for creating a dynamic Chat response

func CreateSequentialChatResponses

func CreateSequentialChatResponses(responses []*schemas.BifrostChatResponse) []ChatResponseFunc

CreateSequentialChatResponses creates multiple response functions that return responses in sequence

func CreateToolCallSequence

func CreateToolCallSequence(sequences []struct {
	ToolCall     schemas.ChatAssistantMessageToolCall
	ExpectedText string // Text to look for in the result before moving to next
	FinalText    string // Final response text
}) []ChatResponseFunc

CreateToolCallSequence creates a sequence of tool call -> result -> response This is useful for multi-turn agent scenarios

func CreateValidatingChatResponse

func CreateValidatingChatResponse(callID string, mustContain []string, successText string, failureText string) ChatResponseFunc

CreateValidatingChatResponse creates a Chat response that validates tool results before responding Example: CreateValidatingChatResponse("call-1", []string{"15", "C"}, "The temperature is 15°C", "Unexpected result")

type DynamicLLMMocker

type DynamicLLMMocker struct {
	// contains filtered or unexported fields
}

DynamicLLMMocker provides dynamic LLM responses that can inspect message history

func NewDynamicLLMMocker

func NewDynamicLLMMocker() *DynamicLLMMocker

NewDynamicLLMMocker creates a new dynamic LLM mocker

func SetupAgentTest

SetupAgentTest creates a complete agent test environment with the specified configuration

func SetupAgentTestWithClients

func SetupAgentTestWithClients(t *testing.T, config AgentTestConfig, customClients []schemas.MCPClientConfig) (*mcp.MCPManager, *DynamicLLMMocker, *schemas.BifrostContext)

SetupAgentTestWithClients creates an agent test environment with custom client configs

func SetupContextFilteredAgentTest

func SetupContextFilteredAgentTest(t *testing.T, inProcessTools []string, stdioClients []string, autoExecute []string, toolFilter []string, clientFilter []string) (*mcp.MCPManager, *DynamicLLMMocker, *schemas.BifrostContext)

SetupContextFilteredAgentTest creates an agent test with context filtering

func SetupMultiClientAgentTest

func SetupMultiClientAgentTest(t *testing.T, inProcessTools []string, stdioClients []string, autoExecute []string, maxDepth int) (*mcp.MCPManager, *DynamicLLMMocker, *schemas.BifrostContext)

SetupMultiClientAgentTest creates an agent test with multiple client types

func (*DynamicLLMMocker) AddChatResponse

func (m *DynamicLLMMocker) AddChatResponse(fn ChatResponseFunc)

AddChatResponse adds a Chat response function

func (*DynamicLLMMocker) AddResponsesResponse

func (m *DynamicLLMMocker) AddResponsesResponse(fn ResponsesResponseFunc)

AddResponsesResponse adds a Responses response function

func (*DynamicLLMMocker) AddStaticChatResponse

func (m *DynamicLLMMocker) AddStaticChatResponse(response *schemas.BifrostChatResponse)

AddStaticChatResponse adds a static Chat response (backwards compatible)

func (*DynamicLLMMocker) AddStaticResponsesResponse

func (m *DynamicLLMMocker) AddStaticResponsesResponse(response *schemas.BifrostResponsesResponse)

AddStaticResponsesResponse adds a static Responses response (backwards compatible)

func (*DynamicLLMMocker) GetChatCallCount

func (m *DynamicLLMMocker) GetChatCallCount() int

GetChatCallCount returns the number of Chat API calls made

func (*DynamicLLMMocker) GetChatHistory

func (m *DynamicLLMMocker) GetChatHistory() [][]schemas.ChatMessage

GetChatHistory returns all Chat message histories

func (*DynamicLLMMocker) GetResponsesCallCount

func (m *DynamicLLMMocker) GetResponsesCallCount() int

GetResponsesCallCount returns the number of Responses API calls made

func (*DynamicLLMMocker) GetResponsesHistory

func (m *DynamicLLMMocker) GetResponsesHistory() [][]schemas.ResponsesMessage

GetResponsesHistory returns all Responses message histories

func (*DynamicLLMMocker) MakeChatRequest

MakeChatRequest implements the LLM caller interface for Chat API

func (*DynamicLLMMocker) MakeResponsesRequest

MakeResponsesRequest implements the LLM caller interface for Responses API

func (*DynamicLLMMocker) SetDefaultChatResponse

func (m *DynamicLLMMocker) SetDefaultChatResponse(fn ChatResponseFunc)

SetDefaultChatResponse sets a default Chat response to use when no more specific responses are available

func (*DynamicLLMMocker) SetDefaultResponsesResponse

func (m *DynamicLLMMocker) SetDefaultResponsesResponse(fn ResponsesResponseFunc)

SetDefaultResponsesResponse sets a default Responses response to use when no more specific responses are available

func (*DynamicLLMMocker) SetDefaultStaticChatResponse

func (m *DynamicLLMMocker) SetDefaultStaticChatResponse(response *schemas.BifrostChatResponse)

SetDefaultStaticChatResponse sets a static default Chat response

func (*DynamicLLMMocker) SetDefaultStaticResponsesResponse

func (m *DynamicLLMMocker) SetDefaultStaticResponsesResponse(response *schemas.BifrostResponsesResponse)

SetDefaultStaticResponsesResponse sets a static default Responses response

type FilteringScenario

type FilteringScenario struct {
	Name             string
	ConfigTools      []string // ToolsToExecute in config
	ContextTools     []string // Tools in context override
	RequestedTool    string   // Tool being requested
	ShouldExecute    bool     // Expected result
	ExpectedBehavior string   // Description of expected behavior
}

FilteringScenario represents a test scenario for tool filtering

func GetFilteringScenarios

func GetFilteringScenarios() []FilteringScenario

GetFilteringScenarios returns comprehensive filtering test scenarios

type MCPLogEntry

type MCPLogEntry struct {
	Request   *schemas.BifrostMCPRequest
	Response  *schemas.BifrostMCPResponse
	Error     *schemas.BifrostError
	Timestamp int64
}

MCPLogEntry represents a logged MCP operation

type ResponsesResponseFunc

type ResponsesResponseFunc func(history []schemas.ResponsesMessage) (*schemas.BifrostResponsesResponse, *schemas.BifrostError)

ResponsesResponseFunc is a function that generates a Responses response based on message history

func CreateAgentTurnWithTextResponses

func CreateAgentTurnWithTextResponses(text string) ResponsesResponseFunc

CreateAgentTurnWithTextResponses creates a mock Responses API response with text

func CreateAgentTurnWithToolCallsResponses

func CreateAgentTurnWithToolCallsResponses(toolCalls ...schemas.ChatAssistantMessageToolCall) ResponsesResponseFunc

CreateAgentTurnWithToolCallsResponses creates a mock Responses API response with tool calls

func CreateDynamicResponsesResponse

func CreateDynamicResponsesResponse(fn func(history []schemas.ResponsesMessage) *schemas.BifrostResponsesResponse) ResponsesResponseFunc

CreateDynamicResponsesResponse is a convenience function for creating a dynamic Responses response

type TestConfig

type TestConfig struct {
	HTTPServerURL string
	HTTPHeaders   map[string]schemas.EnvVar
	SSEServerURL  string
	SSEHeaders    map[string]schemas.EnvVar
	APIKey        string
	Provider      schemas.ModelProvider
	Model         string
	UseRealLLM    bool
	MaxRetries    int
	RetryDelay    time.Duration
}

TestConfig holds configuration for test execution

func GetTestConfig

func GetTestConfig(t *testing.T) *TestConfig

GetTestConfig loads configuration from environment variables

type TestGovernancePlugin

type TestGovernancePlugin struct {
	// contains filtered or unexported fields
}

TestGovernancePlugin blocks tool execution based on configurable rules

func NewTestGovernancePlugin

func NewTestGovernancePlugin() *TestGovernancePlugin

NewTestGovernancePlugin creates a new test governance plugin

func (*TestGovernancePlugin) AllowTool

func (p *TestGovernancePlugin) AllowTool(toolName string)

AllowTool adds a tool to the allow list (only these tools can execute)

func (*TestGovernancePlugin) BlockClient

func (p *TestGovernancePlugin) BlockClient(clientID string)

BlockClient adds a client to the block list

func (*TestGovernancePlugin) BlockTool

func (p *TestGovernancePlugin) BlockTool(toolName string)

BlockTool adds a tool to the block list

func (*TestGovernancePlugin) Cleanup

func (p *TestGovernancePlugin) Cleanup() error

Cleanup implements schemas.BasePlugin

func (*TestGovernancePlugin) ClearAllowList

func (p *TestGovernancePlugin) ClearAllowList()

ClearAllowList clears the allow list

func (*TestGovernancePlugin) GetName

func (p *TestGovernancePlugin) GetName() string

GetName implements schemas.BasePlugin

func (*TestGovernancePlugin) PostMCPHook

PostMCPHook implements schemas.MCPPlugin

func (*TestGovernancePlugin) PreMCPHook

PreMCPHook implements schemas.MCPPlugin

func (*TestGovernancePlugin) SetBlockAllTools

func (p *TestGovernancePlugin) SetBlockAllTools(block bool)

SetBlockAllTools sets whether to block all tools

func (*TestGovernancePlugin) SetBlockMessage

func (p *TestGovernancePlugin) SetBlockMessage(message string)

SetBlockMessage sets the message returned when blocking

func (*TestGovernancePlugin) UnblockClient

func (p *TestGovernancePlugin) UnblockClient(clientID string)

UnblockClient removes a client from the block list

func (*TestGovernancePlugin) UnblockTool

func (p *TestGovernancePlugin) UnblockTool(toolName string)

UnblockTool removes a tool from the block list

type TestLoggingPlugin

type TestLoggingPlugin struct {
	// contains filtered or unexported fields
}

TestLoggingPlugin captures all MCP requests and responses for testing

func NewTestLoggingPlugin

func NewTestLoggingPlugin() *TestLoggingPlugin

NewTestLoggingPlugin creates a new test logging plugin

func (*TestLoggingPlugin) Cleanup

func (p *TestLoggingPlugin) Cleanup() error

Cleanup implements schemas.BasePlugin

func (*TestLoggingPlugin) GetName

func (p *TestLoggingPlugin) GetName() string

GetName implements schemas.BasePlugin

func (*TestLoggingPlugin) GetPostHookCallCount

func (p *TestLoggingPlugin) GetPostHookCallCount() int

GetPostHookCallCount returns the number of PostHook calls

func (*TestLoggingPlugin) GetPostHookCalls

func (p *TestLoggingPlugin) GetPostHookCalls() []MCPLogEntry

GetPostHookCalls returns all PostHook calls

func (*TestLoggingPlugin) GetPreHookCallCount

func (p *TestLoggingPlugin) GetPreHookCallCount() int

GetPreHookCallCount returns the number of PreHook calls

func (*TestLoggingPlugin) GetPreHookCalls

func (p *TestLoggingPlugin) GetPreHookCalls() []MCPLogEntry

GetPreHookCalls returns all PreHook calls

func (*TestLoggingPlugin) PostMCPHook

PostMCPHook implements schemas.MCPPlugin

func (*TestLoggingPlugin) PreMCPHook

PreMCPHook implements schemas.MCPPlugin

func (*TestLoggingPlugin) Reset

func (p *TestLoggingPlugin) Reset()

Reset clears all captured calls

type TestModifyRequestPlugin

type TestModifyRequestPlugin struct {
	// contains filtered or unexported fields
}

TestModifyRequestPlugin modifies MCP requests in PreHook

func NewTestModifyRequestPlugin

func NewTestModifyRequestPlugin() *TestModifyRequestPlugin

NewTestModifyRequestPlugin creates a new test modify request plugin

func (*TestModifyRequestPlugin) Cleanup

func (p *TestModifyRequestPlugin) Cleanup() error

Cleanup implements schemas.BasePlugin

func (*TestModifyRequestPlugin) GetName

func (p *TestModifyRequestPlugin) GetName() string

GetName implements schemas.BasePlugin

func (*TestModifyRequestPlugin) PostMCPHook

PostMCPHook implements schemas.MCPPlugin

func (*TestModifyRequestPlugin) PreMCPHook

PreMCPHook implements schemas.MCPPlugin

func (*TestModifyRequestPlugin) SetArgumentModifier

func (p *TestModifyRequestPlugin) SetArgumentModifier(modifier func(string) string)

SetArgumentModifier sets a function to modify tool arguments

func (*TestModifyRequestPlugin) SetShouldModify

func (p *TestModifyRequestPlugin) SetShouldModify(should bool)

SetShouldModify sets whether to modify requests

type TestModifyResponsePlugin

type TestModifyResponsePlugin struct {
	// contains filtered or unexported fields
}

TestModifyResponsePlugin modifies MCP responses in PostHook

func NewTestModifyResponsePlugin

func NewTestModifyResponsePlugin() *TestModifyResponsePlugin

NewTestModifyResponsePlugin creates a new test modify response plugin

func (*TestModifyResponsePlugin) Cleanup

func (p *TestModifyResponsePlugin) Cleanup() error

Cleanup implements schemas.BasePlugin

func (*TestModifyResponsePlugin) GetName

func (p *TestModifyResponsePlugin) GetName() string

GetName implements schemas.BasePlugin

func (*TestModifyResponsePlugin) PostMCPHook

PostMCPHook implements schemas.MCPPlugin

func (*TestModifyResponsePlugin) PreMCPHook

PreMCPHook implements schemas.MCPPlugin

func (*TestModifyResponsePlugin) SetResponseModifier

func (p *TestModifyResponsePlugin) SetResponseModifier(modifier func(string) string)

SetResponseModifier sets a function to modify tool responses

func (*TestModifyResponsePlugin) SetShouldModify

func (p *TestModifyResponsePlugin) SetShouldModify(should bool)

SetShouldModify sets whether to modify responses

type TestShortCircuitPlugin

type TestShortCircuitPlugin struct {
	// contains filtered or unexported fields
}

TestShortCircuitPlugin short-circuits MCP execution and returns immediately

func NewTestShortCircuitPlugin

func NewTestShortCircuitPlugin() *TestShortCircuitPlugin

NewTestShortCircuitPlugin creates a new test short circuit plugin

func (*TestShortCircuitPlugin) Cleanup

func (p *TestShortCircuitPlugin) Cleanup() error

Cleanup implements schemas.BasePlugin

func (*TestShortCircuitPlugin) GetName

func (p *TestShortCircuitPlugin) GetName() string

GetName implements schemas.BasePlugin

func (*TestShortCircuitPlugin) PostMCPHook

PostMCPHook implements schemas.MCPPlugin

func (*TestShortCircuitPlugin) PreMCPHook

PreMCPHook implements schemas.MCPPlugin

func (*TestShortCircuitPlugin) SetShortCircuitMessage

func (p *TestShortCircuitPlugin) SetShortCircuitMessage(message string)

SetShortCircuitMessage sets the message returned when short-circuiting

func (*TestShortCircuitPlugin) SetShouldShortCircuit

func (p *TestShortCircuitPlugin) SetShouldShortCircuit(should bool)

SetShouldShortCircuit sets whether to short-circuit execution

Jump to

Keyboard shortcuts

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