from __future__ import annotations

import app.core.application as application_module


def test_startup_keeps_backend_alive_when_database_bootstrap_fails(monkeypatch) -> None:
    def fail_bootstrap(*_args, **_kwargs) -> None:
        raise RuntimeError("db down")

    monkeypatch.setattr(application_module, "bootstrap_database", fail_bootstrap)

    app = application_module.ModularApplication()

    app.startup()

    health = app.health_payload()
    assert health["status"] == "degraded"
    assert health["reason"] == "database_unavailable"
    assert "db down" in health["details"]
