MCPcopy Index your code
hub / github.com/coder/coder / setupInjectedToolTest

Function setupInjectedToolTest

aibridge/internal/integrationtest/setupbridge.go:200–250  ·  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

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

Callers 3

TestOpenAIInjectedToolsFunction · 0.85
TestInjectedToolsTraceFunction · 0.85

Calls 15

ParseFunction · 0.92
newFixtureResponseFunction · 0.85
newFixtureToolResponseFunction · 0.85
setupMCPForTestFunction · 0.85
withMCPFunction · 0.85
withTracerFunction · 0.85
withActorFunction · 0.85
newBridgeTestServerFunction · 0.85
newMockUpstreamFunction · 0.70
HelperMethod · 0.65
ContextMethod · 0.65
CleanupMethod · 0.65

Tested by 3

TestOpenAIInjectedToolsFunction · 0.68
TestInjectedToolsTraceFunction · 0.68