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

View File

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