Some checks failed
E2E Tests / e2e (push) Waiting to run
Tests unitaires / Web (Angular · vitest + couverture) (push) Successful in 26s
Build & Push Images / tests (push) Failing after 13s
Build & Push Images / build (brain) (push) Has been skipped
Build & Push Images / build (core) (push) Has been skipped
Build & Push Images / build (web) (push) Has been skipped
Build & Push Images / build-switcher (push) Has been skipped
Tests unitaires / Brain (Python · pytest + couverture) (push) Successful in 1m12s
Tests unitaires / Core (Java · mvn test + JaCoCo) (push) Failing after 1m28s
Mise en place de tests unitaires coté Python et Angular Mise en place de la couverture de test directement dans le workflow : le programme ne build pas si jamais un test échoue Passage en v0.16.2 en conséquence
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
"""Tests des overrides runtime persistés (app.core.settings_store).
|
|
|
|
Le chemin du fichier est redirigé vers un tmp_path pour isoler chaque test.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
from app.core import settings_store
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def isolated_store(tmp_path, monkeypatch):
|
|
monkeypatch.setattr(settings_store, "_OVERRIDES_PATH", tmp_path / "settings.json")
|
|
return tmp_path / "settings.json"
|
|
|
|
|
|
def test_load_missing_file_returns_empty():
|
|
assert settings_store.load_overrides() == {}
|
|
|
|
|
|
def test_save_filters_to_allowlist_and_persists(isolated_store):
|
|
result = settings_store.save_overrides({
|
|
"llm_model": "gemma3:12b",
|
|
"internal_shared_secret": "HACK", # hors allow-list → ignoré
|
|
"champ_inconnu": "x", # hors allow-list → ignoré
|
|
})
|
|
assert result == {"llm_model": "gemma3:12b"}
|
|
on_disk = json.loads(Path(isolated_store).read_text(encoding="utf-8"))
|
|
assert on_disk == {"llm_model": "gemma3:12b"}
|
|
|
|
|
|
def test_save_merges_with_existing():
|
|
settings_store.save_overrides({"llm_model": "a"})
|
|
merged = settings_store.save_overrides({"llm_provider": "ollama"})
|
|
assert merged == {"llm_model": "a", "llm_provider": "ollama"}
|
|
|
|
|
|
def test_load_ignores_non_allowlisted_keys_on_disk(isolated_store):
|
|
Path(isolated_store).write_text(
|
|
json.dumps({"llm_model": "ok", "internal_shared_secret": "leak"}),
|
|
encoding="utf-8",
|
|
)
|
|
assert settings_store.load_overrides() == {"llm_model": "ok"}
|
|
|
|
|
|
def test_load_corrupted_file_returns_empty(isolated_store):
|
|
Path(isolated_store).write_text("{ pas du json", encoding="utf-8")
|
|
assert settings_store.load_overrides() == {}
|
|
|
|
|
|
def test_load_non_dict_json_returns_empty(isolated_store):
|
|
Path(isolated_store).write_text("[1, 2, 3]", encoding="utf-8")
|
|
assert settings_store.load_overrides() == {}
|