hermes-agent/tests/tools/test_tts_minimax_region.py
teknium1 dd1baee0e4 refactor(secrets): drop scope-aware env shims; runtime_provider and the voice/xai tools read the canonical getters
hermes_cli/runtime_provider._getenv was a 4-line copy of get_secret(name,
default) or default; it becomes agent.secret_scope.get_secret_str (returns
default only when the secret is genuinely unset, still raises
UnscopedSecretError — a child's unscoped read is a spawn-site bug). The
runtime_provider_backends/_custom siblings call it directly instead of via
the origin module.

tools/tts_tool, tools/transcription_tools and tools/xai_http each carried an
identical get_env_value re-export kept "so tests can patch" it; the seam is
hermes_cli.config.get_env_value, read lazily at call time. Callers
(tts_streaming, tts_tool_providers, transcription_cloud, voice_client_config,
tools_config) go there directly; resolve_provider_secret already defaults to
it so the env_getter kwarg is gone. Tests repointed at the canonical; the two
tests that only proved the shim forwarded are deleted.

Behavior change: none.
2026-09-13 05:07:50 -07:00

189 lines
5.1 KiB
Python

"""MiniMax TTS region, endpoint, and credential selection tests."""
from unittest.mock import MagicMock, patch
import pytest
from tools.tts_tool import (
_generate_minimax_tts,
_resolve_minimax_tts_runtime,
check_tts_requirements,
)
from tools.tts_tool_providers import DEFAULT_MINIMAX_BASE_URL, DEFAULT_MINIMAX_CN_BASE_URL
GLOBAL_CREDENTIAL_SENTINEL = "FAKE_GLOBAL_CREDENTIAL"
CN_CREDENTIAL_SENTINEL = "FAKE_CN_CREDENTIAL"
@pytest.fixture(autouse=True)
def _fake_minimax_credentials(monkeypatch):
values = {}
monkeypatch.setattr(
"hermes_cli.config.get_env_value",
lambda name, default=None: values.get(name, default),
)
return values
@pytest.mark.parametrize(
("config", "credentials", "expected"),
[
pytest.param(
{},
{"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL},
(
"global",
DEFAULT_MINIMAX_BASE_URL,
"MINIMAX_API_KEY",
GLOBAL_CREDENTIAL_SENTINEL,
),
id="global-only",
),
pytest.param(
{},
{"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL},
(
"cn",
DEFAULT_MINIMAX_CN_BASE_URL,
"MINIMAX_CN_API_KEY",
CN_CREDENTIAL_SENTINEL,
),
id="china-only",
),
pytest.param(
{},
{
"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL,
"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL,
},
(
"global",
DEFAULT_MINIMAX_BASE_URL,
"MINIMAX_API_KEY",
GLOBAL_CREDENTIAL_SENTINEL,
),
id="both-default-to-global",
),
pytest.param(
{"minimax": {"region": "global"}},
{
"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL,
"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL,
},
(
"global",
DEFAULT_MINIMAX_BASE_URL,
"MINIMAX_API_KEY",
GLOBAL_CREDENTIAL_SENTINEL,
),
id="explicit-global",
),
pytest.param(
{"minimax": {"region": "cn"}},
{
"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL,
"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL,
},
(
"cn",
DEFAULT_MINIMAX_CN_BASE_URL,
"MINIMAX_CN_API_KEY",
CN_CREDENTIAL_SENTINEL,
),
id="explicit-china",
),
],
)
def test_runtime_selection_matrix(
_fake_minimax_credentials,
config,
credentials,
expected,
):
_fake_minimax_credentials.update(credentials)
runtime = _resolve_minimax_tts_runtime(config)
assert (
runtime.region,
runtime.endpoint,
runtime.credential_source,
runtime.api_key,
) == expected
@pytest.mark.parametrize(
("region", "credentials", "missing_source"),
[
pytest.param(
"global",
{"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL},
"MINIMAX_API_KEY",
id="global-does-not-borrow-china-key",
),
pytest.param(
"cn",
{"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL},
"MINIMAX_CN_API_KEY",
id="china-does-not-borrow-global-key",
),
],
)
def test_explicit_region_requires_matching_credential(
_fake_minimax_credentials,
region,
credentials,
missing_source,
):
_fake_minimax_credentials.update(credentials)
with pytest.raises(ValueError, match=missing_source):
_resolve_minimax_tts_runtime({"minimax": {"region": region}})
@pytest.mark.parametrize(
("config", "credentials", "expected"),
[
pytest.param(
{"provider": "minimax"},
{"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL},
True,
id="china-only-available",
),
pytest.param(
{"provider": "minimax", "minimax": {"region": "cn"}},
{"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL},
False,
id="selected-region-missing",
),
pytest.param(
{"provider": "minimax", "minimax": {"region": "invalid"}},
{
"MINIMAX_API_KEY": GLOBAL_CREDENTIAL_SENTINEL,
"MINIMAX_CN_API_KEY": CN_CREDENTIAL_SENTINEL,
},
False,
id="invalid-region",
),
],
)
def test_availability_uses_atomic_runtime(
monkeypatch,
_fake_minimax_credentials,
config,
credentials,
expected,
):
_fake_minimax_credentials.update(credentials)
monkeypatch.setattr("tools.tts_tool._load_tts_config", lambda: config)
assert check_tts_requirements() is expected
def test_runtime_repr_excludes_raw_credential(_fake_minimax_credentials):
_fake_minimax_credentials["MINIMAX_API_KEY"] = GLOBAL_CREDENTIAL_SENTINEL
runtime = _resolve_minimax_tts_runtime({})
assert GLOBAL_CREDENTIAL_SENTINEL not in repr(runtime)