Commit graph

389 commits

Author SHA1 Message Date
Paul Gauthier
a39965a9ff Only /undo the files which were part of the last commit, don't stomp other dirty files #513 2024-03-22 10:00:15 -07:00
Paul Gauthier
a9fe4532c7 Aider should fully ignore files in aiderignore #479 2024-02-24 09:39:33 -08:00
Paul Gauthier
35f812859e Rationalized openai model attributes #458 2024-02-07 12:07:30 -08:00
Paul Gauthier
d5f4ba2278 handle multiple udiffs inside a single fenced block 2024-01-04 12:53:01 -08:00
Paul Gauthier
0371b0f58b try and make windows tests happy 2024-01-02 09:44:47 -08:00
paul-gauthier
2824acb5c2
Merge pull request #379 from joshuavial/gpt4-vision
add support for gpt-4-vision
2024-01-02 13:37:17 -04:00
Paul Gauthier
e09a2033e2 Refactored the cmd_undo method to handle dirty files not in the last commit. 2024-01-02 09:04:57 -08:00
Paul Gauthier
cca43e8489 aider: Add test case for undo command with dirty files not in last commit.
# Aider chat conversation:

USER: add a test case for this

ASSISTANT: To add a test case for the updated `/undo` command behavior, we need to modify the `tests/test_commands.py` file. The new test case will ensure that the `/undo` command only aborts if the files modified in the latest commit are dirty.

Here is the diff for the new test case:

```diff
--- tests/test_commands.py
+++ tests/test_commands.py
@@ ... @@
+    def test_cmd_undo_with_dirty_files_not_in_last_commit(self):
+        with GitTemporaryDirectory() as repo_dir:
+            repo = git.Repo(repo_dir)
+            io = InputOutput(pretty=False, yes=True)
+            coder = Coder.create(models.GPT35, None, io)
+            commands = Commands(io, coder)
+
+            # Create and commit a file
+            filename = "test_file.txt"
+            file_path = Path(repo_dir) / filename
+            file_path.write_text("Initial content")
+            repo.git.add(filename)
+            repo.git.commit("-m", "Initial commit")
+
+            # Modify the file and commit again
+            file_path.write_text("Modified content")
+            repo.git.add(filename)
+            repo.git.commit("-m", "aider: Modify test_file.txt")
+
+            # Store the commit hash
+            last_commit_hash = repo.head.commit.hexsha[:7]
+            coder.last_aider_commit_hash = last_commit_hash
+
+            # Create a dirty file that was not in the last commit
+            other_file = "other_file.txt"
+            other_file_path = Path(repo_dir) / other_file
+            other_file_path.write_text("This is an untracked file")
+
+            # Attempt to undo the last commit
+            output = commands.cmd_undo("")
+            self.assertIsNone(output, "Undo should not produce any output")
+
+            # Check that the last commit is still present
+            self.assertEqual(last_commit_hash, repo.head.commit.hexsha[:7])
+
+            # Check that the dirty file is still untracked
+            self.assertTrue(other_file_path.exists())
+            self.assertIn(other_file, repo.untracked_files)
```

This test case creates a repository with an initial commit, then modifies a file and commits that change with a message indicating it was done by `aider`. It then creates another file that is not tracked by git (making the repository dirty, but not with the file that was in the last commit). It then runs the `/undo` command and checks that the last commit is still present and that the untracked file is still untracked, confirming that `/undo` did not abort due to the untracked file.
2024-01-02 08:47:58 -08:00
Paul Gauthier
15c915e481 added basic test coverage for find_diffs 2023-12-31 09:54:01 -08:00
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
Joshua Vial
179b648864 merging from upstream main 2023-12-19 22:04:39 +13:00
Paul Gauthier
7113a30271 unified diffs 2023-12-17 12:54:34 -08:00
Joshua Vial
90d5071709 fix failing tests 2023-12-11 22:37:23 +13:00
Paul Gauthier
9d2f89dd75 fix test 2023-12-06 09:30:19 -08:00
Paul Gauthier
922a56b194 Merge branch 'main' into openai-upgrade 2023-12-06 09:26:05 -08:00
Paul Gauthier
57ab2cc9da Revert "implement deployment id"
This reverts commit b107db98fa.
2023-12-06 09:20:53 -08:00
Your Name
4692a689fe Improvements: flag -f (not -mf); unitest improvements. 2023-12-05 23:55:10 +01:00
Your Name
13ac5f0b60 Add --message-file flag and unit test
This commit introduces the `--message-file` flag to the `aider` tool, allowing users to specify a file containing the message to send to GPT. This feature processes the reply and then exits, disabling the chat mode. The implementation includes reading the content of the specified file and using it as the prompt message.

Additionally, a unit test has been added to `tests/test_main.py` to ensure the correct functionality of the `--message-file` flag. The test includes necessary mocks to handle non-interactive environments and verifies that the tool behaves as expected when a message file is provided.

