Add Dalidou storage foundation and deployment prep
This commit is contained in:
63
tests/test_config.py
Normal file
63
tests/test_config.py
Normal file
@@ -0,0 +1,63 @@
|
||||
"""Tests for configuration and canonical path boundaries."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import atocore.config as config
|
||||
|
||||
|
||||
def test_settings_resolve_canonical_directories(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("ATOCORE_DATA_DIR", str(tmp_path / "data"))
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(tmp_path / "vault-source"))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(tmp_path / "drive-source"))
|
||||
monkeypatch.setenv("ATOCORE_LOG_DIR", str(tmp_path / "logs"))
|
||||
monkeypatch.setenv("ATOCORE_BACKUP_DIR", str(tmp_path / "backups"))
|
||||
|
||||
settings = config.Settings()
|
||||
|
||||
assert settings.db_path == (tmp_path / "data" / "db" / "atocore.db").resolve()
|
||||
assert settings.chroma_path == (tmp_path / "data" / "chroma").resolve()
|
||||
assert settings.cache_path == (tmp_path / "data" / "cache").resolve()
|
||||
assert settings.tmp_path == (tmp_path / "data" / "tmp").resolve()
|
||||
assert settings.resolved_vault_source_dir == (tmp_path / "vault-source").resolve()
|
||||
assert settings.resolved_drive_source_dir == (tmp_path / "drive-source").resolve()
|
||||
assert settings.resolved_log_dir == (tmp_path / "logs").resolve()
|
||||
assert settings.resolved_backup_dir == (tmp_path / "backups").resolve()
|
||||
assert settings.resolved_run_dir == (tmp_path / "run").resolve()
|
||||
|
||||
|
||||
def test_settings_keep_legacy_db_path_when_present(tmp_path, monkeypatch):
|
||||
data_dir = tmp_path / "data"
|
||||
data_dir.mkdir()
|
||||
legacy_db = data_dir / "atocore.db"
|
||||
legacy_db.write_text("", encoding="utf-8")
|
||||
monkeypatch.setenv("ATOCORE_DATA_DIR", str(data_dir))
|
||||
|
||||
settings = config.Settings()
|
||||
|
||||
assert settings.db_path == legacy_db.resolve()
|
||||
|
||||
|
||||
def test_ensure_runtime_dirs_creates_machine_dirs_only(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("ATOCORE_DATA_DIR", str(tmp_path / "data"))
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(tmp_path / "vault-source"))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(tmp_path / "drive-source"))
|
||||
monkeypatch.setenv("ATOCORE_LOG_DIR", str(tmp_path / "logs"))
|
||||
monkeypatch.setenv("ATOCORE_BACKUP_DIR", str(tmp_path / "backups"))
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
config.ensure_runtime_dirs()
|
||||
|
||||
assert config.settings.db_path.parent.exists()
|
||||
assert config.settings.chroma_path.exists()
|
||||
assert config.settings.cache_path.exists()
|
||||
assert config.settings.tmp_path.exists()
|
||||
assert config.settings.resolved_log_dir.exists()
|
||||
assert config.settings.resolved_backup_dir.exists()
|
||||
assert config.settings.resolved_run_dir.exists()
|
||||
assert not config.settings.resolved_vault_source_dir.exists()
|
||||
assert not config.settings.resolved_drive_source_dir.exists()
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
Reference in New Issue
Block a user