Commit graph

1261 commits

Author SHA1 Message Date
Paul Gauthier
f683e76332 copy 2023-05-27 18:10:45 -07:00
Paul Gauthier
52a9df5b34 aider: Added a test function to check if the pretty attribute of the InputOutput class is set to False when the NO_COLOR environment variable is set.
# Context:
USER: add a test for NO_COLOR
ASSISTANT: To add a test for the `NO_COLOR` environment variable, we will create a new test function in the `tests/test_io.py` file. Since this file does not exist, we will create it first.

```python
tests/test_io.py
<<<<<<< ORIGINAL
=======
import os
import unittest
from unittest.mock import patch
from aider.io import InputOutput

class TestInputOutput(unittest.TestCase):
    def test_no_color_environment_variable(self):
        with patch.dict(os.environ, {"NO_COLOR": "1"}):
            io = InputOutput()
            self.assertFalse(io.pretty)

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This test function checks if the `pretty` attribute of the `InputOutput` class is set to `False` when the `NO_COLOR` environment variable is set.
2023-05-27 18:07:52 -07:00
Paul Gauthier
9ce90d059a copy 2023-05-27 18:04:05 -07:00
Paul Gauthier
4b8fff69cb copy 2023-05-27 18:01:58 -07:00
Paul Gauthier
321824299a aider: Added check for NO_COLOR environment variable to disable ANSI color.
# Context:
USER: Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color.
ASSISTANT: To implement this feature, we need to modify the `aider/io.py` file. Please make it *read-write* so I can provide the necessary changes.
USER: I added these *read-write* files: aider/io.py
ASSISTANT: Great! Now, I will make the necessary changes to check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string.

```python
aider/io.py
<<<<<<< ORIGINAL
import os
=======
import os
import os.path
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        self.user_input_color = user_input_color
        self.tool_output_color = tool_output_color
        self.tool_error_color = tool_error_color
        self.input = input
        self.output = output
        self.pretty = pretty
        self.yes = yes
        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        if pretty:
            self.console = Console()
        else:
            self.console = Console(force_terminal=True, no_color=True)
=======
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        user_input_color="blue",
        tool_output_color=None,
        tool_error_color="red",
    ):
        no_color = os.environ.get("NO_COLOR")
        if no_color is not None and no_color != "":
            pretty = False

        self.user_input_color = user_input_color if pretty else None
        self.tool_output_color = tool_output_color if pretty else None
        self.tool_error_color = tool_error_color if pretty else None
        self.input = input
        self.output = output
        self.pretty = pretty
        self.yes = yes
        self.input_history_file = input_history_file
        if chat_history_file is not None:
            self.chat_history_file = Path(chat_history_file)
        else:
            self.chat_history_file = None

        self.console = Console(force_terminal=not pretty, no_color=not pretty)
>>>>>>> UPDATED
```

These changes will make the software check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string.
2023-05-27 17:57:32 -07:00
Paul Gauthier
ffaa28cb7b new gif 2023-05-27 17:34:25 -07:00
Paul Gauthier
80bf696428 new gif 2023-05-27 17:31:02 -07:00
Paul Gauthier
3dacaf65b1 copy 2023-05-27 17:28:28 -07:00
Paul Gauthier
cd735f243b new gif 2023-05-27 17:13:05 -07:00
Paul Gauthier
bd78789bd2 Fixed quote stripping of gpt3.5 commit messages 2023-05-27 17:05:57 -07:00
Paul Gauthier
3d8ecddb3f aider: Added a test method to check if get_commit_message returns the expected message when send method is mocked.
# Context:
USER: add a test for get_commit_message that passes in a dummy diff and context string. mock coder.send to return "a good commit message",False. assert that is the message returned by get_commit_message
ASSISTANT: I will add a new test method called `test_get_commit_message` in the `tests/test_coder.py` file.

```python
tests/test_coder.py
<<<<<<< ORIGINAL

if __name__ == "__main__":
    unittest.main()
=======
    def test_get_commit_message(self):
        # Mock the IO object
        mock_io = MagicMock()

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Mock the send method to return a tuple with a message and False
        coder.send = MagicMock(return_value=("a good commit message", False))

        # Call the get_commit_message method with dummy diff and context
        result = coder.get_commit_message("dummy diff", "dummy context")

        # Assert that the returned message is the expected one
        self.assertEqual(result, "a good commit message")

