Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gateway/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1575,10 +1575,12 @@ def _apply_env_overrides(config: GatewayConfig) -> None:
# Feishu / Lark
feishu_app_id = os.getenv("FEISHU_APP_ID")
feishu_app_secret = os.getenv("FEISHU_APP_SECRET")
feishu_gateway_enabled = _coerce_bool(os.getenv("FEISHU_GATEWAY_ENABLED"), default=True)
if feishu_app_id and feishu_app_secret:
if Platform.FEISHU not in config.platforms:
config.platforms[Platform.FEISHU] = PlatformConfig()
config.platforms[Platform.FEISHU].enabled = True
config.platforms[Platform.FEISHU] = PlatformConfig(enabled=feishu_gateway_enabled)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When Feishu already exists in config but has no explicit enabled key, this branch leaves its default enabled=False unchanged despite credentials. Use the current _enable_from_env(Platform.FEISHU) helper so implicit configs auto-enable while _enabled_explicit disables remain respected.

elif not feishu_gateway_enabled:
config.platforms[Platform.FEISHU].enabled = False
config.platforms[Platform.FEISHU].extra.update({
"app_id": feishu_app_id,
"app_secret": feishu_app_secret,
Expand Down
82 changes: 82 additions & 0 deletions tests/gateway/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import os
from unittest.mock import patch

import pytest

from gateway.config import (
GatewayConfig,
HomeChannel,
Expand Down Expand Up @@ -505,6 +507,86 @@ def test_feishu_allow_bots_env_takes_precedence_over_config_yaml(self, tmp_path,

assert os.environ.get("FEISHU_ALLOW_BOTS") == "none"

def test_feishu_env_creds_auto_enable_gateway_by_default(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()

monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("FEISHU_APP_ID", "app_123")
monkeypatch.setenv("FEISHU_APP_SECRET", "secret_123")
monkeypatch.delenv("FEISHU_GATEWAY_ENABLED", raising=False)

config = load_gateway_config()

feishu_cfg = config.platforms[Platform.FEISHU]
assert feishu_cfg.enabled is True
assert feishu_cfg.extra["app_id"] == "app_123"
assert feishu_cfg.extra["app_secret"] == "secret_123"

@pytest.mark.parametrize("disabled_value", ["false", "0", "off", "no"])
def test_feishu_gateway_enabled_false_prevents_env_auto_enable(
self, tmp_path, monkeypatch, disabled_value
):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()

monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("FEISHU_APP_ID", "app_123")
monkeypatch.setenv("FEISHU_APP_SECRET", "secret_123")
monkeypatch.setenv("FEISHU_GATEWAY_ENABLED", disabled_value)

config = load_gateway_config()

feishu_cfg = config.platforms[Platform.FEISHU]
assert feishu_cfg.enabled is False
assert feishu_cfg.extra["app_id"] == "app_123"
assert feishu_cfg.extra["app_secret"] == "secret_123"

def test_feishu_explicit_enabled_config_stays_enabled_with_env_creds(
self, tmp_path, monkeypatch
):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text("feishu:\n enabled: true\n", encoding="utf-8")

monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("FEISHU_APP_ID", "app_123")
monkeypatch.setenv("FEISHU_APP_SECRET", "secret_123")
monkeypatch.delenv("FEISHU_GATEWAY_ENABLED", raising=False)

config = load_gateway_config()

feishu_cfg = config.platforms[Platform.FEISHU]
assert feishu_cfg.enabled is True
assert feishu_cfg.extra["app_id"] == "app_123"
assert feishu_cfg.extra["app_secret"] == "secret_123"

def test_feishu_explicit_disabled_config_is_not_overridden_by_env_creds(
self, tmp_path, monkeypatch
):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
config_path = hermes_home / "config.yaml"
config_path.write_text(
"feishu:\n"
" enabled: false\n"
" extra:\n"
" connection_mode: websocket\n",
encoding="utf-8",
)

monkeypatch.setenv("HERMES_HOME", str(hermes_home))
monkeypatch.setenv("FEISHU_APP_ID", "app_123")
monkeypatch.setenv("FEISHU_APP_SECRET", "secret_123")

config = load_gateway_config()

feishu_cfg = config.platforms[Platform.FEISHU]
assert feishu_cfg.enabled is False
assert feishu_cfg.extra["app_id"] == "app_123"
assert feishu_cfg.extra["app_secret"] == "secret_123"

def test_invalid_quick_commands_in_config_yaml_are_ignored(self, tmp_path, monkeypatch):
hermes_home = tmp_path / ".hermes"
hermes_home.mkdir()
Expand Down