fix(config): canonicalize platforms.<name>.<display_setting> at one chokepoint; mirror on get/unset (#71047 Problem A)

Follow-up to @zoser69's #78111 cherry-pick:
- lift the redirect into _redirect_platform_display_key() and apply it
  BEFORE _validate_config_key / type coercion, so the unknown-key hint and
  the string-vs-bool coercion both see the canonical path
- widen to the sibling surfaces: config get resolves the canonical key
  (previously echoed the dead top-level value — the misleading half of the
  report) and config unset removes the canonical leaf
- regression tests: get mirrors gateway resolve_display_setting, unset
  removes the redirected leaf, note printed, helper touches ONLY
  OVERRIDEABLE_KEYS (connection keys / 4-segment / already-canonical
  paths untouched)
- docs: configuration.md per-platform section names the canonical CLI
  path and the accepted shorthand
This commit is contained in:
Teknium
2026-09-01 21:23:28 -07:00
parent af709b31ca
commit cb446a5bed
2 changed files with 64 additions and 0 deletions
@@ -93,3 +93,65 @@ class TestPerPlatformDisplayRedirect:
result = yaml.safe_load((home / "config.yaml").read_text())
assert result["display"]["platforms"]["telegram"]["streaming"] is True
assert "platforms" not in result # no stray top-level platforms block
class TestRedirectSiblingSurfaces:
"""The canonicalization must hold for every CLI surface that takes a dotted
key — set, get, unset — and the written value must be what the gateway's
resolver actually reads (the #71047 symptom was CLI and runtime disagreeing).
"""
def test_get_mirrors_gateway_resolution_after_set(self, hermes_home, monkeypatch, capsys):
from gateway.display_config import resolve_display_setting
from hermes_cli.config import get_config_value
_set(monkeypatch, hermes_home, "platforms.telegram.streaming", "false")
capsys.readouterr()
get_config_value("platforms.telegram.streaming")
assert capsys.readouterr().out.strip() == "false"
raw = yaml.safe_load((hermes_home / "config.yaml").read_text())
assert resolve_display_setting(raw, "telegram", "streaming") is False
def test_unset_removes_the_redirected_leaf(self, hermes_home, monkeypatch):
from hermes_cli.config import unset_config_value
_set(monkeypatch, hermes_home, "platforms.telegram.streaming", "false")
unset_config_value("platforms.telegram.streaming")
result = yaml.safe_load((hermes_home / "config.yaml").read_text())
assert "streaming" not in result["display"]["platforms"]["telegram"]
# Sibling display override and connection block untouched.
assert result["display"]["platforms"]["telegram"]["show_reasoning"] is True
assert result["platforms"]["telegram"] == {"token": "secret-bot-token"}
def test_unset_missing_redirected_leaf_exits_nonzero(self, hermes_home, monkeypatch):
from hermes_cli.config import unset_config_value
monkeypatch.setenv("HERMES_HOME", str(hermes_home))
with pytest.raises(SystemExit) as exc:
unset_config_value("platforms.telegram.streaming")
assert exc.value.code == 1
def test_set_prints_redirect_note(self, hermes_home, monkeypatch, capsys):
_set(monkeypatch, hermes_home, "platforms.telegram.streaming", "false")
out = capsys.readouterr().out
assert "saved as display.platforms.telegram.streaming" in out
assert "Set display.platforms.telegram.streaming = False" in out
def test_redirect_helper_only_touches_known_display_keys(self):
from gateway.display_config import OVERRIDEABLE_KEYS
from hermes_cli.config import _redirect_platform_display_key
for setting in OVERRIDEABLE_KEYS:
canonical, note = _redirect_platform_display_key(f"platforms.discord.{setting}")
assert canonical == f"display.platforms.discord.{setting}"
assert note
for key in (
"platforms.telegram.token",
"platforms.telegram.reply_to_mode",
"platforms.telegram.extra.foo", # 4 segments — not a display leaf
"platforms.telegram",
"display.platforms.telegram.streaming", # already canonical
"streaming.enabled",
):
assert _redirect_platform_display_key(key) == (key, None)
+2
View File
@@ -2064,6 +2064,8 @@ display:
tool_progress: 'off' # quiet in shared Slack workspace
```
From the CLI, use the canonical path — `hermes config set display.platforms.telegram.streaming false`. The shorthand `hermes config set platforms.telegram.streaming false` is accepted too: because per-platform *display* settings (`streaming`, `show_reasoning`, `tool_progress`, …) are only ever read from `display.platforms`, `config set`/`get`/`unset` redirect that shorthand to the canonical key and print a note. Connection keys under the top-level `platforms.<name>` block (`token`, `enabled`, `reply_to_mode`, `extra`) are not redirected.
Platforms without an override fall back to the global `tool_progress` value. Valid platform keys: `telegram`, `discord`, `slack`, `signal`, `whatsapp`, `matrix`, `mattermost`, `email`, `sms`, `homeassistant`, `dingtalk`, `feishu`, `wecom`, `weixin`, `bluebubbles`, `qqbot`. The legacy `display.tool_progress_overrides` key still loads for backward compatibility but is deprecated and migrated into `display.platforms` on first load.
Signal is listed as a valid platform key because the setting can be saved per platform, but the current Signal adapter cannot edit sent messages and does not render tool-progress bubbles. Keep Signal `tool_progress` set to `off`; use the CLI or an editing-capable messaging platform if you need to watch each tool call live.