From 25eb45bf541c709fb099732a7f6aaa1687c8c005 Mon Sep 17 00:00:00 2001 From: Abhimanyu Saharan Date: Wed, 11 Feb 2026 18:03:42 +0530 Subject: [PATCH] feat: simplify className prop in StatusDot and refactor conditional check in tasks.py --- backend/app/api/tasks.py | 4 +- backend/tests/test_error_handling.py | 55 +++++++++++++++++++ .../src/components/BoardApprovalsPanel.tsx | 4 +- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/backend/app/api/tasks.py b/backend/app/api/tasks.py index 1ad7b227..d586ad47 100644 --- a/backend/app/api/tasks.py +++ b/backend/app/api/tasks.py @@ -184,9 +184,7 @@ def _coerce_task_event_rows( msg = "Expected (ActivityEvent, Task | None) rows" raise TypeError(msg) - if isinstance(first, ActivityEvent) and ( - isinstance(second, Task) or second is None - ): + if isinstance(first, ActivityEvent) and (isinstance(second, Task) or second is None): rows.append((first, second)) continue diff --git a/backend/tests/test_error_handling.py b/backend/tests/test_error_handling.py index 03150806..3f922101 100644 --- a/backend/tests/test_error_handling.py +++ b/backend/tests/test_error_handling.py @@ -8,6 +8,7 @@ from fastapi.testclient import TestClient from pydantic import BaseModel, Field from starlette.requests import Request +from app.core import error_handling from app.core.error_handling import ( REQUEST_ID_HEADER, _error_payload, @@ -111,6 +112,60 @@ def test_client_provided_request_id_is_preserved(): assert resp.headers.get(REQUEST_ID_HEADER) == "req-123" +def test_slow_request_emits_slow_log(monkeypatch: pytest.MonkeyPatch) -> None: + warnings: list[tuple[str, dict[str, object]]] = [] + + def _fake_warning(message: str, *args: object, **kwargs: object) -> None: + _ = args + extra = kwargs.get("extra") + warnings.append((message, extra if isinstance(extra, dict) else {})) + + perf_ticks = iter((100.0, 100.2)) + + def _fake_perf_counter() -> float: + return next(perf_ticks) + + monkeypatch.setattr(error_handling.settings, "request_log_slow_ms", 1) + monkeypatch.setattr(error_handling, "perf_counter", _fake_perf_counter) + monkeypatch.setattr(error_handling.logger, "warning", _fake_warning) + + app = FastAPI() + install_error_handling(app) + + @app.get("/slow") + def slow() -> dict[str, str]: + return {"ok": "1"} + + client = TestClient(app) + resp = client.get("/slow") + + assert resp.status_code == 200 + assert any( + message == "http.request.slow" and extra.get("slow_threshold_ms") == 1 + for message, extra in warnings + ) + + +def test_health_route_skips_request_logs_when_disabled( + monkeypatch: pytest.MonkeyPatch, +) -> None: + monkeypatch.setattr(error_handling.settings, "request_log_include_health", False) + + app = FastAPI() + install_error_handling(app) + + @app.get("/healthz") + def healthz() -> dict[str, str]: + return {"status": "ok"} + + client = TestClient(app) + resp = client.get("/healthz") + + assert resp.status_code == 200 + assert resp.json() == {"status": "ok"} + assert isinstance(resp.headers.get(REQUEST_ID_HEADER), str) + + def test_get_request_id_returns_none_for_missing_or_invalid_state() -> None: # Empty state req = Request({"type": "http", "headers": [], "state": {}}) diff --git a/frontend/src/components/BoardApprovalsPanel.tsx b/frontend/src/components/BoardApprovalsPanel.tsx index db0d47b0..0b005b32 100644 --- a/frontend/src/components/BoardApprovalsPanel.tsx +++ b/frontend/src/components/BoardApprovalsPanel.tsx @@ -582,9 +582,7 @@ export function BoardApprovalsPanel({