vibe/tests/autocompletion/test_path_completer_recursive.py
Quentin Torroba fa15fc977b Initial commit
Co-Authored-By: Quentin Torroba <quentin.torroba@mistral.ai>
Co-Authored-By: Laure Hugo <laure.hugo@mistral.ai>
Co-Authored-By: Benjamin Trom <benjamin.trom@mistral.ai>
Co-Authored-By: Mathias Gesbert <mathias.gesbert@ext.mistral.ai>
Co-Authored-By: Michel Thomazo <michel.thomazo@mistral.ai>
Co-Authored-By: Clément Drouin <clement.drouin@mistral.ai>
Co-Authored-By: Vincent Guilloux <vincent.guilloux@mistral.ai>
Co-Authored-By: Valentin Berard <val@mistral.ai>
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
2025-12-09 13:13:22 +01:00

69 lines
2.4 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from vibe.core.autocompletion.completers import PathCompleter
@pytest.fixture()
def file_tree(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Path:
(tmp_path / "vibe" / "acp").mkdir(parents=True)
(tmp_path / "vibe" / "acp" / "entrypoint.py").write_text("")
(tmp_path / "vibe" / "acp" / "agent.py").write_text("")
(tmp_path / "vibe" / "cli" / "autocompletion").mkdir(parents=True)
(tmp_path / "vibe" / "cli" / "autocompletion" / "fuzzy.py").write_text("")
(tmp_path / "vibe" / "cli" / "autocompletion" / "completers.py").write_text("")
(tmp_path / "tests" / "autocompletion").mkdir(parents=True)
(tmp_path / "tests" / "autocompletion" / "test_fuzzy.py").write_text("")
(tmp_path / "README.md").write_text("")
monkeypatch.chdir(tmp_path)
return tmp_path
def test_finds_files_recursively_by_filename(file_tree: Path) -> None:
results = PathCompleter().get_completions("@entryp", cursor_pos=7)
assert results[0] == "@vibe/acp/entrypoint.py"
def test_finds_files_recursively_by_partial_path(file_tree: Path) -> None:
results = PathCompleter().get_completions("@acp/entry", cursor_pos=10)
assert results[0] == "@vibe/acp/entrypoint.py"
def test_finds_files_recursively_with_subsequence(file_tree: Path) -> None:
results = PathCompleter().get_completions("@acp/ent", cursor_pos=9)
assert results[0] == "@vibe/acp/entrypoint.py"
def test_finds_multiple_matches_recursively(file_tree: Path) -> None:
results = PathCompleter().get_completions("@fuzzy", cursor_pos=6)
vibe_index = results.index("@vibe/cli/autocompletion/fuzzy.py")
test_index = results.index("@tests/autocompletion/test_fuzzy.py")
assert vibe_index < test_index
def test_prioritizes_exact_path_matches(file_tree: Path) -> None:
results = PathCompleter().get_completions("@vibe/acp/entrypoint", cursor_pos=20)
assert results[0] == "@vibe/acp/entrypoint.py"
def test_finds_files_when_pattern_matches_directory_name(file_tree: Path) -> None:
results = PathCompleter().get_completions("@acp", cursor_pos=4)
assert results == [
"@vibe/acp/",
"@vibe/acp/agent.py",
"@vibe/acp/entrypoint.py",
"@vibe/cli/autocompletion/completers.py",
"@tests/autocompletion/",
"@tests/autocompletion/test_fuzzy.py",
"@vibe/cli/autocompletion/",
"@vibe/cli/autocompletion/fuzzy.py",
]