From 16bb0c93e7c56afddd0228231f40af3c5dbd6cf8 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 31 Mar 2025 08:40:17 +1300 Subject: [PATCH] feat: Warn when using --stream and --cache-prompts together --- aider/main.py | 6 +++--- tests/basic/test_main.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/aider/main.py b/aider/main.py index 652425905..1df438843 100644 --- a/aider/main.py +++ b/aider/main.py @@ -579,9 +579,6 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F io = get_io(False) io.tool_warning("Terminal does not support pretty output (UnicodeDecodeError)") - if args.stream and args.cache_prompts: - io.tool_warning("Cost estimates may be inaccurate when using streaming and caching.") - # Process any environment variables set via --set-env if args.set_env: for env_setting in args.set_env: @@ -1065,6 +1062,9 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F io.tool_output(f"Cur working dir: {Path.cwd()}") io.tool_output(f"Git working dir: {git_root}") + if args.stream and args.cache_prompts: + io.tool_warning("Cost estimates may be inaccurate when using streaming and caching.") + if args.load: commands.cmd_load(args.load) diff --git a/tests/basic/test_main.py b/tests/basic/test_main.py index a6dead0ff..a53ce67a5 100644 --- a/tests/basic/test_main.py +++ b/tests/basic/test_main.py @@ -1246,3 +1246,40 @@ class TestMain(TestCase): # Only set_reasoning_effort should be called, not set_thinking_tokens mock_instance.set_reasoning_effort.assert_called_once_with("3") mock_instance.set_thinking_tokens.assert_not_called() + + @patch("aider.main.InputOutput") + def test_stream_and_cache_warning(self, MockInputOutput): + mock_io_instance = MockInputOutput.return_value + with GitTemporaryDirectory(): + main( + ["--stream", "--cache-prompts", "--exit", "--yes"], + input=DummyInput(), + output=DummyOutput(), + ) + mock_io_instance.tool_warning.assert_called_with( + "Cost estimates may be inaccurate when using streaming and caching." + ) + + @patch("aider.main.InputOutput") + def test_stream_without_cache_no_warning(self, MockInputOutput): + mock_io_instance = MockInputOutput.return_value + with GitTemporaryDirectory(): + main( + ["--stream", "--exit", "--yes"], + input=DummyInput(), + output=DummyOutput(), + ) + for call in mock_io_instance.tool_warning.call_args_list: + self.assertNotIn("Cost estimates may be inaccurate", call[0][0]) + + @patch("aider.main.InputOutput") + def test_cache_without_stream_no_warning(self, MockInputOutput): + mock_io_instance = MockInputOutput.return_value + with GitTemporaryDirectory(): + main( + ["--cache-prompts", "--exit", "--yes"], + input=DummyInput(), + output=DummyOutput(), + ) + for call in mock_io_instance.tool_warning.call_args_list: + self.assertNotIn("Cost estimates may be inaccurate", call[0][0])