From fcae6fb9b804308e934378da902d326fba84652a Mon Sep 17 00:00:00 2001 From: cucurigoo <241698038+cucurigoo@users.noreply.github.com> Date: Wed, 22 Jul 2026 00:30:10 +0000 Subject: [PATCH] test(providers): cover route URL identity boundaries --- tests/run_agent/test_switch_model_context.py | 37 ++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/tests/run_agent/test_switch_model_context.py b/tests/run_agent/test_switch_model_context.py index f526557fbec..c2021161281 100644 --- a/tests/run_agent/test_switch_model_context.py +++ b/tests/run_agent/test_switch_model_context.py @@ -2,6 +2,8 @@ from unittest.mock import MagicMock, patch +import pytest + from run_agent import AIAgent from agent.agent_init import _normalize_route_base_url from agent.context_compressor import ContextCompressor @@ -49,6 +51,41 @@ def test_route_url_normalization_preserves_malformed_trailing_slash(): ) != _normalize_route_base_url("http://[bad/v1") +@pytest.mark.parametrize( + ("configured", "active"), + [ + ("http://EXAMPLE.COM:80/v1/", "http://example.com/v1"), + ( + "https://EXAMPLE.COM:443/v1/#configured-fragment", + "https://example.com/v1#active-fragment", + ), + ("http://[2001:DB8::1]:80/v1/", "http://[2001:db8::1]/v1"), + ], +) +def test_route_url_normalization_accepts_isolated_safe_equivalences( + configured, active +): + """Default ports, fragments, and IPv6 hex case do not change HTTP routes.""" + assert _normalize_route_base_url(configured) == _normalize_route_base_url(active) + + +@pytest.mark.parametrize( + ("configured", "active"), + [ + ("https://example.com/V1", "https://example.com/v1"), + ("https://example.com:8443/v1", "https://example.com/v1"), + ("https://example.com/v1?tenant=large", "https://example.com/v1"), + ("http://example.com/v1", "https://example.com/v1"), + ("https://example.com:notaport/v1", "https://example.com/v1"), + ], +) +def test_route_url_normalization_preserves_significant_components( + configured, active +): + """Path case, route data, schemes, and ambiguous ports stay distinct.""" + assert _normalize_route_base_url(configured) != _normalize_route_base_url(active) + + def _make_direct_start_agent( cfg: dict, *, model: str, provider: str, base_url: str ) -> AIAgent: