@@ -12,7 +12,11 @@ def functional_backend() -> str:
1212from fastapi import FastAPI
1313from fastapi .testclient import TestClient
1414from src .core .app .test_builder import build_test_app as build_app
15- from src .core .common .exceptions import ConfigurationError , JSONParsingError
15+ from src .core .common .exceptions import (
16+ ConfigurationError ,
17+ JSONParsingError ,
18+ ServiceResolutionError ,
19+ )
1620from src .core .config .app_config import load_config
1721from src .core .persistence import ConfigManager
1822
@@ -227,6 +231,34 @@ def test_apply_default_backend_invalid_backend_still_raises_with_cli_override(
227231 }
228232
229233
234+ def test_apply_default_backend_strict_errors_env (
235+ monkeypatch : pytest .MonkeyPatch , tmp_path : Path
236+ ) -> None :
237+ """STRICT_PERSISTENCE_ERRORS should force DI resolution failures to raise."""
238+
239+ class _StrictAppState (_DummyAppState ):
240+ def set_backend_type (self , backend_type : str | None ) -> None : # type: ignore[override]
241+ self .backend_type = backend_type
242+
243+ class _FailingProvider :
244+ def get_required_service (self , _service_type ): # type: ignore[no-untyped-def]
245+ raise ServiceResolutionError ("boom" )
246+
247+ monkeypatch .setenv ("STRICT_PERSISTENCE_ERRORS" , "true" )
248+
249+ manager = ConfigManager (
250+ FastAPI (),
251+ path = str (tmp_path / "config.json" ),
252+ service_provider = _FailingProvider (),
253+ app_state = _StrictAppState (),
254+ )
255+
256+ with pytest .raises (ServiceResolutionError ):
257+ manager ._apply_default_backend ("openai" )
258+
259+ monkeypatch .delenv ("STRICT_PERSISTENCE_ERRORS" , raising = False )
260+
261+
230262def test_load_raises_json_parsing_error_for_invalid_json (tmp_path : Path ) -> None :
231263 cfg_path = tmp_path / "config.json"
232264 cfg_path .write_text ("{not: valid json}" )
0 commit comments