test(dingtalk): cover get_connected_platforms + null platform_toolsets

Follow-ups to the salvaged commits in this PR:

* gateway/config.py — strip trailing whitespace from youngDoo's diff
  (line 315 had ~140 trailing spaces).

* hermes_cli/tools_config.py — replace `config.get("platform_toolsets", {})`
  with `config.get("platform_toolsets") or {}`. Handles the case where the
  YAML key is present but explicitly null (parses as None, previously
  crashed with AttributeError on the next line's .get(platform)).
  Cherry-picked from yyq4193's #9003 with attribution.

* tests/gateway/test_config.py — 4 new tests for TestGetConnectedPlatforms
  covering DingTalk via extras, via env vars, disabled, and missing creds.

* tests/hermes_cli/test_tools_config.py — regression test for the null
  platform_toolsets edge case.

* scripts/release.py — add kagura-agent, youngDoo, yyq4193 to AUTHOR_MAP.

Co-authored-by: yyq4193 <39405770+yyq4193@users.noreply.github.com>
This commit is contained in:
Teknium 2026-04-17 05:40:44 -07:00 committed by Teknium
parent 47a0dd1024
commit c60b6dc317
5 changed files with 62 additions and 2 deletions

View file

@ -312,7 +312,7 @@ class GatewayConfig:
config.extra.get("client_id") or os.getenv("DINGTALK_CLIENT_ID")
) and (
config.extra.get("client_secret") or os.getenv("DINGTALK_CLIENT_SECRET")
):
):
connected.append(platform)
return connected

View file

@ -512,7 +512,7 @@ def _get_platform_tools(
"""Resolve which individual toolset names are enabled for a platform."""
from toolsets import resolve_toolset
platform_toolsets = config.get("platform_toolsets", {})
platform_toolsets = config.get("platform_toolsets") or {}
toolset_names = platform_toolsets.get(platform)
if toolset_names is None or not isinstance(toolset_names, list):

View file

@ -70,6 +70,7 @@ AUTHOR_MAP = {
"27917469+nosleepcassette@users.noreply.github.com": "nosleepcassette",
"241404605+MestreY0d4-Uninter@users.noreply.github.com": "MestreY0d4-Uninter",
"109555139+davetist@users.noreply.github.com": "davetist",
"39405770+yyq4193@users.noreply.github.com": "yyq4193",
"Asunfly@users.noreply.github.com": "Asunfly",
# contributors (manual mapping from git names)
"ahmedsherif95@gmail.com": "asheriif",
@ -181,6 +182,7 @@ AUTHOR_MAP = {
"juan.ovalle@mistral.ai": "jjovalle99",
"julien.talbot@ergonomia.re": "Julientalbot",
"kagura.chen28@gmail.com": "kagura-agent",
"1342088860@qq.com": "youngDoo",
"kamil@gwozdz.me": "kamil-gwozdz",
"karamusti912@gmail.com": "MustafaKara7",
"kira@ariaki.me": "kira-ariaki",

View file

@ -71,6 +71,51 @@ class TestGetConnectedPlatforms:
config = GatewayConfig()
assert config.get_connected_platforms() == []
def test_dingtalk_recognised_via_extras(self):
config = GatewayConfig(
platforms={
Platform.DINGTALK: PlatformConfig(
enabled=True,
extra={"client_id": "cid", "client_secret": "sec"},
),
},
)
assert Platform.DINGTALK in config.get_connected_platforms()
def test_dingtalk_recognised_via_env_vars(self, monkeypatch):
"""DingTalk configured via env vars (no extras) should still be
recognised as connected covers the case where _apply_env_overrides
hasn't populated extras yet."""
monkeypatch.setenv("DINGTALK_CLIENT_ID", "env_cid")
monkeypatch.setenv("DINGTALK_CLIENT_SECRET", "env_sec")
config = GatewayConfig(
platforms={
Platform.DINGTALK: PlatformConfig(enabled=True, extra={}),
},
)
assert Platform.DINGTALK in config.get_connected_platforms()
def test_dingtalk_missing_creds_not_connected(self, monkeypatch):
monkeypatch.delenv("DINGTALK_CLIENT_ID", raising=False)
monkeypatch.delenv("DINGTALK_CLIENT_SECRET", raising=False)
config = GatewayConfig(
platforms={
Platform.DINGTALK: PlatformConfig(enabled=True, extra={}),
},
)
assert Platform.DINGTALK not in config.get_connected_platforms()
def test_dingtalk_disabled_not_connected(self):
config = GatewayConfig(
platforms={
Platform.DINGTALK: PlatformConfig(
enabled=False,
extra={"client_id": "cid", "client_secret": "sec"},
),
},
)
assert Platform.DINGTALK not in config.get_connected_platforms()
class TestSessionResetPolicy:
def test_roundtrip(self):

View file

@ -40,6 +40,19 @@ def test_get_platform_tools_preserves_explicit_empty_selection():
assert enabled == set()
def test_get_platform_tools_handles_null_platform_toolsets():
"""YAML `platform_toolsets:` with no value parses as None — the old
``config.get("platform_toolsets", {})`` pattern would then crash with
``NoneType has no attribute 'get'`` on the next line. Guard against that.
"""
config = {"platform_toolsets": None}
enabled = _get_platform_tools(config, "cli")
# Falls through to defaults instead of raising
assert enabled
def test_platform_toolset_summary_uses_explicit_platform_list():
config = {}