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

Function setupInjectedToolTest

internal/integrationtest/setupbridge.go:199–247  ·  view source on GitHub ↗

setupInjectedToolTest abstracts common setup required for injected-tool integration tests. Extra bridge options (e.g. [withProvider]) are appended after the built-in MCP / tracer / actor options. When no provider option is given the default provider set (all providers) is used.

(
	t *testing.T,
	fixture []byte,
	streaming bool,
	tracer trace.Tracer,
	path string,
	toolRequestValidatorFn func(*http.Request, []byte),
	opts ...bridgeOption,
)

Source from the content-addressed store, hash-verified

197// MCP / tracer / actor options. When no provider option is given the default
198// provider set (all providers) is used.
199func setupInjectedToolTest(
200 t *testing.T,
201 fixture []byte,
202 streaming bool,
203 tracer trace.Tracer,
204 path string,
205 toolRequestValidatorFn func(*http.Request, []byte),
206 opts ...bridgeOption,
207) (*bridgeTestServer, *mockMCP, *http.Response) {
208 t.Helper()
209
210 ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong)
211 t.Cleanup(cancel)
212
213 fix := fixtures.Parse(t, fixture)
214
215 // Setup mock server for multi-turn interaction.
216 // First request → tool call response
217 // Second request → final response.
218 firstResp := newFixtureResponse(fix)
219 toolResp := newFixtureToolResponse(fix)
220 toolResp.OnRequest = toolRequestValidatorFn
221 upstream := newMockUpstream(ctx, t, firstResp, toolResp)
222
223 mockMCP := setupMCPForTest(t, tracer)
224
225 allOpts := []bridgeOption{
226 withMCP(mockMCP),
227 withTracer(tracer),
228 withActor(defaultActorID, nil),
229 }
230 allOpts = append(allOpts, opts...)
231 bridgeServer := newBridgeTestServer(ctx, t, upstream.URL, allOpts...)
232
233 // Add the stream param to the request.
234 reqBody, err := sjson.SetBytes(fix.Request(), "stream", streaming)
235 require.NoError(t, err)
236
237 resp, err := bridgeServer.makeRequest(t, http.MethodPost, path, reqBody)
238 require.NoError(t, err)
239 require.Equal(t, http.StatusOK, resp.StatusCode)
240
241 // Wait both requests (initial + tool call result)
242 require.Eventually(t, func() bool {
243 return upstream.Calls.Load() == 2
244 }, testutil.WaitMedium, testutil.IntervalFast)
245
246 return bridgeServer, mockMCP, resp
247}
248
249// newDefaultProvider creates a Provider with default test configuration.
250func newDefaultProvider(providerType string, addr string) aibridge.Provider {

Callers 3

TestOpenAIInjectedToolsFunction · 0.85
TestInjectedToolsTraceFunction · 0.85

Calls 11

ParseFunction · 0.92
newFixtureResponseFunction · 0.85
newFixtureToolResponseFunction · 0.85
newMockUpstreamFunction · 0.85
setupMCPForTestFunction · 0.85
withMCPFunction · 0.85
withTracerFunction · 0.85
withActorFunction · 0.85
newBridgeTestServerFunction · 0.85
RequestMethod · 0.80
makeRequestMethod · 0.80

Tested by 3

TestOpenAIInjectedToolsFunction · 0.68
TestInjectedToolsTraceFunction · 0.68