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.
This commit is contained in:
2
cli.py
2
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"):
|
||||
|
||||
@@ -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)."""
|
||||
|
||||
Reference in New Issue
Block a user