@@ -80,7 +80,6 @@ func TestAnthropicMessages(t *testing.T) {
8080 require .NoError (t , err )
8181 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
8282 require .Equal (t , http .StatusOK , resp .StatusCode )
83- defer resp .Body .Close ()
8483
8584 // Response-specific checks.
8685 if tc .streaming {
@@ -146,7 +145,6 @@ func TestAWSBedrockIntegration(t *testing.T) {
146145 )
147146
148147 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , fixtures .Request (t , fixtures .AntSingleBuiltinTool ))
149- defer resp .Body .Close ()
150148
151149 require .Equal (t , http .StatusInternalServerError , resp .StatusCode )
152150 body , err := io .ReadAll (resp .Body )
@@ -185,7 +183,6 @@ func TestAWSBedrockIntegration(t *testing.T) {
185183 reqBody , err := sjson .SetBytes (fix .Request (), "stream" , streaming )
186184 require .NoError (t , err )
187185 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
188- defer resp .Body .Close ()
189186
190187 // For streaming responses, consume the body to allow the stream to complete.
191188 if streaming {
@@ -259,7 +256,6 @@ func TestOpenAIChatCompletions(t *testing.T) {
259256 require .NoError (t , err )
260257 resp := bridgeServer .makeRequest (t , http .MethodPost , pathOpenAIChatCompletions , reqBody )
261258 require .Equal (t , http .StatusOK , resp .StatusCode )
262- defer resp .Body .Close ()
263259
264260 // Response-specific checks.
265261 if tc .streaming {
@@ -350,7 +346,6 @@ func TestOpenAIChatCompletions(t *testing.T) {
350346 // Consume the full response body to ensure the interception completes
351347 _ , err = io .ReadAll (resp .Body )
352348 require .NoError (t , err )
353- resp .Body .Close ()
354349
355350 // Verify the MCP tool was actually invoked
356351 invocations := mockMCP .getCallsByTool (mockToolName )
@@ -515,7 +510,6 @@ func TestSimple(t *testing.T) {
515510 require .NoError (t , err )
516511 resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody , http.Header {"User-Agent" : {tc .userAgent }})
517512 require .Equal (t , http .StatusOK , resp .StatusCode )
518- defer resp .Body .Close ()
519513
520514 // Then: I expect the upstream request to have the correct path.
521515 received := upstream .receivedRequests ()
@@ -629,7 +623,6 @@ func TestSessionIDTracking(t *testing.T) {
629623
630624 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody , tc .header )
631625 require .Equal (t , http .StatusOK , resp .StatusCode )
632- defer resp .Body .Close ()
633626
634627 // Drain the body to let the stream complete.
635628 _ , err := io .ReadAll (resp .Body )
@@ -710,7 +703,6 @@ func TestFallthrough(t *testing.T) {
710703 bridgeServer := newBridgeTestServer (t , t .Context (), upstream .URL + tc .basePath )
711704
712705 resp := bridgeServer .makeRequest (t , http .MethodGet , tc .requestPath , nil )
713- defer resp .Body .Close ()
714706
715707 require .Equal (t , http .StatusOK , resp .StatusCode )
716708
@@ -1050,7 +1042,6 @@ func TestErrorHandling(t *testing.T) {
10501042 require .NoError (t , err )
10511043
10521044 resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
1053- t .Cleanup (func () { _ = resp .Body .Close () })
10541045
10551046 tc .responseHandlerFn (resp )
10561047 bridgeServer .Recorder .VerifyAllInterceptionsEnded (t )
@@ -1118,7 +1109,6 @@ func TestErrorHandling(t *testing.T) {
11181109 bridgeServer := newBridgeTestServer (t , ctx , upstream .URL )
11191110
11201111 resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
1121- t .Cleanup (func () { _ = resp .Body .Close () })
11221112
11231113 tc .responseHandlerFn (resp )
11241114 bridgeServer .Recorder .VerifyAllInterceptionsEnded (t )
@@ -1179,7 +1169,6 @@ func TestStableRequestEncoding(t *testing.T) {
11791169 for range count {
11801170 resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
11811171 require .Equal (t , http .StatusOK , resp .StatusCode )
1182- _ = resp .Body .Close ()
11831172 }
11841173
11851174 // All upstream request bodies should be identical.
@@ -1294,7 +1283,6 @@ func TestAnthropicToolChoiceParallelDisabled(t *testing.T) {
12941283
12951284 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
12961285 require .Equal (t , http .StatusOK , resp .StatusCode )
1297- _ = resp .Body .Close ()
12981286
12991287 // Verify tool_choice in the upstream request.
13001288 received := upstream .receivedRequests ()
@@ -1352,7 +1340,6 @@ func TestThinkingAdaptiveIsPreserved(t *testing.T) {
13521340 resp := bridgeServer .makeRequest (t , http .MethodPost , pathAnthropicMessages , reqBody )
13531341 require .Equal (t , http .StatusOK , resp .StatusCode )
13541342 _ , _ = io .ReadAll (resp .Body )
1355- _ = resp .Body .Close ()
13561343
13571344 // Verify the thinking field was preserved in the upstream request.
13581345 received := upstream .receivedRequests ()
@@ -1414,7 +1401,6 @@ func TestEnvironmentDoNotLeak(t *testing.T) {
14141401
14151402 resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , fix .Request ())
14161403 require .Equal (t , http .StatusOK , resp .StatusCode )
1417- defer resp .Body .Close ()
14181404
14191405 // Verify that environment values did not leak.
14201406 received := upstream .receivedRequests ()
@@ -1536,9 +1522,8 @@ func TestActorHeaders(t *testing.T) {
15361522 reqBody , err := sjson .SetBytes (fixtures .Request (t , tc .fixture ), "stream" , tc .streaming )
15371523 require .NoError (t , err )
15381524
1539- resp := bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
1525+ bridgeServer .makeRequest (t , http .MethodPost , tc .path , reqBody )
15401526 require .NotEmpty (t , receivedHeaders )
1541- defer resp .Body .Close ()
15421527
15431528 // Verify that the actor headers were only received if intended.
15441529 found := make (map [string ][]string )
0 commit comments