mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-04-25 00:51:20 +00:00
* test: make test env hermetic; enforce CI parity via scripts/run_tests.sh
Fixes the recurring 'works locally, fails in CI' (and vice versa) class
of flakes by making tests hermetic and providing a canonical local runner
that matches CI's environment.
## Layer 1 — hermetic conftest.py (tests/conftest.py)
Autouse fixture now unsets every credential-shaped env var before every
test, so developer-local API keys can't leak into tests that assert
'auto-detect provider when key present'.
Pattern: unset any var ending in _API_KEY, _TOKEN, _SECRET, _PASSWORD,
_CREDENTIALS, _ACCESS_KEY, _PRIVATE_KEY, etc. Plus an explicit list of
credential names that don't fit the suffix pattern (AWS_ACCESS_KEY_ID,
FAL_KEY, GH_TOKEN, etc.) and all the provider BASE_URL overrides that
change auto-detect behavior.
Also unsets HERMES_* behavioral vars (HERMES_YOLO_MODE, HERMES_QUIET,
HERMES_SESSION_*, etc.) that mutate agent behavior.
Also:
- Redirects HOME to a per-test tempdir (not just HERMES_HOME), so
code reading ~/.hermes/* directly can't touch the real dir.
- Pins TZ=UTC, LANG=C.UTF-8, LC_ALL=C.UTF-8, PYTHONHASHSEED=0 to
match CI's deterministic runtime.
The old _isolate_hermes_home fixture name is preserved as an alias so
any test that yields it explicitly still works.
## Layer 2 — scripts/run_tests.sh canonical runner
'Always use scripts/run_tests.sh, never call pytest directly' is the
new rule (documented in AGENTS.md). The script:
- Unsets all credential env vars (belt-and-suspenders for callers
who bypass conftest — e.g. IDE integrations)
- Pins TZ/LANG/PYTHONHASHSEED
- Uses -n 4 xdist workers (matches GHA ubuntu-latest; -n auto on
a 20-core workstation surfaces test-ordering flakes CI will never
see, causing the infamous 'passes in CI, fails locally' drift)
- Finds the venv in .venv, venv, or main checkout's venv
- Passes through arbitrary pytest args
Installs pytest-split on demand so the script can also be used to run
matrix-split subsets locally for debugging.
## Remove 3 module-level dotenv stubs that broke test isolation
tests/hermes_cli/test_{arcee,xiaomi,api_key}_provider.py each had a
module-level:
if 'dotenv' not in sys.modules:
fake_dotenv = types.ModuleType('dotenv')
fake_dotenv.load_dotenv = lambda *a, **kw: None
sys.modules['dotenv'] = fake_dotenv
This patches sys.modules['dotenv'] to a fake at import time with no
teardown. Under pytest-xdist LoadScheduling, whichever worker collected
one of these files first poisoned its sys.modules; subsequent tests in
the same worker that imported load_dotenv transitively (e.g.
test_env_loader.py via hermes_cli.env_loader) got the no-op lambda and
saw their assertions fail.
dotenv is a required dependency (python-dotenv>=1.2.1 in pyproject.toml),
so the defensive stub was never needed. Removed.
## Validation
- tests/hermes_cli/ alone: 2178 passed, 1 skipped, 0 failed (was 4
failures in test_env_loader.py before this fix)
- tests/test_plugin_skills.py, tests/hermes_cli/test_plugins.py,
tests/test_hermes_logging.py combined: 123 passed (the caplog
regression tests from PR #11453 still pass)
- Local full run shows no F/E clusters in the 0-55% range that were
previously present before the conftest hardening
## Background
See AGENTS.md 'Testing' section for the full list of drift sources
this closes. Matrix split (closed as #11566) will be re-attempted
once this foundation lands — cross-test pollution was the root cause
of the shard-3 hang in that PR.
* fix(conftest): don't redirect HOME — it broke CI subprocesses
PR #11577's autouse fixture was setting HOME to a per-test tempdir.
CI started timing out at 97% complete with dozens of E/F markers and
orphan python processes at cleanup — tests (or transitive deps)
spawn subprocesses that expect a stable HOME, and the redirect broke
them in non-obvious ways.
Env-var unsetting and TZ/LANG/hashseed pinning (the actual CI-drift
fixes) are unchanged and still in place. HERMES_HOME redirection is
also unchanged — that's the canonical way to isolate tests from
~/.hermes/, not HOME.
Any code in the codebase reading ~/.hermes/* via `Path.home() / ".hermes"`
instead of `get_hermes_home()` is a bug to fix at the callsite, not
something to paper over in conftest.
201 lines
7.6 KiB
Python
201 lines
7.6 KiB
Python
"""Tests for Arcee AI provider support — standard direct API provider."""
|
|
|
|
import types
|
|
|
|
import pytest
|
|
|
|
from hermes_cli.auth import (
|
|
PROVIDER_REGISTRY,
|
|
resolve_provider,
|
|
get_api_key_provider_status,
|
|
resolve_api_key_provider_credentials,
|
|
)
|
|
|
|
|
|
_OTHER_PROVIDER_KEYS = (
|
|
"OPENAI_API_KEY", "ANTHROPIC_API_KEY", "DEEPSEEK_API_KEY",
|
|
"GOOGLE_API_KEY", "GEMINI_API_KEY", "DASHSCOPE_API_KEY",
|
|
"XAI_API_KEY", "KIMI_API_KEY", "KIMI_CN_API_KEY",
|
|
"MINIMAX_API_KEY", "MINIMAX_CN_API_KEY", "AI_GATEWAY_API_KEY",
|
|
"KILOCODE_API_KEY", "HF_TOKEN", "GLM_API_KEY", "ZAI_API_KEY",
|
|
"XIAOMI_API_KEY", "COPILOT_GITHUB_TOKEN", "GH_TOKEN", "GITHUB_TOKEN",
|
|
)
|
|
|
|
|
|
# =============================================================================
|
|
# Provider Registry
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeProviderRegistry:
|
|
def test_registered(self):
|
|
assert "arcee" in PROVIDER_REGISTRY
|
|
|
|
def test_name(self):
|
|
assert PROVIDER_REGISTRY["arcee"].name == "Arcee AI"
|
|
|
|
def test_auth_type(self):
|
|
assert PROVIDER_REGISTRY["arcee"].auth_type == "api_key"
|
|
|
|
def test_inference_base_url(self):
|
|
assert PROVIDER_REGISTRY["arcee"].inference_base_url == "https://api.arcee.ai/api/v1"
|
|
|
|
def test_api_key_env_vars(self):
|
|
assert PROVIDER_REGISTRY["arcee"].api_key_env_vars == ("ARCEEAI_API_KEY",)
|
|
|
|
def test_base_url_env_var(self):
|
|
assert PROVIDER_REGISTRY["arcee"].base_url_env_var == "ARCEE_BASE_URL"
|
|
|
|
|
|
# =============================================================================
|
|
# Aliases
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeAliases:
|
|
@pytest.mark.parametrize("alias", ["arcee", "arcee-ai", "arceeai"])
|
|
def test_alias_resolves(self, alias, monkeypatch):
|
|
for key in _OTHER_PROVIDER_KEYS + ("OPENROUTER_API_KEY",):
|
|
monkeypatch.delenv(key, raising=False)
|
|
monkeypatch.setenv("ARCEEAI_API_KEY", "arc-test-12345")
|
|
assert resolve_provider(alias) == "arcee"
|
|
|
|
def test_normalize_provider_models_py(self):
|
|
from hermes_cli.models import normalize_provider
|
|
assert normalize_provider("arcee-ai") == "arcee"
|
|
assert normalize_provider("arceeai") == "arcee"
|
|
|
|
def test_normalize_provider_providers_py(self):
|
|
from hermes_cli.providers import normalize_provider
|
|
assert normalize_provider("arcee-ai") == "arcee"
|
|
assert normalize_provider("arceeai") == "arcee"
|
|
|
|
|
|
# =============================================================================
|
|
# Credentials
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeCredentials:
|
|
def test_status_configured(self, monkeypatch):
|
|
monkeypatch.setenv("ARCEEAI_API_KEY", "arc-test")
|
|
status = get_api_key_provider_status("arcee")
|
|
assert status["configured"]
|
|
|
|
def test_status_not_configured(self, monkeypatch):
|
|
monkeypatch.delenv("ARCEEAI_API_KEY", raising=False)
|
|
status = get_api_key_provider_status("arcee")
|
|
assert not status["configured"]
|
|
|
|
def test_openrouter_key_does_not_make_arcee_configured(self, monkeypatch):
|
|
"""OpenRouter users should NOT see arcee as configured."""
|
|
monkeypatch.delenv("ARCEEAI_API_KEY", raising=False)
|
|
monkeypatch.setenv("OPENROUTER_API_KEY", "sk-or-test")
|
|
status = get_api_key_provider_status("arcee")
|
|
assert not status["configured"]
|
|
|
|
def test_resolve_credentials(self, monkeypatch):
|
|
monkeypatch.setenv("ARCEEAI_API_KEY", "arc-direct-key")
|
|
monkeypatch.delenv("ARCEE_BASE_URL", raising=False)
|
|
creds = resolve_api_key_provider_credentials("arcee")
|
|
assert creds["api_key"] == "arc-direct-key"
|
|
assert creds["base_url"] == "https://api.arcee.ai/api/v1"
|
|
|
|
def test_custom_base_url_override(self, monkeypatch):
|
|
monkeypatch.setenv("ARCEEAI_API_KEY", "arc-x")
|
|
monkeypatch.setenv("ARCEE_BASE_URL", "https://custom.arcee.example/v1")
|
|
creds = resolve_api_key_provider_credentials("arcee")
|
|
assert creds["base_url"] == "https://custom.arcee.example/v1"
|
|
|
|
|
|
# =============================================================================
|
|
# Model catalog
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeModelCatalog:
|
|
def test_static_model_list(self):
|
|
from hermes_cli.models import _PROVIDER_MODELS
|
|
assert "arcee" in _PROVIDER_MODELS
|
|
models = _PROVIDER_MODELS["arcee"]
|
|
assert "trinity-large-thinking" in models
|
|
assert "trinity-large-preview" in models
|
|
assert "trinity-mini" in models
|
|
|
|
def test_canonical_provider_entry(self):
|
|
from hermes_cli.models import CANONICAL_PROVIDERS
|
|
slugs = [p.slug for p in CANONICAL_PROVIDERS]
|
|
assert "arcee" in slugs
|
|
|
|
|
|
# =============================================================================
|
|
# Model normalization
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeNormalization:
|
|
def test_in_matching_prefix_strip_set(self):
|
|
from hermes_cli.model_normalize import _MATCHING_PREFIX_STRIP_PROVIDERS
|
|
assert "arcee" in _MATCHING_PREFIX_STRIP_PROVIDERS
|
|
|
|
def test_strips_prefix(self):
|
|
from hermes_cli.model_normalize import normalize_model_for_provider
|
|
assert normalize_model_for_provider("arcee/trinity-mini", "arcee") == "trinity-mini"
|
|
|
|
def test_bare_name_unchanged(self):
|
|
from hermes_cli.model_normalize import normalize_model_for_provider
|
|
assert normalize_model_for_provider("trinity-mini", "arcee") == "trinity-mini"
|
|
|
|
|
|
# =============================================================================
|
|
# URL mapping
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeURLMapping:
|
|
def test_url_to_provider(self):
|
|
from agent.model_metadata import _URL_TO_PROVIDER
|
|
assert _URL_TO_PROVIDER.get("api.arcee.ai") == "arcee"
|
|
|
|
def test_provider_prefixes(self):
|
|
from agent.model_metadata import _PROVIDER_PREFIXES
|
|
assert "arcee" in _PROVIDER_PREFIXES
|
|
assert "arcee-ai" in _PROVIDER_PREFIXES
|
|
assert "arceeai" in _PROVIDER_PREFIXES
|
|
|
|
def test_trajectory_compressor_detects_arcee(self):
|
|
import trajectory_compressor as tc
|
|
comp = tc.TrajectoryCompressor.__new__(tc.TrajectoryCompressor)
|
|
comp.config = types.SimpleNamespace(base_url="https://api.arcee.ai/api/v1")
|
|
assert comp._detect_provider() == "arcee"
|
|
|
|
|
|
# =============================================================================
|
|
# providers.py overlay + aliases
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeProvidersModule:
|
|
def test_overlay_exists(self):
|
|
from hermes_cli.providers import HERMES_OVERLAYS
|
|
assert "arcee" in HERMES_OVERLAYS
|
|
overlay = HERMES_OVERLAYS["arcee"]
|
|
assert overlay.transport == "openai_chat"
|
|
assert overlay.base_url_env_var == "ARCEE_BASE_URL"
|
|
assert not overlay.is_aggregator
|
|
|
|
def test_label(self):
|
|
from hermes_cli.models import _PROVIDER_LABELS
|
|
assert _PROVIDER_LABELS["arcee"] == "Arcee AI"
|
|
|
|
|
|
# =============================================================================
|
|
# Auxiliary client — main-model-first design
|
|
# =============================================================================
|
|
|
|
|
|
class TestArceeAuxiliary:
|
|
def test_main_model_first_design(self):
|
|
"""Arcee uses main-model-first — no entry in _API_KEY_PROVIDER_AUX_MODELS."""
|
|
from agent.auxiliary_client import _API_KEY_PROVIDER_AUX_MODELS
|
|
assert "arcee" not in _API_KEY_PROVIDER_AUX_MODELS
|