Skip to content

The agent that grows with you

test(gateway): keep only the MSG-44 tests that prove a fix

unsupportedpastels91a4b14f6379
diff --git a/tests/cron/test_cron_multiplex_shared_route_delivery.py b/tests/cron/test_cron_multiplex_shared_route_delivery.py
index a4326c32174..53c446af107 100644
--- a/tests/cron/test_cron_multiplex_shared_route_delivery.py
+++ b/tests/cron/test_cron_multiplex_shared_route_delivery.py
@@ -217,73 +217,3 @@ def test_multiplex_tick_routes_desktop_served_satellite_with_only_local_adapter(
# The routed view releases the primary adapter for exactly the route-mapped target.
assert shared.get(Platform.DISCORD, {"chat_id": "C1"}) is primary
assert shared.get(Platform.DISCORD, {"chat_id": "unmapped"}) is None
-
-
-def test_multiplex_tick_keeps_reconnecting_satellite_off_the_primary_bot(tmp_path, monkeypatch):
- """A satellite whose OWN bot dropped stays in ``_profile_bot_platforms`` while only its
- Desktop LOCAL adapter remains. Its cron tick must deliver via its own map (and fail until the
- bot reconnects), never borrow the primary bot."""
- import threading
-
- from cron.scheduler_provider import InProcessCronScheduler
-
- root = tmp_path / "root"
- sat_home = root / "profiles" / "sat"
- (sat_home / "cron").mkdir(parents=True)
- (root / "config.yaml").write_text(yaml.safe_dump({
- "gateway": {"multiplex_profiles": True, "profile_routes": [
- {"platform": "discord", "guild_id": "G1", "chat_id": "C1", "profile": "sat"}]},
- }), encoding="utf-8")
- monkeypatch.setattr("hermes_constants.get_default_hermes_root", lambda: root)
-
- own = {Platform.LOCAL: object()}
- captured = {}
- stop = threading.Event()
-
- def _tick_and_stop(*_args, **kwargs):
- captured["adapters"] = kwargs["adapters"]
- stop.set()
-
- provider = InProcessCronScheduler()
- with patch("cron.scheduler.tick", side_effect=_tick_and_stop):
- thread = threading.Thread(
- target=provider.start,
- args=(stop,),
- kwargs={
- "interval": 0,
- "profile_homes": [("sat", sat_home)],
- "adapters": {Platform.DISCORD: _primary_adapter()},
- "profile_adapters": {"sat": own},
- "profile_bot_platforms": {"sat": {Platform.DISCORD}},
- "default_profile": "default",
- },
- daemon=True,
- )
- thread.start()
- thread.join(timeout=10)
- stop.set()
- thread.join(timeout=10)
-
- assert not thread.is_alive()
- assert captured["adapters"] is own
-
-
-def test_adapters_for_profile_layers_primary_under_local_only_satellite():
- """#141910: the authz resolution is the third call site that decided "owns its adapters" by
- map truthiness. A shared-bot satellite holding only a Desktop ``local`` adapter must still
- resolve the primary's bots (background notices, tool sends) with its own local adapter
- layered on top — not instead of the primary."""
- from gateway.authz_mixin import GatewayAuthorizationMixin
-
- primary, local = object(), object()
- holder = GatewayAuthorizationMixin()
- holder.adapters = {Platform.DISCORD: primary}
- holder._profile_adapters = {"sat": {Platform.LOCAL: local}}
- holder._is_shared_bot_satellite = lambda profile: True
- resolved = GatewayAuthorizationMixin._adapters_for_profile(holder, "sat")
- assert resolved[Platform.DISCORD] is primary and resolved[Platform.LOCAL] is local
-
- # A satellite that connected a real platform is its own credential boundary: no borrowing.
- holder._profile_adapters = {"sat": {Platform.LOCAL: local, Platform.TELEGRAM: object()}}
- own = holder._profile_adapters["sat"]
- assert GatewayAuthorizationMixin._adapters_for_profile(holder, "sat") is own
diff --git a/tests/gateway/test_cron_delivery_housekeeping.py b/tests/gateway/test_cron_delivery_housekeeping.py
index 038477be712..ae45f894be4 100644
--- a/tests/gateway/test_cron_delivery_housekeeping.py
+++ b/tests/gateway/test_cron_delivery_housekeeping.py
@@ -161,103 +161,6 @@ def test_multiplex_housekeeping_uses_primary_routes_for_credentialless_satellite
]
-def test_multiplex_housekeeping_routes_desktop_served_satellite_with_only_local_adapter(
- tmp_path, monkeypatch
-):
- """#139825: a profile also chatted with from Hermes Desktop holds ``{LOCAL: adapter}`` in
- ``_profile_adapters``. LOCAL carries no platform credential, so the drain must still hand
- that profile the routed primary view instead of its own credentialless map."""
- from gateway.config import Platform
-
- root_adapters = {"discord": object()}
- secondary_home = tmp_path / "secondary"
- runner = SimpleNamespace(
- config=SimpleNamespace(multiplex_profiles=True),
- adapters=root_adapters,
- _profile_adapters={"secondary": {Platform.LOCAL: object()}},
- )
- calls = []
- routed = object()
-
- monkeypatch.setattr(
- gateway_run,
- "_handoff_watch_scopes",
- lambda _runner: [("secondary", secondary_home)],
- )
-
- @contextmanager
- def fake_scope(_home):
- yield
-
- class FakeSharedRouteAdapters:
- def __new__(cls, adapters, routes):
- calls.append(("routed", adapters, routes))
- return routed
-
- monkeypatch.setattr(gateway_run, "_profile_runtime_scope", fake_scope)
- monkeypatch.setattr(sched_preflight, "SharedRouteAdapters", FakeSharedRouteAdapters)
- monkeypatch.setattr(sched_preflight, "_primary_profile_routes_for_current_home",
- lambda: ["route-to-secondary"],
- )
- monkeypatch.setattr(
- scheduler,
- "drain_delivery_queue",
- lambda adapters, _loop: calls.append(("drain", adapters)),
- )
-
- gateway_run._drain_restart_safe_cron_deliveries(
- root_adapters, object(), runner
- )
-
- assert calls == [
- ("routed", root_adapters, ["route-to-secondary"]),
- ("drain", routed),
- ]
-
-
-def test_multiplex_housekeeping_keeps_reconnecting_satellite_off_the_primary_bot(
- tmp_path, monkeypatch
-):
- """A satellite whose OWN bot dropped has it popped from ``_profile_adapters`` while it
- reconnects; ``_profile_bot_platforms`` still names it. With only a Desktop LOCAL adapter left, the drain
- must still treat it as owning its bot, never route its queue through the primary bot."""
- from gateway.config import Platform
-
- root_adapters = {Platform.DISCORD: object()}
- own = {Platform.LOCAL: object()}
- runner = SimpleNamespace(
- config=SimpleNamespace(multiplex_profiles=True),
- adapters=root_adapters,
- _profile_adapters={"secondary": own},
- _profile_bot_platforms={"secondary": {Platform.DISCORD}},
- )
- calls = []
-
- monkeypatch.setattr(
- gateway_run,
- "_handoff_watch_scopes",
- lambda _runner: [("secondary", tmp_path / "secondary")],
- )
-
- @contextmanager
- def fake_scope(_home):
- yield
-
- monkeypatch.setattr(gateway_run, "_profile_runtime_scope", fake_scope)
- monkeypatch.setattr(sched_preflight, "_primary_profile_routes_for_current_home",
- lambda: ["route-to-secondary"],
- )
- monkeypatch.setattr(
- scheduler,
- "drain_delivery_queue",
- lambda adapters, _loop: calls.append(adapters),
- )
-
- gateway_run._drain_restart_safe_cron_deliveries(root_adapters, object(), runner)
-
- assert calls == [own]
-
-
def test_primary_drain_delivers_credentialless_satellite_queue_row_through_primary_adapter(
tmp_path, monkeypatch,
):
diff --git a/tests/gateway/test_multiplex_adapter_registry.py b/tests/gateway/test_multiplex_adapter_registry.py
index b1ac7f989fc..5cba01201c5 100644
--- a/tests/gateway/test_multiplex_adapter_registry.py
+++ b/tests/gateway/test_multiplex_adapter_registry.py
@@ -442,32 +442,6 @@ class TestSecondaryProfileFatalRecovery:
assert not runner._background_tasks
assert runner._adapters_for_profile("reviewer").get(Platform.DISCORD) is None
- @pytest.mark.asyncio
- async def test_credential_repair_during_a_dead_disconnect_connects(self, monkeypatch):
- """A rescan after a credential repair, landing while a non-retryable bot is still
- disconnecting, builds the repaired bot: nothing else will (the dead one is never retried)."""
- runner = _secondary_recovery_runner()
- runner._adapter_disconnect_timeout_secs = lambda: 5
- stale, repaired = _SecondaryRecoveryAdapter(retryable=False), _SecondaryRecoveryAdapter()
- _install_secondary_reconnect_context(monkeypatch, runner, stale)
- _stub_secondary_start(monkeypatch, runner)
- assert await runner._start_one_profile_adapters("reviewer", Path("/profiles/reviewer"), {}) == 1
- disconnecting, release = asyncio.Event(), asyncio.Event()
-
- async def disconnect():
- disconnecting.set()
- await release.wait()
-
- stale.disconnect = disconnect
- handler = asyncio.create_task(
- runner._handle_profile_adapter_fatal_error("reviewer", Platform.DISCORD, stale))
- await asyncio.wait_for(disconnecting.wait(), 5)
- monkeypatch.setattr(runner, "_create_adapter", lambda platform, config: repaired)
- assert await runner._start_one_profile_adapters("reviewer", Path("/profiles/reviewer"), {}) == 1
- release.set()
- await handler
- assert runner._profile_adapters["reviewer"][Platform.DISCORD] is repaired
-
@pytest.mark.asyncio
async def test_secondary_reconnect_keeps_inbound_dedup(self, monkeypatch):
"""A secondary profile's rebuilt adapter still drops an inbound ID the stale one admitted."""