MCPcopy Create free account
hub / github.com/coder/aibridge / openaiChatToolResultValidator

Function openaiChatToolResultValidator

internal/integrationtest/bridge_test.go:1227–1252  ·  view source on GitHub ↗

openaiChatToolResultValidator returns a request validator that asserts the second upstream request contains the assistant's tool_calls and a role=tool result message appended by the inner agentic loop.

(t *testing.T)

Source from the content-addressed store, hash-verified

1225// upstream request contains the assistant's tool_calls and a role=tool result message
1226// appended by the inner agentic loop.
1227func openaiChatToolResultValidator(t *testing.T) func(*http.Request, []byte) {
1228 t.Helper()
1229
1230 return func(_ *http.Request, raw []byte) {
1231 messages := gjson.GetBytes(raw, "messages").Array()
1232
1233 // After the agentic loop the messages must contain at minimum:
1234 // [0] original user message
1235 // [N-2] assistant message with tool_calls array
1236 // [N-1] message with role=tool
1237 require.GreaterOrEqual(t, len(messages), 3,
1238 "second upstream request must contain the original message, assistant tool_calls, and tool result")
1239
1240 assistantMsg := messages[len(messages)-2]
1241 require.Equal(t, "assistant", assistantMsg.Get("role").Str,
1242 "penultimate message must be from the assistant")
1243 require.NotEmpty(t, len(assistantMsg.Get("tool_calls").Array()),
1244 "assistant message must contain a tool_calls array")
1245
1246 toolResultMsg := messages[len(messages)-1]
1247 require.Equal(t, "tool", toolResultMsg.Get("role").Str,
1248 "last message must have role=tool")
1249 require.NotEmpty(t, toolResultMsg.Get("tool_call_id").Str,
1250 "tool result message must have a tool_call_id")
1251 }
1252}
1253
1254func TestErrorHandling(t *testing.T) {
1255 t.Parallel()

Callers 2

TestOpenAIInjectedToolsFunction · 0.85
TestInjectedToolsTraceFunction · 0.85

Calls 1

GetMethod · 0.80

Tested by

no test coverage detected