项目文件夹

文件
wehub-resource-sync b4fbd6fe9f
Deploy Site / deploy-vercel (push) Has been skipped
Deploy Site / deploy-docs (push) Has been skipped
Build Skills Index / build-index (push) Has been skipped
CI / Deny unrelated histories (push) Has been skipped
CI / Detect affected areas (push) Successful in 27m35s
CI / OSV scan (push) Failing after 4s
CI / Build&Test Docker image (push) Successful in 9s
CI / Supply-chain scan (push) Has been skipped
CI / Lint Docker scripts (push) Failing after 5m13s
CI / Check contributors (push) Failing after 12m8s
CI / Docs Site (push) Failing after 12m8s
CI / TypeScript (push) Failing after 12m8s
CI / Python lints (push) Failing after 12m9s
CI / Python tests (push) Failing after 12m9s
CI / Check uv.lock (push) Failing after 23m22s
CI / CI timing report (push) Has been cancelled
Build Skills Index / trigger-deploy (push) Has been cancelled
CI / All required checks pass (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:56:03 +08:00

71 行
2.3 KiB
Python

import json
from pathlib import Path
from unittest.mock import Mock
import pytest
from gateway.session_context import _UNSET, _VAR_MAP
from tools import tts_tool
def _reset_session_context() -> None:
for var in _VAR_MAP.values():
var.set(_UNSET)
@pytest.fixture(autouse=True)
def _clean_session_platform(monkeypatch):
_reset_session_context()
monkeypatch.delenv("HERMES_SESSION_PLATFORM", raising=False)
yield
_reset_session_context()
async def _write_edge_output(_text: str, output_path: str, _tts_config: dict) -> str:
Path(output_path).write_bytes(b"mp3")
return output_path
def test_edge_cli_preserves_native_mp3(tmp_path, monkeypatch):
out = tmp_path / "speech.mp3"
convert = Mock()
monkeypatch.setattr(tts_tool, "_load_tts_config", lambda: {"provider": "edge"})
monkeypatch.setattr(tts_tool, "_import_edge_tts", lambda: object())
monkeypatch.setattr(tts_tool, "_generate_edge_tts", _write_edge_output)
monkeypatch.setattr(tts_tool, "_convert_to_opus", convert)
result = json.loads(tts_tool.text_to_speech_tool("hello", output_path=str(out)))
assert result["success"] is True
assert result["file_path"] == str(out)
assert result["voice_compatible"] is False
assert result["media_tag"] == f"MEDIA:{out}"
convert.assert_not_called()
def test_edge_telegram_converts_to_opus_voice(tmp_path, monkeypatch):
out = tmp_path / "speech.mp3"
opus = tmp_path / "speech.ogg"
def fake_convert(path: str) -> str:
assert path == str(out)
opus.write_bytes(b"ogg")
return str(opus)
convert = Mock(side_effect=fake_convert)
monkeypatch.setenv("HERMES_SESSION_PLATFORM", "telegram")
monkeypatch.setattr(tts_tool, "_load_tts_config", lambda: {"provider": "edge"})
monkeypatch.setattr(tts_tool, "_import_edge_tts", lambda: object())
monkeypatch.setattr(tts_tool, "_generate_edge_tts", _write_edge_output)
monkeypatch.setattr(tts_tool, "_convert_to_opus", convert)
result = json.loads(tts_tool.text_to_speech_tool("hello", output_path=str(out)))
assert result["success"] is True
assert result["file_path"] == str(opus)
assert result["voice_compatible"] is True
assert result["media_tag"] == f"[[audio_as_voice]]\nMEDIA:{opus}"
convert.assert_called_once_with(str(out))