The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test(cli): chat-routing tests follow `hermes chat` back to main's cli.main
Teknium36f46d2232ef
diff --git a/tests/hermes_cli/test_argparse_flag_propagation.py b/tests/hermes_cli/test_argparse_flag_propagation.pyindex 3d688848b60..67c0a1f3926 100644--- a/tests/hermes_cli/test_argparse_flag_propagation.py+++ b/tests/hermes_cli/test_argparse_flag_propagation.py@@ -40,23 +40,24 @@ class TestChatVerboseArg:chat_parser.set_defaults(func=main_mod.cmd_chat)args = parser.parse_args(["chat"])captured = {}- def launch(args):- captured.update(vars(args))- return 0+ fake_cli = types.ModuleType("cli")++ def fake_main(**kwargs):+ captured.update(kwargs)++ fake_cli.main = fake_mainfake_banner = types.ModuleType("hermes_cli.banner")fake_banner.prefetch_update_check = lambda: Nonefake_skills_sync = types.ModuleType("tools.skills_sync")fake_skills_sync.sync_skills = lambda quiet=True: None- monkeypatch.setattr("hermes_cli.gateway_chat.launch_from_args", launch)+ monkeypatch.setitem(sys.modules, "cli", fake_cli)monkeypatch.setitem(sys.modules, "hermes_cli.banner", fake_banner)monkeypatch.setitem(sys.modules, "tools.skills_sync", fake_skills_sync)monkeypatch.setattr(main_mod, "_has_any_provider_configured", lambda: True)monkeypatch.setattr(main_mod, "_pin_kanban_board_env", lambda: None)- with pytest.raises(SystemExit) as result:- main_mod.cmd_chat(args)- assert result.value.code == 0+ main_mod.cmd_chat(args)assert captured["quiet"] is Falseassert "verbose" not in captureddiff --git a/tests/hermes_cli/test_cli_partial_update_hint.py b/tests/hermes_cli/test_cli_partial_update_hint.pyindex 8395d283514..0ce0b8c0338 100644--- a/tests/hermes_cli/test_cli_partial_update_hint.py+++ b/tests/hermes_cli/test_cli_partial_update_hint.py@@ -1,15 +1,16 @@"""Chat startup must explain a mixed-version ImportError (#96900).-A half-updated install can ship a newer launcher importing config helpers-that the older ``hermes_cli.config`` does not export. The transport launch-must preserve the diagnostic previously provided around ``cli.main``.-``cmd_chat`` is the load-bearing catch:+A half-updated install can ship a newer ``cli.py`` (or launcher) importing+config helpers that the older ``hermes_cli.config`` does not export. ``cmd_chat``+(around ``cli.main``) and the ``-z`` transport launch are the load-bearing catches:bare ``hermes`` and ``hermes chat`` (including the fast-chat launch path)all go through it."""from argparse import Namespaceimport io+import sys+import typesimport pytest@@ -56,6 +57,12 @@ def _missing_config_name_error(name: str = "resolve_turn_limit") -> ImportError:return exc+def _install_boom(monkeypatch, boom):+ """``hermes chat`` runs main's ``cli.main``; ``-z`` keeps the gateway transport launcher."""+ monkeypatch.setitem(sys.modules, "cli", types.SimpleNamespace(main=lambda **_kw: boom(None)))+ monkeypatch.setattr("hermes_cli.gateway_chat.launch_from_args", boom)++@pytest.fixturedef main_mod(monkeypatch):import hermes_cli.main as mod@@ -99,7 +106,7 @@ def test_cmd_chat_prints_update_hint_when_config_helper_is_missing(def boom(_args):raise _missing_config_name_error(name)- monkeypatch.setattr("hermes_cli.gateway_chat.launch_from_args", boom)+ _install_boom(monkeypatch, boom)with pytest.raises(SystemExit) as excinfo:getattr(main_mod, entry)(_chat_args())@@ -118,7 +125,7 @@ def test_cmd_chat_still_reraises_unrelated_import_errors(main_mod, monkeypatch,def boom(_args):raise exc- monkeypatch.setattr("hermes_cli.gateway_chat.launch_from_args", boom)+ _install_boom(monkeypatch, boom)with pytest.raises(ImportError) as excinfo:getattr(main_mod, entry)(_chat_args())diff --git a/tests/hermes_cli/test_cli_startup_model_cost_guard.py b/tests/hermes_cli/test_cli_startup_model_cost_guard.pyindex 8e59b5df7db..3d31b3d298f 100644--- a/tests/hermes_cli/test_cli_startup_model_cost_guard.py+++ b/tests/hermes_cli/test_cli_startup_model_cost_guard.py@@ -1,5 +1,6 @@from argparse import Namespaceimport sys+import typesimport pytest@@ -57,11 +58,10 @@ def main_mod(monkeypatch):def fake_cli(monkeypatch):captured = {}- def launch(args):- captured.update(vars(args))- return 0+ def fake_cli_main(**kwargs):+ captured.update(kwargs)- monkeypatch.setattr("hermes_cli.gateway_chat.launch_from_args", launch)+ monkeypatch.setitem(sys.modules, "cli", types.SimpleNamespace(main=fake_cli_main))return captured@@ -127,11 +127,9 @@ def test_cmd_chat_allows_acknowledged_data_training_tier_noninteractively(monkeypatch.setattr(sys, "stdin", _NonInteractiveStdin())_set_startup_config(monkeypatch, ack=True)- with pytest.raises(SystemExit) as result:- main_mod.cmd_chat(- _chat_args(model="muse-spark-1.2-contributor", provider="custom")- )- assert result.value.code == 0+ main_mod.cmd_chat(+ _chat_args(model="muse-spark-1.2-contributor", provider="custom")+ )assert fake_cli["model"] == "muse-spark-1.2-contributor"err = capsys.readouterr().err@@ -215,9 +213,7 @@ def test_cmd_chat_allows_interactive_gpt55_pro_when_confirmed(monkeypatch.setattr(sys.stdin, "isatty", lambda: True)monkeypatch.setattr("builtins.input", lambda _prompt: "yes")- with pytest.raises(SystemExit) as result:- main_mod.cmd_chat(_chat_args(model="openai/gpt-5.5-pro"))- assert result.value.code == 0+ main_mod.cmd_chat(_chat_args(model="openai/gpt-5.5-pro"))assert fake_cli["model"] == "openai/gpt-5.5-pro"@@ -280,9 +276,7 @@ def test_cmd_chat_allows_noninteractive_safe_codex_startup_override(lambda: {"model": {"provider": "openai-codex", "default": "gpt-5.5"}},)- with pytest.raises(SystemExit) as result:- main_mod.cmd_chat(_chat_args(model="gpt-5.5", provider="openai-codex"))- assert result.value.code == 0+ main_mod.cmd_chat(_chat_args(model="gpt-5.5", provider="openai-codex"))assert fake_cli["model"] == "gpt-5.5"assert fake_cli["provider"] == "openai-codex"diff --git a/tests/hermes_cli/test_gateway_startup_consent.py b/tests/hermes_cli/test_gateway_startup_consent.pyindex 65b4ebcaa81..b9793fe3a6b 100644--- a/tests/hermes_cli/test_gateway_startup_consent.py+++ b/tests/hermes_cli/test_gateway_startup_consent.py@@ -1,6 +1,7 @@-"""A consented launch reaches the canonical transport with its scoped options."""+"""A consented launch reaches main's HermesCLI (``cli.main``) with its scoped options."""import osimport sys+import typesimport pytest@@ -8,18 +9,22 @@ import pytestdef test_gateway_launch_honors_interactive_consent_without_policy_environment_mutation(monkeypatch):from hermes_cli import mainfrom tests.hermes_cli.test_cli_startup_model_cost_guard import _chat_args- import hermes_cli.gateway_chat as transportcaptured = []monkeypatch.setattr('hermes_cli.config.load_config', lambda: {'model': {'provider': 'openai-codex', 'default': 'gpt-5.5'}})+ monkeypatch.setattr(main, '_has_any_provider_configured', lambda: True)+ monkeypatch.setattr(main, '_pin_kanban_board_env', lambda: None)monkeypatch.setattr(sys.stdin, 'isatty', lambda: True)- monkeypatch.setattr(transport, 'launch_from_args', lambda args: captured.append(vars(args).copy()) or 0)- before = dict(os.environ)+ monkeypatch.setitem(sys.modules, 'cli', types.SimpleNamespace(main=lambda **kw: captured.append(dict(kw))))for answer, admitted in [('no', False), ('yes', True)]:monkeypatch.setattr('builtins.input', lambda prompt: answer)- with pytest.raises(SystemExit) as result:- main.cmd_chat(_chat_args(model='openai/gpt-5.5-pro', ignore_rules=True, max_turns=3))- assert result.value.code == (0 if admitted else 1)+ before = dict(os.environ)+ if admitted:+ main.cmd_chat(_chat_args(model='openai/gpt-5.5-pro', max_turns=3))+ else:+ with pytest.raises(SystemExit) as result:+ main.cmd_chat(_chat_args(model='openai/gpt-5.5-pro', max_turns=3))+ assert result.value.code == 1+ assert dict(os.environ) == beforeassert bool(captured) == admitted- assert captured[0]['ignore_rules'] is True and captured[0]['max_turns'] == 3- assert dict(os.environ) == before+ assert captured[0]['model'] == 'openai/gpt-5.5-pro' and captured[0]['max_turns'] == 3diff --git a/tests/hermes_cli/test_termux_gateway_launch.py b/tests/hermes_cli/test_termux_gateway_launch.pyindex e0f6068c283..ae3bb90243d 100644--- a/tests/hermes_cli/test_termux_gateway_launch.py+++ b/tests/hermes_cli/test_termux_gateway_launch.py@@ -1,21 +1,20 @@-"""Termux startup hints must not become unsupported execution options."""+"""Termux's interactive fast launch keeps main's deferred-startup hints (main's HermesCLI runs again)."""import sys-def test_termux_fast_launch_preserves_gateway_execution_options(monkeypatch):+def test_termux_fast_launch_defers_agent_startup_like_main(monkeypatch):from hermes_cli import main- from hermes_cli.gateway_chat import validate_optionsmonkeypatch.setenv("TERMUX_VERSION", "fixture")monkeypatch.delenv("HERMES_TERMUX_DISABLE_FAST_CLI", raising=False)+ monkeypatch.delenv("HERMES_DEFER_AGENT_STARTUP", raising=False)+ monkeypatch.delenv("HERMES_FAST_STARTUP_BANNER", raising=False)monkeypatch.setattr(sys, "argv", ["hermes", "--cli"])launches = []-- def launch(args):- validate_options(args)- launches.append(args)-- monkeypatch.setattr(main, "cmd_chat", launch)+ monkeypatch.setattr(main, "cmd_chat", launches.append)assert main._try_termux_fast_cli_launch()assert len(launches) == 1- assert not getattr(launches[0], "compact", False)+ assert launches[0].compact is True+ import os+ assert os.environ["HERMES_DEFER_AGENT_STARTUP"] == "1"+ assert os.environ["HERMES_FAST_STARTUP_BANNER"] == "1"