The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(cli): blank-install TUI reaches its own setup screen (#128663)
preyevates9f4033eabeb3
diff --git a/hermes_cli/main.py b/hermes_cli/main.pyindex 4fb618400d7..9e96f440e10 100644--- a/hermes_cli/main.py+++ b/hermes_cli/main.py@@ -1751,7 +1751,10 @@ def cmd_chat(args):from hermes_cli.free_tier_bootstrap import run_bootstraprun_bootstrap(announce=False)- if not _has_any_provider_configured():+ # The TUI owns its first-run state: it renders "Setup Required" with in-place /setup.+ # The classic prompt only fronts the classic CLI.+ provider_configured = _has_any_provider_configured()+ if not use_tui and not provider_configured:_first_run_setup_guard(args)return@@ -1777,7 +1780,10 @@ def cmd_chat(args):_pin_kanban_board_env()from hermes_cli.observability.shared_metrics_consent import offer_consent_before_chat- offer_consent_before_chat(args)+ # Not before setup: a blank install meets "Setup Required" first. The offer stays+ # undecided, so it is asked on the first launch with a provider.+ if provider_configured:+ offer_consent_before_chat(args)_confirm_startup_expensive_model_override(args)passthrough = {k: getattr(args, k, d) for k, d in _CHAT_PASSTHROUGH}diff --git a/tests/hermes_cli/test_tui_first_run_routing.py b/tests/hermes_cli/test_tui_first_run_routing.pynew file mode 100644index 00000000000..640dcbe9c62--- /dev/null+++ b/tests/hermes_cli/test_tui_first_run_routing.py@@ -0,0 +1,75 @@+"""First-run routing between the classic CLI guard, the TUI and the shared-metrics offer.++A blank install (no provider) must reach the TUI's own "Setup Required" screen under+``hermes --tui``; the classic "Run setup now? [Y/n]" guard only fronts the classic CLI, and the+one-time shared-metrics offer waits until a provider exists (#128663).+"""++from __future__ import annotations++import sys+import types++import pytest+++class _Launched(Exception):+ """Raised by the stubbed ``_launch_tui`` (the real one ``exec``s and never returns)."""+++def _run_chat(monkeypatch, argv, *, provider_configured):+ import hermes_cli.main as main_mod+ from hermes_cli._parser import build_top_level_parser+ import hermes_cli.free_tier_bootstrap as bootstrap+ import hermes_cli.observability.shared_metrics_consent as consent++ parser, _subparsers, chat_parser = build_top_level_parser()+ chat_parser.set_defaults(func=main_mod.cmd_chat)+ args = parser.parse_args(argv)+ calls: list[str] = []++ def launch_tui(*_a, **_k):+ calls.append("tui")+ raise _Launched++ def classic_main(**_k):+ calls.append("classic")++ monkeypatch.setattr(bootstrap, "run_bootstrap", lambda **_k: None)+ monkeypatch.setattr(main_mod, "_has_any_provider_configured", lambda: provider_configured)+ monkeypatch.setattr(main_mod, "_first_run_setup_guard", lambda _args: calls.append("guard"))+ monkeypatch.setattr(consent, "offer_consent_before_chat", lambda _args: calls.append("offer"))+ monkeypatch.setattr(main_mod, "_launch_tui", launch_tui)+ monkeypatch.setattr(main_mod, "_pin_kanban_board_env", lambda: None)+ monkeypatch.setattr(main_mod, "_start_chat_background_prefetch", lambda: None)+ monkeypatch.setattr(main_mod, "_confirm_startup_expensive_model_override", lambda _args: None)+ monkeypatch.setattr(main_mod, "_sync_bundled_skills_for_startup", lambda: None, raising=False)+ fake_cli = types.ModuleType("cli")+ setattr(fake_cli, "main", classic_main)+ monkeypatch.setitem(sys.modules, "cli", fake_cli)+ try:+ main_mod.cmd_chat(args)+ except _Launched:+ pass+ return calls++[email protected](autouse=True)+def _no_tui_env(monkeypatch):+ monkeypatch.delenv("HERMES_TUI", raising=False)+++def test_blank_install_tui_skips_classic_guard_and_offer(monkeypatch):+ assert _run_chat(monkeypatch, ["chat", "--tui"], provider_configured=False) == ["tui"]+++def test_blank_install_classic_cli_still_gets_the_guard(monkeypatch):+ assert _run_chat(monkeypatch, ["chat", "--cli"], provider_configured=False) == ["guard"]+++def test_configured_tui_still_gets_the_one_time_offer(monkeypatch):+ assert _run_chat(monkeypatch, ["chat", "--tui"], provider_configured=True) == ["offer", "tui"]+++def test_configured_classic_cli_still_gets_the_one_time_offer(monkeypatch):+ assert _run_chat(monkeypatch, ["chat", "--cli"], provider_configured=True) == ["offer", "classic"]