diff --git a/hermes_cli/commands_platforms.py b/hermes_cli/commands_platforms.py index 2c90acf8a2..aa7a98e398 100644 --- a/hermes_cli/commands_platforms.py +++ b/hermes_cli/commands_platforms.py @@ -38,6 +38,15 @@ def _sanitize_telegram_name(raw: str) -> str: return _TG_MULTI_UNDERSCORE.sub("_", name).strip("_") +_TG_DASHES = re.compile("[\u2012\u2013\u2014\u2015\u2212]") + + +def _normalize_telegram_desc(desc: str) -> str: + """Fold Unicode dashes (em/en/figure/horizontal-bar/minus) to ASCII ``-``. + BotFather rejects setMyCommands descriptions containing them (#2925).""" + return _TG_DASHES.sub("-", desc) + + def _truncate_desc(desc: str, limit: int) -> str: """Clamp a menu description to *limit* chars with a ``...`` tail.""" return desc if len(desc) <= limit else desc[:limit - 3] + "..." @@ -80,7 +89,7 @@ def telegram_bot_commands(*, include_plugins: bool = True) -> list[tuple[str, st if include_plugins: pairs += [(n, d) for n, d, hint in _iter_plugin_command_entries() if not _requires_argument(hint)] - return [(tg, desc) for name, desc in pairs if (tg := _sanitize_telegram_name(name))] + return [(tg, _normalize_telegram_desc(desc)) for name, desc in pairs if (tg := _sanitize_telegram_name(name))] # Telegram allows 100 BotCommands; the 60-slot default keeps every built-in plus common skill @@ -279,7 +288,7 @@ def telegram_menu_commands(max_commands: int = 100) -> tuple[list[tuple[str, str for name, desc, cmd_key, raw in entries] candidates = _prioritize_telegram_menu_candidates(candidates) overflow_count = max(0, len(candidates) - max_commands) - menu = [(name, desc) for name, desc, _source, _raw_name in candidates[:max_commands]] + menu = [(name, _normalize_telegram_desc(desc)) for name, desc, _source, _raw_name in candidates[:max_commands]] return menu, hidden_count + overflow_count diff --git a/tests/hermes_cli/test_commands.py b/tests/hermes_cli/test_commands.py index 70fb910bbe..e3ca1cd043 100644 --- a/tests/hermes_cli/test_commands.py +++ b/tests/hermes_cli/test_commands.py @@ -172,6 +172,23 @@ class TestTelegramBotCommands: for name, _ in telegram_bot_commands(): assert "-" not in name, f"Telegram command '{name}' contains a hyphen" + def test_no_unicode_dashes_in_descriptions(self): + """BotFather rejects setMyCommands descriptions with em/en dashes (#2925).""" + for name, desc in telegram_bot_commands(): + assert not any(c in desc for c in "\u2012\u2013\u2014\u2015\u2212"), ( + f"Telegram command '{name}' description has a Unicode dash: {desc!r}") + + def test_unicode_dashes_folded_to_hyphen(self, monkeypatch): + """Stubbed registry entry with em/en dashes comes back hyphenated.""" + fake = CommandDef(name="dashy", description="does a \u2014 b \u2013 c", + category="Session") + monkeypatch.setattr("hermes_cli.commands_platforms._gateway_available_commands", + lambda: [fake]) + monkeypatch.setattr("hermes_cli.commands_platforms._iter_plugin_command_entries", + lambda: iter([])) + assert ("dashy", "does a - b - c") in telegram_bot_commands( + include_plugins=False) + def test_includes_builtin_commands_with_required_args(self): """Built-in arg-taking commands (e.g. /queue, /steer, /bg, /btw)