mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
* test: drop the cwd-relative sys.path.insert calls from the test suite
TQ003 stands at 1,077 across 1,058 files, and 1,015 of them are the same shape:
sys.path.insert(0, os.path.abspath("../..")) and its deeper siblings. The
argument resolves against the working directory rather than the file, so from
the repo root, where every job runs pytest, it inserts the directory two levels
above the checkout. It has never pointed at litellm. The package is installed
into the environment anyway, which is what actually makes the import work, and
what the rule's message has said all along.
Removing them leaves 1,634 imports of sys and os with no remaining reference,
and those go too, except where another test module imports the name back out of
the file. The rest of TQ003 is 62 call sites that resolve against __file__ or a
variable, which are a different question and are left alone.
Collection is identical either way: 45,871 tests and the same 51 pre-existing
collection errors before and after, and ruff reports no new undefined name.
* test: drop the duplicate imports the sys.path sweep exposed to F811
* test(pre-call-utils): restore the os import the new bedrock tests need
71 lines
2.2 KiB
Python
71 lines
2.2 KiB
Python
"""
|
|
Test A2A provider registry lookup functionality.
|
|
|
|
Maps to: litellm/llms/a2a/chat/transformation.py
|
|
"""
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
import litellm
|
|
from litellm.llms.a2a.chat.transformation import A2AConfig
|
|
|
|
|
|
def test_resolve_agent_config_from_registry_static_method():
|
|
"""Test the static helper method for registry resolution"""
|
|
|
|
# Test 1: No agent name in model
|
|
api_base, api_key, headers = A2AConfig.resolve_agent_config_from_registry(
|
|
model="a2a",
|
|
api_base="http://test.com",
|
|
api_key=None,
|
|
headers=None,
|
|
optional_params={},
|
|
)
|
|
assert api_base == "http://test.com"
|
|
|
|
# Test 2: All params provided - should not lookup registry
|
|
api_base, api_key, headers = A2AConfig.resolve_agent_config_from_registry(
|
|
model="a2a/test-agent",
|
|
api_base="http://explicit.com",
|
|
api_key="explicit-key",
|
|
headers={"X-Test": "value"},
|
|
optional_params={},
|
|
)
|
|
assert api_base == "http://explicit.com"
|
|
assert api_key == "explicit-key"
|
|
|
|
|
|
def test_a2a_registry_integration():
|
|
"""Test registry lookup in proxy context"""
|
|
|
|
try:
|
|
from litellm.proxy.agent_endpoints.agent_registry import global_agent_registry
|
|
from litellm.types.agents import AgentResponse
|
|
|
|
# Create test agent
|
|
test_agent = AgentResponse(
|
|
agent_id="test-id",
|
|
agent_name="test-agent",
|
|
agent_card_params={"url": "http://registry-url.example.com:9999"},
|
|
litellm_params={"api_key": "registry-key"},
|
|
)
|
|
|
|
# Register and test
|
|
original_agents = global_agent_registry.agent_list.copy()
|
|
global_agent_registry.register_agent(test_agent)
|
|
|
|
try:
|
|
litellm.completion(
|
|
model="a2a/test-agent", messages=[{"role": "user", "content": "Hello"}]
|
|
)
|
|
except Exception as e:
|
|
# Should use registry URL (connection error expected)
|
|
if "registry-url.example.com" not in str(e) and "APIConnectionError" not in type(e).__name__:
|
|
raise
|
|
finally:
|
|
global_agent_registry.agent_list = original_agents
|
|
|
|
except ImportError:
|
|
pytest.skip("Registry not available (not in proxy context)")
|