Fix setup_service to mark setup_complete only after successful runtime DB init

This commit is contained in:
2026-04-12 20:30:22 +02:00
parent e6df045e5e
commit 8e43ef9ad2
4 changed files with 758 additions and 26 deletions

View File

@@ -5,6 +5,7 @@ from __future__ import annotations
import asyncio
import inspect
from pathlib import Path
from unittest.mock import AsyncMock
import aiosqlite
import pytest
@@ -133,6 +134,31 @@ class TestRunSetup:
with pytest.raises(RuntimeError, match="already been completed"):
await setup_service.run_setup(db, **kwargs) # type: ignore[arg-type]
async def test_does_not_mark_setup_complete_on_runtime_db_failure(
self, db: aiosqlite.Connection, tmp_path: Path, monkeypatch: pytest.MonkeyPatch
) -> None:
"""run_setup() must not mark setup complete when runtime DB init fails."""
monkeypatch.setattr(
setup_service,
"_ensure_database_initialized",
AsyncMock(return_value=False),
)
with pytest.raises(RuntimeError, match="Runtime database could not be initialized"):
await setup_service.run_setup(
db,
master_password="mypassword1",
database_path=str(tmp_path / "runtime.db"),
fail2ban_socket="/var/run/fail2ban/fail2ban.sock",
timezone="UTC",
session_duration_minutes=60,
)
assert await setup_service.is_setup_complete(db) is False
bootstrap_settings = await settings_repo.get_all_settings(db)
assert "setup_completed" not in bootstrap_settings
assert not (tmp_path / "runtime.db").exists()
async def test_initializes_map_color_thresholds_with_defaults(
self, db: aiosqlite.Connection, tmp_path: Path
) -> None: