From c8e5c27a2f981dd19d838706617934e32e5929b6 Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Mon, 29 Jul 2024 17:07:51 -0300 Subject: [PATCH] Add a test to trigger the UnboundLocalError bug in the cmd_run method Commit message: Add test to trigger UnboundLocalError in cmd_run method --- tests/basic/test_commands.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/basic/test_commands.py b/tests/basic/test_commands.py index 948db1517..9ef8b8559 100644 --- a/tests/basic/test_commands.py +++ b/tests/basic/test_commands.py @@ -536,6 +536,21 @@ class TestCommands(TestCase): commands.cmd_add("file.txt") self.assertEqual(coder.abs_fnames, set()) + def test_cmd_run_unbound_local_error(self): + with ChdirTemporaryDirectory(): + io = InputOutput(pretty=False, yes=False) + from aider.coders import Coder + + coder = Coder.create(self.GPT35, None, io) + commands = Commands(io, coder) + + # Mock the io.prompt_ask method to simulate user input + io.prompt_ask = lambda *args, **kwargs: "custom instructions" + + # Test the cmd_run method with a command that should trigger the bug + with self.assertRaises(UnboundLocalError): + commands.cmd_run("echo test", add_on_nonzero_exit=False) + def test_cmd_add_drop_untracked_files(self): with GitTemporaryDirectory(): repo = git.Repo()