Files
ZyyandCodex d922c3af60 fix(diagnostics): preserve error chains and avoid logging backpressure
Preserve native failure causes through store, provider, plugin, admin, and
worker boundaries, including secondary cleanup failures. Route operational
failures through the shared diagnostics sink with protected error details.

Use bounded nonblocking file logging with batched writes and reserved
warning/error capacity. Reserve observation capacity for failures and
request lifecycle records, and rate-limit overload warnings.

Validate error propagation and blocked-output HTTP, admin, SSE, and WebSocket
behavior; keep the local migration plan out of version control.

Co-authored-by: Codex <noreply@openai.com>
2026-10-07 00:25:18 +08:00

62 lines
2.0 KiB
Rust

//! 验证管理端来源经用例和 HTTP 出口到达受控记录,公开响应和扩展不泄漏
use axum::{
body::{Body, to_bytes},
http::{Request, StatusCode},
};
use std::sync::Arc;
use tower::ServiceExt;
#[tokio::test]
async fn store_failure_is_recorded_once_with_the_incoming_request_id() {
let fixture = super::AdminTestFixture::new().await;
fixture.auth.insert_session("valid-session");
let diagnostics = Arc::new(crate::support::RecordingDiagnostics::default());
let bundle = crate::openai::api_bundle_with_diagnostics(
fixture.services,
gateway_api::ApiConfig {
asset_directory: std::env::temp_dir(),
request_timeout_seconds: None,
cors_allowed_origins: Vec::new(),
request_id_header: "x-request-id".to_owned(),
},
diagnostics.clone(),
);
let response = bundle
.router()
.oneshot(
Request::builder()
.uri("/api/admin/accounts")
.header("cookie", "cpr_session=valid-session")
.header("x-request-id", "admin-native-cause-test")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
assert!(
response
.extensions()
.get::<gateway_admin::model::AdminError>()
.is_none()
);
let bytes = to_bytes(response.into_body(), 1024 * 1024).await.unwrap();
assert!(!String::from_utf8_lossy(&bytes).contains("PRIVATE_ADMIN_NATIVE_CAUSE"));
let failures = diagnostics.0.lock().unwrap();
assert_eq!(failures.len(), 1);
assert_eq!(failures[0].kind, "unavailable");
assert_eq!(
failures[0].correlation_id.as_deref(),
Some("admin-native-cause-test")
);
assert!(
failures[0]
.details
.as_ref()
.unwrap()
.as_str()
.contains("PRIVATE_ADMIN_NATIVE_CAUSE")
);
}