From dc8f3f2019831c359ac624b020258d252e9b916f Mon Sep 17 00:00:00 2001 From: bot-backend Date: Fri, 29 May 2026 00:25:15 +0300 Subject: [PATCH] feat(backend): add /api/v1/ping liveness endpoint Noop liveness probe returning {"pong": true}. Registered as a public path (no Caddy/RBAC auth) like /health so external monitoring can reach it. Adds unit test via FastAPI TestClient. Closes #633 --- backend/app/api/v1/ping.py | 8 ++++++++ backend/app/main.py | 4 +++- backend/tests/test_ping.py | 10 ++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 backend/app/api/v1/ping.py create mode 100644 backend/tests/test_ping.py diff --git a/backend/app/api/v1/ping.py b/backend/app/api/v1/ping.py new file mode 100644 index 00000000..2b9ba5ec --- /dev/null +++ b/backend/app/api/v1/ping.py @@ -0,0 +1,8 @@ +from fastapi import APIRouter + +router = APIRouter() + + +@router.get("/ping") +async def ping() -> dict[str, bool]: + return {"pong": True} diff --git a/backend/app/main.py b/backend/app/main.py index 3fef12a1..53903ac5 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -30,6 +30,7 @@ from app.api.v1 import ( parcels, photos, pilot, + ping, trade_in, users, ) @@ -86,7 +87,7 @@ app = FastAPI(title="GenDesign API", version="0.1.0", lifespan=lifespan) # Public paths без auth (/health, /docs, /openapi.json) пропускаем без проверки — # X-Authenticated-User там просто не приходит из Caddy. _ADMIN_API_RE = re.compile(r"^/api/v1/admin/") -_PUBLIC_PATHS = frozenset({"/health", "/docs", "/redoc", "/openapi.json"}) +_PUBLIC_PATHS = frozenset({"/health", "/api/v1/ping", "/docs", "/redoc", "/openapi.json"}) @app.middleware("http") @@ -164,6 +165,7 @@ app.include_router(landing.router, prefix="/api/v1", tags=["landing"]) app.include_router(pilot.router, prefix="/api/v1/pilot", tags=["pilot"]) app.include_router(users.router, prefix="/api/v1", tags=["users"]) app.include_router(me.router, prefix="/api/v1", tags=["me"]) +app.include_router(ping.router, prefix="/api/v1", tags=["ping"]) @app.get("/health") diff --git a/backend/tests/test_ping.py b/backend/tests/test_ping.py new file mode 100644 index 00000000..160a49ff --- /dev/null +++ b/backend/tests/test_ping.py @@ -0,0 +1,10 @@ +from fastapi.testclient import TestClient + +from app.main import app + + +def test_ping() -> None: + client = TestClient(app) + response = client.get("/api/v1/ping") + assert response.status_code == 200 + assert response.json() == {"pong": True}