fix: restrict provider URL detection to exact hostname matches
This commit is contained in:
27
tests/agent/test_direct_provider_url_detection.py
Normal file
27
tests/agent/test_direct_provider_url_detection.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from run_agent import AIAgent
|
||||
|
||||
|
||||
def _agent_with_base_url(base_url: str) -> AIAgent:
|
||||
agent = object.__new__(AIAgent)
|
||||
agent.base_url = base_url
|
||||
return agent
|
||||
|
||||
|
||||
def test_direct_openai_url_requires_openai_host():
|
||||
agent = _agent_with_base_url("https://api.openai.com.example/v1")
|
||||
|
||||
assert agent._is_direct_openai_url() is False
|
||||
|
||||
|
||||
def test_direct_openai_url_ignores_path_segment_match():
|
||||
agent = _agent_with_base_url("https://proxy.example.test/api.openai.com/v1")
|
||||
|
||||
assert agent._is_direct_openai_url() is False
|
||||
|
||||
|
||||
def test_direct_openai_url_accepts_native_host():
|
||||
agent = _agent_with_base_url("https://api.openai.com/v1")
|
||||
|
||||
assert agent._is_direct_openai_url() is True
|
||||
@@ -28,6 +28,15 @@ class TestCodexResponsesDetection:
|
||||
# api.openai.com check must exclude openrouter (which routes to openai-hosted models).
|
||||
assert _detect_api_mode_for_url("https://openrouter.ai/api/v1") is None
|
||||
|
||||
def test_openai_host_suffix_does_not_match(self):
|
||||
assert _detect_api_mode_for_url("https://api.openai.com.example/v1") is None
|
||||
|
||||
def test_openai_path_segment_does_not_match(self):
|
||||
assert _detect_api_mode_for_url("https://proxy.example.test/api.openai.com/v1") is None
|
||||
|
||||
def test_xai_host_suffix_does_not_match(self):
|
||||
assert _detect_api_mode_for_url("https://api.x.ai.example/v1") is None
|
||||
|
||||
|
||||
class TestAnthropicMessagesDetection:
|
||||
"""Third-party gateways that speak the Anthropic protocol under /anthropic."""
|
||||
|
||||
Reference in New Issue
Block a user