diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.py index 46ceeb205c03..27992663e4f7 100644 --- a/tests/gateway/test_config.py +++ b/tests/gateway/test_config.py @@ -1467,3 +1467,93 @@ class TestMultiplexProfilesEnvOverride: for noise in ("", " ", "maybe", "2"): monkeypatch.setenv("GATEWAY_MULTIPLEX_PROFILES", noise) assert _env_multiplex_profiles_override() is None, repr(noise) + + +class TestMultiplexProfilesConfig: + """Tests for parsing multiplex_profiles (top-level and nested forms).""" + + def test_multiplex_profiles_top_level(self, tmp_path, monkeypatch): + """Top-level multiplex_profiles is honored.""" + hermes_home = tmp_path / ".hermes" + hermes_home.mkdir() + (hermes_home / "config.yaml").write_text( + "multiplex_profiles: true\n", + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + + config = load_gateway_config() + + assert config.multiplex_profiles is True + + def test_multiplex_profiles_nested_under_gateway(self, tmp_path, monkeypatch): + """gateway.multiplex_profiles (the form written by `hermes config set + gateway.multiplex_profiles true`) must be honored. Regression test for + the silent-fallback bug where the loader only forwarded the top-level + key, so users who wrote it under gateway: got multiplex_profiles=False + with no warning.""" + hermes_home = tmp_path / ".hermes" + hermes_home.mkdir() + (hermes_home / "config.yaml").write_text( + "gateway:\n multiplex_profiles: true\n", + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + + config = load_gateway_config() + + assert config.multiplex_profiles is True, ( + "gateway.multiplex_profiles: true was silently ignored — " + "loader only forwarded the top-level form" + ) + + def test_multiplex_profiles_default_false(self, tmp_path, monkeypatch): + """Default is False when neither form is present.""" + hermes_home = tmp_path / ".hermes" + hermes_home.mkdir() + (hermes_home / "config.yaml").write_text("", encoding="utf-8") + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + + config = load_gateway_config() + + assert config.multiplex_profiles is False + + def test_multiplex_profiles_top_level_overrides_nested(self, tmp_path, monkeypatch): + """When both forms are present, top-level wins (matches profile_routes + and other parity bridges in load_gateway_config).""" + hermes_home = tmp_path / ".hermes" + hermes_home.mkdir() + (hermes_home / "config.yaml").write_text( + "multiplex_profiles: true\n" + "gateway:\n multiplex_profiles: false\n", + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + + config = load_gateway_config() + + assert config.multiplex_profiles is True + + def test_multiplex_profiles_explicit_top_level_false_not_consulting_nested( + self, tmp_path, monkeypatch + ): + """Lock in the `is None` vs `is False` distinction: when top-level is + explicitly false, the loader must forward False WITHOUT consulting the + nested form (so a stale `gateway.multiplex_profiles: true` cannot + silently re-enable multiplexing). Guards against a future regression + that flips the check to `not _mp`.""" + hermes_home = tmp_path / ".hermes" + hermes_home.mkdir() + (hermes_home / "config.yaml").write_text( + "multiplex_profiles: false\n" + "gateway:\n multiplex_profiles: true\n", + encoding="utf-8", + ) + monkeypatch.setenv("HERMES_HOME", str(hermes_home)) + + config = load_gateway_config() + + assert config.multiplex_profiles is False, ( + "Explicit top-level false was overridden by nested true — " + "loader must respect top-level precedence when key is present" + )