fix(gateway): honor MATRIX_HOME_ROOM in onboarding
This commit is contained in:
@@ -232,6 +232,16 @@ def _ensure_ssl_certs() -> None:
|
||||
os.environ["SSL_CERT_FILE"] = candidate
|
||||
return
|
||||
|
||||
def _home_target_env_var(platform_name: str) -> str:
|
||||
"""Return the configured home-target env var for a platform."""
|
||||
from cron.scheduler import _HOME_TARGET_ENV_VARS
|
||||
|
||||
return _HOME_TARGET_ENV_VARS.get(
|
||||
platform_name.lower(),
|
||||
f"{platform_name.upper()}_HOME_CHANNEL",
|
||||
)
|
||||
|
||||
|
||||
_ensure_ssl_certs()
|
||||
|
||||
# Add parent directory to path
|
||||
@@ -5801,7 +5811,7 @@ class GatewayRunner:
|
||||
# Skip for webhooks - they deliver directly to configured targets (github_comment, etc.)
|
||||
if not history and source.platform and source.platform != Platform.LOCAL and source.platform != Platform.WEBHOOK:
|
||||
platform_name = source.platform.value
|
||||
env_key = f"{platform_name.upper()}_HOME_CHANNEL"
|
||||
env_key = _home_target_env_var(platform_name)
|
||||
if not os.getenv(env_key):
|
||||
adapter = self.adapters.get(source.platform)
|
||||
if adapter:
|
||||
@@ -7691,16 +7701,16 @@ class GatewayRunner:
|
||||
platform_name = source.platform.value if source.platform else "unknown"
|
||||
chat_id = source.chat_id
|
||||
chat_name = source.chat_name or chat_id
|
||||
|
||||
env_key = f"{platform_name.upper()}_HOME_CHANNEL"
|
||||
|
||||
|
||||
env_key = _home_target_env_var(platform_name)
|
||||
|
||||
# Save to .env so it persists across restarts
|
||||
try:
|
||||
from hermes_cli.config import save_env_value
|
||||
save_env_value(env_key, str(chat_id))
|
||||
except Exception as e:
|
||||
return f"Failed to save home channel: {e}"
|
||||
|
||||
|
||||
return (
|
||||
f"✅ Home channel set to **{chat_name}** (ID: {chat_id}).\n"
|
||||
f"Cron jobs and cross-platform messages will be delivered here."
|
||||
|
||||
36
tests/gateway/test_home_target_env_var.py
Normal file
36
tests/gateway/test_home_target_env_var.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""Regression tests for /sethome env-var resolution.
|
||||
|
||||
The `/sethome` command writes to a platform's home-target env var. Two platforms
|
||||
don't follow the `{PLATFORM}_HOME_CHANNEL` convention: matrix uses
|
||||
`MATRIX_HOME_ROOM` and email uses `EMAIL_HOME_ADDRESS`. Before PR #12698
|
||||
`/sethome` hardcoded the `_HOME_CHANNEL` suffix, so Matrix and Email saves went
|
||||
to env vars nothing read on startup — the home channel appeared to set
|
||||
successfully but was lost on every new gateway session.
|
||||
"""
|
||||
|
||||
from gateway.run import _home_target_env_var
|
||||
|
||||
|
||||
def test_matrix_home_target_env_var_uses_home_room():
|
||||
assert _home_target_env_var("matrix") == "MATRIX_HOME_ROOM"
|
||||
|
||||
|
||||
def test_email_home_target_env_var_uses_home_address():
|
||||
assert _home_target_env_var("email") == "EMAIL_HOME_ADDRESS"
|
||||
|
||||
|
||||
def test_telegram_home_target_env_var_uses_home_channel():
|
||||
assert _home_target_env_var("telegram") == "TELEGRAM_HOME_CHANNEL"
|
||||
|
||||
|
||||
def test_discord_home_target_env_var_uses_home_channel():
|
||||
assert _home_target_env_var("discord") == "DISCORD_HOME_CHANNEL"
|
||||
|
||||
|
||||
def test_unknown_platform_home_target_env_var_falls_back_to_home_channel():
|
||||
assert _home_target_env_var("custom") == "CUSTOM_HOME_CHANNEL"
|
||||
|
||||
|
||||
def test_case_insensitive_platform_name():
|
||||
assert _home_target_env_var("MATRIX") == "MATRIX_HOME_ROOM"
|
||||
assert _home_target_env_var("Email") == "EMAIL_HOME_ADDRESS"
|
||||
Reference in New Issue
Block a user