test(gateway): pin config/registration relay-URL agreement under multiplex scope

sol-reviewer round-3 findings: the regression tests stopped at the
config boundary, so config/registration agreement was only manually
verified. New TestConfigRegistrationAgreementUnderMultiplexScope
exercises both sides under an active profile scope: a process-env
stamp yields Platform.RELAY enabled AND relay_url()/
register_relay_adapter() agreement AND a constructed RelayAdapter with
a live transport; a profile-only .env stamp is inert on BOTH sides (no
half-enabled state). Also narrows the test_config docstring that
overclaimed profile .env stamps are unsupported — the launch profile's
.env still activates relay via load_hermes_dotenv's os.environ export;
only an isolated multiplex scope is never consulted.
This commit is contained in:
Ben Barclay
2026-08-21 13:35:20 +10:00
parent 3d25fd59b9
commit d97cb8f253
2 changed files with 101 additions and 2 deletions
@@ -42,3 +42,99 @@ def test_registers_when_url_configured(monkeypatch):
assert platform_registry.is_registered("relay") is True
class TestConfigRegistrationAgreementUnderMultiplexScope:
"""The config loader and the relay registration path must resolve the SAME
GATEWAY_RELAY_URL under an active multiplex profile scope — the routing
stamp is process-global (agent/secret_scope.py), so neither side may see a
value the other doesn't. Regression for the split-brain states: adapter
registered with Platform.RELAY absent from config (process stamp dropped
by the scoped reload), and enabled RELAY config with no adapter
(profile-only stamp invisible to relay_url())."""
def test_process_stamp_agrees_on_both_sides_under_scope(
self, tmp_path, monkeypatch
):
from agent import secret_scope as ss
from gateway.config import Platform, load_gateway_config
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
(hermes_home / "config.yaml").write_text(
"gateway:\n"
" platforms:\n"
" telegram:\n"
" enabled: true\n"
" bot_token: '123:abc'\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("GATEWAY_RELAY_URL", "wss://deploy.example/relay")
profile_dir = tmp_path / "profile-a"
profile_dir.mkdir()
(profile_dir / ".env").write_text("", encoding="utf-8")
ss.set_multiplex_active(True)
tok = ss.set_secret_scope(ss.build_profile_secret_scope(profile_dir))
try:
config = load_gateway_config()
# Registration-side reader agrees with the config side.
assert relay_url() == "wss://deploy.example/relay"
assert register_relay_adapter() is True
finally:
ss.reset_secret_scope(tok)
ss.set_multiplex_active(False)
assert config.platforms[Platform.RELAY].enabled is True
assert config.platforms[Platform.TELEGRAM].enabled is False
# The registered factory actually constructs an adapter with a live
# transport dialing the same URL — the connect loop's contract.
adapter = platform_registry.create_adapter(
"relay", config.platforms[Platform.RELAY]
)
assert isinstance(adapter, RelayAdapter)
# A URL-configured registration builds a live transport (force=True's
# transport-less posture is the test-only path) — private attr, no
# public accessor on the adapter.
assert adapter._transport is not None
def test_profile_only_stamp_is_inert_on_both_sides_under_scope(
self, tmp_path, monkeypatch
):
from agent import secret_scope as ss
from gateway.config import Platform, load_gateway_config
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
(hermes_home / "config.yaml").write_text(
"gateway:\n"
" platforms:\n"
" telegram:\n"
" enabled: true\n"
" bot_token: '123:abc'\n",
encoding="utf-8",
)
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
profile_dir = tmp_path / "profile-a"
profile_dir.mkdir()
(profile_dir / ".env").write_text(
"GATEWAY_RELAY_URL=wss://profile.example/relay\n", encoding="utf-8"
)
ss.set_multiplex_active(True)
tok = ss.set_secret_scope(ss.build_profile_secret_scope(profile_dir))
try:
config = load_gateway_config()
# Both sides agree the stamp is absent: no half-enabled state.
assert relay_url() is None
assert register_relay_adapter() is False
finally:
ss.reset_secret_scope(tok)
ss.set_multiplex_active(False)
relay_cfg = config.platforms.get(Platform.RELAY)
assert relay_cfg is None or relay_cfg.enabled is False
assert config.platforms[Platform.TELEGRAM].enabled is True
+5 -2
View File
@@ -776,8 +776,11 @@ class TestLoadGatewayConfig:
API_SERVER listener vars, #69379): the scoped runner reload in a
multiplexed gateway must keep seeing it, so config's relay enablement
and sweep agree with gateway.relay.relay_url()/register_relay_adapter()
(which read os.environ). A relay URL in a profile's .env is NOT a
supported activation path — the scope is never consulted for globals."""
(which read os.environ). A secondary profile's .env stamp does NOT
override the shared process stamp — an isolated multiplex scope is
never consulted for globals. (A single-profile gateway, or the profile
the process is launched under, still activates via its .env because
load_hermes_dotenv exports that file into os.environ at startup.)"""
from agent import secret_scope as ss
hermes_home = tmp_path / ".hermes"