From afb680b50dc24db81c862a035b7a927d8095e0a8 Mon Sep 17 00:00:00 2001 From: teknium1 Date: Mon, 2 Mar 2026 01:15:10 -0800 Subject: [PATCH] fix(cli): fix max_turns comment and test for correct priority order Priority is: CLI arg > config file > env var > default (not env var > config file as the old comment stated) The test failed because config.yaml had max_turns at both root level and inside agent section. The test cleared agent.max_turns but the root-level value still took precedence over the env var. Fixed the test to clear both, and corrected the comment to match the intended priority order. --- cli.py | 2 +- tests/test_cli_init.py | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cli.py b/cli.py index 028a96c56..bbd09e2b3 100755 --- a/cli.py +++ b/cli.py @@ -850,7 +850,7 @@ class HermesCLI: self.api_key = api_key or os.getenv("OPENAI_API_KEY") or os.getenv("OPENROUTER_API_KEY") self._nous_key_expires_at: Optional[str] = None self._nous_key_source: Optional[str] = None - # Max turns priority: CLI arg > env var > config file (agent.max_turns or root max_turns) > default + # Max turns priority: CLI arg > config file > env var > default if max_turns is not None: # CLI arg was explicitly set self.max_turns = max_turns elif CLI_CONFIG["agent"].get("max_turns"): diff --git a/tests/test_cli_init.py b/tests/test_cli_init.py index 90ce05c72..c868d85b2 100644 --- a/tests/test_cli_init.py +++ b/tests/test_cli_init.py @@ -38,14 +38,18 @@ class TestMaxTurnsResolution: """Env var is used when config file doesn't set max_turns.""" monkeypatch.setenv("HERMES_MAX_ITERATIONS", "42") import cli as cli_module - original = cli_module.CLI_CONFIG["agent"].get("max_turns") + original_agent = cli_module.CLI_CONFIG["agent"].get("max_turns") + original_root = cli_module.CLI_CONFIG.get("max_turns") cli_module.CLI_CONFIG["agent"]["max_turns"] = None + cli_module.CLI_CONFIG.pop("max_turns", None) try: cli_obj = _make_cli() assert cli_obj.max_turns == 42 finally: - if original is not None: - cli_module.CLI_CONFIG["agent"]["max_turns"] = original + if original_agent is not None: + cli_module.CLI_CONFIG["agent"]["max_turns"] = original_agent + if original_root is not None: + cli_module.CLI_CONFIG["max_turns"] = original_root def test_max_turns_never_none_for_agent(self): """The value passed to AIAgent must never be None (causes TypeError in run_conversation)."""