Spaces:
Running
Running
| from pathlib import Path | |
| from app.persistence import PersistenceStore | |
| def test_persistence_falls_back_when_configured_path_is_not_directory( | |
| tmp_path: Path, | |
| monkeypatch, | |
| ) -> None: | |
| blocked_path = tmp_path / "blocked-target" | |
| blocked_path.write_text("not-a-directory", encoding="utf-8") | |
| monkeypatch.setenv("STORAGE_ENABLED", "true") | |
| monkeypatch.setenv("OPENENV_DATA_DIR", str(blocked_path)) | |
| monkeypatch.delenv("STORAGE_DATA_DIR", raising=False) | |
| store = PersistenceStore(repo_root=tmp_path) | |
| expected_dir = (tmp_path / "outputs" / "persist").resolve() | |
| assert store.enabled is True | |
| assert store.data_dir == expected_dir | |
| assert store.db_path.exists() | |
| assert store.training_runs_dir.exists() | |
| def test_persistence_is_disabled_via_env(tmp_path: Path, monkeypatch) -> None: | |
| monkeypatch.setenv("STORAGE_ENABLED", "false") | |
| monkeypatch.delenv("OPENENV_DATA_DIR", raising=False) | |
| monkeypatch.delenv("STORAGE_DATA_DIR", raising=False) | |
| store = PersistenceStore(repo_root=tmp_path) | |
| assert store.enabled is False | |
| assert store.data_dir == (tmp_path / "outputs" / "persist").resolve() | |
| assert not store.db_path.exists() | |