@@ -253,6 +253,38 @@ async def test_auth_flow_omits_call_id_when_absent() -> None:
253253 assert "x-agent-foundry-call-id" not in prepared .headers
254254
255255
256+ async def test_async_auth_flow_removes_call_id_from_reused_request_when_context_absent () -> None :
257+ auth = _ToolboxAuth (_FakeCredential (), "scope" ) # type: ignore
258+ request = httpx .Request ("POST" , "https://h/toolboxes/tb/mcp" )
259+
260+ token = set_request_context (FoundryAgentRequestContext (call_id = "canary-call-id" ))
261+ try :
262+ prepared = await anext (auth .async_auth_flow (request ))
263+ assert prepared .headers ["x-agent-foundry-call-id" ] == "canary-call-id"
264+ finally :
265+ reset_request_context (token )
266+
267+ prepared = await anext (auth .async_auth_flow (request ))
268+
269+ assert "x-agent-foundry-call-id" not in prepared .headers
270+
271+
272+ def test_sync_auth_flow_removes_call_id_from_reused_request_when_context_absent () -> None :
273+ auth = _ToolboxAuth (_FakeCredential (), "scope" ) # type: ignore
274+ request = httpx .Request ("POST" , "https://h/toolboxes/tb/mcp" )
275+
276+ token = set_request_context (FoundryAgentRequestContext (call_id = "canary-call-id" ))
277+ try :
278+ prepared = next (auth .sync_auth_flow (request ))
279+ assert prepared .headers ["x-agent-foundry-call-id" ] == "canary-call-id"
280+ finally :
281+ reset_request_context (token )
282+
283+ prepared = next (auth .sync_auth_flow (request ))
284+
285+ assert "x-agent-foundry-call-id" not in prepared .headers
286+
287+
256288async def test_close_closes_owned_http_client () -> None :
257289 toolbox = FoundryToolbox (
258290 _FakeCredential (), # type: ignore
0 commit comments