if __name__ == "__main__":
    unittest.main()
>>>>>>> UPDATED
```

This new test method mocks the `send` method of the `Coder` object to return a predefined commit message and checks if the `get_commit_message` method returns the expected message.
2023-05-27 17:03:27 -07:00
Paul Gauthier
41222d9c1f new gif 2023-05-27 16:55:46 -07:00
Paul Gauthier
b0ba9cdaa1 new gif 2023-05-27 16:35:07 -07:00
Paul Gauthier
fb2cedb043 new gif 2023-05-27 16:31:48 -07:00
Paul Gauthier
e3f34d710c moved screenshots to assets 2023-05-27 16:31:07 -07:00
Paul Gauthier
2ec6757f86 aider: Added new arguments --user-input-color, --tool-output-color, and --tool-error-color to main function and passed them to InputOutput class.
# Context:
USER: add args --user-input-color default green, --tool-output-color default None and --tool-error-color default red. pass them to InputOutput
ASSISTANT: I will add the new arguments to the `main` function and pass them to the `InputOutput` class.

```python
aider/main.py
<<<<<<< ORIGINAL
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
=======
    parser.add_argument(
        "--pretty",
        action="store_true",
        default=True,
        help="Enable pretty, colorized output (default: True)",
    )
    parser.add_argument(
        "--no-pretty",
        action="store_false",
        dest="pretty",
        help="Disable pretty, colorized output",
    )
    parser.add_argument(
        "--user-input-color",
        default="green",
        help="Set the color for user input (default: green)",
    )
    parser.add_argument(
        "--tool-output-color",
        default=None,
        help="Set the color for tool output (default: None)",
    )
    parser.add_argument(
        "--tool-error-color",
        default="red",
        help="Set the color for tool error messages (default: red)",
    )
>>>>>>> UPDATED
```

```python
aider/main.py
<<<<<<< ORIGINAL
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
    )
=======
    io = InputOutput(
        args.pretty,
        args.yes,
        args.input_history_file,
        args.chat_history_file,
        input=input,
        output=output,
        user_input_color=args.user_input_color,
        tool_output_color=args.tool_output_color,
        tool_error_color=args.tool_error_color,
    )
>>>>>>> UPDATED
```

Now the new arguments are added and passed to the `InputOutput` class.
2023-05-27 15:21:57 -07:00
Paul Gauthier
0fa660066f color the hrule 2023-05-27 15:19:53 -07:00
Paul Gauthier
70b912250a rename 2023-05-27 15:18:31 -07:00
Paul Gauthier
b8e480d699 rename 2023-05-27 15:18:13 -07:00
Paul Gauthier
cc9b21df06 renamed io.tool() -> io.tool_output() 2023-05-27 15:17:33 -07:00
Paul Gauthier
f6d07d9849 Accept colors for various prompts 2023-05-27 15:14:56 -07:00
Paul Gauthier
03cc679a5b aider: Added tool_color and tool_error_color properties to InputOutput class and updated style and console print accordingly.
# Context:
USER: move the red and green colors for tool and tool_error into self. properties. add args to init with red and green defaults.
ASSISTANT: To make the changes, I will modify the `aider/io.py` file. Here are the changes:

```python
aider/io.py
<<<<<<< ORIGINAL
class InputOutput:
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
    ):
=======
class InputOutput:
    def __init__(
        self,
        pretty=True,
        yes=False,
        input_history_file=None,
        chat_history_file=None,
        input=None,
        output=None,
        tool_color="green",
        tool_error_color="red",
    ):
        self.tool_color = tool_color
        self.tool_error_color = tool_error_color
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        style = Style.from_dict({"": "green"})
=======
        style = Style.from_dict({"": self.tool_color})
>>>>>>> UPDATED
```

```python
aider/io.py
<<<<<<< ORIGINAL
        self.console.print(message, style="red")
=======
        self.console.print(message, style=self.tool_error_color)
