v2.2.1 (#403)
Co-authored-by: Quentin Torroba <quentin.torroba@mistral.ai> Co-authored-by: Vincent Guilloux <vincent.guilloux@mistral.ai> Co-authored-by: Thomas Kenbeek <thomas.kenbeek@mistral.ai> Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
parent
ec7f3b25ea
commit
a560a47ce8
52 changed files with 1026 additions and 562 deletions
|
|
@ -16,7 +16,7 @@ from vibe.core.autocompletion.file_indexer import FileIndexer
|
|||
|
||||
@pytest.fixture
|
||||
def file_indexer() -> Generator[FileIndexer]:
|
||||
indexer = FileIndexer()
|
||||
indexer = FileIndexer(should_enable_watcher=lambda: True)
|
||||
yield indexer
|
||||
indexer.shutdown()
|
||||
|
||||
|
|
@ -30,6 +30,20 @@ def _wait_for(condition: Callable[[], bool], timeout=3.0) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _assert_index_state_stable(
|
||||
file_indexer: FileIndexer,
|
||||
expected_entries: set[str],
|
||||
expected_incremental_updates: int,
|
||||
duration: float = 1.0,
|
||||
) -> None:
|
||||
deadline = time.monotonic() + duration
|
||||
while time.monotonic() < deadline:
|
||||
current_entries = {entry.rel for entry in file_indexer.get_index(Path("."))}
|
||||
assert current_entries == expected_entries
|
||||
assert file_indexer.stats.incremental_updates == expected_incremental_updates
|
||||
time.sleep(0.1)
|
||||
|
||||
|
||||
def test_updates_index_on_file_creation(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch, file_indexer: FileIndexer
|
||||
) -> None:
|
||||
|
|
@ -143,7 +157,9 @@ def test_rebuilds_index_when_mass_change_threshold_is_exceeded(
|
|||
# detected by the watcher
|
||||
number_of_files = mass_change_threshold * 3
|
||||
monkeypatch.chdir(tmp_path)
|
||||
indexer = FileIndexer(mass_change_threshold=mass_change_threshold)
|
||||
indexer = FileIndexer(
|
||||
mass_change_threshold=mass_change_threshold, should_enable_watcher=lambda: True
|
||||
)
|
||||
try:
|
||||
indexer.get_index(Path("."))
|
||||
rebuilds_before = indexer.stats.rebuilds
|
||||
|
|
@ -229,3 +245,101 @@ def test_shutdown_cleans_up_resources(
|
|||
|
||||
file_indexer.shutdown()
|
||||
assert file_indexer.get_index(Path(".")) == []
|
||||
|
||||
|
||||
def test_watcher_is_disabled_by_default(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
file_indexer = FileIndexer()
|
||||
try:
|
||||
baseline_entries = {entry.rel for entry in file_indexer.get_index(Path("."))}
|
||||
incremental_before = file_indexer.stats.incremental_updates
|
||||
(tmp_path / "file.py").write_text("", encoding="utf-8")
|
||||
|
||||
_assert_index_state_stable(
|
||||
file_indexer=file_indexer,
|
||||
expected_entries=baseline_entries,
|
||||
expected_incremental_updates=incremental_before,
|
||||
)
|
||||
finally:
|
||||
file_indexer.shutdown()
|
||||
|
||||
|
||||
def test_disabling_watcher_stops_runtime_updates(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
watcher_enabled = True
|
||||
file_indexer = FileIndexer(should_enable_watcher=lambda: watcher_enabled)
|
||||
try:
|
||||
tracked = tmp_path / "tracked.py"
|
||||
tracked.write_text("", encoding="utf-8")
|
||||
file_indexer.get_index(Path("."))
|
||||
assert any(
|
||||
entry.rel == "tracked.py" for entry in file_indexer.get_index(Path("."))
|
||||
)
|
||||
|
||||
watcher_enabled = False
|
||||
file_indexer.get_index(Path("."))
|
||||
|
||||
expected_entries = {entry.rel for entry in file_indexer.get_index(Path("."))}
|
||||
incremental_before = file_indexer.stats.incremental_updates
|
||||
tracked.unlink()
|
||||
|
||||
_assert_index_state_stable(
|
||||
file_indexer=file_indexer,
|
||||
expected_entries=expected_entries,
|
||||
expected_incremental_updates=incremental_before,
|
||||
)
|
||||
finally:
|
||||
file_indexer.shutdown()
|
||||
|
||||
|
||||
def _current_entries(file_indexer: FileIndexer) -> set[str]:
|
||||
return {entry.rel for entry in file_indexer.get_index(Path("."))}
|
||||
|
||||
|
||||
def _assert_created_file_is_not_indexed(
|
||||
file_indexer: FileIndexer, tmp_path: Path, filename: str
|
||||
) -> None:
|
||||
expected_entries = _current_entries(file_indexer)
|
||||
expected_incremental_updates = file_indexer.stats.incremental_updates
|
||||
(tmp_path / filename).write_text("", encoding="utf-8")
|
||||
|
||||
_assert_index_state_stable(
|
||||
file_indexer=file_indexer,
|
||||
expected_entries=expected_entries,
|
||||
expected_incremental_updates=expected_incremental_updates,
|
||||
)
|
||||
|
||||
|
||||
def _assert_created_file_is_indexed(
|
||||
file_indexer: FileIndexer, tmp_path: Path, filename: str
|
||||
) -> None:
|
||||
incremental_before = file_indexer.stats.incremental_updates
|
||||
(tmp_path / filename).write_text("", encoding="utf-8")
|
||||
|
||||
assert _wait_for(lambda: filename in _current_entries(file_indexer))
|
||||
assert file_indexer.stats.incremental_updates >= incremental_before + 1
|
||||
|
||||
|
||||
def test_watcher_toggle_flow_off_on_off(
|
||||
tmp_path: Path, monkeypatch: pytest.MonkeyPatch
|
||||
) -> None:
|
||||
monkeypatch.chdir(tmp_path)
|
||||
watcher_enabled = False
|
||||
file_indexer = FileIndexer(should_enable_watcher=lambda: watcher_enabled)
|
||||
try:
|
||||
file_indexer.get_index(Path("."))
|
||||
_assert_created_file_is_not_indexed(file_indexer, tmp_path, "off_before.py")
|
||||
|
||||
watcher_enabled = True
|
||||
file_indexer.get_index(Path("."))
|
||||
_assert_created_file_is_indexed(file_indexer, tmp_path, "on_file.py")
|
||||
|
||||
watcher_enabled = False
|
||||
file_indexer.get_index(Path("."))
|
||||
_assert_created_file_is_not_indexed(file_indexer, tmp_path, "off_after.py")
|
||||
finally:
|
||||
file_indexer.shutdown()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue