The setup provider->model sub-menu (and three sibling pickers) used simple_term_menu.TerminalMenu, whose ESC and arrow-key handling was unreliable across terminals — notably ESC failed to back out of the model selection list on terminals that emit raw escape sequences (e.g. Ghostty). The codebase already notes simple_term_menu 'conflicts with /dev/tty' and causes 'ghost-duplication rendering', and a prior attempt to migrate these (closed PR) confirmed the same root cause. Route all four single-select pickers through the shared, already-hardened curses_radiolist (which decodes raw CSI/SS3 escape sequences and handles ESC consistently, fixed in #35776): - auth.py _prompt_model_selection — model picker; the pricing column header and the unavailable-models block are passed as the radiolist description so they survive the curses screen clear. ESC now cancels. - main.py _prompt_reasoning_effort_selection — reasoning-effort picker. - main.py _model_flow_named_custom — named custom-provider model picker. - main.py _remove_custom_provider — provider-removal picker. simple_term_menu is no longer imported anywhere (only stale comments referenced it; one in setup.py is corrected). The numbered-input fallbacks are unchanged and still trigger on curses errors / non-TTY. Tests: updated test_terminal_menu_fallbacks / test_reasoning_effort_menu / test_custom_provider_model_switch / test_model_provider_persistence to drive the fallback via curses_radiolist errors instead of breaking simple_term_menu. New test_setup_menu_curses_migration.py asserts each picker routes through curses_radiolist, ESC cancels, and the pricing header is preserved. Net -147/+183 (mostly the new test file; production code shrinks by removing TerminalMenu boilerplate).
91 lines
3.1 KiB
Python
91 lines
3.1 KiB
Python
"""Regression tests for numbered fallbacks when the interactive curses menu
|
|
cannot initialize (e.g. non-TTY, curses unavailable, terminal error)."""
|
|
|
|
import subprocess
|
|
|
|
from hermes_cli.config import load_config, save_config
|
|
|
|
|
|
def _raise_menu(*args, **kwargs):
|
|
# Mimic curses_radiolist hitting an unrecoverable terminal error so the
|
|
# caller's except clause routes to the numbered-input fallback.
|
|
raise subprocess.CalledProcessError(2, ["tput", "clear"])
|
|
|
|
|
|
def test_prompt_model_selection_falls_back_on_menu_runtime_error(monkeypatch):
|
|
from hermes_cli.auth import _prompt_model_selection
|
|
|
|
monkeypatch.setattr("hermes_cli.curses_ui.curses_radiolist", _raise_menu)
|
|
responses = iter(["2"])
|
|
monkeypatch.setattr("builtins.input", lambda _prompt="": next(responses))
|
|
|
|
selected = _prompt_model_selection(["model-a", "model-b"])
|
|
|
|
assert selected == "model-b"
|
|
|
|
|
|
def test_prompt_reasoning_effort_falls_back_on_menu_runtime_error(monkeypatch):
|
|
from hermes_cli.main import _prompt_reasoning_effort_selection
|
|
|
|
monkeypatch.setattr("hermes_cli.curses_ui.curses_radiolist", _raise_menu)
|
|
responses = iter(["3"])
|
|
monkeypatch.setattr("builtins.input", lambda _prompt="": next(responses))
|
|
|
|
selected = _prompt_reasoning_effort_selection(["low", "medium", "high"], current_effort="")
|
|
|
|
assert selected == "high"
|
|
|
|
|
|
def test_remove_custom_provider_falls_back_on_menu_runtime_error(tmp_path, monkeypatch):
|
|
from hermes_cli.main import _remove_custom_provider
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
monkeypatch.setattr("hermes_cli.curses_ui.curses_radiolist", _raise_menu)
|
|
|
|
cfg = load_config()
|
|
cfg["custom_providers"] = [
|
|
{"name": "Local A", "base_url": "http://localhost:8001/v1"},
|
|
{"name": "Local B", "base_url": "http://localhost:8002/v1"},
|
|
]
|
|
save_config(cfg)
|
|
|
|
responses = iter(["1"])
|
|
monkeypatch.setattr("builtins.input", lambda _prompt="": next(responses))
|
|
|
|
_remove_custom_provider(cfg)
|
|
|
|
reloaded = load_config()
|
|
assert reloaded["custom_providers"] == [
|
|
{"name": "Local B", "base_url": "http://localhost:8002/v1"},
|
|
]
|
|
|
|
|
|
def test_named_custom_provider_model_picker_falls_back_on_menu_runtime_error(tmp_path, monkeypatch):
|
|
from hermes_cli.main import _model_flow_named_custom
|
|
|
|
monkeypatch.setenv("HERMES_HOME", str(tmp_path))
|
|
monkeypatch.setattr("hermes_cli.curses_ui.curses_radiolist", _raise_menu)
|
|
monkeypatch.setattr("hermes_cli.models.fetch_api_models", lambda *args, **kwargs: ["model-a", "model-b"])
|
|
monkeypatch.setattr("hermes_cli.auth.deactivate_provider", lambda: None)
|
|
|
|
cfg = load_config()
|
|
save_config(cfg)
|
|
|
|
responses = iter(["2"])
|
|
monkeypatch.setattr("builtins.input", lambda _prompt="": next(responses))
|
|
|
|
_model_flow_named_custom(
|
|
cfg,
|
|
{
|
|
"name": "Local",
|
|
"base_url": "http://localhost:8000/v1",
|
|
"api_key": "",
|
|
"model": "",
|
|
},
|
|
)
|
|
|
|
reloaded = load_config()
|
|
assert reloaded["model"]["provider"] == "custom"
|
|
assert reloaded["model"]["base_url"] == "http://localhost:8000/v1"
|
|
assert reloaded["model"]["default"] == "model-b"
|