@@ -18,33 +18,40 @@ func TestIntegration_ProjectExtractionFlow(t *testing.T) {
1818		expectError      bool 
1919	}{
2020		{
21- 			name :            "HTTP header  project takes precedence" ,
21+ 			name :            "request  project takes precedence over HTTP header " ,
2222			httpHeaders :     map [string ]string {"X-Project" : "http-project" },
2323			requestProject :  "request-project" ,
24- 			expectedProject : "http -project" ,
24+ 			expectedProject : "request -project" ,
2525			expectError :     false ,
2626		},
2727		{
28- 			name :            "fallback to  request when no HTTP header" ,
28+ 			name :            "use  request project  when no HTTP header" ,
2929			httpHeaders :     map [string ]string {},
3030			requestProject :  "request-project" ,
3131			expectedProject : "request-project" ,
3232			expectError :     false ,
3333		},
3434		{
35- 			name :            "fallback to  request when empty HTTP header" ,
35+ 			name :            "use  request project  when empty HTTP header" ,
3636			httpHeaders :     map [string ]string {"X-Project" : "" },
3737			requestProject :  "request-project" ,
3838			expectedProject : "request-project" ,
3939			expectError :     false ,
4040		},
4141		{
42- 			name :            "fallback to  request when whitespace HTTP header" ,
42+ 			name :            "use  request project  when whitespace HTTP header" ,
4343			httpHeaders :     map [string ]string {"X-Project" : "   " },
4444			requestProject :  "request-project" ,
4545			expectedProject : "request-project" ,
4646			expectError :     false ,
4747		},
48+ 		{
49+ 			name :            "fallback to HTTP header when no request project" ,
50+ 			httpHeaders :     map [string ]string {"X-Project" : "http-project" },
51+ 			requestProject :  "" ,
52+ 			expectedProject : "http-project" ,
53+ 			expectError :     false ,
54+ 		},
4855		{
4956			name :            "error when no project anywhere" ,
5057			httpHeaders :     map [string ]string {},
@@ -53,12 +60,19 @@ func TestIntegration_ProjectExtractionFlow(t *testing.T) {
5360			expectError :     true ,
5461		},
5562		{
56- 			name :            "HTTP header with whitespace is trimmed" ,
63+ 			name :            "HTTP header with whitespace is trimmed when used " ,
5764			httpHeaders :     map [string ]string {"X-Project" : "  http-project  " },
58- 			requestProject :  "request-project " ,
65+ 			requestProject :  "" ,
5966			expectedProject : "http-project" ,
6067			expectError :     false ,
6168		},
69+ 		{
70+ 			name :            "request project with whitespace is trimmed" ,
71+ 			httpHeaders :     map [string ]string {"X-Project" : "http-project" },
72+ 			requestProject :  "  request-project  " ,
73+ 			expectedProject : "request-project" ,
74+ 			expectError :     false ,
75+ 		},
6276	}
6377
6478	for  _ , tt  :=  range  tests  {
@@ -101,17 +115,19 @@ func TestIntegration_ProjectExtractionFlow(t *testing.T) {
101115
102116func  TestIntegration_CompleteHTTPFlow (t  * testing.T ) {
103117	// Test the complete flow from HTTP request to tool execution 
118+ 	// Request parameter should take precedence over HTTP header 
104119	req  :=  httptest .NewRequest ("GET" , "/test" , nil )
105- 	req .Header .Set ("X-Project" , "integration-test -project" )
120+ 	req .Header .Set ("X-Project" , "header -project" )
106121
107122	var  capturedProject  string 
108123	var  projectFound  bool 
109124
110125	// Create a handler that simulates the MCP tool execution 
111126	handler  :=  http .HandlerFunc (func (w  http.ResponseWriter , r  * http.Request ) {
112- 		// Simulate MCP tool request 
127+ 		// Simulate MCP tool request with explicit project parameter 
128+ 		// This should take precedence over the HTTP header 
113129		mcpRequest  :=  MockCallToolRequest {
114- 			project : "fallback -project" ,
130+ 			project : "request -project" ,
115131		}
116132
117133		// Extract project using our function 
@@ -133,8 +149,8 @@ func TestIntegration_CompleteHTTPFlow(t *testing.T) {
133149	// Execute request 
134150	middleware .ServeHTTP (rr , req )
135151
136- 	// Verify results 
152+ 	// Verify results - request parameter should win  
137153	assert .Equal (t , http .StatusOK , rr .Code )
138154	assert .True (t , projectFound )
139- 	assert .Equal (t , "integration-test -project" , capturedProject )
155+ 	assert .Equal (t , "request -project" , capturedProject )
140156}
0 commit comments