Commit graph

3300 commits

Author SHA1 Message Date
Paul Gauthier
cf83d5ecd2 aider: Added tests for key functionality of udiff coder.
# Aider chat conversation:

USER: write some basic tests for the key functionality of udiff coder

ASSISTANT: ```diff
--- tests/test_udiff.py
+++ tests/test_udiff.py
@@ ... @@
+import unittest
+from unittest.mock import MagicMock, patch
+from pathlib import Path
+from aider.coders.udiff_coder import UnifiedDiffCoder, do_replace, apply_hunk, find_diffs
+from aider.io import InputOutput
+
+class TestUnifiedDiffCoder(unittest.TestCase):
+    def setUp(self):
+        self.coder = UnifiedDiffCoder(io=InputOutput())
+
+    def test_do_replace_new_file(self):
+        # Test do_replace when it should create a new file
+        hunk = [
+            "--- /dev/null",
+            "+++ newfile.txt",
+            "@@ -0,0 +1 @@",
+            "+New content\n"
+        ]
+        result = do_replace('newfile.txt', None, hunk)
+        self.assertEqual(result, 'New content\n')
+
+    def test_apply_hunk_with_changes(self):
+        # Test apply_hunk with actual changes
+        content = "Original line 1\nOriginal line 2\n"
+        hunk = [
+            "@@ -1,2 +1,2 @@",
+            " Original line 1",
+            "-Original line 2",
+            "+Modified line 2"
+        ]
+        result = apply_hunk(content, hunk)
+        self.assertEqual(result, "Original line 1\nModified line 2\n")
+
+    def test_find_diffs_single_hunk(self):
+        # Test find_diffs with a single hunk
+        content = "```diff\n--- a/file.txt\n+++ b/file.txt\n@@ -1,2 +1,2 @@\n-Original\n+Modified\n```\n"
+        result = find_diffs(content)
+        self.assertEqual(len(result), 1)
+        self.assertEqual(result[0][0], 'b/file.txt')
+        self.assertEqual(result[0][1], ['@@ -1,2 +1,2 @@\n', '-Original\n', '+Modified\n'])
+
+if __name__ == '__main__':
+    unittest.main()
```
2023-12-31 09:45:33 -08:00
Paul Gauthier
dc4bec2986 Fix extracting file path from diff headers in udiff_coder. 2023-12-31 09:42:19 -08:00
Paul Gauthier
4dee2ab2f4 aider: Fix parsing of file paths with spaces in udiff_coder.py.
# Aider chat conversation:

USER: I just tried aider on a project where the folder names have spaces, and it has an issue parsing the diffs.

For example:

```diff
--- PRAW and URS Reddit Scraping/Classify.py
+++ PRAW and URS Reddit Scraping/Classify.py
@@ ... @@
 def classify(filename:str, model: str = 'gpt-3.5-turbo-1106'):
     d = json.load(open(filename))
     for post in d['fetched_posts']:
         messages = copy(MESSAGE_TEMPLATE_CLASSIFY)
...
```

Gives:

```Allow creation of new file PRAW? y```

Which is not correct, a new file is not being created here.

ASSISTANT: To address the issue with folder names containing spaces, we need to update the `find_diffs` function in `udiff_coder.py` to correctly parse file paths that include spaces. The current implementation seems to split the file path on spaces, which leads to incorrect behavior when folder or file names contain spaces.

Here's the diff with the necessary changes:

```diff
--- aider/coders/udiff_coder.py
+++ aider/coders/udiff_coder.py
@@ ... @@
 def find_diffs(content):
     # We can always use triple-quotes, because all the udiff content
     # is prefixed with +/-/space.

     if not content.endswith("\n"):
         content = content + "\n"

     lines = content.splitlines(keepends=True)
     line_num = 0
     edits = []
     while line_num < len(lines):
         while line_num < len(lines):
             line = lines[line_num]
             if line.startswith("```diff"):
                 line_num, these_edits = process_fenced_block(lines, line_num + 1)
                 edits += these_edits
                 break
             line_num += 1

     # For now, just take 1!
     # edits = edits[:1]

     return edits

 def process_fenced_block(lines, start_line_num):
     for line_num in range(start_line_num, len(lines)):
         line = lines[line_num]
         if line.startswith("```"):
             break

     block = lines[start_line_num:line_num]
     block.append("@@ @@")

