The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(run_agent): delete dead _is_copilot_url/_is_copilot_provider
Teknium4ba300b51b2a
diff --git a/run_agent.py b/run_agent.pyindex 790c50b01a1..63656ac8260 100644--- a/run_agent.py+++ b/run_agent.py@@ -614,15 +614,6 @@ class AIAgent("""Return True when the base URL targets OpenRouter."""return base_url_host_matches(self._base_url_lower, "openrouter.ai")- def _is_copilot_url(self) -> bool:- """Return True when the base URL targets GitHub Copilot or GitHub Models."""- return any(base_url_host_matches(self._base_url_lower, h) for h in ("api.githubcopilot.com", "models.github.ai"))-- def _is_copilot_provider(self) -> bool:- """True when the active provider is GitHub Copilot under any alias (``copilot`` / ``github-copilot`` /- ``github``) or by base URL; a bare equality check would silently skip credential recovery."""- return (self.provider or "").strip().lower() in {"copilot", "github-copilot", "github"} or self._is_copilot_url()-def _is_codex_backend(self) -> bool:"""Return True for the ChatGPT OAuth Codex Responses backend."""return (getattr(self, "api_mode", None) == "codex_responses"diff --git a/tests/agent/test_copilot_initiator.py b/tests/agent/test_copilot_initiator.pyindex dc7c95392d8..8efbdca7b0e 100644--- a/tests/agent/test_copilot_initiator.py+++ b/tests/agent/test_copilot_initiator.py@@ -44,21 +44,6 @@ def _make_agent(monkeypatch, base_url, api_mode="chat_completions"):skip_memory=True,)-class TestIsCopilotUrl:- """_is_copilot_url() detects GitHub Copilot endpoints."""-- def test_standard_copilot_url(self, monkeypatch):- agent = _make_agent(monkeypatch, "https://api.githubcopilot.com")- assert agent._is_copilot_url() is True-- def test_github_models_url(self, monkeypatch):- agent = _make_agent(monkeypatch, "https://models.github.ai/inference")- assert agent._is_copilot_url() is True-- def test_openrouter_url(self, monkeypatch):- agent = _make_agent(monkeypatch, "https://openrouter.ai/api/v1")- assert agent._is_copilot_url() is False-class TestUserInitiatedTurnFlag:"""_is_user_initiated_turn lifecycle."""diff --git a/tests/hermes_cli/test_base_url_host_identity.py b/tests/hermes_cli/test_base_url_host_identity.pyindex de409899bf6..5c55bbe2f56 100644--- a/tests/hermes_cli/test_base_url_host_identity.py+++ b/tests/hermes_cli/test_base_url_host_identity.py@@ -115,20 +115,6 @@ def test_run_agent_azure_url_predicate():assert probe._is_azure_openai_url("https://openai.azure.com.evil.io/v1") is False-def test_run_agent_copilot_url_predicate():- from run_agent import AIAgent-- probe = object.__new__(AIAgent)- probe._base_url_lower = "https://api.githubcopilot.com/v1"- assert probe._is_copilot_url() is True- probe._base_url_lower = "https://proxy.test/api.githubcopilot.com/v1"- assert probe._is_copilot_url() is False- probe._base_url_lower = "https://models.github.ai/inference"- assert probe._is_copilot_url() is True- probe._base_url_lower = "https://models.github.ai.evil.com/v1"- assert probe._is_copilot_url() is False--def test_dotted_model_name_provider_allowlist_host_anchored():from run_agent import AIAgentdiff --git a/tests/plugins/model_providers/test_copilot_hosts.py b/tests/plugins/model_providers/test_copilot_hosts.pynew file mode 100644index 00000000000..44e3c7528ef--- /dev/null+++ b/tests/plugins/model_providers/test_copilot_hosts.py@@ -0,0 +1,51 @@+"""Copilot endpoint identity, owned by the copilot plugin's profile hooks.++The premium-request ``x-initiator: user`` header (issue #3040) goes only to the Copilot API and+GitHub Models hosts (the copilot profile's ``request_headers``), and host-based routing must match+URL *hostnames*, never substrings (``providers.profile_for_host``): a proxy path or a lookalike+domain that merely contains a Copilot host is not Copilot.+"""++from __future__ import annotations++import pytest+++def copilot_profile():+ import providers++ profile = providers.get_provider_profile("copilot")+ assert profile is not None+ return profile+++def _marks_user_turn(profile, url: str) -> bool:+ return "x-initiator" in profile.request_headers(base_url=url, user_initiated=True)+++def _is_copilot_host(url: str) -> bool:+ from providers import profile_for_host++ profile = profile_for_host(url)+ return profile is not None and profile.name == "copilot"+++class TestInitiatorHosts:+ """The x-initiator hook targets GitHub Copilot endpoints only."""++ def test_standard_copilot_url(self, copilot_profile):+ assert _marks_user_turn(copilot_profile, "https://api.githubcopilot.com") is True++ def test_github_models_url(self, copilot_profile):+ assert _marks_user_turn(copilot_profile, "https://models.github.ai/inference") is True++ def test_openrouter_url(self, copilot_profile):+ assert _marks_user_turn(copilot_profile, "https://openrouter.ai/api/v1") is False+++def test_copilot_host_identity_is_host_anchored():+ assert _is_copilot_host("https://api.githubcopilot.com/v1") is True+ assert _is_copilot_host("https://proxy.test/api.githubcopilot.com/v1") is False+ assert _is_copilot_host("https://models.github.ai/inference") is True+ assert _is_copilot_host("https://models.github.ai.evil.com/v1") is False