Files
hermes-agent/tests/hermes_cli/test_setup_prompt_menus.py

30 lines
1013 B
Python
Raw Normal View History

from hermes_cli import setup as setup_mod
def test_prompt_choice_uses_curses_helper(monkeypatch):
fix(ci): resolve 4 pre-existing main failures (docs lint + 3 stale tests) (#11373) * docs: fix ascii-guard border alignment errors Three docs pages had ASCII diagram boxes with off-by-one column alignment issues that failed docs-site-checks CI: - architecture.md: outer box is 71 cols but inner-box content lines and border corners were offset by 1 col, making content-line right border at col 70/72 while top/bottom border was at col 71. Inner boxes also had border corners at cols 19/36/53 but content pipes at cols 20/37/54. Rewrote the diagram with consistent 71-col width throughout, aligned inner boxes at cols 4-19, 22-37, 40-55 with 2-space gaps and 15-space trailing padding. - gateway-internals.md: same class of issue — outer box at 51 cols, inner content lines varied 52-54 cols. Rewrote with consistent 51-col width, inner boxes at cols 4-15, 18-29, 32-43. Also restructured the bottom-half message flow so it's bare text (not half-open box cells) matching the intent of the original. - agent-loop.md line 112-114: box 2 (API thread) content lines had one extra space pushing the right border to col 46 while the top and bottom borders of that box sat at col 45. Trimmed one trailing space from each of the three content lines. All 123 docs files now pass `npm run lint:diagrams`: ✓ Errors: 0 (warnings: 6, non-fatal) Pre-existing failures on main — unrelated to any open PR. * test(setup): accept description kwarg in prompt_choice mock lambdas setup.py's `_curses_prompt_choice` gained an optional `description` parameter (used for rendering context hints alongside the prompt). `prompt_choice` forwards it via keyword arg. The two existing tests mocked `_curses_prompt_choice` with lambdas that didn't accept the new kwarg, so the forwarded call raised TypeError. Fix: add `description=None` to both mock lambda signatures so they absorb the new kwarg without changing behavior. * test(matrix): update stale audio-caching assertion test_regular_audio_has_http_url asserted that non-voice audio messages keep their HTTP URL and are NOT downloaded/cached. That was true when the caching code only triggered on `is_voice_message`. Since bec02f37 (encrypted-media caching refactor), matrix.py caches all media locally — photos, audio, video, documents — so downstream tools can read them as real files via media_urls. This applies to regular audio too. Renamed the test to `test_regular_audio_is_cached_locally`, flipped the assertions accordingly, and documented the intentional behavior change in the docstring. Other tests in the file (voice-specific caching, message-type detection, reply-to threading) continue to pass. * test(413): allow multi-pass preflight compression run_agent.py's preflight compression runs up to 3 passes in a loop for very large sessions (each pass summarizes the middle N turns, then re-checks tokens). The loop breaks when a pass returns a message list no shorter than its input (can't compress further). test_preflight_compresses_oversized_history used a static mock return value that returned the same 2 messages regardless of input, so the loop ran pass 1 (41 -> 2) and pass 2 (2 -> 2 -> break), making call_count == 2. The assert_called_once() assertion was strictly wrong under the multi-pass design. The invariant the test actually cares about is: preflight ran, and its first invocation received the full oversized history. Replaced the count assertion with those two invariants. * docs: drop '...' from gateway diagram, merge side-by-side boxes ascii-guard 2.3.0 flagged two remaining issues after the initial fix pass: 1. gateway-internals.md L33: the '...' suffix after inner box 3's right border got parsed as 'extra characters after inner-box right border'. Dropped the '...' — the surrounding prose already conveys 'and more platforms' without needing the visual hint. 2. agent-loop.md: ascii-guard can't cleanly parse two side-by-side boxes of different heights (main thread 7 rows, API thread 5 rows). Even equalizing heights didn't help — the linter treats the left box's right border as the end of the diagram. Merged into a single 54-char-wide outer box with both threads labeled as regions inside, keeping the ▶ arrow to preserve the main→API flow direction.
2026-04-16 20:43:41 -07:00
monkeypatch.setattr(setup_mod, "_curses_prompt_choice", lambda question, choices, default=0, description=None: 1)
idx = setup_mod.prompt_choice("Pick one", ["a", "b", "c"], default=0)
assert idx == 1
def test_prompt_choice_falls_back_to_numbered_input(monkeypatch):
fix(ci): resolve 4 pre-existing main failures (docs lint + 3 stale tests) (#11373) * docs: fix ascii-guard border alignment errors Three docs pages had ASCII diagram boxes with off-by-one column alignment issues that failed docs-site-checks CI: - architecture.md: outer box is 71 cols but inner-box content lines and border corners were offset by 1 col, making content-line right border at col 70/72 while top/bottom border was at col 71. Inner boxes also had border corners at cols 19/36/53 but content pipes at cols 20/37/54. Rewrote the diagram with consistent 71-col width throughout, aligned inner boxes at cols 4-19, 22-37, 40-55 with 2-space gaps and 15-space trailing padding. - gateway-internals.md: same class of issue — outer box at 51 cols, inner content lines varied 52-54 cols. Rewrote with consistent 51-col width, inner boxes at cols 4-15, 18-29, 32-43. Also restructured the bottom-half message flow so it's bare text (not half-open box cells) matching the intent of the original. - agent-loop.md line 112-114: box 2 (API thread) content lines had one extra space pushing the right border to col 46 while the top and bottom borders of that box sat at col 45. Trimmed one trailing space from each of the three content lines. All 123 docs files now pass `npm run lint:diagrams`: ✓ Errors: 0 (warnings: 6, non-fatal) Pre-existing failures on main — unrelated to any open PR. * test(setup): accept description kwarg in prompt_choice mock lambdas setup.py's `_curses_prompt_choice` gained an optional `description` parameter (used for rendering context hints alongside the prompt). `prompt_choice` forwards it via keyword arg. The two existing tests mocked `_curses_prompt_choice` with lambdas that didn't accept the new kwarg, so the forwarded call raised TypeError. Fix: add `description=None` to both mock lambda signatures so they absorb the new kwarg without changing behavior. * test(matrix): update stale audio-caching assertion test_regular_audio_has_http_url asserted that non-voice audio messages keep their HTTP URL and are NOT downloaded/cached. That was true when the caching code only triggered on `is_voice_message`. Since bec02f37 (encrypted-media caching refactor), matrix.py caches all media locally — photos, audio, video, documents — so downstream tools can read them as real files via media_urls. This applies to regular audio too. Renamed the test to `test_regular_audio_is_cached_locally`, flipped the assertions accordingly, and documented the intentional behavior change in the docstring. Other tests in the file (voice-specific caching, message-type detection, reply-to threading) continue to pass. * test(413): allow multi-pass preflight compression run_agent.py's preflight compression runs up to 3 passes in a loop for very large sessions (each pass summarizes the middle N turns, then re-checks tokens). The loop breaks when a pass returns a message list no shorter than its input (can't compress further). test_preflight_compresses_oversized_history used a static mock return value that returned the same 2 messages regardless of input, so the loop ran pass 1 (41 -> 2) and pass 2 (2 -> 2 -> break), making call_count == 2. The assert_called_once() assertion was strictly wrong under the multi-pass design. The invariant the test actually cares about is: preflight ran, and its first invocation received the full oversized history. Replaced the count assertion with those two invariants. * docs: drop '...' from gateway diagram, merge side-by-side boxes ascii-guard 2.3.0 flagged two remaining issues after the initial fix pass: 1. gateway-internals.md L33: the '...' suffix after inner box 3's right border got parsed as 'extra characters after inner-box right border'. Dropped the '...' — the surrounding prose already conveys 'and more platforms' without needing the visual hint. 2. agent-loop.md: ascii-guard can't cleanly parse two side-by-side boxes of different heights (main thread 7 rows, API thread 5 rows). Even equalizing heights didn't help — the linter treats the left box's right border as the end of the diagram. Merged into a single 54-char-wide outer box with both threads labeled as regions inside, keeping the ▶ arrow to preserve the main→API flow direction.
2026-04-16 20:43:41 -07:00
monkeypatch.setattr(setup_mod, "_curses_prompt_choice", lambda question, choices, default=0, description=None: -1)
monkeypatch.setattr("builtins.input", lambda _prompt="": "2")
idx = setup_mod.prompt_choice("Pick one", ["a", "b", "c"], default=0)
assert idx == 1
def test_prompt_checklist_uses_shared_curses_checklist(monkeypatch):
monkeypatch.setattr(
"hermes_cli.curses_ui.curses_checklist",
lambda title, items, selected, cancel_returns=None: {0, 2},
)
selected = setup_mod.prompt_checklist("Pick tools", ["one", "two", "three"], pre_selected=[1])
assert selected == [0, 2]