-    if block[1].startswith("+++ "):
-        fname = block[1].split()[1]
+    if block[1].startswith("--- ") and block[2].startswith("+++ "):
+        # Extract the file path, considering that it might contain spaces
+        fname = block[1][4:].strip()
+        # Ensure that the file path is the same for both the original and new file
+        assert fname == block[2][4:].strip(), "File paths in diff headers do not match"
         block = block[2:]
     else:
         fname = None

     edits = []

     keeper = False
     hunk = []
     op = " "
     for line in block:
         hunk.append(line)
         if len(line) < 2:
             continue
         op = line[0]
         if op in "-+":
             keeper = True
             continue
         if op != "@":
             continue
         if not keeper:
             hunk = []
             continue

         hunk = hunk[:-1]
         edits.append((fname, hunk))
         hunk = []

     return line_num + 1, edits
@@ ... @@
```

This change ensures that the file path is correctly extracted from the diff headers, even if it contains spaces. It also adds an assertion to check that the file paths for the original and new files match, which is a common requirement in diffs.
2023-12-31 09:40:08 -08:00
paul-gauthier
45210c1c84
Merge pull request #413 from ctoth/run-utf8
Use encoding supplied to --encoding by default while running commands
2023-12-29 14:52:04 -04:00
paul-gauthier
6f8ace9f38
Merge pull request #417 from joshuavial/fix-docker-action-error
skip docker github action if credentials not present
2023-12-29 14:51:20 -04:00
Christopher Toth
5f65d5d036 Respect --encoding instead of defaulting to UTF-8 when running commands with /run 2023-12-29 13:40:33 -05:00
Christopher Toth
8be1af8721 Use UTF-8 encoding while running commands by default
This fixes issues with /run on Windows which usually manifested as encoding errors.

Sample: Error running command: 'charmap' codec can't decode byte 0x9d in position 298: character maps to <undefined>
2023-12-29 13:31:42 -05:00
paul-gauthier
9023d1bc02
Merge pull request #420 from ctoth/fix-windows-paths 2023-12-29 14:12:49 -04:00
Christopher Toth
ba87510db1 Fix issue with path normalization that was causing files to be marked dirty on Windows when they were not 2023-12-29 13:04:46 -05:00
Joshua Vial
62da17e333 aider: Adjust DockerHub login action to complete without failing if credentials are not present.
# Aider chat conversation:

USER: please adjust this github action file so it will complete without failing if the dockerhub_username or password are not there

ASSISTANT: ```diff
--- .github/workflows/docker-build-test.yml
+++ .github/workflows/docker-build-test.yml
@@ ... @@
     - name: Login to DockerHub
       uses: docker/login-action@v3
       with:
         username: ${{ secrets.DOCKERHUB_USERNAME }}
         password: ${{ secrets.DOCKERHUB_PASSWORD }}
