mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-11-20 18:50:12 +03:00
refactor(speech): stop resolving the TTS output dir at import
tools/tts_tool.py resolved the profile's audio cache dir at import (DEFAULT_OUTPUT_DIR = _DEFAULT_OUTPUT_DIR_AT_IMPORT = ...) only so a test or "external patcher" that replaced DEFAULT_OUTPUT_DIR would win over the per-call resolution _default_output_dir() already did. No caller outside tts_tool.py reads either name (the website/scripts hit is an unrelated local), neither is in plugin_api.json or old_updater_surface.json, and no test patches DEFAULT_OUTPUT_DIR. _default_output_dir() now just resolves get_hermes_dir per call (the function-level import moves to the module top), so importing the module reads no profile home. The profile-scope test sets HERMES_HOME instead of reloading the module and still fails if the dir is frozen at import.
This commit is contained in:
committed by
Siddharth Balyan
Unverified
parent
a54daf9a5f
commit
7ebec7fed2
@@ -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,
|
||||
|
||||
+6
-23
@@ -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]:
|
||||
|
||||
Reference in New Issue
Block a user