"""X-Request-Id: поведение слоя, общее для любых его реализаций. Эти тесты фиксируют то, что видит клиент, и не зависят от того, как написан middleware (в лабе 1 его переписали на чистое ASGI, трек «5»). Ответ 401 формирует AuthenticationMiddleware, а не роутер: id из входящего заголовка должен дойти и до него. """ import re import httpx import pytest from helpers import USERS, assert_error GENERATED_ID = re.compile(r"[0-9a-f]{32}") @pytest.mark.parametrize( ("path", "status", "code"), [ ("/health/live", 200, None), (f"{USERS}/me", 401, "unauthorized"), ("/no-such-path", 404, "not_found"), ], ids=["ok", "unauthorized", "unknown-path"], ) def test_safe_incoming_request_id_is_echoed( client: httpx.Client, path: str, status: int, code: str | None, ) -> None: response = client.get(path, headers={"X-Request-Id": "trace-42.a_b"}) assert response.status_code == status assert response.headers["X-Request-Id"] == "trace-42.a_b" if code is not None: # тот же id и в теле ошибки: assert_error сверяет его с заголовком assert_error(response, status, code) @pytest.mark.parametrize( "incoming", ["bad id", "x" * 65, "