diff --git a/tests/tools/test_tts_output_dir_profile_scope.py b/tests/tools/test_tts_output_dir_profile_scope.py index 4d7bc2c979..556d9955ea 100644 --- a/tests/tools/test_tts_output_dir_profile_scope.py +++ b/tests/tools/test_tts_output_dir_profile_scope.py @@ -1,22 +1,13 @@ """Regression tests for profile-scoped TTS default output dir (#98749). -``DEFAULT_OUTPUT_DIR`` was resolved once at import time, so long-lived -multi-profile runtimes (dashboard console, TUI/Desktop backend, cron, kanban -workers) kept writing synthesized audio into the launch profile's -``cache/audio`` even while the request was scoped to a different profile via -``HERMES_HOME`` or ``set_hermes_home_override()``. The call-time accessor -``_default_output_dir()`` re-resolves from the live profile-scoped home; -these pins keep the synthesis paths from re-freezing the launch profile. +Long-lived multi-profile runtimes (dashboard console, TUI/Desktop backend, +cron, kanban workers) must write synthesized audio into the active profile's +``cache/audio`` when a request is scoped via ``set_hermes_home_override()``, +not into the launch profile's. """ -import importlib -from pathlib import Path +from tools import tts_tool -def _reload_tts_tool(import_home: Path, monkeypatch): - monkeypatch.setenv("HERMES_HOME", str(import_home)) - from tools import tts_tool - - return importlib.reload(tts_tool) def test_default_output_dir_follows_contextvar_profile_override(tmp_path, monkeypatch): """The web server scopes profiles via set_hermes_home_override() rather @@ -26,7 +17,7 @@ def test_default_output_dir_follows_contextvar_profile_override(tmp_path, monkey default_home.mkdir(parents=True) profile_home.mkdir(parents=True) - tts_tool = _reload_tts_tool(default_home, monkeypatch) + monkeypatch.setenv("HERMES_HOME", str(default_home)) from hermes_constants import ( reset_hermes_home_override, diff --git a/tools/tts_tool.py b/tools/tts_tool.py index 0a657d708a..e2f5226062 100644 --- a/tools/tts_tool.py +++ b/tools/tts_tool.py @@ -24,7 +24,7 @@ from typing import Callable, Dict, Any, List, Optional import copy -from hermes_constants import display_hermes_home +from hermes_constants import display_hermes_home, get_hermes_dir logger = logging.getLogger(__name__) @@ -112,29 +112,12 @@ def _check_piper_available() -> bool: return _package_installed("piper") DEFAULT_PROVIDER = "edge" -def _get_default_output_dir() -> str: - from hermes_constants import get_hermes_dir - return str(get_hermes_dir("cache/audio", "audio_cache")) - - -DEFAULT_OUTPUT_DIR = _DEFAULT_OUTPUT_DIR_AT_IMPORT = _get_default_output_dir() - - def _default_output_dir() -> str: - """The active profile's audio output dir at call time (long-lived runtimes switch profiles - after import); a monkeypatched ``DEFAULT_OUTPUT_DIR`` wins. - - Same bug class as skills_tool (f8723c478) and skills_sync (#65828): long-lived multi-profile runtimes - (dashboard console, TUI/Desktop backend, cron, kanban workers) import this module once under the launch - HERMES_HOME and later scope requests to a different profile via - ``hermes_constants.set_hermes_home_override()`` — a frozen module constant keeps writing synthesized - audio into the launch profile's cache instead of the active profile's (#98749). Keep the legacy - ``DEFAULT_OUTPUT_DIR`` module attribute for tests and external patchers; when it has not been patched, - re-resolve from the live profile-scoped HERMES_HOME on every call. - """ - if DEFAULT_OUTPUT_DIR != _DEFAULT_OUTPUT_DIR_AT_IMPORT: - return DEFAULT_OUTPUT_DIR - return _get_default_output_dir() + """The active profile's audio output dir, resolved per call: long-lived multi-profile runtimes + (dashboard console, TUI/Desktop backend, cron, kanban workers) import this module once under the + launch HERMES_HOME and later scope requests to another profile via + ``hermes_constants.set_hermes_home_override()`` (#98749).""" + return str(get_hermes_dir("cache/audio", "audio_cache")) def _load_tts_config() -> dict[str, Any]: