Handle missing filenames by scanning for mentions in the text

This commit is contained in:
Paul Gauthier 2023-06-24 15:32:35 -07:00
parent f2a03e917d
commit ac560c2877
3 changed files with 61 additions and 7 deletions

View file

@ -1,6 +1,7 @@
import os
import tempfile
import unittest
from pathlib import Path
from aider import models
from aider.coders.wholefile_coder import WholeFileCoder
@ -68,7 +69,7 @@ class TestWholeFileCoder(unittest.TestCase):
updated_content = f.read()
self.assertEqual(updated_content, "Updated content\n")
def test_update_files_earlier_filename(self):
def test_update_files_no_filename_single_file_in_chat(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
@ -104,6 +105,47 @@ class TestWholeFileCoder(unittest.TestCase):
updated_content = f.read()
self.assertEqual(updated_content, content)
def test_update_files_earlier_filename(self):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
print(temp_dir)
fname_a = Path("a.txt")
fname_b = Path("b.txt")
fname_a.write_text("before a\n")
fname_b.write_text("before b\n")
response = """
Here is a new version of `a.txt` for you to consider:
```
after a
```
And here is `b.txt`:
```
after b
```
"""
# Initialize WholeFileCoder with the temporary directory
io = InputOutput(yes=True)
coder = WholeFileCoder(main_model=models.GPT35, io=io, fnames=[fname_a, fname_b])
# Set the partial response content with the updated content
coder.partial_response_content = response
# Call update_files method
edited_files = coder.update_files()
# Check if the sample file was updated
self.assertIn(str(fname_a), edited_files)
self.assertIn(str(fname_b), edited_files)
self.assertEqual(fname_a.read_text(), "after a\n")
self.assertEqual(fname_b.read_text(), "after b\n")
if __name__ == "__main__":
unittest.main()