AbanteAI / mentat

Mentat - The AI Coding Assistant
https://mentat.ai
Apache License 2.0
2.53k stars 233 forks source link

Fix `test_start_project_from_scratch` benchmark #71

Closed waydegg closed 1 year ago

waydegg commented 1 year ago

The test_start_project_from_scratch is raising a FileNotFoundError on the main branch.

It's looking for calculator.py which shouldn't be needed in this test anyways 😕

===================================== test session starts ======================================
platform darwin -- Python 3.11.4, pytest-7.4.0, pluggy-1.2.0
rootdir: /Users/waydegg/ghq/github.com/biobootloader/mentat
plugins: reportlog-0.4.0, mock-3.11.1, repeat-0.9.1
collected 34 items

tests/benchmark_test.py ....F                                                            [100%]

=========================================== FAILURES ===========================================
_______________________________ test_start_project_from_scratch ________________________________

mock_collect_user_input = <MagicMock id='4711084368'>

    def test_start_project_from_scratch(mock_collect_user_input):
        # Clear the testbed so we can test that it works with empty directories
        for item in os.listdir("."):
            if os.path.isfile(item):
                os.remove(item)
            elif os.path.isdir(item):
                if item != ".git":
                    shutil.rmtree(item)

        mock_collect_user_input.side_effect = [
            "make a file that does fizzbuzz, named fizzbuzz.py, going up to 10",
            "y",
            KeyboardInterrupt,
        ]
>       run(["."])

/Users/waydegg/ghq/github.com/biobootloader/mentat/tests/benchmark_test.py:126:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/app.py:70: in run
    loop(paths, exclude_paths, cost_tracker)
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/app.py:92: in loop
    code_file_manager = CodeFileManager(
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/code_file_manager.py:110: in __init__
    self._set_file_paths(paths, exclude_paths)
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/code_file_manager.py:143: in _set_file_paths
    file_paths_direct, file_paths_from_dirs = _abs_file_paths_from_list(
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/code_file_manager.py:90: in _abs_file_paths_from_list
    file_paths_from_dirs.update(
/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/code_file_manager.py:92: in <lambda>
    lambda f: (not check_for_text) or _is_file_text_encoded(f),
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

file_path = '/private/var/folders/f0/l3msd5g16kn5vkkrdy0hbsnw0000gn/T/tmphjm0i8zm/testbed/multifile_calculator/calculator.py'

    def _is_file_text_encoded(file_path):
        try:
            # The ultimate filetype test
>           with open(file_path) as f:
E           FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/f0/l3msd5g16kn5vkkrdy0hbsnw0000gn/T/tmphjm0i8zm/testbed/multifile_calculator/calculator.py'

/Users/waydegg/ghq/github.com/biobootloader/mentat/mentat/code_file_manager.py:65: FileNotFoundError
------------------------------------- Captured stdout call -------------------------------------

Total session cost: $0.00
=================================== short test summary info ====================================
FAILED tests/benchmark_test.py::test_start_project_from_scratch - FileNotFoundError: [Errno 2] No such file or directory: '/private/var/folders/f0/l3msd5g16k...
=========================== 1 failed, 4 passed in 126.61s (0:02:06) ============================
waydegg commented 1 year ago

So it looks like we aren't clearing the testbed properly. git ls-files shows a bunch of files that were removed here:

https://github.com/biobootloader/mentat/blob/3a77290355f8797971f83bbeaa172a41d8189bfe/tests/benchmark_test.py#L113-L120

These file's aren't removed from the .git cache, so that's why we're getting outdated info from ls-files.

waydegg commented 1 year ago

Created a PR for this #72

biobootloader commented 1 year ago

Nice writeup, thanks!