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, )
| 197 | // MCP / tracer / actor options. When no provider option is given the default |
| 198 | // provider set (all providers) is used. |
| 199 | func 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. |
| 250 | func newDefaultProvider(providerType string, addr string) aibridge.Provider { |