fix(tests): stabilize xai env and provider parity
This commit is contained in:
@@ -254,8 +254,12 @@ class TestDeveloperRoleSwap:
|
|||||||
assert messages[0]["role"] == "system"
|
assert messages[0]["role"] == "system"
|
||||||
|
|
||||||
def test_developer_role_via_nous_portal(self, monkeypatch):
|
def test_developer_role_via_nous_portal(self, monkeypatch):
|
||||||
agent = _make_agent(monkeypatch, "nous", base_url="https://inference-api.nousresearch.com/v1")
|
agent = _make_agent(
|
||||||
agent.model = "gpt-5"
|
monkeypatch,
|
||||||
|
"nous",
|
||||||
|
base_url="https://inference-api.nousresearch.com/v1",
|
||||||
|
model="gpt-5",
|
||||||
|
)
|
||||||
messages = [
|
messages = [
|
||||||
{"role": "system", "content": "You are helpful."},
|
{"role": "system", "content": "You are helpful."},
|
||||||
{"role": "user", "content": "hi"},
|
{"role": "user", "content": "hi"},
|
||||||
@@ -346,14 +350,24 @@ class TestBuildApiKwargsAIGateway:
|
|||||||
class TestBuildApiKwargsNousPortal:
|
class TestBuildApiKwargsNousPortal:
|
||||||
def test_includes_nous_product_tags(self, monkeypatch):
|
def test_includes_nous_product_tags(self, monkeypatch):
|
||||||
from agent.portal_tags import nous_portal_tags
|
from agent.portal_tags import nous_portal_tags
|
||||||
agent = _make_agent(monkeypatch, "nous", base_url="https://inference-api.nousresearch.com/v1")
|
agent = _make_agent(
|
||||||
|
monkeypatch,
|
||||||
|
"nous",
|
||||||
|
base_url="https://inference-api.nousresearch.com/v1",
|
||||||
|
model="gpt-5",
|
||||||
|
)
|
||||||
messages = [{"role": "user", "content": "hi"}]
|
messages = [{"role": "user", "content": "hi"}]
|
||||||
kwargs = agent._build_api_kwargs(messages)
|
kwargs = agent._build_api_kwargs(messages)
|
||||||
extra = kwargs.get("extra_body", {})
|
extra = kwargs.get("extra_body", {})
|
||||||
assert extra.get("tags") == nous_portal_tags()
|
assert extra.get("tags") == nous_portal_tags()
|
||||||
|
|
||||||
def test_uses_chat_completions_format(self, monkeypatch):
|
def test_uses_chat_completions_format(self, monkeypatch):
|
||||||
agent = _make_agent(monkeypatch, "nous", base_url="https://inference-api.nousresearch.com/v1")
|
agent = _make_agent(
|
||||||
|
monkeypatch,
|
||||||
|
"nous",
|
||||||
|
base_url="https://inference-api.nousresearch.com/v1",
|
||||||
|
model="gpt-5",
|
||||||
|
)
|
||||||
messages = [{"role": "user", "content": "hi"}]
|
messages = [{"role": "user", "content": "hi"}]
|
||||||
kwargs = agent._build_api_kwargs(messages)
|
kwargs = agent._build_api_kwargs(messages)
|
||||||
assert "messages" in kwargs
|
assert "messages" in kwargs
|
||||||
|
|||||||
@@ -58,6 +58,33 @@ class TestProviderSelectionGate:
|
|||||||
finally:
|
finally:
|
||||||
importlib.reload(tt)
|
importlib.reload(tt)
|
||||||
|
|
||||||
|
def test_xai_resolver_import_after_config_env_patch_uses_restored_dotenv_loader(self):
|
||||||
|
"""xAI HTTP auth must not cache a temporarily patched env helper."""
|
||||||
|
import importlib
|
||||||
|
import hermes_cli.config as config_mod
|
||||||
|
from tools import xai_http
|
||||||
|
|
||||||
|
with pytest.MonkeyPatch.context() as mp:
|
||||||
|
mp.setattr(config_mod, "get_env_value", lambda name, default=None: "")
|
||||||
|
xai_http = importlib.reload(xai_http)
|
||||||
|
|
||||||
|
try:
|
||||||
|
with patch(
|
||||||
|
"hermes_cli.runtime_provider.resolve_runtime_provider",
|
||||||
|
side_effect=RuntimeError("no oauth"),
|
||||||
|
), patch(
|
||||||
|
"hermes_cli.auth.resolve_xai_oauth_runtime_credentials",
|
||||||
|
return_value={},
|
||||||
|
), patch(
|
||||||
|
"hermes_cli.config.load_env",
|
||||||
|
return_value={"XAI_API_KEY": "dotenv-secret"},
|
||||||
|
):
|
||||||
|
creds = xai_http.resolve_xai_http_credentials()
|
||||||
|
finally:
|
||||||
|
importlib.reload(xai_http)
|
||||||
|
|
||||||
|
assert creds["api_key"] == "dotenv-secret"
|
||||||
|
|
||||||
def test_explicit_groq_sees_dotenv(self):
|
def test_explicit_groq_sees_dotenv(self):
|
||||||
from tools import transcription_tools as tt
|
from tools import transcription_tools as tt
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,6 @@ from __future__ import annotations
|
|||||||
import os
|
import os
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
|
|
||||||
try:
|
|
||||||
from hermes_cli.config import get_env_value as _hermes_get_env_value
|
|
||||||
except Exception:
|
|
||||||
_hermes_get_env_value = None
|
|
||||||
|
|
||||||
|
|
||||||
def get_env_value(name: str, default=None):
|
def get_env_value(name: str, default=None):
|
||||||
"""Read ``name`` from ``~/.hermes/.env`` first, then ``os.environ``.
|
"""Read ``name`` from ``~/.hermes/.env`` first, then ``os.environ``.
|
||||||
|
|
||||||
@@ -18,10 +12,14 @@ def get_env_value(name: str, default=None):
|
|||||||
``tools.xai_http.get_env_value`` to inject dotenv-only secrets into the
|
``tools.xai_http.get_env_value`` to inject dotenv-only secrets into the
|
||||||
xAI credential resolver.
|
xAI credential resolver.
|
||||||
"""
|
"""
|
||||||
if _hermes_get_env_value is not None:
|
try:
|
||||||
|
from hermes_cli.config import get_env_value as _hermes_get_env_value
|
||||||
|
|
||||||
value = _hermes_get_env_value(name)
|
value = _hermes_get_env_value(name)
|
||||||
if value is not None:
|
if value is not None:
|
||||||
return value
|
return value
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
return os.environ.get(name, default)
|
return os.environ.get(name, default)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user