>>>>>>> UPDATED
```
2023-05-27 14:54:04 -07:00
Paul Gauthier
387477d5c2 try running all tests w/ctags 2023-05-27 14:16:58 -07:00
Paul Gauthier
a84f93b9e4 aider: Added step to install "universal ctags" before installing Python dependencies.
# Context:
USER: i need to install the "universal ctags" binary in ubuntu before i run tests
ASSISTANT: To install the "universal ctags" binary in Ubuntu before running tests, you can add a new step in the `.github/workflows/python-tests.yml` file.

```yaml
.github/workflows/python-tests.yml
<<<<<<< ORIGINAL
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
=======
    - name: Install universal ctags
      run: |
        sudo apt-get update
        sudo apt-get install -y universal-ctags

    - name: Install dependencies
      run: |
        python
^C KeyboardInterrupt
USER: sorry, do that again
ASSISTANT: Sure, here's the updated step to install "universal ctags" in the `.github/workflows/python-tests.yml` file.

```yaml
.github/workflows/python-tests.yml
<<<<<<< ORIGINAL
    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
=======
    - name: Install universal ctags
      run: |
        sudo apt-get update
        sudo apt-get install -y universal-ctags

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt
>>>>>>> UPDATED
```

This change adds a new step to install "universal ctags" before installing the Python dependencies.
2023-05-27 14:16:41 -07:00
Paul Gauthier
9d1b4a9f5d aider: Changed approach to exclude specific test case using unittest module.
# Context:
USER: the  -k 'not test_get_tags_map_with_identifiers' seems to have made it skip all the tests
ASSISTANT: It seems that the `-k` flag with the `not` expression is not working as expected. Let's change the approach and use the `unittest` module to exclude the specific test case. We'll modify the `python-tests.yml` file to achieve this.

```yaml
.github/workflows/python-tests.yml
<<<<<<< ORIGINAL
    - name: Run tests excluding test_get_tags_map_with_identifiers
      run: |
        python -m unittest discover -k 'not test_get_tags_map_with_identifiers'
=======
    - name: Run tests excluding test_get_tags_map_with_identifiers
      run: |
        python -c "import unittest; loader = unittest.TestLoader(); suite = loader.discover('.'); suite_filtered = unittest.TestSuite([t for t in suite if 'test_get_tags_map_with_identifiers' not in str(t)]); unittest.TextTestRunner().run(suite_filtered)"
>>>>>>> UPDATED
```

This change will discover all tests, filter out the `test_get_tags_map_with_identifiers` test case, and then run the remaining tests.
2023-05-27 14:08:32 -07:00
Paul Gauthier
42e4e6b0ca aider: Added dummy values for user.email and user.name after running git init in test_main_with_empty_git_dir_new_file function.
# Context:
USER: after git init, git config user.email and user.name with dummy values
ASSISTANT: I understand that you want to set dummy values for `user.email` and `user.name` after running `git init`. I will make the necessary changes in the `test_main_with_empty_git_dir_new_file` function in the `tests/test_main.py` file.

```python
tests/test_main.py
<<<<<<< ORIGINAL
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"], cwd=temp_dir)
            pipe_input = create_input(StringIO(""))
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
=======
    def test_main_with_empty_git_dir_new_file(self):
        with tempfile.TemporaryDirectory() as temp_dir:
            os.chdir(temp_dir)
            subprocess.run(["git", "init"], cwd=temp_dir)
            subprocess.run(["git", "config", "user.email", "dummy@example.com"], cwd=temp_dir)
            subprocess.run(["git", "config", "user.name", "Dummy User"], cwd=temp_dir)
            pipe_input = create_input(StringIO(""))
            main(["--yes", "foo.txt"], input=pipe_input, output=DummyOutput())
            pipe_input.close()
            self.assertTrue(os.path.exists("foo.txt"))
>>>>>>> UPDATED
```

Now, after running `git init`, the test function will also set dummy values for `user.email` and `user.name`.
2023-05-27 14:06:09 -07:00
Paul Gauthier
81f54a0322 aider: Excluded test_get_tags_map_with_identifiers from running in GitHub Actions.
# Context:
USER: how can i exclude running test_get_tags_map_with_identifiers from tests/test_repomap.py when tests run in github actions?
ASSISTANT: To exclude the `test_get_tags_map_with_identifiers` test from running in GitHub Actions, you can modify the `python-tests.yml` file to include a command-line option for the `unittest discover` command. You can use the `-k` option to specify a pattern that matches all test methods except `test_get_tags_map_with_identifiers`.

