TestIntegration is not an exhaustive test against the upstream AI providers' SDKs (see coder/aibridge for those). This test validates that: - intercepted requests can be authenticated/authorized - requests can be routed to an appropriate handler - responses can be returned as expected - interception
(t *testing.T)
| 46 | // - MCP server configurations are returned as expected |
| 47 | // - tracing spans are properly recorded |
| 48 | func TestIntegration(t *testing.T) { |
| 49 | t.Parallel() |
| 50 | |
| 51 | ctx := testutil.Context(t, testutil.WaitLong) |
| 52 | |
| 53 | sr := tracetest.NewSpanRecorder() |
| 54 | tp := sdktrace.NewTracerProvider(sdktrace.WithSpanProcessor(sr)) |
| 55 | tracer := tp.Tracer(t.Name()) |
| 56 | defer func() { _ = tp.Shutdown(t.Context()) }() |
| 57 | |
| 58 | // Create mock MCP server. |
| 59 | var mcpTokenReceived string |
| 60 | mockMCPServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 61 | t.Logf("Mock MCP server received request: %s %s", r.Method, r.URL.Path) |
| 62 | |
| 63 | if r.Method == http.MethodPost && r.URL.Path == "/" { |
| 64 | // Mark that init was called. |
| 65 | mcpTokenReceived = r.Header.Get("Authorization") |
| 66 | t.Log("MCP init request received") |
| 67 | |
| 68 | // Return a basic MCP init response. |
| 69 | w.Header().Set("Content-Type", "application/json") |
| 70 | w.Header().Set("Mcp-Session-Id", "test-session-123") |
| 71 | w.WriteHeader(http.StatusOK) |
| 72 | _, _ = w.Write([]byte(`{ |
| 73 | "jsonrpc": "2.0", |
| 74 | "id": 1, |
| 75 | "result": { |
| 76 | "protocolVersion": "2024-11-05", |
| 77 | "capabilities": {}, |
| 78 | "serverInfo": { |
| 79 | "name": "test-mcp-server", |
| 80 | "version": "1.0.0" |
| 81 | } |
| 82 | } |
| 83 | }`)) |
| 84 | } |
| 85 | })) |
| 86 | t.Cleanup(mockMCPServer.Close) |
| 87 | t.Logf("Mock MCP server running at: %s", mockMCPServer.URL) |
| 88 | |
| 89 | // Set up mock OpenAI server that returns a tool call response. |
| 90 | mockOpenAI := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| 91 | w.Header().Set("Content-Type", "application/json") |
| 92 | w.WriteHeader(http.StatusOK) |
| 93 | _, _ = w.Write([]byte(`{ |
| 94 | "id": "chatcmpl-BwkyFElDIr1egmFyfQ9z4vPBto7m2", |
| 95 | "object": "chat.completion", |
| 96 | "created": 1753343279, |
| 97 | "model": "gpt-4.1-2025-04-14", |
| 98 | "choices": [ |
| 99 | { |
| 100 | "index": 0, |
| 101 | "message": { |
| 102 | "role": "assistant", |
| 103 | "content": null, |
| 104 | "tool_calls": [ |
| 105 | { |
nothing calls this directly
no test coverage detected