Skip to content

The agent that grows with you

test(multiplex): invariants for the residue fixes; retire allowlist tests

Tekniumfc71fb63e595
diff --git a/tests/acp_adapter/test_acp_mcp_discovery.py b/tests/acp_adapter/test_acp_mcp_discovery.py
index b9f6403beff..9f27ca5b37d 100644
--- a/tests/acp_adapter/test_acp_mcp_discovery.py
+++ b/tests/acp_adapter/test_acp_mcp_discovery.py
@@ -64,10 +64,10 @@ def _reset_mcp_startup_state():
"""Ensure each test starts with a clean discovery thread state."""
saved_started = mcp_startup._mcp_discovery_started
saved_thread = mcp_startup._mcp_discovery_thread
- mcp_startup._mcp_discovery_started = False
- mcp_startup._mcp_discovery_thread = None
+ mcp_startup._mcp_discovery_started = set()
+ mcp_startup._mcp_discovery_thread = {}
yield
- thread = mcp_startup._mcp_discovery_thread
+ thread = mcp_startup._current_home_thread()
if thread is not None and thread.is_alive():
thread.join(timeout=2.0)
mcp_startup._mcp_discovery_started = saved_started
@@ -113,10 +113,11 @@ def test_acp_background_discovery_does_not_block_startup(monkeypatch):
elapsed = time.monotonic() - start
assert elapsed < 0.2, "start_background_mcp_discovery blocked for {:.3f}s".format(elapsed)
- assert mcp_startup._mcp_discovery_thread is not None
- assert mcp_startup._mcp_discovery_thread.is_alive()
+ thread = mcp_startup._current_home_thread()
+ assert thread is not None
+ assert thread.is_alive()
block.set()
- mcp_startup._mcp_discovery_thread.join(timeout=2.0)
+ thread.join(timeout=2.0)
# ---------------------------------------------------------------------------
diff --git a/tests/cron/test_cron_multiplex_desktop_ticker_scope.py b/tests/cron/test_cron_multiplex_desktop_ticker_scope.py
index 7305f810eab..31d5dc22da8 100644
--- a/tests/cron/test_cron_multiplex_desktop_ticker_scope.py
+++ b/tests/cron/test_cron_multiplex_desktop_ticker_scope.py
@@ -115,7 +115,7 @@ def test_desktop_ticker_gates_on_profile_gateway_running(tmp_path, monkeypatch,
homes = [("default", tmp_path / "default"), ("ops", tmp_path / "ops")][:profile_count]
running = {homes[-1][1]}
monkeypatch.setattr(
- "hermes_cli.profiles.profiles_to_serve", lambda multiplex=False, profile_allowlist=None: list(homes)
+ "hermes_cli.profiles.profiles_to_serve", lambda multiplex=False: list(homes)
)
monkeypatch.setattr(
"hermes_cli.profiles._check_gateway_running", lambda home: home in running
diff --git a/tests/gateway/test_api_server_multiplex_secret_scope.py b/tests/gateway/test_api_server_multiplex_secret_scope.py
index e11923ab6d2..5b88f499609 100644
--- a/tests/gateway/test_api_server_multiplex_secret_scope.py
+++ b/tests/gateway/test_api_server_multiplex_secret_scope.py
@@ -110,7 +110,7 @@ async def test_profile_middleware_binds_auth_before_handler(
)()
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: [
+ lambda multiplex: [
("default", tmp_path), ("worker", worker_home)
],
)
diff --git a/tests/gateway/test_api_server_profile_prefix_misdelivery.py b/tests/gateway/test_api_server_profile_prefix_misdelivery.py
index f78bbd844d5..b5ed691bc19 100644
--- a/tests/gateway/test_api_server_profile_prefix_misdelivery.py
+++ b/tests/gateway/test_api_server_profile_prefix_misdelivery.py
@@ -77,13 +77,11 @@ class TestResolverWithMultiplexOff:
class TestMultiplexOnUnchanged:
def test_served_profile_resolves(self, adapter, monkeypatch):
adapter.gateway_runner = SimpleNamespace(
- config=SimpleNamespace(
- multiplex_profiles=True, multiplex_profile_allowlist=None
- )
+ config=SimpleNamespace(multiplex_profiles=True)
)
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist: [("worker", object())],
+ lambda multiplex: [("worker", object())],
)
assert adapter._resolve_request_profile(_request("worker")) == "worker"
assert adapter._resolve_request_profile(_request("ghost")) is _PROFILE_REJECTED
diff --git a/tests/gateway/test_config.py b/tests/gateway/test_config.py
index 8cdd6d62533..297eb7de152 100644
--- a/tests/gateway/test_config.py
+++ b/tests/gateway/test_config.py
@@ -321,16 +321,16 @@ class TestLoadGatewayConfig:
assert config.multiplex_profiles is True
- def test_multiplex_allowlist_from_nested_gateway_section(self, tmp_path, monkeypatch):
+ def test_stale_multiplex_allowlist_key_is_ignored(self, tmp_path, monkeypatch):
+ # The removed ``multiplex_profile_allowlist`` key may linger in an un-migrated
+ # config.yaml; it must not break loading or the multiplex flag.
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
(hermes_home / "config.yaml").write_text(
"gateway:\n"
" multiplex_profiles: true\n"
" multiplex_profile_allowlist:\n"
- " - Worker\n"
- " - worker\n"
- " - guest\n",
+ " - worker\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
@@ -338,7 +338,7 @@ class TestLoadGatewayConfig:
config = load_gateway_config()
assert config.multiplex_profiles is True
- assert config.multiplex_profile_allowlist == ["worker", "guest"]
+ assert not hasattr(config, "multiplex_profile_allowlist")
def test_discord_websocket_health_settings_seed_platform_extra(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
diff --git a/tests/gateway/test_handoff_watcher_multiprofile.py b/tests/gateway/test_handoff_watcher_multiprofile.py
index bea32bc7bce..54a1904d139 100644
--- a/tests/gateway/test_handoff_watcher_multiprofile.py
+++ b/tests/gateway/test_handoff_watcher_multiprofile.py
@@ -25,9 +25,8 @@ from gateway import run
class _FakeConfig:
- def __init__(self, multiplex, allowlist=None):
+ def __init__(self, multiplex):
self.multiplex_profiles = multiplex
- self.multiplex_profile_allowlist = allowlist
def test_scopes_single_profile_gateway_is_root_only():
diff --git a/tests/gateway/test_kanban_routed_transport.py b/tests/gateway/test_kanban_routed_transport.py
index 5768d32af8e..4742957ea96 100644
--- a/tests/gateway/test_kanban_routed_transport.py
+++ b/tests/gateway/test_kanban_routed_transport.py
@@ -116,9 +116,12 @@ def test_route_denials_leave_events_retryable_at_claim_and_send(tmp_path, monkey
runner._profile_adapters["yuki"] = {Platform.TELEGRAM: RecordingAdapter()}
assert not collect(runner)
runner._profile_adapters["yuki"] = {}
- runner.config.multiplex_profile_allowlist = ["other"]
+ # A tombstoned (deleted) owner profile is no longer served by the multiplexer.
+ from hermes_constants import clear_named_profile_deleted, mark_named_profile_deleted
+ yuki_home = tmp_path / ".hermes" / "profiles" / "yuki"
+ mark_named_profile_deleted(yuki_home)
assert not collect(runner)
- runner.config.multiplex_profile_allowlist = ["yuki"]
+ clear_named_profile_deleted(yuki_home)
rows = collect(runner)
assert [row["task"].id for row in rows] == [good]
# Reassignment after the claim must rewind, never send using stale authority.
diff --git a/tests/gateway/test_multiplex_adapter_registry.py b/tests/gateway/test_multiplex_adapter_registry.py
index 972701ddaf2..876697358f4 100644
--- a/tests/gateway/test_multiplex_adapter_registry.py
+++ b/tests/gateway/test_multiplex_adapter_registry.py
@@ -808,10 +808,7 @@ class TestSecondaryProfileConfigHandling:
from gateway.config import GatewayConfig
runner = GatewayRunner.__new__(GatewayRunner)
- runner.config = GatewayConfig(
- multiplex_profiles=True,
- multiplex_profile_allowlist=["bad", "good"],
- )
+ runner.config = GatewayConfig(multiplex_profiles=True)
runner.adapters = {}
runner._profile_adapters = {}
runner.pairing_stores = {
@@ -828,9 +825,8 @@ class TestSecondaryProfileConfigHandling:
runner._profile_adapters[profile_name] = {}
return 2
- def fake_profiles_to_serve(multiplex, profile_allowlist=None):
+ def fake_profiles_to_serve(multiplex):
assert multiplex is True
- assert profile_allowlist == ["bad", "good"]
return [
("default", Path("/tmp/default")),
("bad", Path("/tmp/bad")),
@@ -879,7 +875,7 @@ class TestSecondaryProfileConfigHandling:
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: [
+ lambda multiplex: [
("default", Path("/tmp/default")),
("unsafe", Path("/tmp/unsafe")),
],
diff --git a/tests/gateway/test_multiplex_api_server_routing.py b/tests/gateway/test_multiplex_api_server_routing.py
index f96966eba2b..d5485566441 100644
--- a/tests/gateway/test_multiplex_api_server_routing.py
+++ b/tests/gateway/test_multiplex_api_server_routing.py
@@ -16,17 +16,12 @@ from gateway.platforms.api_server import (
)
-def _make_adapter(
- multiplex: bool = True, allowlist: list[str] | None = None
-) -> APIServerAdapter:
+def _make_adapter(multiplex: bool = True) -> APIServerAdapter:
cfg = PlatformConfig(enabled=True, extra={"host": "127.0.0.1", "port": 8642, "key": "test-key"})
adapter = APIServerAdapter(cfg)
class _Runner:
- config = GatewayConfig(
- multiplex_profiles=multiplex,
- multiplex_profile_allowlist=allowlist,
- )
+ config = GatewayConfig(multiplex_profiles=multiplex)
adapter.gateway_runner = _Runner()
return adapter
@@ -43,10 +38,10 @@ class TestApiServerProfileResolution:
assert adapter._resolve_request_profile(_FakeReq(None)) is None
def test_unserved_prefix_is_rejected(self, monkeypatch):
- adapter = _make_adapter(multiplex=True, allowlist=["worker"])
+ adapter = _make_adapter(multiplex=True)
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: [
+ lambda multiplex: [
("default", "/profiles/default"),
("worker", "/profiles/worker"),
],
diff --git a/tests/gateway/test_multiplex_http_routing.py b/tests/gateway/test_multiplex_http_routing.py
index da917cd9a22..d2a80628149 100644
--- a/tests/gateway/test_multiplex_http_routing.py
+++ b/tests/gateway/test_multiplex_http_routing.py
@@ -20,22 +20,14 @@ class TestSessionSourceProfileField:
class TestWebhookProfileResolution:
"""_resolve_request_profile validates the /p/<profile>/ prefix."""
- def _adapter(
- self,
- multiplex: bool,
- served=("default", "coder"),
- allowlist=None,
- ):
+ def _adapter(self, multiplex: bool, served=("default", "coder")):
from gateway.platforms.webhook import WebhookAdapter, _PROFILE_REJECTED
class _FakeReq:
def __init__(self, profile):
self.match_info = {"profile": profile} if profile is not None else {}
- cfg = GatewayConfig(
- multiplex_profiles=multiplex,
- multiplex_profile_allowlist=allowlist,
- )
+ cfg = GatewayConfig(multiplex_profiles=multiplex)
class _Runner:
config = cfg
@@ -51,15 +43,11 @@ class TestWebhookProfileResolution:
def test_unserved_prefix_is_rejected(self, monkeypatch):
adapter, Req, rejected, served = self._adapter(
- multiplex=True,
- served=("default", "worker"),
- allowlist=["worker"],
+ multiplex=True, served=("default", "worker"),
)
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: [
- (name, f"/profiles/{name}") for name in served
- ],
+ lambda multiplex: [(name, f"/profiles/{name}") for name in served],
)
assert adapter._resolve_request_profile(Req("worker")) == "worker"
diff --git a/tests/gateway/test_multiplex_lifecycle.py b/tests/gateway/test_multiplex_lifecycle.py
index 94aebccc8db..d710f71d41a 100644
--- a/tests/gateway/test_multiplex_lifecycle.py
+++ b/tests/gateway/test_multiplex_lifecycle.py
@@ -21,32 +21,27 @@ class TestServedProfilesStatus:
importlib.reload(status)
-def test_cron_profile_homes_follow_allowlist(tmp_path, monkeypatch):
- """The helper wired into in-process cron returns only selected profiles."""
+def test_cron_profile_homes_serve_every_live_profile(tmp_path, monkeypatch):
+ """The helper wired into in-process cron returns default + every live named profile;
+ a tombstoned profile dir is skipped."""
monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
default_home = tmp_path / ".hermes"
monkeypatch.setenv("HERMES_HOME", str(default_home))
- for name in ("worker", "guest"):
+ for name in ("worker", "guest", "gone"):
(default_home / "profiles" / name).mkdir(parents=True)
+ from hermes_constants import mark_named_profile_deleted
+ mark_named_profile_deleted(default_home / "profiles" / "gone")
import gateway.run as gateway_run
- homes = gateway_run._multiplex_profile_homes(
- GatewayConfig(
- multiplex_profiles=True,
- multiplex_profile_allowlist=["worker"],
- )
- )
+ homes = gateway_run._multiplex_profile_homes(GatewayConfig(multiplex_profiles=True))
- assert [name for name, _home in homes] == ["default", "worker"]
+ assert [name for name, _home in homes] == ["default", "guest", "worker"]
def test_cron_tick_homes_include_active_named_host(tmp_path, monkeypatch):
- """Named-profile gateway + allowlist must still tick the host store.
-
- Adapter homes stay allowlist-only so the host is not started a second
- time as a secondary (same bot token). Cron unions the active profile.
- """
+ """A named-profile host running the multiplexer ticks its own store exactly once:
+ it is part of the served set, and cron must not union it a second time."""
monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
default_home = tmp_path / ".hermes"
for name in ("host", "worker"):
@@ -55,17 +50,14 @@ def test_cron_tick_homes_include_active_named_host(tmp_path, monkeypatch):
import gateway.run as gateway_run
- cfg = GatewayConfig(
- multiplex_profiles=True,
- multiplex_profile_allowlist=["worker"],
- )
+ cfg = GatewayConfig(multiplex_profiles=True)
adapter_names = [name for name, _home in gateway_run._multiplex_profile_homes(cfg)]
cron_homes = gateway_run._cron_tick_profile_homes(cfg)
cron_names = [name for name, _home in cron_homes]
cron_by_name = dict(cron_homes)
- assert adapter_names == ["default", "worker"]
- assert cron_names == ["default", "worker", "host"]
+ assert adapter_names == ["default", "host", "worker"]
+ assert cron_names == ["default", "host", "worker"]
assert cron_by_name["host"] == default_home / "profiles" / "host"
@@ -115,34 +107,29 @@ class TestNamedProfileMultiplexerGuard:
gw._guard_named_profile_under_multiplexer(force=False)
assert excinfo.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE
- def test_served_profile_is_still_guarded(self, monkeypatch, tmp_path):
+ def test_recorded_served_profiles_win_over_config(self, monkeypatch, tmp_path):
+ """The live gateway's own ``served_profiles`` record is authoritative: a named profile
+ it does not list may run standalone even though the default config multiplexes."""
self._fake_running_default_gateway(monkeypatch, tmp_path)
(tmp_path / "config.yaml").write_text(
- "gateway:\n"
- " multiplex_profiles: true\n"
- " multiplex_profile_allowlist:\n"
- " - Coder\n",
+ "gateway:\n multiplex_profiles: true\n",
encoding="utf-8",
)
+ import gateway.status as status
+ monkeypatch.setattr(
+ status, "read_runtime_status",
+ lambda path=None: {"gateway_state": "running", "served_profiles": ["default", "worker"]},
+ )
from hermes_cli import gateway as gw
- with pytest.raises(SystemExit) as excinfo:
- gw._guard_named_profile_under_multiplexer(force=False)
- assert excinfo.value.code == GATEWAY_FATAL_CONFIG_EXIT_CODE
+ gw._guard_named_profile_under_multiplexer(force=False)
+ assert gw.named_profile_served_by_running_multiplexer("worker") is True
- @pytest.mark.parametrize(
- "allowlist_yaml",
- ["[]", "[worker]", "coder"],
- )
- def test_unserved_profile_may_run_standalone(
- self, monkeypatch, tmp_path, allowlist_yaml
- ):
+ def test_non_multiplexing_default_gateway_lets_named_profile_run(self, monkeypatch, tmp_path):
self._fake_running_default_gateway(monkeypatch, tmp_path)
(tmp_path / "config.yaml").write_text(
- "gateway:\n"
- " multiplex_profiles: true\n"
- f" multiplex_profile_allowlist: {allowlist_yaml}\n",
+ "gateway:\n multiplex_profiles: false\n",
encoding="utf-8",
)
diff --git a/tests/gateway/test_multiplex_mcp_discovery.py b/tests/gateway/test_multiplex_mcp_discovery.py
index 95be0c1c9d6..e80f227e6f2 100644
--- a/tests/gateway/test_multiplex_mcp_discovery.py
+++ b/tests/gateway/test_multiplex_mcp_discovery.py
@@ -33,7 +33,7 @@ async def test_gateway_boot_discovers_mcp_under_every_profile_home(
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: homes,
+ lambda multiplex: homes,
)
monkeypatch.setattr(_mcp_discovery, "discover_mcp_tools", fake_discover)
diff --git a/tests/gateway/test_multiplex_phase0.py b/tests/gateway/test_multiplex_phase0.py
index 69f324519b5..f228961e8c6 100644
--- a/tests/gateway/test_multiplex_phase0.py
+++ b/tests/gateway/test_multiplex_phase0.py
@@ -105,39 +105,6 @@ class TestMultiplexConfigFlag:
cfg = GatewayConfig.from_dict({"multiplex_profiles": True})
assert cfg.multiplex_profiles is True
- def test_profile_allowlist_defaults_to_serve_all(self):
- assert GatewayConfig().multiplex_profile_allowlist is None
-
- def test_profile_allowlist_normalizes_and_round_trips(self):
- cfg = GatewayConfig.from_dict(
- {
- "gateway": {
- "multiplex_profiles": True,
- "multiplex_profile_allowlist": [
- " Worker ",
- "worker",
- "Guest",
- "default",
- "bad/name",
- 7,
- ],
- }
- }
- )
-
- assert cfg.multiplex_profile_allowlist == ["worker", "guest"]
- restored = GatewayConfig.from_dict(cfg.to_dict())
- assert restored.multiplex_profile_allowlist == ["worker", "guest"]
-
- def test_invalid_profile_allowlist_fails_safe_to_default_only(self, caplog):
- with caplog.at_level("WARNING", logger="gateway.config"):
- cfg = GatewayConfig.from_dict(
- {"gateway": {"multiplex_profile_allowlist": "worker"}}
- )
-
- assert cfg.multiplex_profile_allowlist == []
- assert "serving only the default profile" in caplog.text
-
class TestSessionStoreProfileResolution:
"""SessionStore._generate_session_key honors the flag: legacy namespace
diff --git a/tests/gateway/test_multiplex_residue_parity.py b/tests/gateway/test_multiplex_residue_parity.py
new file mode 100644
index 00000000000..c2b5672030f
--- /dev/null
+++ b/tests/gateway/test_multiplex_residue_parity.py
@@ -0,0 +1,118 @@
+"""Multiplex parity: a served profile reads ITS ``sessions.*`` / proxy env, never the launch
+profile's; a stale served route never re-scaffolds an archived profile; MCP discovery runs once
+per served profile home."""
+
+import logging
+import threading
+
+import pytest
+
+from agent import secret_scope as ss
+from hermes_constants import reset_hermes_home_override, set_hermes_home_override
+
+
+def two_homes(tmp_path, monkeypatch):
+ root = tmp_path / ".hermes"
+ alpha = root / "profiles" / "alpha"
+ for home in (root, alpha):
+ (home / "sessions").mkdir(parents=True)
+ (home / ".env").write_text("", encoding="utf-8")
+ (root / "config.yaml").write_text(
+ "sessions:\n cjk_fts: true\n search_slow_ms: 1000\n", encoding="utf-8")
+ (alpha / "config.yaml").write_text(
+ "sessions:\n cjk_fts: false\n search_slow_ms: 50\n", encoding="utf-8")
+ monkeypatch.setattr("pathlib.Path.home", lambda: tmp_path)
+ monkeypatch.setenv("HERMES_HOME", str(root))
+ ss.set_multiplex_active(False)
+ yield root, alpha
+ ss.set_multiplex_active(False)
+
+
+def test_served_profile_reads_its_own_sessions_settings(two_homes, monkeypatch):
+ root, alpha = two_homes
+ from hermes_state_fts import _cjk_fts_config_enabled
+ from hermes_state_search import _search_slow_ms
+ # The multiplexer bridged the LAUNCH (default) profile's sessions.* into env at import.
+ monkeypatch.setenv("HERMES_CJK_FTS", "true")
+ monkeypatch.setenv("HERMES_SEARCH_SLOW_MS", "1000")
+ assert _cjk_fts_config_enabled() is True and _search_slow_ms() == 1000.0 # unscoped = env bridge
+ token = set_hermes_home_override(str(alpha))
+ try:
+ assert _cjk_fts_config_enabled() is False
+ assert _search_slow_ms() == 50.0
+ finally:
+ reset_hermes_home_override(token)
+
+
+def test_per_turn_sessions_bridge_skips_secondary_scope(two_homes, monkeypatch):
+ root, alpha = two_homes
+ from gateway import run as gw_run
+ monkeypatch.delenv("HERMES_CJK_FTS", raising=False)
+ ss.set_multiplex_active(True)
+ with gw_run._profile_runtime_scope(alpha):
+ gw_run._bridge_max_turns_from_config(alpha)
+ assert "HERMES_CJK_FTS" not in __import__("os").environ, "secondary scope must not write the process env"
+
+
+def test_resolve_proxy_url_reads_routed_profile_scope(two_homes, monkeypatch):
+ root, alpha = two_homes
+ from gateway.platforms.base import resolve_proxy_url
+ monkeypatch.setenv("TELEGRAM_PROXY", "socks5://default-proxy:1080") # launch profile's .env
+ ss.set_multiplex_active(True)
+ token = ss.set_secret_scope({"TELEGRAM_PROXY": "socks5://alpha-proxy:1080"})
+ try:
+ assert resolve_proxy_url("TELEGRAM_PROXY") == "socks5://alpha-proxy:1080"
+ finally:
+ ss.reset_secret_scope(token)
+ token = ss.set_secret_scope({}) # a served profile with NO proxy must not borrow the default's
+ try:
+ monkeypatch.delenv("HTTPS_PROXY", raising=False)
+ assert resolve_proxy_url("TELEGRAM_PROXY") is None
+ finally:
+ ss.reset_secret_scope(token)
+ ss.set_multiplex_active(False)
+ assert resolve_proxy_url("TELEGRAM_PROXY") == "socks5://default-proxy:1080" # standalone: env
+
+
+def test_stale_served_turn_never_recreates_archived_profile(two_homes):
+ """#94590: a multiplexer still holding an archived profile's route must not re-scaffold it."""
+ import shutil
+ root, alpha = two_homes
+ from gateway import run as gw_run
+ shutil.rmtree(alpha)
+ ss.set_multiplex_active(True)
+ with gw_run._profile_runtime_scope(alpha):
+ from hermes_state import SessionDB
+ with pytest.raises(FileNotFoundError):
+ SessionDB()
+ assert not alpha.exists()
+
+
+def test_mcp_discovery_slot_is_per_profile_home(two_homes, monkeypatch):
+ """#67605: alpha building an agent after default must still get ITS discovery run."""
+ root, alpha = two_homes
+ import hermes_cli.mcp_startup as ms
+ from hermes_constants import get_hermes_home
+ for home in (root, alpha):
+ (home / "config.yaml").write_text("mcp_servers:\n demo:\n command: /bin/true\n", encoding="utf-8")
+ monkeypatch.setattr(ms, "_mcp_discovery_started", set())
+ monkeypatch.setattr(ms, "_mcp_discovery_thread", {})
+ seen, done = [], threading.Event()
+
+ def fake_discover(**_kw):
+ seen.append(get_hermes_home().name)
+ done.set()
+
+ monkeypatch.setattr("tools.mcp_tool_discovery.discover_mcp_tools", fake_discover)
+ monkeypatch.setattr("tools.mcp_tool_discovery.get_mcp_status", lambda *a, **k: [{"connected": True}])
+ for home in (root, alpha):
+ token = set_hermes_home_override(str(home))
+ try:
+ done.clear()
+ ms.start_background_mcp_discovery(logger=logging.getLogger("t"), thread_name=f"mcp-{home.name}")
+ assert done.wait(5)
+ ms.wait_for_mcp_discovery(timeout=5)
+ finally:
+ reset_hermes_home_override(token)
+ assert seen == [root.name, "alpha"]
diff --git a/tests/gateway/test_profile_resolution.py b/tests/gateway/test_profile_resolution.py
index 051a0a907e0..16c95315cb4 100644
--- a/tests/gateway/test_profile_resolution.py
+++ b/tests/gateway/test_profile_resolution.py
@@ -175,8 +175,7 @@ class TestNonDiscordProfileRouting:
):
assert mock_runner._profile_name_for_source(telegram_source) == "tg-profile"
- def test_route_inside_allowlist_resolves(self, mock_runner, telegram_source):
- mock_runner.config.multiplex_profile_allowlist = ["worker"]
+ def test_route_to_served_profile_resolves(self, mock_runner, telegram_source):
mock_runner.config.profile_routes = [
ProfileRoute(
name="worker-route",
@@ -194,12 +193,9 @@ class TestNonDiscordProfileRouting:
) as enumerate_profiles:
assert mock_runner._profile_name_for_source(telegram_source) == "worker"
- enumerate_profiles.assert_called_once_with(
- multiplex=True, profile_allowlist=["worker"]
- )
+ enumerate_profiles.assert_called_once_with(multiplex=True)
- def test_route_outside_allowlist_rejects(self, mock_runner, telegram_source, caplog):
- mock_runner.config.multiplex_profile_allowlist = ["worker"]
+ def test_route_to_unserved_profile_rejects(self, mock_runner, telegram_source, caplog):
mock_runner.config.profile_routes = [
ProfileRoute(
name="restricted-route",
@@ -221,7 +217,6 @@ class TestNonDiscordProfileRouting:
assert "target profile 'restricted' is not served" in caplog.text
def test_no_route_match_preserves_default_sentinel(self, mock_runner, telegram_source):
- mock_runner.config.multiplex_profile_allowlist = ["worker"]
mock_runner.config.profile_routes = [
ProfileRoute(
name="other-chat",
@@ -376,7 +371,6 @@ class TestAdapterToSessionKeyIntegration:
@pytest.mark.asyncio
async def test_adapter_drops_rejected_route_before_dispatch(self, mock_runner):
- mock_runner.config.multiplex_profile_allowlist = []
mock_runner.config.profile_routes = [
ProfileRoute(
name="restricted-route",
@@ -407,7 +401,6 @@ class TestAdapterToSessionKeyIntegration:
@pytest.mark.asyncio
async def test_direct_source_is_rejected_at_shared_ingress(self, mock_runner):
mock_runner.config.multiplex_profiles = True
- mock_runner.config.multiplex_profile_allowlist = []
mock_runner.config.profile_routes = [
ProfileRoute(
name="restricted-route",
diff --git a/tests/gateway/test_webhook_adapter.py b/tests/gateway/test_webhook_adapter.py
index 95d5398ad9e..22cd20a7b67 100644
--- a/tests/gateway/test_webhook_adapter.py
+++ b/tests/gateway/test_webhook_adapter.py
@@ -974,7 +974,7 @@ class TestMultiplexProfileWebhookAuthentication:
adapter.gateway_runner = runner
monkeypatch.setattr(
"hermes_cli.profiles.profiles_to_serve",
- lambda multiplex, profile_allowlist=None: [
+ lambda multiplex: [
("default", tmp_path),
("worker", tmp_path / "profiles" / "worker"),
("other", tmp_path / "profiles" / "other"),
diff --git a/tests/hermes_cli/test_config.py b/tests/hermes_cli/test_config.py
index da6c6ac8c37..1dce2353341 100644
--- a/tests/hermes_cli/test_config.py
+++ b/tests/hermes_cli/test_config.py
@@ -1006,6 +1006,25 @@ class TestConfigSupportFloor:
assert (tmp_path / ".env").read_text(encoding="utf-8") == expected_env
+class TestRetiredMultiplexAllowlist:
+ def test_v43_drops_multiplex_profile_allowlist_from_user_config(self, tmp_path, monkeypatch):
+ """The multiplexer serves every profile; a stale allowlist must not linger in config.yaml."""
+ from hermes_cli.config import DEFAULT_CONFIG
+ from hermes_cli.config_migrations import run_migrations
+
+ config_path = tmp_path / "config.yaml"
+ config_path.write_text(yaml.safe_dump({
+ "_config_version": 42,
+ "gateway": {"multiplex_profiles": True, "multiplex_profile_allowlist": ["worker"]},
+ }), encoding="utf-8")
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+ run_migrations(42, {"env_added": [], "config_added": [], "warnings": []}, quiet=True)
+ raw = yaml.safe_load(config_path.read_text(encoding="utf-8"))
+ assert "multiplex_profile_allowlist" not in raw["gateway"]
+ assert raw["gateway"]["multiplex_profiles"] is True
+ assert "multiplex_profile_allowlist" not in DEFAULT_CONFIG["gateway"]
+
+
class TestCustomProviderCompatibility:
"""Custom provider compatibility across legacy and v12+ config schemas.
diff --git a/tests/hermes_cli/test_desktop_cron_ticker_profiles.py b/tests/hermes_cli/test_desktop_cron_ticker_profiles.py
index 941d6872fc6..d112f28d3ca 100644
--- a/tests/hermes_cli/test_desktop_cron_ticker_profiles.py
+++ b/tests/hermes_cli/test_desktop_cron_ticker_profiles.py
@@ -132,28 +132,33 @@ def test_external_provider_never_gets_profile_homes(monkeypatch, tmp_path):
assert external.start_kwargs == {"interval": 13}
-def test_desktop_ticker_honours_allowlist_and_yields_to_default_multiplexer(monkeypatch, _providers, tmp_path):
- """The Desktop ticker mirrors the multiplexer's served set (allowlist) and stands down for a
- satellite the live default multiplexer already ticks — that profile has no gateway.pid of its
- own, so the per-home liveness check alone lets both tickers race for its fires (#107485)."""
+def test_desktop_ticker_serves_every_profile_and_yields_to_owning_gateway(monkeypatch, _providers, tmp_path):
+ """The Desktop ticker mirrors the multiplexer's served set (default + every live profile dir)
+ and stands down, per tick, for a profile already owned by a gateway: its own running gateway,
+ or the live default multiplexer that already ticks it — such a satellite has no gateway.pid
+ of its own, so the per-home liveness check alone lets both tickers race for its fires
+ (#107485, #108428)."""
import hermes_cli.profiles as profiles_mod
import yaml
_sp, builtin = _providers
root = tmp_path / ".hermes"
- for name in ("worker", "guest"):
+ for name in ("worker", "guest", "solo"):
(root / "profiles" / name).mkdir(parents=True)
- (root / "config.yaml").write_text(yaml.safe_dump(
- {"gateway": {"multiplex_profiles": True, "multiplex_profile_allowlist": ["worker"]}}))
+ (root / "config.yaml").write_text(yaml.safe_dump({"gateway": {"multiplex_profiles": True}}))
monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)
monkeypatch.setattr(profiles_mod, "_get_default_hermes_home", lambda: root)
monkeypatch.setattr(profiles_mod, "_get_profiles_root", lambda: root / "profiles")
- monkeypatch.setattr(profiles_mod, "_check_gateway_running", lambda home: False)
+ monkeypatch.setattr(
+ profiles_mod, "_check_gateway_running", lambda home: home == root / "profiles" / "solo")
monkeypatch.setattr(profiles_mod, "_served_by_running_multiplexer", lambda name: name == "worker")
ws._start_desktop_cron_ticker(threading.Event(), interval=0)
- assert [name for name, _ in builtin.start_kwargs["profile_homes"]] == ["default", "worker"]
+ assert [name for name, _ in builtin.start_kwargs["profile_homes"]] == [
+ "default", "guest", "solo", "worker"]
gate = builtin.start_kwargs["profile_gate"]
assert gate("default", root) is True
+ assert gate("guest", root / "profiles" / "guest") is True
assert gate("worker", root / "profiles" / "worker") is False
+ assert gate("solo", root / "profiles" / "solo") is False
diff --git a/tests/hermes_cli/test_mcp_discovery_timing.py b/tests/hermes_cli/test_mcp_discovery_timing.py
index cfe0ad6cd7a..fe2671e0986 100644
--- a/tests/hermes_cli/test_mcp_discovery_timing.py
+++ b/tests/hermes_cli/test_mcp_discovery_timing.py
@@ -24,6 +24,7 @@ import types
import pytest
from hermes_cli import mcp_startup
+from hermes_constants import hermes_home_key
@pytest.fixture(autouse=True)
@@ -31,11 +32,11 @@ def _reset_mcp_startup_state():
saved_started = mcp_startup._mcp_discovery_started
saved_thread = mcp_startup._mcp_discovery_thread
try:
- mcp_startup._mcp_discovery_started = False
- mcp_startup._mcp_discovery_thread = None
+ mcp_startup._mcp_discovery_started = set()
+ mcp_startup._mcp_discovery_thread = {}
yield
finally:
- thread = mcp_startup._mcp_discovery_thread
+ thread = mcp_startup._current_home_thread()
if thread is not None and thread.is_alive():
thread.join(timeout=1.0)
mcp_startup._mcp_discovery_started = saved_started
@@ -135,7 +136,7 @@ def test_ensure_helper_starts_discovery_and_waits(monkeypatch):
)
# Discovery was started (thread created)
- assert mcp_startup._mcp_discovery_thread is not None or waited
+ assert mcp_startup._current_home_thread() is not None or waited
# Wait was called with single_query=True
assert any(call[1] is True for call in waited)
@@ -146,12 +147,12 @@ def test_ensure_helper_is_idempotent(monkeypatch):
logger = types.SimpleNamespace(debug=lambda *_a, **_k: None, warning=lambda *_a, **_k: None)
mcp_startup.ensure_mcp_discovery_before_agent_build(logger=logger)
- thread1 = mcp_startup._mcp_discovery_thread
+ thread1 = mcp_startup._current_home_thread()
if thread1:
thread1.join(timeout=2.0)
mcp_startup.ensure_mcp_discovery_before_agent_build(logger=logger)
- thread2 = mcp_startup._mcp_discovery_thread
+ thread2 = mcp_startup._current_home_thread()
if thread2:
thread2.join(timeout=2.0)
@@ -289,7 +290,7 @@ def test_wait_stays_bounded_when_discovery_is_slow(monkeypatch):
stop = threading.Event()
thread = threading.Thread(target=lambda: stop.wait(10), daemon=True)
thread.start()
- mcp_startup._mcp_discovery_thread = thread
+ mcp_startup._mcp_discovery_thread[hermes_home_key()] = thread
try:
start = time.monotonic()
@@ -306,7 +307,7 @@ def test_wait_stays_bounded_when_discovery_is_slow(monkeypatch):
def test_wait_returns_instantly_when_discovery_done():
"""When discovery is already complete, the wait returns immediately."""
- mcp_startup._mcp_discovery_thread = None
+ mcp_startup._mcp_discovery_thread.clear()
t0 = time.time()
mcp_startup.wait_for_mcp_discovery(single_query=True)
assert time.time() - t0 < 0.2
diff --git a/tests/hermes_cli/test_mcp_startup.py b/tests/hermes_cli/test_mcp_startup.py
index f6b751c3d5c..ebfe99701fe 100644
--- a/tests/hermes_cli/test_mcp_startup.py
+++ b/tests/hermes_cli/test_mcp_startup.py
@@ -21,11 +21,11 @@ def _reset_mcp_startup_state():
saved_started = mcp_startup._mcp_discovery_started
saved_thread = mcp_startup._mcp_discovery_thread
try:
- mcp_startup._mcp_discovery_started = False
- mcp_startup._mcp_discovery_thread = None
+ mcp_startup._mcp_discovery_started = set()
+ mcp_startup._mcp_discovery_thread = {}
yield
finally:
- thread = mcp_startup._mcp_discovery_thread
+ thread = mcp_startup._current_home_thread()
if thread is not None and thread.is_alive():
thread.join(timeout=1.0)
mcp_startup._mcp_discovery_started = saved_started
@@ -96,8 +96,9 @@ def test_prepare_agent_startup_backgrounds_blocking_mcp_for_chat(monkeypatch):
while calls["mcp"] == 0 and time.monotonic() < deadline:
time.sleep(0.01)
assert calls["mcp"] == 1
- assert mcp_startup._mcp_discovery_thread is not None
- assert mcp_startup._mcp_discovery_thread.is_alive()
+ thread = mcp_startup._current_home_thread()
+ assert thread is not None
+ assert thread.is_alive()
finally:
stop.set()
@@ -149,7 +150,7 @@ def test_prepare_agent_startup_skips_discovery_when_chat_resolves_to_tui(
assert calls["background"] == 0
assert calls["inline"] == 0
- assert mcp_startup._mcp_discovery_thread is None
+ assert mcp_startup._current_home_thread() is None
def test_prepare_agent_startup_keeps_discovery_for_non_chat_commands(
@@ -229,8 +230,9 @@ def test_background_mcp_discovery_suppresses_interactive_oauth(monkeypatch):
logger=types.SimpleNamespace(debug=lambda *_a, **_k: None),
thread_name="test-mcp-discovery",
)
- assert mcp_startup._mcp_discovery_thread is not None
- mcp_startup._mcp_discovery_thread.join(timeout=1.0)
+ thread = mcp_startup._current_home_thread()
+ assert thread is not None
+ thread.join(timeout=1.0)
assert state["during_discover"] is True
assert state["active"] is False
@@ -268,8 +270,9 @@ def test_background_mcp_discovery_propagates_profile_secret_scope(monkeypatch):
logger=types.SimpleNamespace(debug=lambda *_a, **_k: None),
thread_name="test-mcp-discovery",
)
- assert mcp_startup._mcp_discovery_thread is not None
- mcp_startup._mcp_discovery_thread.join(timeout=1.0)
+ thread = mcp_startup._current_home_thread()
+ assert thread is not None
+ thread.join(timeout=1.0)
finally:
reset_secret_scope(token)
diff --git a/tests/hermes_cli/test_profiles.py b/tests/hermes_cli/test_profiles.py
index 93437a08dca..b7c7bf61a4f 100644
--- a/tests/hermes_cli/test_profiles.py
+++ b/tests/hermes_cli/test_profiles.py
@@ -1115,32 +1115,6 @@ class TestProfilesToServe:
assert serve["default"] == _get_default_hermes_home()
assert serve["coder"] == get_profile_dir("coder")
- def test_empty_allowlist_serves_only_default(self, profile_env):
- create_profile("worker", no_alias=True)
-
- serve = dict(profiles_to_serve(multiplex=True, profile_allowlist=[]))
-
- assert serve == {"default": _get_default_hermes_home()}
-
- def test_allowlist_normalizes_deduplicates_and_keeps_default(self, profile_env):
- create_profile("worker", no_alias=True)
- create_profile("guest", no_alias=True)
-
- serve = dict(
- profiles_to_serve(
- multiplex=True,
- profile_allowlist=[" Worker ", "worker", "default", "missing"],
- )
- )
-
- assert set(serve) == {"default", "worker"}
- assert serve["worker"] == get_profile_dir("worker")
-
-
-
- assert set(serve) == {"default", "worker"}
- assert serve["worker"] == get_profile_dir("worker")
-
# ---------------------------------------------------------------------------
# resolve_profile_env spelling preservation (#82581 junction follow-up)
diff --git a/tests/hermes_cli/test_serve_mcp_discovery_after_bind.py b/tests/hermes_cli/test_serve_mcp_discovery_after_bind.py
index d53d6925799..e2fb041971c 100644
--- a/tests/hermes_cli/test_serve_mcp_discovery_after_bind.py
+++ b/tests/hermes_cli/test_serve_mcp_discovery_after_bind.py
@@ -17,8 +17,8 @@ from tests.hermes_cli.test_dashboard_auth_gate import _stub_uvicorn_run
def _reset_discovery_state(monkeypatch):
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_started", False)
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_started", set())
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
monkeypatch.setattr(mcp_startup, "_mcp_discovery_deferred", None)
diff --git a/tests/test_tui_entry_mcp_owner.py b/tests/test_tui_entry_mcp_owner.py
index 78d2c9bcd43..c1d19d743d8 100644
--- a/tests/test_tui_entry_mcp_owner.py
+++ b/tests/test_tui_entry_mcp_owner.py
@@ -11,6 +11,7 @@ import threading
import time
from hermes_cli import mcp_startup
+from hermes_constants import hermes_home_key
from tui_gateway import entry
@@ -31,7 +32,7 @@ def test_wait_falls_through_to_shared_owner(monkeypatch):
)
thread = threading.Thread(target=lambda: time.sleep(0.05), daemon=True)
thread.start()
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", thread)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {hermes_home_key(): thread})
start = time.monotonic()
entry.wait_for_mcp_discovery(timeout=2.0)
@@ -43,7 +44,7 @@ def test_wait_falls_through_to_shared_owner(monkeypatch):
def test_wait_noop_when_no_owner_has_a_thread(monkeypatch):
monkeypatch.setattr(entry, "_mcp_discovery_thread", None)
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
start = time.monotonic()
entry.wait_for_mcp_discovery(timeout=2.0)
@@ -78,7 +79,7 @@ def test_wait_reinvokes_shared_spawn_when_discovery_enabled(monkeypatch):
calls.append(thread_name)
monkeypatch.setattr(mcp_startup, "start_background_mcp_discovery", _fake_start)
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
entry.wait_for_mcp_discovery(timeout=0.1)
@@ -96,7 +97,7 @@ def test_wait_skips_spawn_when_discovery_not_enabled(monkeypatch):
calls.append(thread_name)
monkeypatch.setattr(mcp_startup, "start_background_mcp_discovery", _fake_start)
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
entry.wait_for_mcp_discovery(timeout=0.1)
diff --git a/tests/test_tui_gateway_server.py b/tests/test_tui_gateway_server.py
index 443f3e5ce8a..0f08d29b50f 100644
--- a/tests/test_tui_gateway_server.py
+++ b/tests/test_tui_gateway_server.py
@@ -841,8 +841,8 @@ def test_profile_scoped_mcp_discovery_uses_target_home(monkeypatch, tmp_path):
seen = []
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_started", False)
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_started", set())
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
# ensure_mcp_discovery_started flips this module global; monkeypatch it so
# the enablement doesn't leak into sibling tests in this file.
monkeypatch.setattr(entry, "_mcp_discovery_enabled", False)
@@ -854,13 +854,11 @@ def test_profile_scoped_mcp_discovery_uses_target_home(monkeypatch, tmp_path):
try:
entry.ensure_mcp_discovery_started()
- thread = mcp_startup._mcp_discovery_thread
+ thread = mcp_startup._current_home_thread()
assert thread is not None
thread.join(timeout=2)
finally:
reset_hermes_home_override(token)
- mcp_startup._mcp_discovery_thread = None
- mcp_startup._mcp_discovery_started = False
assert seen == [str(profile_home)]
diff --git a/tests/tools/test_refresh_agent_mcp_tools.py b/tests/tools/test_refresh_agent_mcp_tools.py
index 1643c8571d3..37a2d1ba843 100644
--- a/tests/tools/test_refresh_agent_mcp_tools.py
+++ b/tests/tools/test_refresh_agent_mcp_tools.py
@@ -221,7 +221,7 @@ def test_wait_returns_instantly_when_no_discovery_thread(monkeypatch):
import time
from hermes_cli import mcp_startup
- monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", None)
+ monkeypatch.setattr(mcp_startup, "_mcp_discovery_thread", {})
import hermes_cli.config as cfg
monkeypatch.setattr(cfg, "load_config", lambda: {"mcp_discovery_timeout": 999.0})
diff --git a/tests/tui_gateway/test_mcp_late_refresh_thread_owner.py b/tests/tui_gateway/test_mcp_late_refresh_thread_owner.py
index bf47e52fdca..79aac06d103 100644
--- a/tests/tui_gateway/test_mcp_late_refresh_thread_owner.py
+++ b/tests/tui_gateway/test_mcp_late_refresh_thread_owner.py
@@ -25,6 +25,7 @@ import threading
import pytest
import hermes_cli.mcp_startup as startup
+from hermes_constants import hermes_home_key
import tui_gateway.entry as entry
@@ -34,7 +35,7 @@ def clean_discovery_globals():
saved_entry = entry._mcp_discovery_thread
saved_startup = startup._mcp_discovery_thread
entry._mcp_discovery_thread = None
- startup._mcp_discovery_thread = None
+ startup._mcp_discovery_thread = {}
try:
yield
finally:
@@ -55,14 +56,14 @@ def test_entry_in_flight_sees_startup_thread(clean_discovery_globals):
scheduler does not bail (the #51587 bug).
"""
stop = threading.Event()
- startup._mcp_discovery_thread = _alive_thread(stop)
+ startup._mcp_discovery_thread[hermes_home_key()] = _alive_thread(stop)
try:
# Entry's own thread is None, but the startup thread is alive.
assert entry._mcp_discovery_thread is None
assert entry.mcp_discovery_in_flight() is True
finally:
stop.set()
- startup._mcp_discovery_thread.join(timeout=2.0)
+ startup._current_home_thread().join(timeout=2.0)
# After the thread exits, neither owner is in flight.
assert entry.mcp_discovery_in_flight() is False
@@ -81,7 +82,7 @@ def test_startup_module_exposes_in_flight_helpers(clean_discovery_globals):
stop = threading.Event()
t = _alive_thread(stop)
- startup._mcp_discovery_thread = t
+ startup._mcp_discovery_thread[hermes_home_key()] = t
try:
assert startup.mcp_discovery_in_flight() is True
assert startup.join_mcp_discovery(timeout=0.1) is False