Skip to content

The agent that grows with you

test(gateway): cover named-custom context pin on session-info banner

xxxigm942ff91f21a3
diff --git a/tests/agent/test_context_route_mismatch.py b/tests/agent/test_context_route_mismatch.py
new file mode 100644
index 00000000000..c03a0ae21b7
--- /dev/null
+++ b/tests/agent/test_context_route_mismatch.py
@@ -0,0 +1,56 @@
+"""Tests for agent_init._context_route_mismatch context-pin scoping."""
+
+from agent.agent_init import _context_route_mismatch
+
+
+class TestContextRouteMismatchNamedCustomProvider:
+ """Named custom providers store the URL under custom_providers, not model.base_url.
+
+ Gateway session-reset banners used to treat empty model.base_url + a runtime
+ custom URL as a route mismatch, drop model.context_length, and fall back to
+ the Qwen family default (131072) even though /status still showed the pin.
+ """
+
+ def test_same_named_custom_provider_keeps_pin_without_configured_url(self):
+ assert (
+ _context_route_mismatch(
+ None,
+ "http://127.0.0.1:8080/v1",
+ "custom-local-agentw",
+ "custom-local-agentw",
+ )
+ is False
+ )
+
+ def test_different_provider_still_clears_pin(self):
+ assert (
+ _context_route_mismatch(
+ None,
+ "http://127.0.0.1:8080/v1",
+ "custom-local-agentw",
+ "openrouter",
+ )
+ is True
+ )
+
+ def test_explicit_base_url_mismatch_still_clears_pin(self):
+ assert (
+ _context_route_mismatch(
+ "http://127.0.0.1:8080/v1",
+ "http://10.0.0.2:8080/v1",
+ "custom-local-agentw",
+ "custom-local-agentw",
+ )
+ is True
+ )
+
+ def test_catalog_provider_rejects_non_default_runtime_url(self):
+ assert (
+ _context_route_mismatch(
+ None,
+ "http://127.0.0.1:8080/v1",
+ "openrouter",
+ "openrouter",
+ )
+ is True
+ )
diff --git a/tests/gateway/test_session_info.py b/tests/gateway/test_session_info.py
index a2c0fe2ca7e..7d16d6b8070 100644
--- a/tests/gateway/test_session_info.py
+++ b/tests/gateway/test_session_info.py
@@ -64,6 +64,58 @@ class TestFormatSessionInfo:
assert "localhost:11434" in info
assert "8K" in info
+ def test_named_custom_provider_keeps_context_pin_without_model_base_url(
+ self, runner, tmp_path
+ ):
+ """Session-reset banner must honor model.context_length for named custom providers.
+
+ Repro: /status shows 262144 from config while the reset banner said
+ ``131K tokens (detected)`` because empty model.base_url + runtime URL
+ falsely cleared the pin and fell through to the Qwen family default.
+ """
+ model = "custom-local-agentw/Qwen-AgentWorld-35B-A3B-Q5_K_XL"
+ config_yaml = (
+ "model:\n"
+ f" default: {model}\n"
+ " provider: custom-local-agentw\n"
+ " context_length: 262144\n"
+ "custom_providers:\n"
+ " - name: custom-local-agentw\n"
+ " base_url: http://127.0.0.1:8080/v1\n"
+ " models: {}\n"
+ )
+ p1, p2, p3 = _patch_info(
+ tmp_path,
+ config_yaml,
+ model,
+ {
+ "provider": "custom-local-agentw",
+ "base_url": "http://127.0.0.1:8080/v1",
+ "api_key": "",
+ },
+ )
+ with p1, p2, p3, patch(
+ "hermes_cli.config.get_compatible_custom_providers",
+ return_value=[
+ {
+ "name": "custom-local-agentw",
+ "base_url": "http://127.0.0.1:8080/v1",
+ "models": {},
+ }
+ ],
+ ), patch(
+ "agent.model_metadata.get_model_context_length",
+ side_effect=lambda *args, **kwargs: (
+ kwargs.get("config_context_length")
+ if kwargs.get("config_context_length")
+ else 131072
+ ),
+ ):
+ info = runner._format_session_info()
+ assert "262K" in info
+ assert "config" in info
+ assert "131K" not in info
+
class TestResetNoticeSessionInfo:
"""#59003: the auto-reset banner must report the serving profile's config,