mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-07-31 19:16:29 +00:00
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.
135 lines
4.9 KiB
Python
135 lines
4.9 KiB
Python
"""Tests for per-provider TTS input-character limits.
|
|
|
|
Replaces the old global ``MAX_TEXT_LENGTH = 4000`` cap that truncated every
|
|
provider at 4000 chars even though OpenAI allows 4096, xAI allows 15000,
|
|
MiniMax allows 10000, and ElevenLabs allows 5000-40000 depending on model.
|
|
"""
|
|
|
|
import json
|
|
|
|
|
|
from tools.tts_tool import (
|
|
FALLBACK_MAX_TEXT_LENGTH,
|
|
PROVIDER_MAX_TEXT_LENGTH,
|
|
_resolve_max_text_length,
|
|
)
|
|
|
|
|
|
class TestResolveMaxTextLength:
|
|
def test_edge_default(self):
|
|
assert _resolve_max_text_length("edge", {}) == PROVIDER_MAX_TEXT_LENGTH["edge"]
|
|
|
|
def test_openai_default_is_4096(self):
|
|
assert _resolve_max_text_length("openai", {}) == 4096
|
|
|
|
def test_xai_default_is_15000(self):
|
|
assert _resolve_max_text_length("xai", {}) == 15000
|
|
|
|
def test_minimax_default_is_10000(self):
|
|
assert _resolve_max_text_length("minimax", {}) == 10000
|
|
|
|
def test_mistral_default(self):
|
|
assert _resolve_max_text_length("mistral", {}) == PROVIDER_MAX_TEXT_LENGTH["mistral"]
|
|
|
|
def test_gemini_default(self):
|
|
assert _resolve_max_text_length("gemini", {}) == PROVIDER_MAX_TEXT_LENGTH["gemini"]
|
|
|
|
def test_unknown_provider_falls_back(self):
|
|
assert _resolve_max_text_length("does-not-exist", {}) == FALLBACK_MAX_TEXT_LENGTH
|
|
|
|
def test_empty_provider_falls_back(self):
|
|
assert _resolve_max_text_length("", {}) == FALLBACK_MAX_TEXT_LENGTH
|
|
assert _resolve_max_text_length(None, {}) == FALLBACK_MAX_TEXT_LENGTH
|
|
|
|
|
|
# --- Overrides ---
|
|
|
|
|
|
# --- ElevenLabs model-aware ---
|
|
|
|
|
|
# --- Sanity: the table covers every provider listed in the schema ---
|
|
|
|
def test_all_documented_providers_have_defaults(self):
|
|
expected = {"edge", "openai", "xai", "minimax", "mistral",
|
|
"gemini", "elevenlabs", "neutts", "kittentts"}
|
|
assert expected.issubset(PROVIDER_MAX_TEXT_LENGTH.keys())
|
|
|
|
|
|
class TestTextToSpeechToolTruncation:
|
|
"""End-to-end: verify the resolver actually drives the text_to_speech_tool
|
|
truncation path rather than the old 4000-char global."""
|
|
|
|
def test_openai_truncates_at_4096_not_4000(self, tmp_path, monkeypatch, caplog):
|
|
import logging
|
|
caplog.set_level(logging.WARNING, logger="tools.tts_tool")
|
|
|
|
# 5000 chars -- over OpenAI's 4096 limit but under xAI's 15k
|
|
text = "A" * 5000
|
|
captured_text = {}
|
|
|
|
def fake_openai(t, out, cfg, **_kw):
|
|
captured_text["text"] = t
|
|
with open(out, "wb") as f:
|
|
f.write(b"\x00")
|
|
return out
|
|
|
|
monkeypatch.setattr("tools.tts_tool._generate_openai_tts", fake_openai)
|
|
monkeypatch.setattr("tools.tts_tool._load_tts_config",
|
|
lambda: {"provider": "openai"})
|
|
|
|
from tools.tts_tool import text_to_speech_tool
|
|
out = str(tmp_path / "out.mp3")
|
|
result = json.loads(text_to_speech_tool(text=text, output_path=out))
|
|
|
|
assert result["success"] is True
|
|
# Should be truncated to 4096, not the old 4000
|
|
assert len(captured_text["text"]) == 4096
|
|
# And the warning should mention the provider
|
|
assert any("openai" in rec.message.lower() for rec in caplog.records)
|
|
|
|
def test_xai_accepts_much_longer_input(self, tmp_path, monkeypatch):
|
|
# 12000 chars -- over old global 4000, under xAI's 15000
|
|
text = "B" * 12000
|
|
captured_text = {}
|
|
|
|
def fake_xai(t, out, cfg):
|
|
captured_text["text"] = t
|
|
with open(out, "wb") as f:
|
|
f.write(b"\x00")
|
|
return out
|
|
|
|
monkeypatch.setattr("tools.tts_tool._generate_xai_tts", fake_xai)
|
|
monkeypatch.setattr("tools.tts_tool._load_tts_config",
|
|
lambda: {"provider": "xai"})
|
|
|
|
from tools.tts_tool import text_to_speech_tool
|
|
out = str(tmp_path / "out.mp3")
|
|
result = json.loads(text_to_speech_tool(text=text, output_path=out))
|
|
|
|
assert result["success"] is True
|
|
# xAI should accept the full 12000 chars
|
|
assert len(captured_text["text"]) == 12000
|
|
|
|
def test_user_override_is_respected(self, tmp_path, monkeypatch):
|
|
# User says "cap openai at 100 chars" -- we must honor it
|
|
text = "C" * 500
|
|
captured_text = {}
|
|
|
|
def fake_openai(t, out, cfg, **_kw):
|
|
captured_text["text"] = t
|
|
with open(out, "wb") as f:
|
|
f.write(b"\x00")
|
|
return out
|
|
|
|
monkeypatch.setattr("tools.tts_tool._generate_openai_tts", fake_openai)
|
|
monkeypatch.setattr("tools.tts_tool._load_tts_config",
|
|
lambda: {"provider": "openai",
|
|
"openai": {"max_text_length": 100}})
|
|
|
|
from tools.tts_tool import text_to_speech_tool
|
|
out = str(tmp_path / "out.mp3")
|
|
result = json.loads(text_to_speech_tool(text=text, output_path=out))
|
|
|
|
assert result["success"] is True
|
|
assert len(captured_text["text"]) == 100
|