feat(cloud-api): add correlated lifecycle logging

This commit is contained in:
2026-07-12 18:37:51 +08:00
parent a5de7399f8
commit 8131c0124b
7 changed files with 256 additions and 1 deletions
+37
View File
@@ -255,6 +255,43 @@ def test_readiness_reports_stopped_worker() -> None:
assert response.json()["checks"]["workers"] is False
def test_request_correlation_id_is_propagated_without_sensitive_headers(
monkeypatch,
tmp_path,
) -> None:
request_logs: list[dict[str, object]] = []
def record_info(_message: str, *, extra: dict[str, object]) -> None:
request_logs.append(extra)
monkeypatch.setattr(app_module.logger, "info", record_info)
app = create_app(
config=CloudControlConfig(
database_url=f"sqlite:///{(tmp_path / 'correlation.sqlite3').as_posix()}"
)
)
with TestClient(app) as client:
response = client.get(
"/health/live",
headers={
"X-Correlation-ID": "request-123",
"Authorization": "Bearer never-log-this",
},
)
assert response.headers["X-Correlation-ID"] == "request-123"
assert request_logs == [
{
"correlation_id": "request-123",
"method": "GET",
"path": "/health/live",
"status_code": 200,
}
]
assert "never-log-this" not in repr(request_logs)
def test_production_app_rejects_missing_credentials() -> None:
with pytest.raises(CloudConfigurationError, match="credential"):
create_app(