(t *testing.T)
| 295 | } |
| 296 | |
| 297 | func TestToolInjectionOrder(t *testing.T) { |
| 298 | t.Parallel() |
| 299 | |
| 300 | // Setup. |
| 301 | logger := slogtest.Make(t, &slogtest.Options{IgnoreErrors: false}).Leveled(slog.LevelDebug) |
| 302 | ctx, cancel := context.WithTimeout(t.Context(), testutil.WaitLong) |
| 303 | t.Cleanup(cancel) |
| 304 | |
| 305 | // Given: a MCP mock server offering a set of tools. |
| 306 | mcpSrv := httptest.NewServer(createMockMCPSrv(t)) |
| 307 | t.Cleanup(mcpSrv.Close) |
| 308 | |
| 309 | tracer := otel.Tracer("forTesting") |
| 310 | // When: creating two MCP server proxies, both listing the same tools by name but under different server namespaces. |
| 311 | proxy, err := mcp.NewStreamableHTTPServerProxy("coder", mcpSrv.URL, nil, nil, nil, logger, tracer) |
| 312 | require.NoError(t, err) |
| 313 | proxy2, err := mcp.NewStreamableHTTPServerProxy("shmoder", mcpSrv.URL, nil, nil, nil, logger, tracer) |
| 314 | require.NoError(t, err) |
| 315 | |
| 316 | // Then: initialize both proxies. |
| 317 | require.NoError(t, proxy.Init(ctx)) |
| 318 | require.NoError(t, proxy2.Init(ctx)) |
| 319 | |
| 320 | // Then: validate that their tools are separately sorted stably. |
| 321 | validateToolOrder(t, proxy) |
| 322 | validateToolOrder(t, proxy2) |
| 323 | |
| 324 | // When: creating a manager which contains both MCP server proxies. |
| 325 | mgr := mcp.NewServerProxyManager(map[string]mcp.ServerProxier{ |
| 326 | "coder": proxy, |
| 327 | "shmoder": proxy2, |
| 328 | }, otel.GetTracerProvider().Tracer("test")) |
| 329 | require.NoError(t, mgr.Init(ctx)) |
| 330 | |
| 331 | // Then: the tools from both servers should be collectively sorted stably. |
| 332 | validateToolOrder(t, mgr) |
| 333 | } |
| 334 | |
| 335 | func validateToolOrder(t *testing.T, proxy mcp.ServerProxier) { |
| 336 | t.Helper() |
nothing calls this directly
no test coverage detected