+      if: ${{ secrets.DOCKERHUB_USERNAME }} && ${{ secrets.DOCKERHUB_PASSWORD }}
```
2023-12-28 11:07:35 +13:00
paul-gauthier
00d5348ee6
Update unified-diffs.md 2023-12-26 20:36:47 -04:00
paul-gauthier
1a110bc1f6
Update unified-diffs.md 2023-12-26 20:35:58 -04:00
paul-gauthier
15829fe211
Update unified-diffs.md 2023-12-26 20:29:33 -04:00
Paul Gauthier
2aca415b31 set version to 0.19.2-dev 2023-12-21 08:59:40 -04:00
Paul Gauthier
0272881bc2 version bump to 0.19.1 2023-12-21 08:59:09 -04:00
Paul Gauthier
a7ea85e7c7 Merge remote-tracking branch 'origin/main' 2023-12-21 08:58:39 -04:00
Paul Gauthier
f4dc8c776b sssh 2023-12-21 08:58:06 -04:00
paul-gauthier
5c4f8a4b76
Update unified-diffs.md 2023-12-20 17:59:39 -06:00
paul-gauthier
fa097537e4
Update unified-diffs.md 2023-12-20 17:58:41 -06:00
Paul Gauthier
208f9ef24a copy 2023-12-20 14:31:04 -04:00
Paul Gauthier
7453624945 copy 2023-12-20 14:29:57 -04:00
Paul Gauthier
97fd65c6ce copy 2023-12-20 13:13:44 -04:00
Paul Gauthier
8a3bde342f copy 2023-12-19 21:54:24 -06:00
Paul Gauthier
c5aba3bead copy 2023-12-19 20:42:04 -06:00
Paul Gauthier
dd389a42d1 copy 2023-12-19 20:22:46 -06:00
Paul Gauthier
67f8d87347 copy 2023-12-19 20:20:27 -06:00
Paul Gauthier
3a7998fdc6 set version to 0.19.1-dev 2023-12-19 20:13:09 -06:00
Paul Gauthier
ac280f54b3 version bump to 0.19.0 2023-12-19 20:12:27 -06:00
Paul Gauthier
76c1deae6a improved test for toplevel refactored func 2023-12-19 15:58:24 -08:00
Paul Gauthier
7028a533f1 copy 2023-12-19 15:30:15 -08:00
Paul Gauthier
d36c18f9dc copy 2023-12-19 15:10:18 -08:00
Paul Gauthier
837fd9e30b copy 2023-12-19 14:59:55 -08:00
Paul Gauthier
3e639639d5 copy 2023-12-19 11:43:42 -08:00
Paul Gauthier
81dca1ead6 copy 2023-12-19 11:13:13 -08:00
Paul Gauthier
755b3858eb copy 2023-12-19 11:11:58 -08:00
Paul Gauthier
4c330bcd48 Revert "folk prompting"
This reverts commit 29150bc6f4.
2023-12-19 10:40:46 -08:00
Paul Gauthier
80d6312817 Revert "folk prompting for udiff"
This reverts commit cb55165c81.
2023-12-19 10:40:35 -08:00
Paul Gauthier
cb55165c81 folk prompting for udiff 2023-12-19 10:12:05 -08:00
Paul Gauthier
29150bc6f4 folk prompting 2023-12-19 09:55:49 -08:00
Paul Gauthier
ef2a1f3875 diff with move hint 2023-12-18 19:09:32 -08:00
Paul Gauthier
d9a301c9f8 laziness24-turbo-diff-never2x 2023-12-18 18:49:30 -08:00
Paul Gauthier
308007a8e9 laziness24-turbo-udiff-never2x 2023-12-18 18:43:15 -08:00
paul-gauthier
3a119ff1b1
Update unified-diffs.md 2023-12-18 12:24:43 -08:00
Paul Gauthier
fd4e890217 copy 2023-12-18 11:07:25 -08:00
paul-gauthier
ca710bddcb
Update unified-diffs.md 2023-12-18 10:54:43 -08:00
Paul Gauthier
2f2b60f4f5 copy 2023-12-18 10:29:34 -08:00
Paul Gauthier
e3c8fac604 copy 2023-12-18 10:20:40 -08:00
Paul Gauthier
b0c03820e9 copy 2023-12-18 10:19:38 -08:00
Paul Gauthier
088454db2e copy 2023-12-18 10:15:07 -08:00
Paul Gauthier
16534e914b better graph 2023-12-18 10:02:52 -08:00