From 4b69e2b85cbbf040a9371b8705ef6c2ac7ea2304 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 21 Jun 2023 21:33:51 -0700 Subject: [PATCH] fixed test --- aider/coders/base_coder.py | 6 +++++- aider/coders/editblock_coder.py | 6 +----- aider/coders/func_coder.py | 10 ++++++++-- aider/coders/wholefile_coder.py | 5 +++-- tests/test_commands.py | 2 +- 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index b6f292c08..1fc553124 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -720,7 +720,6 @@ class Coder: def apply_updates(self): try: edited = self.update_files() - return edited, None except ValueError as err: err = err.args[0] self.io.tool_error("Malformed response, retrying...") @@ -733,6 +732,11 @@ class Coder: traceback.print_exc() return None, err + if edited: + for path in sorted(edited): + self.io.tool_output(f"Applied edit to {path}") + return edited, None + def parse_partial_args(self): # dump(self.partial_response_function_call) diff --git a/aider/coders/editblock_coder.py b/aider/coders/editblock_coder.py index c829175da..0bdc17f78 100644 --- a/aider/coders/editblock_coder.py +++ b/aider/coders/editblock_coder.py @@ -52,12 +52,8 @@ class EditBlockCoder(Coder): ): self.repo.git.add(full_path) - edited.add(path) if do_replace(full_path, original, updated, self.dry_run): - if self.dry_run: - self.io.tool_output(f"Dry run, did not apply edit to {path}") - else: - self.io.tool_output(f"Applied edit to {path}") + edited.add(path) else: self.io.tool_error(f"Failed to apply edit to {path}") diff --git a/aider/coders/func_coder.py b/aider/coders/func_coder.py index 9673d629e..8f3203c74 100644 --- a/aider/coders/func_coder.py +++ b/aider/coders/func_coder.py @@ -111,18 +111,24 @@ class FunctionCoder(Coder): files = args.get("files", []) + chat_files = self.get_inchat_relative_files() + edited = set() for file_upd in files: path = file_upd.get("path") if not path: raise ValueError(f"Missing path: {file_upd}") + if path not in chat_files: + raise ValueError(f"File {path} not in chat session.") + content = file_upd.get("content") if not content: raise ValueError(f"Missing content: {file_upd}") - full_path = os.path.abspath(os.path.join(self.root, path)) - Path(full_path).write_text(content) edited.add(path) + if not self.dry_run: + full_path = os.path.abspath(os.path.join(self.root, path)) + Path(full_path).write_text(content) return edited diff --git a/aider/coders/wholefile_coder.py b/aider/coders/wholefile_coder.py index f9597f876..1c7cfef70 100644 --- a/aider/coders/wholefile_coder.py +++ b/aider/coders/wholefile_coder.py @@ -54,9 +54,10 @@ class WholeFileCoder(Coder): ).splitlines() output += show_diff else: - new_lines = "".join(new_lines) - Path(full_path).write_text(new_lines) edited.add(fname) + if not self.dry_run: + new_lines = "".join(new_lines) + Path(full_path).write_text(new_lines) fname = None new_lines = [] diff --git a/tests/test_commands.py b/tests/test_commands.py index 8d5d6790c..7bd186ad6 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -23,7 +23,7 @@ class TestCommands(TestCase): io = InputOutput(pretty=False, yes=True) from aider.coders import Coder - coder = Coder.create(models.GPT35, io, openai_api_key="deadbeef") + coder = Coder.create(models.GPT35, None, io, openai_api_key="deadbeef") commands = Commands(io, coder) # Call the cmd_add method with 'foo.txt' and 'bar.txt' as a single string