refactor(hermes_cli): drop dead generate_bot_username/slug + DEFAULT_MANAGER_BOT (tests only)
This commit is contained in:
@@ -86,7 +86,6 @@ _validate_access_token = _rules_validator("Access token", (
|
||||
(lambda s: not s.startswith("EAA"), _not_meta_token_reason),
|
||||
(lambda s: len(s) < 100, lambda s: f"Access token looks too short ({len(s)} chars, expected 100+)")))
|
||||
|
||||
|
||||
# --- Prompt helpers
|
||||
|
||||
def _prompt(message: str, default: Optional[str] = None, secret: bool = False) -> str:
|
||||
|
||||
@@ -78,7 +78,6 @@ _APIKEY_PROVIDERS = {
|
||||
"StepFun Step Plan": ("STEPFUN_API_KEY",), "MiniMax": ("MINIMAX_API_KEY",),
|
||||
"MiniMax (China)": ("MINIMAX_CN_API_KEY",), "DeepInfra": ("DEEPINFRA_API_KEY",)}
|
||||
|
||||
|
||||
# Nous Tool Gateway per-feature state: first matching (predicate(feature, nous_auth), text(feature)).
|
||||
_FEATURE_STATES = (
|
||||
(lambda f, _: f.managed_by_nous, lambda f: "active via Nous subscription"),
|
||||
|
||||
@@ -5,7 +5,6 @@ from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import secrets
|
||||
import sys
|
||||
import time
|
||||
from dataclasses import dataclass
|
||||
@@ -16,14 +15,10 @@ import httpx
|
||||
# Nous-hosted pairing API; override for PoC/staging with TELEGRAM_ONBOARDING_URL.
|
||||
DEFAULT_API_URL = "https://setup.hermes-agent.nousresearch.com"
|
||||
TELEGRAM_ONBOARDING_URL_ENV = "TELEGRAM_ONBOARDING_URL"
|
||||
# Manager bot username (without @); the backend returns the real deep link, so this is only
|
||||
# used by local helpers/tests.
|
||||
DEFAULT_MANAGER_BOT = "HermesSetupBot"
|
||||
DEFAULT_BOT_NAME = "Hermes Agent"
|
||||
DEFAULT_POLL_TIMEOUT = 180
|
||||
POLL_INTERVAL = 2
|
||||
|
||||
_USERNAME_SLUG_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567"
|
||||
_TELEGRAM_BOT_TOKEN_RE = re.compile(r"^\d+:[A-Za-z0-9_-]{30,}$")
|
||||
|
||||
|
||||
@@ -86,18 +81,6 @@ def print_qr_code(url: str, *, include_link: bool = True) -> None:
|
||||
print(f" Link: {url}")
|
||||
|
||||
|
||||
def generate_username_slug(length: int = 16) -> str:
|
||||
"""Generate a base32-ish slug for Telegram username correlation."""
|
||||
return "".join(secrets.choice(_USERNAME_SLUG_ALPHABET) for _ in range(length))
|
||||
|
||||
|
||||
def generate_bot_username(profile_name: Optional[str] = None) -> str:
|
||||
"""Suggested bot username ``hermes_<slug>_bot``; ``profile_name`` is accepted for backward
|
||||
compatibility but not embedded (the slug must carry the entropy for backend correlation)."""
|
||||
_ = profile_name
|
||||
return f"hermes_{generate_username_slug()}_bot"
|
||||
|
||||
|
||||
def create_pairing(
|
||||
api_url: str | None = None, bot_name: str = DEFAULT_BOT_NAME, timeout: float = 10.0
|
||||
) -> TelegramPairing | None:
|
||||
@@ -164,7 +147,7 @@ def poll_for_setup_result(
|
||||
|
||||
|
||||
def auto_setup_telegram_bot_result(
|
||||
api_url: str | None = None, manager_bot: str = DEFAULT_MANAGER_BOT,
|
||||
api_url: str | None = None, manager_bot: str = "HermesSetupBot",
|
||||
profile_name: Optional[str] = None, poll_timeout: float = DEFAULT_POLL_TIMEOUT,
|
||||
) -> Optional[TelegramBotSetupResult]:
|
||||
"""Run the full automatic Telegram bot creation flow."""
|
||||
|
||||
@@ -9,7 +9,6 @@ from hermes_cli.telegram_managed_bot import (
|
||||
TELEGRAM_ONBOARDING_URL_ENV,
|
||||
TelegramPairing,
|
||||
create_pairing,
|
||||
generate_bot_username,
|
||||
poll_for_setup_result,
|
||||
print_qr_code,
|
||||
render_qr_terminal,
|
||||
@@ -20,20 +19,6 @@ VALID_TOKEN = "123456789:ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef"
|
||||
SECOND_VALID_TOKEN = "987654321:abcdefghijklmnopqrstuvwxyzABCDEF"
|
||||
|
||||
|
||||
class TestGenerateBotUsername:
|
||||
def test_secure_default_format(self):
|
||||
name = generate_bot_username()
|
||||
assert name.startswith("hermes_")
|
||||
assert name.endswith("_bot")
|
||||
assert len(name) == len("hermes_") + 16 + len("_bot")
|
||||
assert len(name) <= 32
|
||||
|
||||
|
||||
def test_uniqueness(self):
|
||||
names = {generate_bot_username() for _ in range(20)}
|
||||
assert len(names) == 20
|
||||
|
||||
|
||||
class TestQRCode:
|
||||
def test_render_returns_string(self):
|
||||
result = render_qr_terminal("https://example.com")
|
||||
|
||||
Reference in New Issue
Block a user