Files
hermes-agent/tests/gateway/test_gateway_streaming_nested_config.py
T
teknium1 d10bb2ab6f test: make tests/ mirror the source tree; drop issue numbers from filenames
`scripts/run_tests.sh tests/<dir>/` is how a change gets its regression
coverage run, so a test filed under the wrong directory is a test nobody
runs when that code changes. Two kinds of drift had accumulated.

Parallel directories for one source package, folded into the mirror:
  tests/acp        -> tests/acp_adapter   (its __init__/conftest move with it)
  tests/cli        -> tests/hermes_cli    (prompt_toolkit fixture merged into
                                           hermes_cli/conftest.py)
  tests/run_agent  -> tests/agent         (backoff fixture becomes
                                           agent/conftest.py)
  tests/relay      -> tests/gateway/relay
  tests/state      -> tests/hermes_state

246 loose files at tests/ root, routed by the package they import/patch:
hermes_cli, hermes_state, agent, gateway, tools, plugins, tui_gateway, cron.
Installer and desktop-update script tests go to tests/scripts/{install,
desktop_update}/. 43 tests of root-level modules (batch_runner, utils,
hermes_constants, packaging) stay at the root.

Filenames drop their issue numbers (95 files: test_89315_x.py -> test_x.py);
the number stays in the module docstring where it has context.

Collisions: test_cli_skin_integration.py existed in both tests/ and tests/cli
with different subsets — merged into one (10 tests, all kept);
run_agent/test_pre_compress_memory_context.py -> agent/..._handoff.py;
tests/test_account_usage.py -> agent/test_account_usage_fetch.py;
tests/test_web_server.py -> hermes_cli/test_web_server_ws_ping.py.
Deleted: test_minisweagent_path.py (empty since PR #2804),
test_model_picker_scroll.py (tested a private copy of the logic, imported
nothing), test_process_loop_event_loop_warning.py (asserted asyncio behaviour,
imported nothing from Hermes).

Repo-root path arithmetic (Path(__file__).parents[N], dirname chains) is
bumped for the 202 files that changed depth and verified by evaluating every
such expression against the new location. classify_changes' desktop-updater
lane prefix, tests-os.yml's ignore glob and every in-tree path comment follow
the moves. tests/test_tests_tree_layout.py keeps the tree from drifting back.
2026-09-13 09:18:02 -07:00

115 lines
4.0 KiB
Python

"""Regression test for #25676 — nested gateway.streaming config must be loaded."""
from pathlib import Path
from unittest.mock import patch, MagicMock
def _load_with_yaml_dict(yaml_dict: dict):
"""Patch filesystem so load_gateway_config() sees *yaml_dict* as config.yaml."""
from gateway.config import load_gateway_config
fake_home = Path("/tmp/fake_hermes_home_25676")
def fake_exists(self):
return str(self).endswith("config.yaml")
with patch("gateway.config.get_hermes_home", return_value=fake_home), \
patch.object(Path, "exists", fake_exists), \
patch("builtins.open", create=True) as mock_file:
mock_file.return_value.__enter__ = lambda s: s
mock_file.return_value.__exit__ = MagicMock(return_value=False)
with patch("yaml.safe_load", return_value=yaml_dict):
return load_gateway_config()
class TestStreamingConfigNested:
def test_top_level_streaming(self):
cfg = _load_with_yaml_dict({"streaming": {"enabled": True, "transport": "draft"}})
assert cfg.streaming.enabled is True
assert cfg.streaming.transport == "draft"
def test_top_level_takes_precedence(self):
cfg = _load_with_yaml_dict({
"streaming": {"enabled": True, "transport": "edit"},
"gateway": {"streaming": {"enabled": False, "transport": "draft"}},
})
assert cfg.streaming.enabled is True
assert cfg.streaming.transport == "edit"
class TestStreamingModeAlias:
"""``streaming: {mode: ...}`` is an alias that also implies ``enabled``.
Regression for a live config footgun: ``streaming: {mode: auto}`` was
silently ignored (mode was never read), so streaming stayed disabled and
the whole reply buffered before the first Telegram send.
"""
def test_mode_auto_enables_streaming(self):
from gateway.config import StreamingConfig
sc = StreamingConfig.from_dict({"mode": "auto"})
assert sc.enabled is True
assert sc.transport == "auto"
def test_mode_edit_enables_streaming(self):
from gateway.config import StreamingConfig
sc = StreamingConfig.from_dict({"mode": "edit"})
assert sc.enabled is True
assert sc.transport == "edit"
def test_explicit_enabled_overrides_mode(self):
from gateway.config import StreamingConfig
sc = StreamingConfig.from_dict({"mode": "auto", "enabled": False})
assert sc.enabled is False
# transport still resolves from mode
assert sc.transport == "auto"
def test_empty_block_stays_disabled(self):
from gateway.config import StreamingConfig
sc = StreamingConfig.from_dict({})
assert sc.enabled is False
class TestStreamingYamlBooleanQuirk:
"""YAML 1.1 parses bare ``off``/``on`` as booleans; ``mode``/``transport``
must normalize those back to canonical string tokens.
Regression for the review on PR #62873: bare ``mode: off`` arrived as
Python ``False`` and stringified to ``"false"``, which is not ``"off"``,
so streaming was enabled instead of honoring the advertised disable.
"""
def test_mode_bare_off_boolean_disables(self):
from gateway.config import StreamingConfig
# yaml.safe_load("off") -> False
sc = StreamingConfig.from_dict({"mode": False})
assert sc.enabled is False
assert sc.transport == "off"
def test_mode_bare_on_boolean_enables(self):
from gateway.config import StreamingConfig
# yaml.safe_load("on") -> True
sc = StreamingConfig.from_dict({"mode": True})
assert sc.enabled is True
assert sc.transport == "auto"
def test_loader_normalizes_bare_yaml_off(self):
"""End-to-end through load_gateway_config(): unquoted ``mode: off``
(a YAML boolean) must keep streaming disabled."""
cfg = _load_with_yaml_dict({"streaming": {"mode": False}})
assert cfg.streaming.enabled is False
assert cfg.streaming.transport == "off"