fix(ci): Add authorization parameter to api_recorder tool runtime patches

The ACTUAL root cause of the signature mismatch errors was found!

The api_recorder.py module patches tool runtime invoke_tool methods for test
recording/replay, but the patched methods were missing the new 'authorization'
parameter. The debug logging revealed:

  Object method: patched_tavily_invoke_tool (from api_recorder module)
  Object method's module: llama_stack.testing.api_recorder

Changes made:
1. Updated _patched_tool_invoke_method() to accept authorization parameter
2. Updated patched_tavily_invoke_tool() signature to include authorization
3. Added debug logging to resolver to help identify similar issues in the future

This fix ensures that when tests run in record/replay mode, the patched methods
preserve the full signature including the authorization parameter, allowing the
protocol compliance checks to pass.
This commit is contained in:
Omar Abdelwahab 2025-11-12 16:06:29 -08:00
parent bae5b14adf
commit d156451890

View file

@ -609,14 +609,14 @@ def _combine_model_list_responses(endpoint: str, records: list[dict[str, Any]])
async def _patched_tool_invoke_method( async def _patched_tool_invoke_method(
original_method, provider_name: str, self, tool_name: str, kwargs: dict[str, Any] original_method, provider_name: str, self, tool_name: str, kwargs: dict[str, Any], authorization: str | None = None
): ):
"""Patched version of tool runtime invoke_tool method for recording/replay.""" """Patched version of tool runtime invoke_tool method for recording/replay."""
global _current_mode, _current_storage global _current_mode, _current_storage
if _current_mode == APIRecordingMode.LIVE or _current_storage is None: if _current_mode == APIRecordingMode.LIVE or _current_storage is None:
# Normal operation # Normal operation
return await original_method(self, tool_name, kwargs) return await original_method(self, tool_name, kwargs, authorization=authorization)
request_hash = normalize_tool_request(provider_name, tool_name, kwargs) request_hash = normalize_tool_request(provider_name, tool_name, kwargs)
@ -634,7 +634,7 @@ async def _patched_tool_invoke_method(
if _current_mode in (APIRecordingMode.RECORD, APIRecordingMode.RECORD_IF_MISSING): if _current_mode in (APIRecordingMode.RECORD, APIRecordingMode.RECORD_IF_MISSING):
# Make the tool call and record it # Make the tool call and record it
result = await original_method(self, tool_name, kwargs) result = await original_method(self, tool_name, kwargs, authorization=authorization)
request_data = { request_data = {
"test_id": get_test_context(), "test_id": get_test_context(),
@ -885,9 +885,9 @@ def patch_inference_clients():
OllamaAsyncClient.list = patched_ollama_list OllamaAsyncClient.list = patched_ollama_list
# Create patched methods for tool runtimes # Create patched methods for tool runtimes
async def patched_tavily_invoke_tool(self, tool_name: str, kwargs: dict[str, Any]): async def patched_tavily_invoke_tool(self, tool_name: str, kwargs: dict[str, Any], authorization: str | None = None):
return await _patched_tool_invoke_method( return await _patched_tool_invoke_method(
_original_methods["tavily_invoke_tool"], "tavily", self, tool_name, kwargs _original_methods["tavily_invoke_tool"], "tavily", self, tool_name, kwargs, authorization=authorization
) )
# Apply tool runtime patches # Apply tool runtime patches