Add Dalidou storage foundation and deployment prep
This commit is contained in:
48
tests/test_api_storage.py
Normal file
48
tests/test_api_storage.py
Normal file
@@ -0,0 +1,48 @@
|
||||
"""Tests for storage-related API readiness endpoints."""
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
import atocore.config as config
|
||||
from atocore.main import app
|
||||
|
||||
|
||||
def test_sources_endpoint_reports_configured_sources(tmp_data_dir, monkeypatch):
|
||||
vault_dir = tmp_data_dir / "vault-source"
|
||||
drive_dir = tmp_data_dir / "drive-source"
|
||||
vault_dir.mkdir()
|
||||
drive_dir.mkdir()
|
||||
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(vault_dir))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(drive_dir))
|
||||
config.settings = config.Settings()
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/sources")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["vault_enabled"] is True
|
||||
assert body["drive_enabled"] is True
|
||||
assert len(body["sources"]) == 2
|
||||
assert all(source["read_only"] for source in body["sources"])
|
||||
|
||||
|
||||
def test_health_endpoint_exposes_machine_paths_and_source_readiness(tmp_data_dir, monkeypatch):
|
||||
vault_dir = tmp_data_dir / "vault-source"
|
||||
drive_dir = tmp_data_dir / "drive-source"
|
||||
vault_dir.mkdir()
|
||||
drive_dir.mkdir()
|
||||
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(vault_dir))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(drive_dir))
|
||||
config.settings = config.Settings()
|
||||
|
||||
client = TestClient(app)
|
||||
response = client.get("/health")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.json()
|
||||
assert body["status"] == "ok"
|
||||
assert body["sources_ready"] is True
|
||||
assert "db_path" in body["machine_paths"]
|
||||
assert "run_dir" in body["machine_paths"]
|
||||
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
|
||||
18
tests/test_logging.py
Normal file
18
tests/test_logging.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Tests for logging configuration."""
|
||||
|
||||
from types import SimpleNamespace
|
||||
|
||||
import atocore.config as config
|
||||
from atocore.observability.logger import setup_logging
|
||||
|
||||
|
||||
def test_setup_logging_uses_dynamic_settings_without_name_error():
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = SimpleNamespace(debug=False)
|
||||
setup_logging()
|
||||
|
||||
config.settings = SimpleNamespace(debug=True)
|
||||
setup_logging()
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
70
tests/test_sources.py
Normal file
70
tests/test_sources.py
Normal file
@@ -0,0 +1,70 @@
|
||||
"""Tests for configured source registration and readiness."""
|
||||
|
||||
import atocore.config as config
|
||||
from atocore.ingestion.pipeline import get_source_status, ingest_configured_sources
|
||||
|
||||
|
||||
def test_get_source_status_reports_read_only_inputs(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(tmp_path / "vault"))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(tmp_path / "drive"))
|
||||
monkeypatch.setenv("ATOCORE_SOURCE_DRIVE_ENABLED", "false")
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
status = get_source_status()
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
assert status[0]["name"] == "vault"
|
||||
assert status[0]["enabled"] is True
|
||||
assert status[0]["read_only"] is True
|
||||
assert status[0]["exists"] is False
|
||||
assert status[1]["name"] == "drive"
|
||||
assert status[1]["enabled"] is False
|
||||
|
||||
|
||||
def test_ingest_configured_sources_reports_missing_and_disabled(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(tmp_path / "vault"))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(tmp_path / "drive"))
|
||||
monkeypatch.setenv("ATOCORE_SOURCE_DRIVE_ENABLED", "false")
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
results = ingest_configured_sources()
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
assert results[0]["source"] == "vault"
|
||||
assert results[0]["status"] == "missing"
|
||||
assert results[1]["source"] == "drive"
|
||||
assert results[1]["status"] == "disabled"
|
||||
|
||||
|
||||
def test_ingest_configured_sources_uses_ingest_folder(tmp_path, monkeypatch):
|
||||
vault_dir = tmp_path / "vault"
|
||||
drive_dir = tmp_path / "drive"
|
||||
vault_dir.mkdir()
|
||||
drive_dir.mkdir()
|
||||
monkeypatch.setenv("ATOCORE_VAULT_SOURCE_DIR", str(vault_dir))
|
||||
monkeypatch.setenv("ATOCORE_DRIVE_SOURCE_DIR", str(drive_dir))
|
||||
|
||||
calls = []
|
||||
|
||||
def fake_ingest_folder(path, purge_deleted=True):
|
||||
calls.append((str(path), purge_deleted))
|
||||
return [{"file": str(path / "note.md"), "status": "ingested"}]
|
||||
|
||||
original_settings = config.settings
|
||||
try:
|
||||
config.settings = config.Settings()
|
||||
monkeypatch.setattr("atocore.ingestion.pipeline.ingest_folder", fake_ingest_folder)
|
||||
results = ingest_configured_sources()
|
||||
finally:
|
||||
config.settings = original_settings
|
||||
|
||||
assert len(calls) == 2
|
||||
assert all(purge_deleted is False for _, purge_deleted in calls)
|
||||
assert results[0]["status"] == "ingested"
|
||||
assert "results" in results[0]
|
||||
Reference in New Issue
Block a user