feat: comprehensive health check with DB, scheduler, cache

- Add /api/v1/health endpoint with component-level checks
- Verify DB connectivity, fail2ban socket, scheduler, session cache
- Add SQLite WAL cleanup on startup (orphan crash files)
- Migration 8: import_log.timestamp → INTEGER UNIX epoch
- Align import_log timestamps with history_archive (already UNIX int)
- Add unit tests for DB cleanup and health router

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-05-02 23:03:57 +02:00
parent b631c1c546
commit 1285bc8571
12 changed files with 472 additions and 241 deletions

View File

@@ -7,6 +7,7 @@ import pytest
from app.db import (
_apply_migration,
_cleanup_wal_files,
_parse_migration_statements,
init_db,
open_db,
@@ -241,3 +242,32 @@ async def test_init_db_idempotent(tmp_path: Path) -> None:
finally:
await db.close()
async def test_cleanup_wal_files_removes_orphaned_files(tmp_path: Path) -> None:
"""Test that _cleanup_wal_files removes orphaned WAL and SHM files."""
db_path = str(tmp_path / "test_wal.db")
wal_path = Path(db_path + "-wal")
shm_path = Path(db_path + "-shm")
# Create the orphaned files
wal_path.write_text("orphan")
shm_path.write_text("orphan")
assert wal_path.exists()
assert shm_path.exists()
# Run cleanup
await _cleanup_wal_files(db_path)
# Both files should be removed
assert not wal_path.exists()
assert not shm_path.exists()
async def test_cleanup_wal_files_handles_missing_files(tmp_path: Path) -> None:
"""Test that _cleanup_wal_files handles non-existent files gracefully."""
db_path = str(tmp_path / "nonexistent.db")
# Should not raise
await _cleanup_wal_files(db_path)