Here's the change you need to make in the `.github/workflows/python-tests.yml` file:

```yaml
.github/workflows/python-tests.yml
<<<<<<< ORIGINAL
    - name: Run tests
      run: |
        python -m unittest discover
=======
    - name: Run tests excluding test_get_tags_map_with_identifiers
      run: |
        python -m unittest discover -k 'not test_get_tags_map_with_identifiers'
>>>>>>> UPDATED
```

This change will exclude the `test_get_tags_map_with_identifiers` test method from running when the GitHub Actions workflow is executed.
2023-05-27 14:03:10 -07:00
Paul Gauthier
0ec5c69fc4 aider: Set OPENAI_API_KEY environment variable to "deadbeef" for all tests.
# Context:
USER: set env OPENAI_API_KEY=deadbeef for all tests
ASSISTANT: To set the environment variable `OPENAI_API_KEY` for all tests, you can modify the `setUp` method in the `TestMain` class in the `tests/test_main.py` file. Here's the change:

```python
tests/test_main.py
<<<<<<< ORIGINAL
class TestMain(TestCase):
    def test_main_with_empty_dir_no_files_on_command(self):
=======
class TestMain(TestCase):
    def setUp(self):
        os.environ["OPENAI_API_KEY"] = "deadbeef"

    def test_main_with_empty_dir_no_files_on_command(self):
>>>>>>> UPDATED
```

This will set the `OPENAI_API_KEY` environment variable to "deadbeef" before running each test.
2023-05-27 13:59:48 -07:00
Paul Gauthier
775f6fc192 updated python version list 2023-05-27 13:55:37 -07:00
Paul Gauthier
35621f3b11 updated python version list 2023-05-27 13:54:32 -07:00
Paul Gauthier
8967cd6efc updated python version list 2023-05-27 13:51:45 -07:00
Paul Gauthier
203b37a051 aider: Added GitHub Actions workflow for running Python tests on push and pull request to the main branch.
# Context:
USER: how can i run my tests in ci on github?
ASSISTANT: To run your tests in a CI environment on GitHub, you can use GitHub Actions. Here's a step-by-step guide to set up a basic Python testing workflow:

1. Create a new directory named `.github` in the root of your repository if it doesn't exist.
2. Inside the `.github` directory, create another directory named `workflows`.
3. Create a new file named `python-tests.yml` inside the `workflows` directory.

Now, add the following content to the `python-tests.yml` file:

```yaml
.github/workflows/python-tests.yml
<<<<<<< ORIGINAL
=======
name: Python Tests

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.6, 3.7, 3.8, 3.9]

    steps:
    - name: Check out repository
      uses: actions/checkout@v2

    - name: Set up Python ${{ matrix.python-version }}
      uses: actions/setup-python@v2
      with:
        python-version: ${{ matrix.python-version }}

    - name: Install dependencies
      run: |
        python -m pip install --upgrade pip
        pip install -r requirements.txt

    - name: Run tests
      run: |
        python -m unittest discover
>>>>>>> UPDATED
```

This workflow will run your tests on every push and pull request to the `main` branch using Python versions 3.6, 3.7, 3.8, and 3.9.

After you've added the `python-tests.yml` file to your repository, GitHub Actions will automatically start running your tests according to the specified workflow.
2023-05-27 13:48:03 -07:00
Paul Gauthier
76c964bade copy 2023-05-27 13:46:35 -07:00
Paul Gauthier
73e1fed1d5 copy 2023-05-27 13:36:07 -07:00
Paul Gauthier
db4fc2fe23 autocomplete file paths by (unique) basenames 2023-05-27 09:09:33 -07:00
Paul Gauthier
5ba084edec auto-complete filenames 2023-05-27 08:54:10 -07:00
Paul Gauthier
40d764e9f8 removed wip: prefix from dirty commits 2023-05-27 08:49:16 -07:00
Paul Gauthier
767c241e95 Refactor rel_fnames assignment in coder.py. 2023-05-27 08:48:39 -07:00
Paul Gauthier
4bc4e6f611 aider: Updated Coder class in aider/coder.py to call the new get_input function with root parameter and rel_fnames instead of absolute file names.
# Context:
USER: update coder.py to call the new get_input
ASSISTANT: I will update the `Coder` class in the `aider/coder.py` file to call the new `get_input` function.

