From 10a52505271229e56c5b6143e74719d85e774674 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Tue, 11 Mar 2025 11:48:13 -0700 Subject: [PATCH] test: Add tests for /think-tokens and /reasoning-effort commands --- tests/basic/test_commands.py | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index a234c9b1d..60a8e0b47 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -1282,6 +1282,35 @@ class TestCommands(TestCase): # Verify the file was not added self.assertEqual(len(coder.abs_fnames), 0) + + def test_cmd_think_tokens(self): + io = InputOutput(pretty=False, fancy_input=False, yes=True) + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + # Test with various formats + test_values = { + "8k": 8000, + "8K": 8000, + "10.5k": 10500, + "0.5M": 500000, + "1000": 1000, + } + + for input_value, expected_tokens in test_values.items(): + with mock.patch.object(io, "tool_output") as mock_tool_output: + commands.cmd_think_tokens(input_value) + + # Check that the model's thinking tokens were updated + self.assertEqual(coder.main_model.extra_params["thinking"]["budget_tokens"], expected_tokens) + + # Check that the tool output shows the correct value + mock_tool_output.assert_any_call(f"Set thinking token budget to {expected_tokens:,} tokens.") + + # Test with no value provided + with mock.patch.object(io, "tool_error") as mock_tool_error: + commands.cmd_think_tokens("") + mock_tool_error.assert_called_once_with("Please specify a token budget (e.g., 8k, 10k, 0.5M).") def test_cmd_add_aiderignored_file(self): with GitTemporaryDirectory(): @@ -1721,6 +1750,34 @@ class TestCommands(TestCase): del coder del commands + + def test_cmd_reasoning_effort(self): + io = InputOutput(pretty=False, fancy_input=False, yes=True) + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + # Test with numeric values + with mock.patch.object(io, "tool_output") as mock_tool_output: + commands.cmd_reasoning_effort("0.8") + mock_tool_output.assert_any_call("Set reasoning effort to 0.8") + + # Test with text values (low/medium/high) + for effort_level in ["low", "medium", "high"]: + with mock.patch.object(io, "tool_output") as mock_tool_output: + commands.cmd_reasoning_effort(effort_level) + mock_tool_output.assert_any_call(f"Set reasoning effort to {effort_level}") + + # Check model's reasoning effort was updated + with mock.patch.object(coder.main_model, "set_reasoning_effort") as mock_set_effort: + commands.cmd_reasoning_effort("0.5") + mock_set_effort.assert_called_once_with("0.5") + + # Test with no value provided + with mock.patch.object(io, "tool_error") as mock_tool_error: + commands.cmd_reasoning_effort("") + mock_tool_error.assert_called_once_with( + "Please specify a reasoning effort value (a number or low/medium/high)." + ) def test_cmd_load_with_switch_coder(self): with GitTemporaryDirectory() as repo_dir: