39975613b1
Second, deeper pass over tools/gateway/hermes_cli plus first pass over the trees wave 1 missed (acp, acp_adapter, skills, computer_use, docker, dashboard, conformance, monitoring, secret_sources, hermes_state, providers). Same rubric as wave 1 (AGENTS.md test policy); security, alternation/caching invariants, issue-number regressions, and E2E kept. Real test-quality fixes found and rooted out along the way: - tests/tools/test_command_guards.py made real auxiliary-LLM HTTPS calls (DEFAULT_CONFIG smart-approval leaked in) — pinned approval mode=manual via autouse fixture: 17.4s → 0.4s. - test_model_switch_custom_providers.py / test_user_providers_model_switch.py silently probed live provider catalogs (~2s/test) — stubbed cached_provider_model_ids/provider_model_ids/fetch_api_models. - test_telegram_noise_filter.py: 15-platform copy-paste matrix over shared gateway.run logic → 3 representative platforms (55s → 3.9s). - test_gateway_shutdown.py: stop()'s 5s interrupt-deadline loop spun on MagicMock agents — interrupt.side_effect now clears _running_agents (22s → 1.0s). - test_gateway_inactivity_timeout.py poll-harness timings shrunk 3-5x (24s → 1.1s); test_mcp_stability.py backoff/SIGTERM-grace sleeps patched (15.4s → 2.5s); test_async_delegation.py negative-drain wait 5s → 0.5s. - test_telegram_init_deadline.py: loop-block margin restored to 1.0s with rationale comment — the watchdog-dump assertion needs the loop blocked well past deadline+grace under parallel load (flaked once in the 40-worker verification run at a 0.2s margin). Verification: full hermetic suite via scripts/run_tests.sh — 2,438 files, 21,718 tests passed, 0 failed, 293.9s wall. Suite totals vs original baseline: 46,820 → 19,757 test functions (−57.8%), wall 583.5s → 293.9s (−50%), subprocess CPU 13,564s → 11,623s.
191 lines
5.1 KiB
Python
191 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 (
|
|
DEFAULT_MINIMAX_BASE_URL,
|
|
DEFAULT_MINIMAX_CN_BASE_URL,
|
|
_generate_minimax_tts,
|
|
_resolve_minimax_tts_runtime,
|
|
check_tts_requirements,
|
|
)
|
|
|
|
|
|
GLOBAL_CREDENTIAL_SENTINEL = "FAKE_GLOBAL_CREDENTIAL"
|
|
CN_CREDENTIAL_SENTINEL = "FAKE_CN_CREDENTIAL"
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def _fake_minimax_credentials(monkeypatch):
|
|
values = {}
|
|
monkeypatch.setattr(
|
|
"tools.tts_tool.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)
|