```python
aider/coder.py
<<<<<<< ORIGINAL
        inp = self.io.get_input(self.abs_fnames, self.commands)
=======
        rel_fnames = [os.path.relpath(fname, self.root) for fname in self.abs_fnames]
        inp = self.io.get_input(self.root, rel_fnames, self.commands)
>>>>>>> UPDATED
```

This change updates the `run_loop` method in the `Coder` class to call the new `get_input` function with the `root` parameter and the `rel_fnames` instead of the absolute file names.
2023-05-27 08:47:21 -07:00
Paul Gauthier
487040203e aider: Updated get_input to take a root param and receive rel_fnames not abs fnames, and updated FileContentCompleter to work with them.
# Context:
USER: change get_input to take a root param and receive rel_fnames not abs fnames. don't compute short_fnames, just use rel_fnames. also update FileContentCompleter to take root and rel_fnames and work with them.
ASSISTANT: To make the requested changes, I need you to provide me with *read-write* access to the following files:

1. `aider/io.py`
2. `aider/prompts.py`

Once you've granted me access to these files, I can provide you with the necessary code modifications.
USER: I added these *read-write* files: aider/io.py
ASSISTANT: Great! I will now make the changes to the `get_input` function and the `FileContentCompleter` class in the `aider/io.py` file.

```python
aider/io.py
<<<<<<< ORIGINAL
class FileContentCompleter(Completer):
    def __init__(self, fnames, commands):
        self.commands = commands

        self.words = set()
        for fname in fnames:
            with open(fname, "r") as f:
                content = f.read()
=======
class FileContentCompleter(Completer):
    def __init__(self, root, rel_fnames, commands):
        self.commands = commands

        self.words = set()
        for rel_fname in rel_fnames:
            fname = os.path.join(root, rel_fname)
            with open(fname, "r") as f:
                content = f.read()
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
    def get_input(self, fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        fnames = list(fnames)
        if len(fnames) > 1:
            common_prefix = os.path.commonpath(fnames)
            if not common_prefix.endswith(os.path.sep):
                common_prefix += os.path.sep
            short_fnames = [fname.replace(common_prefix, "", 1) for fname in fnames]
        elif len(fnames):
            short_fnames = [os.path.basename(fnames[0])]
        else:
            short_fnames = []

        show = " ".join(short_fnames)
=======
    def get_input(self, root, rel_fnames, commands):
        if self.pretty:
            self.console.rule()
        else:
            print()

        rel_fnames = list(rel_fnames)
        show = " ".join(rel_fnames)
>>>>>>> UPDATED

```python
aider/io.py
<<<<<<< ORIGINAL
            completer_instance = FileContentCompleter(fnames, commands)
=======
            completer_instance = FileContentCompleter(root, rel_fnames, commands)
>>>>>>> UPDATED
```

These changes will update the `get_input` function to take a `root` parameter and receive `rel_fnames` instead of absolute file names. The `FileContentCompleter` class is also updated to take the `root` and `rel_fnames` parameters and work with them.
2023-05-27 08:46:06 -07:00
Paul Gauthier
e19df5804c updated add prompt 2023-05-27 08:42:03 -07:00
Paul Gauthier
4fd1bf7f21 Added test_check_for_ambiguous_filename_mentions_of_longer_paths 2023-05-27 08:39:18 -07:00
Paul Gauthier
08164034ff aider: Updated check_for_file_mentions to only add a filename match if it is unambiguous and no other addable_rel_fnames have a basename that also matches.
# Context:
USER: on check_for_file_mentions, only add a fname match if it is unambiguous and no other addable_rel_fnames have a basename that also matches
ASSISTANT: To update the `check_for_file_mentions` method to only add a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches, modify the method as follows:

```python
aider/coder.py
<<<<<<< ORIGINAL
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname in words or rel_fname in words:
                mentioned_rel_fnames.add(rel_fname)
