test_setup_agent_settings.py
1 """Tests for agent-settings copy in the interactive setup wizard.""" 2 3 from hermes_cli.setup import setup_agent_settings 4 5 6 def test_setup_agent_settings_uses_displayed_max_iterations_value(tmp_path, monkeypatch, capsys): 7 """The helper text should match the value shown in the prompt. 8 9 After PR#18413 max_turns is read exclusively from config.yaml — the 10 .env `HERMES_MAX_ITERATIONS` fallback was removed because it was 11 shadowing the user's current config (see the 60-vs-500 incident). 12 """ 13 monkeypatch.setenv("HERMES_HOME", str(tmp_path)) 14 15 config = { 16 "agent": {"max_turns": 60}, 17 "display": {"tool_progress": "all"}, 18 "compression": {"threshold": 0.50}, 19 "session_reset": {"mode": "both", "idle_minutes": 1440, "at_hour": 4}, 20 } 21 22 prompt_answers = iter(["60", "all", "0.5"]) 23 24 monkeypatch.setattr("hermes_cli.setup.prompt", lambda *args, **kwargs: next(prompt_answers)) 25 monkeypatch.setattr("hermes_cli.setup.prompt_choice", lambda *args, **kwargs: 4) 26 monkeypatch.setattr("hermes_cli.setup.save_env_value", lambda *args, **kwargs: None) 27 monkeypatch.setattr("hermes_cli.setup.remove_env_value", lambda *args, **kwargs: None) 28 monkeypatch.setattr("hermes_cli.setup.save_config", lambda *args, **kwargs: None) 29 30 setup_agent_settings(config) 31 32 out = capsys.readouterr().out 33 assert "Press Enter to keep 60." in out 34 assert "Default is 90" not in out 35 36 37 def test_setup_agent_settings_prefers_config_over_stale_env(tmp_path, monkeypatch, capsys): 38 """Config.yaml wins even when a stale .env value disagrees. 39 40 Regression guard for the bug where `.env HERMES_MAX_ITERATIONS=60` 41 from an old `hermes setup` run shadowed `agent.max_turns: 500` in 42 config.yaml. The wizard must now display the config value. 43 """ 44 monkeypatch.setenv("HERMES_HOME", str(tmp_path)) 45 46 config = { 47 "agent": {"max_turns": 500}, # user bumped this in config.yaml 48 "display": {"tool_progress": "all"}, 49 "compression": {"threshold": 0.50}, 50 "session_reset": {"mode": "both", "idle_minutes": 1440, "at_hour": 4}, 51 } 52 53 prompt_answers = iter(["500", "all", "0.5"]) 54 55 # Simulate stale .env value — the wizard must ignore this. 56 monkeypatch.setattr( 57 "hermes_cli.setup.get_env_value", 58 lambda key: "60" if key == "HERMES_MAX_ITERATIONS" else "", 59 ) 60 monkeypatch.setattr("hermes_cli.setup.prompt", lambda *args, **kwargs: next(prompt_answers)) 61 monkeypatch.setattr("hermes_cli.setup.prompt_choice", lambda *args, **kwargs: 4) 62 monkeypatch.setattr("hermes_cli.setup.save_env_value", lambda *args, **kwargs: None) 63 64 removed_keys: list[str] = [] 65 monkeypatch.setattr( 66 "hermes_cli.setup.remove_env_value", 67 lambda key: (removed_keys.append(key), True)[1], 68 ) 69 monkeypatch.setattr("hermes_cli.setup.save_config", lambda *args, **kwargs: None) 70 71 setup_agent_settings(config) 72 73 out = capsys.readouterr().out 74 # Config value wins 75 assert "Press Enter to keep 500." in out 76 assert "Press Enter to keep 60." not in out 77 # And the stale .env entry gets cleaned up 78 assert "HERMES_MAX_ITERATIONS" in removed_keys