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

Function TestCopilot_CreateInterceptor

aibridge/provider/copilot_internal_test.go:68–297  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

66}
67
68func TestCopilot_CreateInterceptor(t *testing.T) {
69 t.Parallel()
70
71 provider := NewCopilot(config.Copilot{})
72
73 t.Run("MissingAuthorizationHeader", func(t *testing.T) {
74 t.Parallel()
75
76 body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}]}`
77 req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body))
78 w := httptest.NewRecorder()
79
80 interceptor, err := provider.CreateInterceptor(w, req, testTracer)
81
82 require.Error(t, err)
83 require.Nil(t, interceptor)
84 assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid")
85 })
86
87 t.Run("InvalidAuthorizationFormat", func(t *testing.T) {
88 t.Parallel()
89
90 body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}]}`
91 req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body))
92 req.Header.Set("Authorization", "InvalidFormat")
93 w := httptest.NewRecorder()
94
95 interceptor, err := provider.CreateInterceptor(w, req, testTracer)
96
97 require.Error(t, err)
98 require.Nil(t, interceptor)
99 assert.Contains(t, err.Error(), "missing Copilot authorization: Authorization header not found or invalid")
100 })
101
102 t.Run("ChatCompletions_NonStreamingRequest_BlockingInterceptor", func(t *testing.T) {
103 t.Parallel()
104
105 body := `{"model": "claude-haiku-4.5", "messages": [{"role": "user", "content": "hello"}], "stream": false}`
106 req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body))
107 req.Header.Set("Authorization", "Bearer test-token")
108 w := httptest.NewRecorder()
109
110 interceptor, err := provider.CreateInterceptor(w, req, testTracer)
111
112 require.NoError(t, err)
113 require.NotNil(t, interceptor)
114 assert.False(t, interceptor.Streaming())
115 })
116
117 t.Run("ChatCompletions_StreamingRequest_StreamingInterceptor", func(t *testing.T) {
118 t.Parallel()
119
120 body := `{"model": "gpt-4.1", "messages": [{"role": "user", "content": "hello"}], "stream": true}`
121 req := httptest.NewRequest(http.MethodPost, routeCopilotChatCompletions, bytes.NewBufferString(body))
122 req.Header.Set("Authorization", "Bearer test-token")
123 w := httptest.NewRecorder()
124
125 interceptor, err := provider.CreateInterceptor(w, req, testTracer)

Callers

nothing calls this directly

Calls 15

CreateInterceptorMethod · 0.95
NewCopilotFunction · 0.85
RunMethod · 0.65
SetMethod · 0.65
StreamingMethod · 0.65
WriteMethod · 0.65
CleanupMethod · 0.65
SetupMethod · 0.65
ProcessRequestMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45
ContainsMethod · 0.45

Tested by

no test coverage detected