=======
        fname_to_rel_fnames = {}
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname not in fname_to_rel_fnames:
                fname_to_rel_fnames[fname] = []
            fname_to_rel_fnames[fname].append(rel_fname)

        for fname, rel_fnames in fname_to_rel_fnames.items():
            if len(rel_fnames) == 1 and (fname in words or rel_fnames[0] in words):
                mentioned_rel_fnames.add(rel_fnames[0])
>>>>>>> UPDATED
```

This change will ensure that the method only adds a filename match if it is unambiguous and no other `addable_rel_fnames` have a basename that also matches.
2023-05-27 08:34:20 -07:00
Paul Gauthier
3732f62a9c Use ./ paths for the test 2023-05-27 08:32:39 -07:00
Paul Gauthier
4dc2e6a5c8 aider: Enhanced check_for_file_mentions to match filenames without the path and add the correct fully pathed file to abs_fnames.
# Context:
USER: the test_check_for_filename_mentions_of_longer_paths is failing. because check_for_file_mentions only matches on the full path. enhance check_for_file_mentions so that if the filename is mentioned without the path, it still adds the correct fully pathed file to abs_fnames
ASSISTANT: To enhance the `check_for_file_mentions` method to match filenames without the path and add the correct fully pathed file to `abs_fnames`, update the method as follows:

```python
aider/coder.py
<<<<<<< ORIGINAL
        for word in words:
            if word in addable_rel_fnames:
                mentioned_rel_fnames.add(word)
=======
        for rel_fname in addable_rel_fnames:
            fname = os.path.basename(rel_fname)
            if fname in words or rel_fname in words:
                mentioned_rel_fnames.add(rel_fname)
>>>>>>> UPDATED
```

This change will ensure that the method matches filenames without the path and adds the correct fully pathed file to `abs_fnames`.
2023-05-27 08:31:42 -07:00
Paul Gauthier
c8cf78b5cf Added a new test to check for filename mentions of longer paths. 2023-05-27 08:30:17 -07:00
Paul Gauthier
7e75cfb1fa added missing import 2023-05-27 08:29:05 -07:00
Paul Gauthier
bcf258f1c6 aider: Modified test to check if coder.abs_fnames contains both files.
# Context:
USER: don't compare the result string. check that coder.abs_fnames now contains both files
ASSISTANT: To update the test to check if `coder.abs_fnames` contains both files, modify the test as follows:

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Check if the result is as expected
        self.assertEqual(result, "Added files: file1.txt, file2.py")
=======
        # Check if coder.abs_fnames contains both files
        expected_files = {os.path.abspath("file1.txt"), os.path.abspath("file2.py")}
        self.assertEqual(coder.abs_fnames, expected_files)
>>>>>>> UPDATED
```

This change will ensure that the test checks if `coder.abs_fnames` contains both files instead of comparing the result string.
2023-05-27 08:28:31 -07:00
Paul Gauthier
4ac2143cc2 Initialized Coder object with mocked IO and mocked repo, and updated coder.repo instead of coder.root. 2023-05-27 08:27:45 -07:00
Paul Gauthier
0fc40df8e6 aider: Replaced manual setting of abs_fnames with a mocked git.Repo object that has its ls_files method return the desired file paths.
# Context:
USER: don't set the files in abs_fnames. patch self.repo.git.ls_files to return them
ASSISTANT: To patch `self.repo.git.ls_files` to return the files in `abs_fnames`, we will modify the `test_check_for_file_mentions` function in the `tests/test_coder.py` file.

```python
tests/test_coder.py
<<<<<<< ORIGINAL
        # Initialize the Coder object with the mocked IO
        coder = Coder(io=mock_io, openai_api_key="fake_key")

        # Add sample files to the Coder object
        coder.abs_fnames = {
            "/path/to/repo/file1.txt",
            "/path/to/repo/file2.py",
        }
        coder.root = "/path/to/repo"
=======
        # Mock the git repo
        mock_repo = MagicMock()
        mock_repo.git.ls_files.return_value = "file1.txt\nfile2.py"

        # Initialize the Coder object with the mocked IO and mocked repo
        coder = Coder(io=mock_io, openai_api_key="fake_key", repo=mock_repo)
        coder.root = "/path/to/repo"
>>>>>>> UPDATED
```

This change replaces the manual setting of `abs_fnames` with a mocked `git.Repo` object that has its `ls_files` method return the desired file paths.
2023-05-27 08:26:16 -07:00