Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion deep_agent/aegra/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ async def _ensure_database() -> str:
return "ok"
except Exception as exc:
logger.error("Database setup failed: %s", exc)
return f"error: {exc}"
raise


async def _warm_caches() -> str:
Expand Down
46 changes: 46 additions & 0 deletions tests/unit/aegra/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ async def test_idempotent(self):
result = await startup.run_startup()
assert result["status"] == "already_complete"

async def test_not_ready_when_database_fails(self):
with (
patch.object(
startup, "_validate_config", new_callable=AsyncMock, return_value="ok"
),
patch.object(
startup,
"_init_aegra_db",
new_callable=AsyncMock,
return_value="ok",
),
patch.object(
startup,
"_ensure_database",
new_callable=AsyncMock,
side_effect=ConnectionError("db down"),
),
):
with pytest.raises(ConnectionError, match="db down"):
await startup.run_startup()
assert startup.is_ready() is False


class TestValidateConfig:
async def test_valid(self):
Expand Down Expand Up @@ -98,6 +120,30 @@ async def test_db_ok(self):
mock_feedback.ensure_table.assert_awaited_once()
mock_mcp_store.ensure_tables.assert_awaited_once()

async def test_db_failure_propagates(self):
mock_settings = MagicMock()
mock_settings.database_uri = "postgresql://test"
mock_settings.MONGODB_URI = ""
mock_personalization = AsyncMock()
mock_personalization.ensure_tables.side_effect = ConnectionError("refused")
with (
patch("deep_agent.src.settings.settings", mock_settings),
patch(
"deep_agent.src.personalization.repository.PersonalizationRepository",
return_value=mock_personalization,
),
patch(
"deep_agent.src.feedback.repository.FeedbackRepository",
return_value=AsyncMock(),
),
patch(
"deep_agent.aegra.mcp_token_store.McpTokenStore",
return_value=AsyncMock(),
),
):
with pytest.raises(ConnectionError, match="refused"):
await startup._ensure_database()

async def test_mongo_indexes_when_configured(self):
import sys

Expand Down
Loading