Compare commits

..

No commits in common. "dce7373845558d63027d6ec2701e39f3aa099d81" and "2891a0cfd81539efed9bd13b5c8ade068b7b6aa5" have entirely different histories.

2 changed files with 6 additions and 20 deletions

View File

@ -22,10 +22,6 @@ FRONTEND_DIR = Path(__file__).resolve().parent.parent / "frontend"
class ContextPayloadError(ValueError):
"""Raised when Gitea returns a structurally invalid context payload."""
class ReadinessPayloadError(ValueError):
"""Raised when Gitea returns a structurally invalid readiness payload."""
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
@ -60,19 +56,13 @@ async def readiness():
current_user(), timeout=READINESS_TIMEOUT_SECONDS
)
if not isinstance(user, dict) or not user.get("login"):
raise ReadinessPayloadError(
"Gitea current-user response did not include a login"
)
raise ValueError("Gitea current-user response did not include a login")
except Exception as exc:
timed_out = isinstance(exc, TimeoutError)
error_message = (
f"Gitea readiness check timed out after {READINESS_TIMEOUT_SECONDS:g}s"
if timed_out
else (
str(exc)
if isinstance(exc, ReadinessPayloadError)
else "Gitea readiness check is temporarily unavailable"
)
else str(exc)
)
return JSONResponse(
{

View File

@ -29,21 +29,17 @@ async def test_readiness_endpoint_reports_connected_gitea_user(monkeypatch):
@pytest.mark.anyio
async def test_readiness_endpoint_hides_unexpected_upstream_error_details(monkeypatch):
async def test_readiness_endpoint_returns_503_when_gitea_is_unavailable(monkeypatch):
async def unavailable_user():
raise RuntimeError("secret internal upstream detail")
raise RuntimeError("connection refused")
monkeypatch.setattr(main, "current_user", unavailable_user)
response = await main.readiness()
assert response.status_code == 503
assert json.loads(response.body) == {
"status": "not_ready",
"service": "stackchain-dashboard",
"error": "Gitea readiness check is temporarily unavailable",
}
assert b"secret internal upstream detail" not in response.body
assert b'"status":"not_ready"' in response.body
assert b'"error":"connection refused"' in response.body
@pytest.mark.anyio