This enhancement improves the usability of the `aider` tool for users who prefer or require non-interactive execution, such as in scripting or automated workflows.
2023-12-05 23:55:10 +01:00
Paul Gauthier
b107db98fa implement deployment id 2023-12-05 11:31:17 -08:00
Paul Gauthier
d92a93221c fixed test_wholefile 2023-12-05 11:11:48 -08:00
Paul Gauthier
5b21d5704a fixed test_sendchat 2023-12-05 11:08:14 -08:00
Paul Gauthier
a68d3d8a20 fixed test_models 2023-12-05 10:56:03 -08:00
Paul Gauthier
23e6c4ee55 fixed test_coder 2023-12-05 10:51:50 -08:00
Paul Gauthier
fb07b784f6 move to gpt-3.5-turbo-1106 2023-12-05 10:28:27 -08:00
Paul Gauthier
6ebc142377 roughed in openai 1.x 2023-12-05 07:37:05 -08:00
Your Name
3e81cb1c6b Fixes #374 - test_main.py += unit test for --message flag.
Fixes https://github.com/paul-gauthier/aider/issues/374
2023-11-30 13:20:22 +01:00
Paul Gauthier
bf6cd8294e handle submodules (or other dirs) which are git tracked #336 2023-11-15 13:34:29 -08:00
Paul Gauthier
d54f883698 do not include added files in the repo map #315 2023-11-15 13:06:22 -08:00
Paul Gauthier
95fe1be4c5 /add and /drop should work on untracked files in a repo (without committing them) 2023-11-15 13:06:22 -08:00
Paul Gauthier
5dd7287ee3 fixed test for windows 2023-11-14 13:19:57 -08:00
Paul Gauthier
6c77c32d06 aider: Refactored test_check_gitignore to use a temporary git config file and set the GIT_CONFIG_GLOBAL environment variable during the test execution.
# Aider chat conversation:

USER: in `test_check_gitignore` can we have gitpython not use the global gitignore?

ASSISTANT: To ensure that GitPython does not use the global gitignore, we can set the `GIT_CONFIG_GLOBAL` environment variable to point to a non-existent file or an empty temporary file during the test execution. This will effectively ignore the global gitignore settings.

We will modify the `test_check_gitignore` method in the `tests/test_main.py` file to set the `GIT_CONFIG_GLOBAL` environment variable before the test runs and reset it after the test is completed.

Here are the *SEARCH/REPLACE* blocks:

tests/test_main.py
```python
<<<<<<< SEARCH
    def test_check_gitignore(self):
        make_repo()
        io = InputOutput(pretty=False, yes=True)
        cwd = Path.cwd()
        gitignore = cwd / ".gitignore"

        self.assertFalse(gitignore.exists())
        check_gitignore(cwd, io)
        self.assertTrue(gitignore.exists())

        self.assertEqual(".aider*", gitignore.read_text().splitlines()[0])

        gitignore.write_text("one\ntwo\n")
        check_gitignore(cwd, io)
        self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text())
=======
    def test_check_gitignore(self):
        with tempfile.NamedTemporaryFile() as temp_gitconfig:
            os.environ['GIT_CONFIG_GLOBAL'] = temp_gitconfig.name
            make_repo()
            io = InputOutput(pretty=False, yes=True)
            cwd = Path.cwd()
            gitignore = cwd / ".gitignore"

            self.assertFalse(gitignore.exists())
            check_gitignore(cwd, io)
            self.assertTrue(gitignore.exists())

            self.assertEqual(".aider*", gitignore.read_text().splitlines()[0])

            gitignore.write_text("one\ntwo\n")
            check_gitignore(cwd, io)
            self.assertEqual("one\ntwo\n.aider*\n", gitignore.read_text())
            del os.environ['GIT_CONFIG_GLOBAL']
>>>>>>> REPLACE
```

This change will create a temporary file to act as a dummy global git configuration file and set the `GIT_CONFIG_GLOBAL` environment variable to its path. After the test, it will delete the environment variable to avoid affecting other tests or operations.
2023-11-14 13:05:47 -08:00
Paul Gauthier
f3d3815201 Armor AutoCompleter against unicode errors #305 2023-11-03 07:26:21 -07:00
Paul Gauthier
997d7a995d cleanup inside GitTemporaryDirectory 2023-11-02 16:24:28 -07:00
Paul Gauthier
6b3342a150 really cleanup for winsows 2023-11-02 16:20:04 -07:00
Paul Gauthier
a7e89ea965 commit the dirty repo 2023-11-02 16:11:26 -07:00
Paul Gauthier
2e232b1d20 Ignore PermissionError when testing too 2023-11-02 16:07:08 -07:00
Paul Gauthier
d720bfe459 Properly test if /added file is already in the repo #314 2023-11-02 15:50:30 -07:00
Paul Gauthier
2609ec1b06 find_original_update_blocks now accepts fence param, raises on mangled <source>filename.ext #317 2023-11-02 12:05:39 -07:00
Paul Gauthier
6556265c23 added test for #310 2023-11-02 09:45:16 -07:00
paul-gauthier
41435228a3
Update test_commands.py 2023-10-25 16:00:20 -07:00
Paul Gauthier
b6142af12b make sure **.txt does not crash chat #293 2023-10-25 15:52:26 -07:00
Paul Gauthier
95f2b4546e fixed tests 2023-10-25 15:31:23 -07:00
Paul Gauthier
277a92b3c6 fixed tests 2023-10-25 15:30:33 -07:00
Paul Gauthier
3299d90317 Handle successive editblocks from same file w/o filename #267 2023-10-22 11:28:22 -07:00
Paul Gauthier
4654e81241 Merge branch 'main' into sitter-map 2023-10-20 08:05:33 -07:00
Paul Gauthier
6791bc19c6 added test for --encoding 2023-10-20 08:04:02 -07:00
Paul Gauthier
7929e825e7 fixed test 2023-10-19 15:27:51 -07:00
Paul Gauthier
c0375d3328 fix tests; fix off-by-one bug in output of repomap 2023-10-18 15:42:38 -07:00
Paul Gauthier
1085549548 Give up testing aiderignore caching in github actions 2023-10-18 12:28:24 -07:00
Paul Gauthier
df27007c00 wtf 2023-10-18 12:22:01 -07:00