Co-authored-by: Antoine <33425718+anth2o@users.noreply.github.com>
Co-authored-by: Bastien <bastien.baret@gmail.com>
Co-authored-by: Clément Sirieix <clement.sirieix@mistral.ai>
Co-authored-by: Kim-Adeline Miguel <51720070+kimadeline@users.noreply.github.com>
Co-authored-by: Mathias Gesbert <mathias.gesbert@mistral.ai>
Co-authored-by: Maxime Dolores <maxime.dolores@ext.mistral.ai>
Co-authored-by: Michel Thomazo <51709227+michelTho@users.noreply.github.com>
Co-authored-by: Nelson PROIA <144663685+Nelson-PROIA@users.noreply.github.com>
Co-authored-by: Pierre Rossinès <pierre.rossines@mistral.ai>
Co-authored-by: Quentin <quentin.torroba@mistral.ai>
Co-authored-by: Robin Gullo <robin.gullo@mistral.ai>
Co-authored-by: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
Clément Drouin 2026-04-28 17:44:07 +02:00 committed by GitHub
parent a83c81ecf5
commit 632ea8c032
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
253 changed files with 13965 additions and 2525 deletions

View file

@ -2,8 +2,10 @@ from __future__ import annotations
import json
from pathlib import Path
import tomllib
import pytest
import tomli_w
from vibe.cli.update_notifier.adapters.filesystem_update_cache_repository import (
FileSystemUpdateCacheRepository,
@ -11,11 +13,21 @@ from vibe.cli.update_notifier.adapters.filesystem_update_cache_repository import
from vibe.cli.update_notifier.ports.update_cache_repository import UpdateCache
def _write_cache_toml(base: Path, data: dict) -> None:
with (base / "cache.toml").open("wb") as f:
tomli_w.dump(data, f)
@pytest.mark.asyncio
async def test_reads_cache_from_file_when_present(tmp_path: Path) -> None:
cache_file = tmp_path / "update_cache.json"
cache_file.write_text(
json.dumps({"latest_version": "1.2.3", "stored_at_timestamp": 1_700_000_000})
async def test_reads_cache_from_toml_when_present(tmp_path: Path) -> None:
_write_cache_toml(
tmp_path,
{
"update_cache": {
"latest_version": "1.2.3",
"stored_at_timestamp": 1_700_000_000,
}
},
)
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
@ -28,61 +40,70 @@ async def test_reads_cache_from_file_when_present(tmp_path: Path) -> None:
@pytest.mark.asyncio
async def test_returns_none_when_cache_file_is_missing(tmp_path: Path) -> None:
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is None
@pytest.mark.asyncio
async def test_returns_none_when_cache_file_is_corrupted(tmp_path: Path) -> None:
cache_dir = tmp_path / ".vibe"
cache_dir.mkdir()
(cache_dir / "update_cache.json").write_text("{not-json")
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is None
@pytest.mark.asyncio
async def test_overwrites_existing_cache(tmp_path: Path) -> None:
cache_file = tmp_path / "update_cache.json"
cache_file.write_text(
async def test_falls_back_to_json_when_toml_missing(tmp_path: Path) -> None:
(tmp_path / "update_cache.json").write_text(
json.dumps({"latest_version": "1.0.0", "stored_at_timestamp": 1_600_000_000})
)
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
await repository.set(
UpdateCache(latest_version="1.1.0", stored_at_timestamp=1_700_200_000)
)
content = json.loads(cache_file.read_text())
assert content["latest_version"] == "1.1.0"
assert content["stored_at_timestamp"] == 1_700_200_000
assert content.get("seen_whats_new_version") is None
@pytest.mark.asyncio
async def test_reads_cache_with_seen_whats_new_version(tmp_path: Path) -> None:
cache_file = tmp_path / "update_cache.json"
cache_file.write_text(
json.dumps({
"latest_version": "1.2.3",
"stored_at_timestamp": 1_700_000_000,
"seen_whats_new_version": "1.2.0",
})
)
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is not None
assert cache.latest_version == "1.2.3"
assert cache.stored_at_timestamp == 1_700_000_000
assert cache.latest_version == "1.0.0"
assert cache.stored_at_timestamp == 1_600_000_000
@pytest.mark.asyncio
async def test_returns_none_when_no_cache_exists(tmp_path: Path) -> None:
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is None
@pytest.mark.asyncio
async def test_returns_none_when_toml_is_corrupted(tmp_path: Path) -> None:
(tmp_path / "cache.toml").write_text("{not-toml")
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is None
@pytest.mark.asyncio
async def test_set_writes_to_toml(tmp_path: Path) -> None:
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
await repository.set(
UpdateCache(latest_version="1.1.0", stored_at_timestamp=1_700_200_000)
)
with (tmp_path / "cache.toml").open("rb") as f:
data = tomllib.load(f)
assert data["update_cache"]["latest_version"] == "1.1.0"
assert data["update_cache"]["stored_at_timestamp"] == 1_700_200_000
assert data["update_cache"].get("seen_whats_new_version") is None
@pytest.mark.asyncio
async def test_reads_cache_with_seen_whats_new_version(tmp_path: Path) -> None:
_write_cache_toml(
tmp_path,
{
"update_cache": {
"latest_version": "1.2.3",
"stored_at_timestamp": 1_700_000_000,
"seen_whats_new_version": "1.2.0",
}
},
)
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is not None
assert cache.seen_whats_new_version == "1.2.0"
@ -98,22 +119,43 @@ async def test_writes_cache_with_seen_whats_new_version(tmp_path: Path) -> None:
)
)
cache_file = tmp_path / "update_cache.json"
content = json.loads(cache_file.read_text())
assert content["latest_version"] == "1.1.0"
assert content["stored_at_timestamp"] == 1_700_200_000
assert content["seen_whats_new_version"] == "1.1.0"
with (tmp_path / "cache.toml").open("rb") as f:
data = tomllib.load(f)
assert data["update_cache"]["seen_whats_new_version"] == "1.1.0"
@pytest.mark.asyncio
async def test_silently_ignores_errors_when_writing_cache_fails(tmp_path: Path) -> None:
cache_dir = tmp_path / ".vibe"
cache_dir.mkdir()
(cache_dir / "update_cache.json").mkdir()
async def test_set_preserves_other_sections(tmp_path: Path) -> None:
_write_cache_toml(tmp_path, {"feedback": {"last_shown_at": 123.0}})
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
await repository.set(
UpdateCache(latest_version="1.2.0", stored_at_timestamp=1_700_300_000)
UpdateCache(latest_version="2.0.0", stored_at_timestamp=1_800_000_000)
)
assert (cache_dir / "update_cache.json").is_dir()
with (tmp_path / "cache.toml").open("rb") as f:
data = tomllib.load(f)
assert data["feedback"]["last_shown_at"] == 123.0
assert data["update_cache"]["latest_version"] == "2.0.0"
@pytest.mark.asyncio
async def test_prefers_toml_over_json(tmp_path: Path) -> None:
_write_cache_toml(
tmp_path,
{
"update_cache": {
"latest_version": "2.0.0",
"stored_at_timestamp": 1_800_000_000,
}
},
)
(tmp_path / "update_cache.json").write_text(
json.dumps({"latest_version": "1.0.0", "stored_at_timestamp": 1_600_000_000})
)
repository = FileSystemUpdateCacheRepository(base_path=tmp_path)
cache = await repository.get()
assert cache is not None
assert cache.latest_version == "2.0.0"