Wires the salvaged search helpers into the shared curses menu driver and turns on type-to-filter for the CLI model pickers (the 100+ model lists that previously required scrolling). - Search lives in the shared `_run_curses_menu` driver behind a `searchable` flag + `search_labels`, so both `curses_radiolist` and `curses_single_select` get it without per-menu duplication. `/` opens the filter, BACKSPACE edits, Ctrl+U clears, ESC clears the filter then cancels. Returned values are always original item indices. - `_filter_indices` RANKS matches (best-first) via a Python port of the TS scorer in ui-tui/src/lib/fuzzy.ts and web/src/lib/fuzzy.ts. The port is byte-identical in score: same per-char bonuses, prefix (+8) and exact (+20) bonuses, camelCase/word-boundary detection (matching on the lowercased target, boundary on the original case), and the -len*0.01 length tiebreak — so the CLI, TUI, and WebUI rank results identically. A cross-language parity test pins the exact scores. - `_prompt_model_selection` (the canonical picker across the model flows) and the custom-provider model list pass `searchable=True`. - Split `_decode_menu_key` out of `read_menu_key` so the search loop can peek the raw key (catch `/`) before nav decoding. - ESC during active search now clears the query (restores the full list) so a no-match filter can't strand the user; printable-key capture is restricted to ASCII to avoid Latin-1 mojibake. - Update two setup-menu tests whose mock signatures predate the new `searchable` kwarg; add ranked-scorer + parity + state-machine tests.
85 lines
3.1 KiB
Python
85 lines
3.1 KiB
Python
"""Regression tests confirming the setup model/provider/reasoning pickers route
|
|
through the shared curses radiolist (ESC + arrow-key handling that works across
|
|
terminals, incl. Ghostty) instead of simple_term_menu.
|
|
|
|
Guards against silently regressing back to simple_term_menu, whose ESC/arrow
|
|
handling was unreliable in `hermes setup` (the provider->model sub-menu).
|
|
"""
|
|
from unittest.mock import patch
|
|
|
|
|
|
def test_prompt_model_selection_uses_curses_radiolist():
|
|
from hermes_cli.auth import _prompt_model_selection
|
|
|
|
seen = {}
|
|
|
|
def _fake(title, items, *, selected=0, cancel_returns=None, description=None, searchable=False):
|
|
seen["title"] = title
|
|
seen["items"] = items
|
|
return 1 # pick second model
|
|
|
|
with patch("hermes_cli.curses_ui.curses_radiolist", side_effect=_fake), \
|
|
patch("builtins.print"):
|
|
result = _prompt_model_selection(["model-a", "model-b"])
|
|
|
|
assert result == "model-b"
|
|
assert seen["title"] == "Select default model:"
|
|
# Items are the models plus the custom/skip entries.
|
|
assert seen["items"][:2] == ["model-a", "model-b"]
|
|
assert "Skip (keep current)" in seen["items"]
|
|
|
|
|
|
def test_prompt_model_selection_esc_cancels():
|
|
from hermes_cli.auth import _prompt_model_selection
|
|
|
|
# curses_radiolist returns the cancel sentinel (-1) on ESC.
|
|
with patch("hermes_cli.curses_ui.curses_radiolist", return_value=-1), \
|
|
patch("builtins.print"):
|
|
result = _prompt_model_selection(["model-a", "model-b"])
|
|
|
|
assert result is None
|
|
|
|
|
|
def test_reasoning_effort_uses_curses_radiolist():
|
|
from hermes_cli.main import _prompt_reasoning_effort_selection
|
|
|
|
with patch("hermes_cli.curses_ui.curses_radiolist", return_value=2), \
|
|
patch("builtins.print"):
|
|
result = _prompt_reasoning_effort_selection(["low", "medium", "high"], current_effort="")
|
|
|
|
assert result == "high"
|
|
|
|
|
|
def test_reasoning_effort_esc_cancels():
|
|
from hermes_cli.main import _prompt_reasoning_effort_selection
|
|
|
|
with patch("hermes_cli.curses_ui.curses_radiolist", return_value=-1), \
|
|
patch("builtins.print"):
|
|
result = _prompt_reasoning_effort_selection(["low", "medium", "high"], current_effort="")
|
|
|
|
assert result is None
|
|
|
|
|
|
def test_model_selection_with_pricing_passes_description():
|
|
"""When pricing is supplied, the aligned header is passed as the curses
|
|
description (multi-line text above the list), not lost."""
|
|
from hermes_cli.auth import _prompt_model_selection
|
|
|
|
seen = {}
|
|
|
|
def _fake(title, items, *, selected=0, cancel_returns=None, description=None, searchable=False):
|
|
seen["description"] = description
|
|
return len(items) - 1 # Skip
|
|
|
|
pricing = {
|
|
"model-a": {"prompt": "0.000001", "completion": "0.000002"},
|
|
"model-b": {"prompt": "0.000003", "completion": "0.000004"},
|
|
}
|
|
with patch("hermes_cli.curses_ui.curses_radiolist", side_effect=_fake), \
|
|
patch("builtins.print"):
|
|
_prompt_model_selection(["model-a", "model-b"], pricing=pricing)
|
|
|
|
# The description should carry the In/Out price header.
|
|
assert seen["description"] is not None
|
|
assert "In" in seen["description"] and "Out" in seen["description"]
|