diff --git a/aider/utils.py b/aider/utils.py index b64d989dd..d758340dd 100644 --- a/aider/utils.py +++ b/aider/utils.py @@ -215,6 +215,9 @@ def find_original_update_blocks(content): pieces.reverse() processed = [] + # Keep using the same filename in cases where GPT produces an edit block + # without a filename. + current_filename = None try: while pieces: cur = pieces.pop() @@ -233,12 +236,20 @@ def find_original_update_blocks(content): try: if not len(filename) or "`" in filename: filename = processed[-2].splitlines()[-2].strip() - if not len(filename) or "`" in filename: + if not len(filename) or "`" in filename: + if current_filename: + filename = current_filename + else: raise ValueError( f"Bad/missing filename. It should go right above {ORIGINAL}" ) except IndexError: - raise ValueError(f"Bad/missing filename. It should go right above {ORIGINAL}") + if current_filename: + filename = current_filename + else: + raise ValueError(f"Bad/missing filename. It should go right above {ORIGINAL}") + + current_filename = filename original_text = pieces.pop() processed.append(original_text) diff --git a/tests/test_utils.py b/tests/test_utils.py index 30c0dcaae..85d736e81 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -195,9 +195,10 @@ tests/test_repomap.py These changes replace the `subprocess.run` patches with `subprocess.check_output` patches in both `test_check_for_ctags_failure` and `test_check_for_ctags_success` tests. """ - with self.assertRaises(ValueError) as cm: - list(utils.find_original_update_blocks(edit)) - self.assertIn("missing filename", str(cm.exception)) + edit_blocks = list(utils.find_original_update_blocks(edit)) + self.assertEqual(len(edit_blocks), 2) # 2 edits + self.assertEqual(edit_blocks[0][0], "tests/test_repomap.py") + self.assertEqual(edit_blocks[1][0], "tests/test_repomap.py") if __name__ == "__main__":