aider/tests
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
..
__init__.py aider: Added empty __init__.py file to tests directory to fix ModuleNotFoundError when running tests. 2023-05-11 17:12:42 -07:00
test_coder.py unified diffs 2023-12-17 12:54:34 -08:00
test_commands.py aider: Add test case for undo command with dirty files not in last commit. 2024-01-02 08:47:58 -08:00
test_editblock.py find_original_update_blocks now accepts fence param, raises on mangled <source>filename.ext #317 2023-11-02 12:05:39 -07:00
test_io.py unified diffs 2023-12-17 12:54:34 -08:00
test_main.py unified diffs 2023-12-17 12:54:34 -08:00
test_models.py fixed test_models 2023-12-05 10:56:03 -08:00
test_repo.py unified diffs 2023-12-17 12:54:34 -08:00
test_repomap.py unified diffs 2023-12-17 12:54:34 -08:00
test_sendchat.py Revert "implement deployment id" 2023-12-06 09:20:53 -08:00
test_udiff.py added basic test coverage for find_diffs 2023-12-31 09:54:01 -08:00
test_wholefile.py fixed test_wholefile 2023-12-05 11:11:48 -08:00