Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Add file to context if it really exits but could not be expanded by g…
Browse files Browse the repository at this point in the history
…lob, which is the case of pages/[slug]/index.tsx or simillar pattern, common in nextjs (#301)

Co-authored-by: Paul Swingle <[email protected]>
  • Loading branch information
rogeriochaves and PCSwingle authored Nov 21, 2023
1 parent 2752338 commit b4a88c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mentat/include_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def expand_paths(paths: list[Path]) -> tuple[list[Path], list[str]]:
new_paths = glob.glob(pathname=str(path), recursive=True)
if new_paths:
globbed_paths.update(new_paths)
elif Path(path).exists():
globbed_paths.add(str(path))
else:
split = str(path).rsplit(":", 1)
p = Path(split[0])
Expand Down
26 changes: 26 additions & 0 deletions tests/code_context_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,32 @@ async def test_path_gitignoring(temp_testbed, mock_session_context):
case.assertListEqual(sorted(expected_file_paths), sorted(file_paths))


@pytest.mark.asyncio
async def test_bracket_file(temp_testbed, mock_session_context):
file_path_1 = Path("[file].tsx")
file_path_2 = Path("test:[file].tsx")

with file_path_1.open("w") as file_1:
file_1.write("Testing")
with file_path_2.open("w") as file_2:
file_2.write("Testing")

paths = [file_path_1, file_path_2]
code_context = CodeContext(
mock_session_context.stream,
mock_session_context.git_root,
)
code_context.set_paths(paths, [])
expected_file_paths = [
temp_testbed / file_path_1,
temp_testbed / file_path_2,
]

case = TestCase()
file_paths = list(code_context.include_files.keys())
case.assertListEqual(sorted(expected_file_paths), sorted(file_paths))


@pytest.mark.asyncio
async def test_config_glob_exclude(mocker, temp_testbed, mock_session_context):
# Makes sure glob exclude config works
Expand Down

0 comments on commit b4a88c4

Please sign in to comment.