hermes-agent/tests/hermes_cli/test_fireworks_provider.py
teknium1 4f1dcc2dad test: purge low-value tests, lane py11 (303 removed)
Change-detectors, tautologies, source-reading tests, redundant duplicates,
mock-echo tests and dead/unrunnable tests. Per-test rationale in the lane
ledger (category + reason for every removal).
2026-09-23 03:15:26 -07:00

156 lines
5.9 KiB
Python

"""Focused tests for Fireworks AI first-class provider wiring.
These tests pin the wiring that makes Fireworks a real provider — alias
resolution through both CLI resolvers, config/doctor/overlay registration,
and credential/base-URL resolution — without
any live network calls.
"""
from __future__ import annotations
import contextlib
import io
import sys
import types
from argparse import Namespace
import pytest
if "dotenv" not in sys.modules:
fake_dotenv = types.ModuleType("dotenv")
fake_dotenv.load_dotenv = lambda *args, **kwargs: None
sys.modules["dotenv"] = fake_dotenv
from hermes_cli.auth import resolve_api_key_provider_credentials
from hermes_cli.models import normalize_provider
@pytest.fixture(autouse=True)
def _clear_provider_env(monkeypatch):
for key in ("FIREWORKS_API_KEY", "FIREWORKS_BASE_URL"):
monkeypatch.delenv(key, raising=False)
class TestFireworksAliases:
"""Both CLI resolvers must map the aliases — the plugin's aliases= tuple is
NOT consulted by these static maps, so they need explicit coverage."""
@pytest.mark.parametrize("alias", ["fireworks", "fireworks-ai", "fw", "FW", " Fireworks-AI "])
def test_models_normalize_provider(self, alias):
assert normalize_provider(alias) == "fireworks"
@pytest.mark.parametrize("alias", ["fireworks", "fireworks-ai", "fw"])
def test_providers_normalize_provider(self, alias):
from hermes_cli.providers import normalize_provider as normalize_in_providers
assert normalize_in_providers(alias) == "fireworks"
class TestFireworksConfigRegistry:
def test_optional_env_vars_include_fireworks(self):
from hermes_cli.config import OPTIONAL_ENV_VARS
assert "FIREWORKS_API_KEY" in OPTIONAL_ENV_VARS
assert OPTIONAL_ENV_VARS["FIREWORKS_API_KEY"]["category"] == "provider"
assert OPTIONAL_ENV_VARS["FIREWORKS_API_KEY"]["password"] is True
assert "FIREWORKS_BASE_URL" not in OPTIONAL_ENV_VARS
class TestFireworksDoctor:
def test_slash_form_model_is_not_flagged_as_vendor_prefixed(self, monkeypatch, tmp_path):
"""Fireworks' native model IDs are slash-form (accounts/fireworks/...),
so doctor must NOT warn that provider should be 'openrouter' / the prefix
dropped — that heuristic is for aggregator vendor slugs only."""
from hermes_cli import doctor as doctor_mod
home = tmp_path / ".hermes"
home.mkdir(parents=True)
(home / "config.yaml").write_text(
"model:\n"
" provider: fireworks\n"
" default: accounts/fireworks/models/kimi-k2p6\n"
"memory: {}\n",
encoding="utf-8",
)
(home / ".env").write_text("FIREWORKS_API_KEY=fw_test\n", encoding="utf-8")
project = tmp_path / "project"
project.mkdir()
monkeypatch.setattr(doctor_mod, "HERMES_HOME", home)
monkeypatch.setattr(doctor_mod, "PROJECT_ROOT", project)
monkeypatch.setattr(doctor_mod, "_DHH", str(home))
monkeypatch.setenv("FIREWORKS_API_KEY", "fw_test")
# Keep the run offline and cheap.
import httpx
monkeypatch.setattr(httpx, "get", lambda *a, **k: types.SimpleNamespace(status_code=200))
monkeypatch.setitem(
sys.modules,
"model_tools",
types.SimpleNamespace(check_tool_availability=lambda *a, **k: ([], []), TOOLSET_REQUIREMENTS={}),
)
with contextlib.suppress(Exception):
from hermes_cli import auth as _auth_mod
monkeypatch.setattr(_auth_mod, "get_nous_auth_status", lambda: {})
monkeypatch.setattr(_auth_mod, "get_codex_auth_status", lambda: {})
buf = io.StringIO()
with contextlib.suppress(SystemExit), contextlib.redirect_stdout(buf):
doctor_mod.run_doctor(Namespace(fix=False))
out = buf.getvalue()
assert "vendor-prefixed" not in out
assert "vendor/model slug" not in out
class TestFireworksCredentials:
def test_resolves_default_base_url(self, monkeypatch):
monkeypatch.setenv("FIREWORKS_API_KEY", "fw_test_key")
creds = resolve_api_key_provider_credentials("fireworks")
assert creds["api_key"] == "fw_test_key"
assert creds["base_url"] == "https://api.fireworks.ai/inference/v1"
class TestFireworksAuxiliary:
"""resolve_provider_client wires the BYOK key and PAYG-safe aux model."""
def _resolve(self, name):
from unittest.mock import patch
from agent.auxiliary_client import resolve_provider_client
with patch("agent.auxiliary_client.OpenAI") as mock_openai:
mock_openai.return_value = object()
client, model = resolve_provider_client(name)
return client, model, mock_openai.call_args.kwargs
def test_client_sends_attribution_headers(self, monkeypatch):
monkeypatch.setenv("FIREWORKS_API_KEY", "fw_test_key")
client, model, kwargs = self._resolve("fireworks")
assert client is not None
headers = kwargs.get("default_headers", {})
assert headers["HTTP-Referer"] == "https://hermes-agent.nousresearch.com"
assert headers["X-Title"] == "Hermes Agent"
assert kwargs["base_url"] == "https://api.fireworks.ai/inference/v1"
def test_client_sends_hermes_user_agent(self, monkeypatch):
"""The profile's User-Agent survives the generic default_headers
fallback and reaches OpenAI client construction."""
monkeypatch.setenv("FIREWORKS_API_KEY", "fw_test_key")
_client, _model, kwargs = self._resolve("fireworks")
headers = kwargs.get("default_headers", {})
assert headers["User-Agent"].startswith("HermesAgent/")
class TestFireworksModelMetadata:
def test_url_infers_fireworks(self):
from agent.model_metadata import _infer_provider_from_url
assert _infer_provider_from_url("https://api.fireworks.ai/inference/v1") == "fireworks"