|
Option C oc_diagnostics
|
Functions | |
| _make_http_scope (method="GET", path="/ping", headers=None, client=("127.0.0.1", 9999)) | |
| test_http_scope_status_passthrough () | |
| test_websocket_passthrough () | |
| test_lifespan_scope_passthrough () | |
| test_exception_reraise () | |
| test_http_header_redaction () | |
| test_elapsed_time_in_log () | |
Variables | |
| _REPO_ROOT = os.path.normpath(os.path.join(os.path.dirname(__file__), "..")) | |
Regression Tests — fastapi_middleware
=======================================
Purpose
-------
Verify the ASGI contract of ``DiagnosticsMiddleware``: correct HTTP scope
handling, non-HTTP passthrough, exception logging and re-raising, header
redaction, elapsed-time reporting, and lifespan scope passthrough.
Responsibilities
----------------
- Confirm HTTP status codes are captured and passed through to the client.
- Confirm non-HTTP scopes (WebSocket, lifespan) are forwarded unchanged.
- Confirm application exceptions are logged at L2 and then re-raised.
- Confirm sensitive request headers are redacted in log output (FS-17).
- Confirm elapsed time in milliseconds appears in the completion log line.
- Confirm lifespan scope passes through without any HTTP logging.
Diagnostics
-----------
Domain: TEST
Levels:
L2 — lifecycle
L3 — semantic details
L4 — deep tracing
Contracts
---------
- Must not permanently modify oc_diagnostics global state.
- Must restore all patched globals and mocked internals in finally blocks.
- Must not start servers or require network access.
- Must run deterministically across repeated invocations.
- Pure ASGI contract — does not require the FastAPI package.
|
protected |
Build a minimal HTTP ASGI scope dict for testing.
Definition at line 58 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_elapsed_time_in_log | ( | ) |
Elapsed milliseconds appear in the completion log line for HTTP requests.
Definition at line 226 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_exception_reraise | ( | ) |
Application exceptions are logged at L2 and then re-raised unchanged.
Definition at line 139 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_http_header_redaction | ( | ) |
Sensitive request headers appear as [REDACTED] in log output; others are not redacted.
Definition at line 167 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_http_scope_status_passthrough | ( | ) |
HTTP response status code is captured and passed through to the caller.
Definition at line 74 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_lifespan_scope_passthrough | ( | ) |
lifespan scope is forwarded to the app without any HTTP logging.
Definition at line 117 of file test_fastapi_middleware.py.
| test_fastapi_middleware.test_websocket_passthrough | ( | ) |
WebSocket scope is forwarded to the app without any HTTP logging.
Definition at line 99 of file test_fastapi_middleware.py.
|
protected |
Definition at line 50 of file test_fastapi_middleware.py.