Improve gateway transport and usage runtime

This commit is contained in:
elky
2026-06-25 22:36:27 +08:00
parent d336d1a7fa
commit 6f00e9fc67
112 changed files with 12456 additions and 1387 deletions
@@ -1468,8 +1468,15 @@ async fn gateway_executes_openai_chat_cross_format_tool_use_upstream_stream_via_
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_skips_openai_chat_antigravity_cross_format_sync_candidate_as_transport_unsupported(
#[test]
fn gateway_skips_openai_chat_antigravity_cross_format_sync_candidate_as_transport_unsupported() {
run_openai_chat_finalize_test(
"gateway_skips_openai_chat_antigravity_cross_format_sync_candidate_as_transport_unsupported",
gateway_skips_openai_chat_antigravity_cross_format_sync_candidate_as_transport_unsupported_impl,
);
}
async fn gateway_skips_openai_chat_antigravity_cross_format_sync_candidate_as_transport_unsupported_impl(
) {
fn hash_api_key(value: &str) -> String {
let mut hasher = Sha256::new();
@@ -1,9 +1,9 @@
use super::{
any, build_router_with_execution_runtime_override, build_router_with_state,
build_state_with_execution_runtime_override, json, start_server, to_bytes, Arc, Body, Bytes,
HeaderName, HeaderValue, Json, Mutex, Request, Response, Router, StatusCode,
CONTROL_EXECUTED_HEADER, EXECUTION_PATH_EXECUTION_RUNTIME_SYNC, EXECUTION_PATH_HEADER,
TRACE_ID_HEADER,
build_state_with_execution_runtime_override, json, run_finalize_local_cli_test, start_server,
to_bytes, Arc, Body, Bytes, HeaderName, HeaderValue, Json, Mutex, Request, Response, Router,
StatusCode, CONTROL_EXECUTED_HEADER, EXECUTION_PATH_EXECUTION_RUNTIME_SYNC,
EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
};
use crate::data::GatewayDataState;
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
@@ -25,8 +25,16 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_openai_responses_compact_openai_family_upstream_stream_via_local_finalize_response(
#[test]
fn gateway_executes_openai_responses_compact_openai_family_upstream_stream_via_local_finalize_response(
) {
run_finalize_local_cli_test(
"gateway_executes_openai_responses_compact_openai_family_upstream_stream_via_local_finalize_response",
gateway_executes_openai_responses_compact_openai_family_upstream_stream_via_local_finalize_response_impl,
);
}
async fn gateway_executes_openai_responses_compact_openai_family_upstream_stream_via_local_finalize_response_impl(
) {
use base64::Engine as _;
@@ -1,9 +1,9 @@
use super::{
any, build_router_with_execution_runtime_override, build_router_with_state,
build_state_with_execution_runtime_override, json, start_server, to_bytes, Arc, Body, Bytes,
HeaderName, HeaderValue, Json, Mutex, Request, Response, Router, StatusCode,
CONTROL_EXECUTED_HEADER, EXECUTION_PATH_EXECUTION_RUNTIME_SYNC, EXECUTION_PATH_HEADER,
TRACE_ID_HEADER,
build_state_with_execution_runtime_override, json, run_finalize_local_cli_test, start_server,
to_bytes, Arc, Body, Bytes, HeaderName, HeaderValue, Json, Mutex, Request, Response, Router,
StatusCode, CONTROL_EXECUTED_HEADER, EXECUTION_PATH_EXECUTION_RUNTIME_SYNC,
EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
};
use crate::data::GatewayDataState;
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
@@ -25,8 +25,15 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_openai_responses_cross_format_upstream_stream_via_local_finalize_response(
#[test]
fn gateway_executes_openai_responses_cross_format_upstream_stream_via_local_finalize_response() {
run_finalize_local_cli_test(
"gateway_executes_openai_responses_cross_format_upstream_stream_via_local_finalize_response",
gateway_executes_openai_responses_cross_format_upstream_stream_via_local_finalize_response_impl,
);
}
async fn gateway_executes_openai_responses_cross_format_upstream_stream_via_local_finalize_response_impl(
) {
use base64::Engine as _;
@@ -490,8 +497,16 @@ async fn gateway_executes_openai_responses_cross_format_upstream_stream_via_loca
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_openai_responses_cross_format_function_call_upstream_stream_via_local_finalize_response(
#[test]
fn gateway_executes_openai_responses_cross_format_function_call_upstream_stream_via_local_finalize_response(
) {
run_finalize_local_cli_test(
"gateway_executes_openai_responses_cross_format_function_call_upstream_stream_via_local_finalize_response",
gateway_executes_openai_responses_cross_format_function_call_upstream_stream_via_local_finalize_response_impl,
);
}
async fn gateway_executes_openai_responses_cross_format_function_call_upstream_stream_via_local_finalize_response_impl(
) {
use base64::Engine as _;
@@ -953,8 +968,16 @@ async fn gateway_executes_openai_responses_cross_format_function_call_upstream_s
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_openai_responses_antigravity_cross_format_upstream_stream_via_local_finalize_response(
#[test]
fn gateway_executes_openai_responses_antigravity_cross_format_upstream_stream_via_local_finalize_response(
) {
run_finalize_local_cli_test(
"gateway_executes_openai_responses_antigravity_cross_format_upstream_stream_via_local_finalize_response",
gateway_executes_openai_responses_antigravity_cross_format_upstream_stream_via_local_finalize_response_impl,
);
}
async fn gateway_executes_openai_responses_antigravity_cross_format_upstream_stream_via_local_finalize_response_impl(
) {
use base64::Engine as _;
@@ -49,8 +49,15 @@ where
}
}
#[tokio::test]
async fn gateway_executes_openai_responses_sync_upstream_stream_via_local_finalize_response() {
#[test]
fn gateway_executes_openai_responses_sync_upstream_stream_via_local_finalize_response() {
run_kiro_claude_cli_finalize_test(
"gateway_executes_openai_responses_sync_upstream_stream_via_local_finalize_response",
gateway_executes_openai_responses_sync_upstream_stream_via_local_finalize_response_impl,
);
}
async fn gateway_executes_openai_responses_sync_upstream_stream_via_local_finalize_response_impl() {
use base64::Engine as _;
#[derive(Debug, Clone)]
@@ -23,6 +23,30 @@ use super::{
UsageRuntimeConfig, VideoTaskTruthSourceMode,
};
const FINALIZE_LOCAL_CLI_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_finalize_local_cli_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(FINALIZE_LOCAL_CLI_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("finalize local cli test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
mod compact;
mod cross_format;
mod direct;
@@ -22,6 +22,30 @@ use sha2::{Digest, Sha256};
use crate::data::GatewayDataState;
use crate::tests::next_non_keepalive_chunk;
const LIFECYCLE_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_lifecycle_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(LIFECYCLE_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("lifecycle test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn hash_api_key(value: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(value.as_bytes());
@@ -163,8 +187,15 @@ fn sample_local_openai_key() -> StoredProviderCatalogKey {
.expect("key transport should build")
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn gateway_completes_sync_response_on_local_execution_runtime_path() {
#[test]
fn gateway_completes_sync_response_on_local_execution_runtime_path() {
run_lifecycle_test(
"gateway_completes_sync_response_on_local_execution_runtime_path",
gateway_completes_sync_response_on_local_execution_runtime_path_impl,
);
}
async fn gateway_completes_sync_response_on_local_execution_runtime_path_impl() {
let public_hits = Arc::new(Mutex::new(0usize));
let public_hits_clone = Arc::clone(&public_hits);
let upstream = Router::new().route(
@@ -261,8 +292,15 @@ async fn gateway_completes_sync_response_on_local_execution_runtime_path() {
upstream_handle.abort();
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn gateway_stops_execution_runtime_stream_when_client_disconnects() {
#[test]
fn gateway_stops_execution_runtime_stream_when_client_disconnects() {
run_lifecycle_test(
"gateway_stops_execution_runtime_stream_when_client_disconnects",
gateway_stops_execution_runtime_stream_when_client_disconnects_impl,
);
}
async fn gateway_stops_execution_runtime_stream_when_client_disconnects_impl() {
let seen_report = Arc::new(Mutex::new(0usize));
let seen_report_clone = Arc::clone(&seen_report);
let public_hits = Arc::new(Mutex::new(0usize));
@@ -388,8 +426,15 @@ async fn gateway_stops_execution_runtime_stream_when_client_disconnects() {
upstream_handle.abort();
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn gateway_returns_error_body_when_prefetch_detects_embedded_stream_error() {
#[test]
fn gateway_returns_error_body_when_prefetch_detects_embedded_stream_error() {
run_lifecycle_test(
"gateway_returns_error_body_when_prefetch_detects_embedded_stream_error",
gateway_returns_error_body_when_prefetch_detects_embedded_stream_error_impl,
);
}
async fn gateway_returns_error_body_when_prefetch_detects_embedded_stream_error_impl() {
let public_hits = Arc::new(Mutex::new(0usize));
let public_hits_clone = Arc::clone(&public_hits);
@@ -1,8 +1,8 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override, json, start_server,
strip_sse_keepalive_comments, to_bytes, AppState, Arc, Body, Bytes, HeaderName, HeaderValue,
Json, Mutex, Request, Response, Router, StatusCode, EXECUTION_PATH_EXECUTION_RUNTIME_STREAM,
EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
strip_sse_keepalive_comments, to_bytes, wait_until, AppState, Arc, Body, Bytes, HeaderName,
HeaderValue, Json, Mutex, Request, Response, Router, StatusCode,
EXECUTION_PATH_EXECUTION_RUNTIME_STREAM, EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
};
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
use aether_data::repository::auth::{
@@ -22,8 +22,40 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_openai_chat_stream_via_local_decision_gate_without_execution_runtime_override(
const STREAM_DECISION_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_decision_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_DECISION_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream decision test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[test]
fn gateway_executes_openai_chat_stream_via_local_decision_gate_without_execution_runtime_override()
{
run_stream_decision_test(
"gateway_executes_openai_chat_stream_via_local_decision_gate_without_execution_runtime_override",
gateway_executes_openai_chat_stream_via_local_decision_gate_without_execution_runtime_override_impl,
);
}
async fn gateway_executes_openai_chat_stream_via_local_decision_gate_without_execution_runtime_override_impl(
) {
#[derive(Debug, Clone)]
struct SeenUpstreamStreamRequest {
@@ -310,50 +342,19 @@ async fn gateway_executes_openai_chat_stream_via_local_decision_gate_without_exe
"user-openai-local-stream-1",
),
)]));
let mut backup_candidate_row = sample_candidate_row();
backup_candidate_row.provider_id = "provider-openai-local-stream-2".to_string();
backup_candidate_row.endpoint_id = "endpoint-openai-local-stream-2".to_string();
backup_candidate_row.key_id = "key-openai-local-stream-2".to_string();
backup_candidate_row.key_name = "backup".to_string();
backup_candidate_row.key_internal_priority = 6;
backup_candidate_row.model_id = "model-openai-local-stream-2".to_string();
backup_candidate_row.global_model_id = "global-model-openai-local-stream-2".to_string();
backup_candidate_row.model_provider_model_name = "gpt-5-upstream-backup".to_string();
backup_candidate_row.model_provider_model_mappings = Some(vec![StoredProviderModelMapping {
name: "gpt-5-upstream-backup".to_string(),
priority: 1,
api_formats: Some(vec!["openai:chat".to_string()]),
endpoint_ids: None,
}]);
let candidate_selection_repository =
Arc::new(InMemoryMinimalCandidateSelectionReadRepository::seed(vec![
sample_candidate_row(),
backup_candidate_row,
]));
let request_candidate_repository = Arc::new(InMemoryRequestCandidateRepository::default());
let mut backup_provider = sample_provider_catalog_provider();
backup_provider.id = "provider-openai-local-stream-2".to_string();
let mut backup_endpoint = sample_provider_catalog_endpoint();
backup_endpoint.id = "endpoint-openai-local-stream-2".to_string();
backup_endpoint.provider_id = "provider-openai-local-stream-2".to_string();
backup_endpoint.base_url = "https://api.openai.backup.example".to_string();
let mut backup_key = sample_provider_catalog_key();
backup_key.id = "key-openai-local-stream-2".to_string();
backup_key.provider_id = "provider-openai-local-stream-2".to_string();
backup_key.name = "backup".to_string();
backup_key.encrypted_api_key = Some(
encrypt_python_fernet_plaintext(DEVELOPMENT_ENCRYPTION_KEY, "sk-upstream-openai-backup")
.expect("api key should encrypt"),
);
let (upstream_url, upstream_handle) = start_server(upstream).await;
let (provider_url, provider_handle) = start_server(provider).await;
let mut primary_endpoint = sample_provider_catalog_endpoint();
primary_endpoint.base_url = format!("{provider_url}/v1");
backup_endpoint.base_url = "http://127.0.0.1:9".to_string();
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
vec![sample_provider_catalog_provider(), backup_provider],
vec![primary_endpoint, backup_endpoint],
vec![sample_provider_catalog_key(), backup_key],
vec![sample_provider_catalog_provider()],
vec![primary_endpoint],
vec![sample_provider_catalog_key()],
));
let gateway_state = AppState::new()
.expect("gateway state should build")
@@ -443,8 +444,16 @@ async fn gateway_executes_openai_chat_stream_via_local_decision_gate_without_exe
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_openai_chat_stream_via_local_openai_responses_cross_format_candidate() {
#[test]
fn gateway_executes_openai_chat_stream_via_local_openai_responses_cross_format_candidate() {
run_stream_decision_test(
"gateway_executes_openai_chat_stream_via_local_openai_responses_cross_format_candidate",
gateway_executes_openai_chat_stream_via_local_openai_responses_cross_format_candidate_impl,
);
}
async fn gateway_executes_openai_chat_stream_via_local_openai_responses_cross_format_candidate_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -821,10 +830,10 @@ async fn gateway_executes_openai_chat_stream_via_local_openai_responses_cross_fo
Arc::clone(&request_candidate_repository),
DEVELOPMENT_ENCRYPTION_KEY,
)
.with_system_config_values_for_tests(vec![(
"provider_priority_mode".to_string(),
json!("global_key"),
)]),
.with_system_config_values_for_tests(vec![
("scheduling_mode".to_string(), json!("fixed_order")),
("provider_priority_mode".to_string(), json!("global_key")),
]),
);
let gateway = build_router_with_state(gateway_state);
let (gateway_url, gateway_handle) = start_server(gateway).await;
@@ -928,8 +937,16 @@ async fn gateway_executes_openai_chat_stream_via_local_openai_responses_cross_fo
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candidate_with_stream_path_rewrite(
#[test]
fn gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candidate_with_stream_path_rewrite(
) {
run_stream_decision_test(
"gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candidate_with_stream_path_rewrite",
gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candidate_with_stream_path_rewrite_impl,
);
}
async fn gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candidate_with_stream_path_rewrite_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1350,8 +1367,16 @@ async fn gateway_executes_openai_chat_stream_via_local_cross_format_gemini_candi
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_openai_chat_stream_with_custom_path_via_local_decision_gate_with_local_stream_decision(
#[test]
fn gateway_executes_openai_chat_stream_with_custom_path_via_local_decision_gate_with_local_stream_decision(
) {
run_stream_decision_test(
"gateway_executes_openai_chat_stream_with_custom_path_via_local_decision_gate_with_local_stream_decision",
gateway_executes_openai_chat_stream_with_custom_path_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_openai_chat_stream_with_custom_path_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1844,8 +1869,16 @@ async fn gateway_executes_openai_chat_stream_with_custom_path_via_local_decision
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable_429_execution_runtime_status(
#[test]
fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable_429_execution_runtime_status(
) {
run_stream_decision_test(
"gateway_retries_next_local_openai_chat_stream_candidate_after_retryable_429_execution_runtime_status",
gateway_retries_next_local_openai_chat_stream_candidate_after_retryable_429_execution_runtime_status_impl,
);
}
async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable_429_execution_runtime_status_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -2024,7 +2057,7 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
let seen_execution_runtime_clone = Arc::clone(&seen_execution_runtime);
let seen_report = Arc::new(Mutex::new(false));
let seen_report_clone = Arc::clone(&seen_report);
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits = Arc::new(std::sync::atomic::AtomicUsize::new(0));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let decision_hits = Arc::new(Mutex::new(0usize));
let decision_hits_clone = Arc::clone(&decision_hits);
@@ -2106,24 +2139,26 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
let raw_body = to_bytes(body, usize::MAX).await.expect("body should read");
let payload: serde_json::Value =
serde_json::from_slice(&raw_body).expect("execution runtime payload should parse");
let mut hits = execution_runtime_hits_inner.lock().expect("mutex should lock");
*hits += 1;
let attempt = *hits;
drop(hits);
let request_url = payload
.get("url")
.and_then(|value| value.as_str())
.unwrap_or_default()
.to_string();
let attempt = execution_runtime_hits_inner
.fetch_add(1, std::sync::atomic::Ordering::SeqCst)
+ 1;
seen_execution_runtime_inner.lock().expect("mutex should lock").push(
SeenExecutionRuntimeStreamRequest {
seen_execution_runtime_inner
.lock()
.expect("mutex should lock")
.push(SeenExecutionRuntimeStreamRequest {
trace_id: parts
.headers
.get(TRACE_ID_HEADER)
.and_then(|value| value.to_str().ok())
.unwrap_or_default()
.to_string(),
url: payload
.get("url")
.and_then(|value| value.as_str())
.unwrap_or_default()
.to_string(),
url: request_url.clone(),
model: payload
.get("body")
.and_then(|value| value.get("json_body"))
@@ -2149,8 +2184,7 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
.and_then(|value| value.as_str())
.unwrap_or_default()
.to_string(),
},
);
});
let frames = if attempt == 1 {
concat!(
@@ -2289,38 +2323,47 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
"data: {\"id\":\"chatcmpl-local-stream-failover-123\"}\n\ndata: [DONE]\n\n"
);
wait_until(5_000, || {
seen_execution_runtime
.lock()
.expect("mutex should lock")
.len()
>= 2
})
.await;
let seen_execution_runtime_requests = seen_execution_runtime
.lock()
.expect("mutex should lock")
.clone();
assert_eq!(seen_execution_runtime_requests.len(), 2);
let primary_request = seen_execution_runtime_requests
.iter()
.find(|request| request.url == "https://api.openai.primary.example/chat/completions")
.expect("primary execution runtime request should be captured");
let backup_request = seen_execution_runtime_requests
.iter()
.find(|request| request.url == "https://api.openai.backup.example/chat/completions")
.expect("backup execution runtime request should be captured");
assert_eq!(
seen_execution_runtime_requests[0].trace_id,
primary_request.trace_id,
"trace-openai-chat-local-stream-failover-123"
);
assert_eq!(primary_request.model, "gpt-5-upstream-primary");
assert!(primary_request.stream);
assert_eq!(primary_request.accept, "text/event-stream");
assert_eq!(
seen_execution_runtime_requests[0].url,
"https://api.openai.primary.example/chat/completions"
);
assert_eq!(
seen_execution_runtime_requests[0].authorization,
primary_request.authorization,
"Bearer sk-upstream-openai-primary"
);
assert_eq!(
seen_execution_runtime_requests[1].url,
"https://api.openai.backup.example/chat/completions"
backup_request.trace_id,
"trace-openai-chat-local-stream-failover-123"
);
assert_eq!(backup_request.model, "gpt-5-upstream-backup");
assert!(backup_request.stream);
assert_eq!(backup_request.accept, "text/event-stream");
assert_eq!(
seen_execution_runtime_requests[1].model,
"gpt-5-upstream-backup"
);
assert!(seen_execution_runtime_requests[1].stream);
assert_eq!(
seen_execution_runtime_requests[1].accept,
"text/event-stream"
);
assert_eq!(
seen_execution_runtime_requests[1].authorization,
backup_request.authorization,
"Bearer sk-upstream-openai-backup"
);
let stored_candidates = request_candidate_repository
@@ -2328,18 +2371,25 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
.await
.expect("request candidate trace should read");
assert_eq!(stored_candidates.len(), 2);
assert_eq!(stored_candidates[0].candidate_index, 0);
assert_eq!(stored_candidates[0].status, RequestCandidateStatus::Failed);
assert_eq!(stored_candidates[0].status_code, Some(429));
let failed_candidate = stored_candidates
.iter()
.find(|candidate| candidate.candidate_index == 0)
.expect("primary failed candidate should be stored");
let success_candidate = stored_candidates
.iter()
.find(|candidate| candidate.candidate_index == 1)
.expect("backup success candidate should be stored");
assert_eq!(failed_candidate.status, RequestCandidateStatus::Failed);
assert_eq!(failed_candidate.status_code, Some(429));
assert_eq!(
stored_candidates[0].error_type.as_deref(),
failed_candidate.error_type.as_deref(),
Some("retryable_upstream_status")
);
assert_eq!(
stored_candidates[0].error_message.as_deref(),
failed_candidate.error_message.as_deref(),
Some("execution runtime stream returned retryable status 429")
);
let failed_upstream_response = stored_candidates[0]
let failed_upstream_response = failed_candidate
.extra_data
.as_ref()
.and_then(|value| value.get("upstream_response"))
@@ -2353,11 +2403,10 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
failed_upstream_response["body"]["error"]["type"],
json!("rate_limit_error")
);
assert_eq!(stored_candidates[1].candidate_index, 1);
assert_eq!(stored_candidates[1].status, RequestCandidateStatus::Success);
assert_eq!(stored_candidates[1].status_code, Some(200));
assert!(stored_candidates[1].started_at_unix_ms.is_some());
assert!(stored_candidates[1].finished_at_unix_ms.is_some());
assert_eq!(success_candidate.status, RequestCandidateStatus::Success);
assert_eq!(success_candidate.status_code, Some(200));
assert!(success_candidate.started_at_unix_ms.is_some());
assert!(success_candidate.finished_at_unix_ms.is_some());
tokio::time::sleep(std::time::Duration::from_millis(100)).await;
assert!(
@@ -2366,7 +2415,7 @@ async fn gateway_retries_next_local_openai_chat_stream_candidate_after_retryable
);
assert_eq!(
*execution_runtime_hits.lock().expect("mutex should lock"),
execution_runtime_hits.load(std::sync::atomic::Ordering::SeqCst),
2
);
assert_eq!(*decision_hits.lock().expect("mutex should lock"), 0);
@@ -18,8 +18,39 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth_refresh() {
const STREAM_IMAGE_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_image_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_IMAGE_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream image test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[test]
fn gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth_refresh() {
run_stream_image_test(
"gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth_refresh",
gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth_refresh_impl,
);
}
async fn gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth_refresh_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -438,8 +469,15 @@ async fn gateway_executes_codex_image_stream_via_local_decision_gate_after_oauth
refresh_handle.abort();
}
#[tokio::test]
async fn gateway_bridges_codex_image_sync_json_to_streaming_image_sse() {
#[test]
fn gateway_bridges_codex_image_sync_json_to_streaming_image_sse() {
run_stream_image_test(
"gateway_bridges_codex_image_sync_json_to_streaming_image_sse",
gateway_bridges_codex_image_sync_json_to_streaming_image_sse_impl,
);
}
async fn gateway_bridges_codex_image_sync_json_to_streaming_image_sse_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -1057,8 +1095,16 @@ fn image_bridge_execution_runtime(
)
}
#[tokio::test]
async fn gateway_routes_openai_responses_stream_image_intent_to_openai_image_plan_without_streaming_support(
#[test]
fn gateway_routes_openai_responses_stream_image_intent_to_openai_image_plan_without_streaming_support(
) {
run_stream_image_test(
"gateway_routes_openai_responses_stream_image_intent_to_openai_image_plan_without_streaming_support",
gateway_routes_openai_responses_stream_image_intent_to_openai_image_plan_without_streaming_support_impl,
);
}
async fn gateway_routes_openai_responses_stream_image_intent_to_openai_image_plan_without_streaming_support_impl(
) {
let seen_execution_plan = Arc::new(Mutex::new(None::<SeenImageBridgeExecutionPlan>));
let execution_runtime = image_bridge_execution_runtime(Arc::clone(&seen_execution_plan));
@@ -228,8 +228,39 @@ fn collect_email_sentinel(text: &str) -> String {
text[start..end].to_string()
}
#[tokio::test]
async fn ai_execute_stream_pii_redaction_round_trip() {
const STREAM_PII_REDACTION_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_pii_redaction_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_PII_REDACTION_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream pii redaction test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[test]
fn ai_execute_stream_pii_redaction_round_trip() {
run_stream_pii_redaction_test(
"ai_execute_stream_pii_redaction_round_trip",
ai_execute_stream_pii_redaction_round_trip_impl,
);
}
async fn ai_execute_stream_pii_redaction_round_trip_impl() {
let seen_provider_request = Arc::new(Mutex::new(None::<SeenProviderStreamRequest>));
let seen_provider_request_clone = Arc::clone(&seen_provider_request);
let provider_app = Router::new().route(
@@ -1,8 +1,8 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override, json, start_server,
to_bytes, Arc, Body, Bytes, HeaderName, HeaderValue, Infallible, Json, Mutex, Request,
Response, Router, StatusCode, EXECUTION_PATH_EXECUTION_RUNTIME_STREAM, EXECUTION_PATH_HEADER,
TRACE_ID_HEADER,
any, build_router_with_state, build_state_with_execution_runtime_override, json,
run_stream_cli_test, start_server, to_bytes, Arc, Body, Bytes, HeaderName, HeaderValue,
Infallible, Json, Mutex, Request, Response, Router, StatusCode,
EXECUTION_PATH_EXECUTION_RUNTIME_STREAM, EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
};
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
use aether_data::repository::auth::{
@@ -22,8 +22,16 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_openai_responses_compact_stream_via_local_decision_gate_with_local_stream_decision(
#[test]
fn gateway_executes_openai_responses_compact_stream_via_local_decision_gate_with_local_stream_decision(
) {
run_stream_cli_test(
"gateway_executes_openai_responses_compact_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_openai_responses_compact_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_openai_responses_compact_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1,7 +1,8 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override, json, start_server,
strip_sse_keepalive_comments, to_bytes, Arc, Body, Bytes, HeaderName, HeaderValue, Infallible,
Json, Mutex, Request, Response, Router, StatusCode, UsageRuntimeConfig, TRACE_ID_HEADER,
any, build_router_with_state, build_state_with_execution_runtime_override, json,
run_stream_cli_test, start_server, strip_sse_keepalive_comments, to_bytes, Arc, Body, Bytes,
HeaderName, HeaderValue, Infallible, Json, Mutex, Request, Response, Router, StatusCode,
UsageRuntimeConfig, TRACE_ID_HEADER,
};
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
use aether_data::repository::auth::{
@@ -23,8 +24,15 @@ use aether_data_contracts::repository::provider_catalog::{
use aether_data_contracts::repository::usage::UsageReadRepository;
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_codex_cli_stream_via_local_decision_gate_after_oauth_refresh() {
#[test]
fn gateway_executes_codex_cli_stream_via_local_decision_gate_after_oauth_refresh() {
run_stream_cli_test(
"gateway_executes_codex_cli_stream_via_local_decision_gate_after_oauth_refresh",
gateway_executes_codex_cli_stream_via_local_decision_gate_after_oauth_refresh_impl,
);
}
async fn gateway_executes_codex_cli_stream_via_local_decision_gate_after_oauth_refresh_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -23,5 +23,29 @@ use super::{
GatewayFallbackReason, UsageRuntimeConfig, VideoTaskTruthSourceMode,
};
const STREAM_CLI_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_cli_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_CLI_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream cli test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
mod compact;
mod direct;
@@ -22,8 +22,39 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
#[tokio::test]
async fn gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_candidate() {
const STREAM_PROVIDER_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_provider_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_PROVIDER_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream provider test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[test]
fn gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_candidate() {
run_stream_provider_test(
"gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_candidate",
gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_candidate_impl,
);
}
async fn gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_candidate_impl() {
use base64::Engine as _;
#[derive(Debug, Clone)]
@@ -578,8 +609,16 @@ async fn gateway_executes_kiro_claude_cli_stream_via_local_provider_catalog_cand
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_claude_cli_stream_via_local_decision_gate_without_waiting_for_same_format_prefetch(
#[test]
fn gateway_executes_claude_cli_stream_via_local_decision_gate_without_waiting_for_same_format_prefetch(
) {
run_stream_provider_test(
"gateway_executes_claude_cli_stream_via_local_decision_gate_without_waiting_for_same_format_prefetch",
gateway_executes_claude_cli_stream_via_local_decision_gate_without_waiting_for_same_format_prefetch_impl,
);
}
async fn gateway_executes_claude_cli_stream_via_local_decision_gate_without_waiting_for_same_format_prefetch_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1026,8 +1065,15 @@ async fn gateway_executes_claude_cli_stream_via_local_decision_gate_without_wait
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_local_stream_decision(
#[test]
fn gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_local_stream_decision() {
run_stream_provider_test(
"gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1558,8 +1604,16 @@ async fn gateway_executes_claude_code_cli_stream_via_local_decision_gate_with_lo
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_claude_chat_stream_via_local_decision_gate_with_local_stream_decision() {
#[test]
fn gateway_executes_claude_chat_stream_via_local_decision_gate_with_local_stream_decision() {
run_stream_provider_test(
"gateway_executes_claude_chat_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_claude_chat_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_claude_chat_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -1,17 +1,25 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override,
encrypt_python_fernet_plaintext, json, start_server, strip_sse_keepalive_comments, to_bytes,
Arc, Body, Bytes, Digest, HeaderName, HeaderValue, InMemoryAuthApiKeySnapshotRepository,
InMemoryMinimalCandidateSelectionReadRepository, InMemoryProviderCatalogReadRepository,
InMemoryRequestCandidateRepository, Json, Mutex, Request, RequestCandidateReadRepository,
RequestCandidateStatus, Response, Router, Sha256, StatusCode, StoredAuthApiKeySnapshot,
StoredMinimalCandidateSelectionRow, StoredProviderCatalogEndpoint, StoredProviderCatalogKey,
StoredProviderCatalogProvider, StoredProviderModelMapping, DEVELOPMENT_ENCRYPTION_KEY,
TRACE_ID_HEADER,
encrypt_python_fernet_plaintext, json, run_stream_provider_gemini_test, start_server,
strip_sse_keepalive_comments, to_bytes, Arc, Body, Bytes, Digest, HeaderName, HeaderValue,
InMemoryAuthApiKeySnapshotRepository, InMemoryMinimalCandidateSelectionReadRepository,
InMemoryProviderCatalogReadRepository, InMemoryRequestCandidateRepository, Json, Mutex,
Request, RequestCandidateReadRepository, RequestCandidateStatus, Response, Router, Sha256,
StatusCode, StoredAuthApiKeySnapshot, StoredMinimalCandidateSelectionRow,
StoredProviderCatalogEndpoint, StoredProviderCatalogKey, StoredProviderCatalogProvider,
StoredProviderModelMapping, DEVELOPMENT_ENCRYPTION_KEY, TRACE_ID_HEADER,
};
#[tokio::test]
async fn gateway_executes_gemini_chat_stream_via_local_decision_gate_with_local_stream_decision() {
#[test]
fn gateway_executes_gemini_chat_stream_via_local_decision_gate_with_local_stream_decision() {
run_stream_provider_gemini_test(
"gateway_executes_gemini_chat_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_gemini_chat_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_gemini_chat_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -1,17 +1,25 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override,
encrypt_python_fernet_plaintext, json, start_server, strip_sse_keepalive_comments, to_bytes,
Arc, Body, Bytes, Digest, HeaderName, HeaderValue, InMemoryAuthApiKeySnapshotRepository,
InMemoryMinimalCandidateSelectionReadRepository, InMemoryProviderCatalogReadRepository,
InMemoryRequestCandidateRepository, Json, Mutex, Request, RequestCandidateReadRepository,
RequestCandidateStatus, Response, Router, Sha256, StatusCode, StoredAuthApiKeySnapshot,
StoredMinimalCandidateSelectionRow, StoredProviderCatalogEndpoint, StoredProviderCatalogKey,
StoredProviderCatalogProvider, StoredProviderModelMapping, DEVELOPMENT_ENCRYPTION_KEY,
TRACE_ID_HEADER,
encrypt_python_fernet_plaintext, json, run_stream_provider_gemini_test, start_server,
strip_sse_keepalive_comments, to_bytes, Arc, Body, Bytes, Digest, HeaderName, HeaderValue,
InMemoryAuthApiKeySnapshotRepository, InMemoryMinimalCandidateSelectionReadRepository,
InMemoryProviderCatalogReadRepository, InMemoryRequestCandidateRepository, Json, Mutex,
Request, RequestCandidateReadRepository, RequestCandidateStatus, Response, Router, Sha256,
StatusCode, StoredAuthApiKeySnapshot, StoredMinimalCandidateSelectionRow,
StoredProviderCatalogEndpoint, StoredProviderCatalogKey, StoredProviderCatalogProvider,
StoredProviderModelMapping, DEVELOPMENT_ENCRYPTION_KEY, TRACE_ID_HEADER,
};
#[tokio::test]
async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision() {
#[test]
fn gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision() {
run_stream_provider_gemini_test(
"gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -446,8 +454,15 @@ async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_with_local_s
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh() {
#[test]
fn gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh() {
run_stream_provider_gemini_test(
"gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh",
gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh_impl,
);
}
async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
trace_id: String,
@@ -1001,8 +1016,16 @@ async fn gateway_executes_gemini_cli_stream_via_local_decision_gate_after_oauth_
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision(
#[test]
fn gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision()
{
run_stream_provider_gemini_test(
"gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision",
gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision_impl,
);
}
async fn gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_with_local_stream_decision_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -1436,8 +1459,15 @@ async fn gateway_executes_vertex_ai_gemini_cli_stream_via_local_decision_gate_wi
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_antigravity_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh(
#[test]
fn gateway_executes_antigravity_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh() {
run_stream_provider_gemini_test(
"gateway_executes_antigravity_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh",
gateway_executes_antigravity_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh_impl,
);
}
async fn gateway_executes_antigravity_gemini_cli_stream_via_local_decision_gate_after_oauth_refresh_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
@@ -40,5 +40,29 @@ use aether_data_contracts::repository::provider_catalog::{
};
use sha2::{Digest, Sha256};
const STREAM_PROVIDER_GEMINI_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_stream_provider_gemini_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(STREAM_PROVIDER_GEMINI_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("stream provider gemini test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
mod local_chat;
mod local_cli;
@@ -1,11 +1,9 @@
use super::{
any, build_router_with_state, build_state_with_execution_runtime_override, json, start_server,
to_bytes, Arc, Body, Json, Mutex, Request, Router, StatusCode,
to_bytes, wait_until, Arc, Body, Json, Mutex, Request, Router, StatusCode,
EXECUTION_PATH_EXECUTION_RUNTIME_SYNC, EXECUTION_PATH_HEADER, TRACE_ID_HEADER,
};
use crate::constants::{
EXECUTION_PATH_LOCAL_API_KEY_CONCURRENCY_LIMITED, LOCAL_EXECUTION_RUNTIME_MISS_REASON_HEADER,
};
use crate::constants::LOCAL_EXECUTION_RUNTIME_MISS_REASON_HEADER;
use aether_crypto::{encrypt_python_fernet_plaintext, DEVELOPMENT_ENCRYPTION_KEY};
use aether_data::repository::auth::{
InMemoryAuthApiKeySnapshotRepository, StoredAuthApiKeySnapshot,
@@ -780,6 +778,7 @@ async fn gateway_waits_for_api_key_concurrency_slot_then_executes_openai_respons
"auth_context": {
"user_id": "user-openai-cli-local-limit-123",
"api_key_id": "key-openai-cli-local-limit-123",
"api_key_concurrent_limit": 1,
"access_allowed": true
},
"public_path": "/v1/responses"
@@ -969,15 +968,15 @@ async fn gateway_waits_for_api_key_concurrency_slot_then_executes_openai_respons
}
#[test]
fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_openai_responses_sync() {
fn gateway_executes_openai_responses_sync_after_api_key_concurrency_wait_budget_elapses() {
run_cli_sync_test(
"gateway_returns_concurrency_limited_after_wait_budget_expires_for_openai_responses_sync",
gateway_returns_concurrency_limited_after_wait_budget_expires_for_openai_responses_sync_impl,
"gateway_executes_openai_responses_sync_after_api_key_concurrency_wait_budget_elapses",
gateway_executes_openai_responses_sync_after_api_key_concurrency_wait_budget_elapses_impl,
);
}
async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_openai_responses_sync_impl(
) {
async fn gateway_executes_openai_responses_sync_after_api_key_concurrency_wait_budget_elapses_impl()
{
fn hash_api_key(value: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(value.as_bytes());
@@ -1126,36 +1125,7 @@ async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_opena
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let public_hits = Arc::new(Mutex::new(0usize));
let public_hits_clone = Arc::clone(&public_hits);
let now_unix_ms = chrono::Utc::now().timestamp_millis().max(0);
let request_candidate_repository = Arc::new(InMemoryRequestCandidateRepository::seed(vec![
aether_data_contracts::repository::candidates::StoredRequestCandidate::new(
"cand-pending-openai-cli-local-timeout-1".to_string(),
"req-inflight-openai-cli-local-timeout-1".to_string(),
Some("user-openai-cli-local-timeout-123".to_string()),
Some("key-openai-cli-local-timeout-123".to_string()),
Some("alice".to_string()),
Some("default".to_string()),
0,
0,
Some("provider-openai-cli-local-timeout-1".to_string()),
Some("endpoint-openai-cli-local-timeout-1".to_string()),
Some("key-openai-cli-local-timeout-1".to_string()),
RequestCandidateStatus::Pending,
None,
false,
None,
None,
None,
None,
None,
None,
None,
now_unix_ms,
Some(now_unix_ms),
None,
)
.expect("pending candidate should build"),
]));
let request_candidate_repository = Arc::new(InMemoryRequestCandidateRepository::default());
let upstream = Router::new()
.route(
@@ -1171,6 +1141,7 @@ async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_opena
"auth_context": {
"user_id": "user-openai-cli-local-timeout-123",
"api_key_id": "key-openai-cli-local-timeout-123",
"api_key_concurrent_limit": 1,
"access_allowed": true
},
"public_path": "/v1/responses"
@@ -1204,6 +1175,7 @@ async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_opena
*execution_runtime_hits_inner
.lock()
.expect("mutex should lock") += 1;
tokio::time::sleep(std::time::Duration::from_millis(300)).await;
Json(json!({
"request_id": "trace-openai-cli-local-timeout-123",
"status_code": 200,
@@ -1265,8 +1237,51 @@ async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_opena
let gateway = build_router_with_state(gateway_state);
let (gateway_url, gateway_handle) = start_server(gateway).await;
let client = reqwest::Client::new();
let first_client = client.clone();
let first_gateway_url = gateway_url.clone();
let first_request = tokio::spawn(async move {
first_client
.post(format!("{first_gateway_url}/v1/responses"))
.header(http::header::CONTENT_TYPE, "application/json")
.header(
http::header::AUTHORIZATION,
"Bearer sk-client-openai-cli-local-timeout",
)
.header(
TRACE_ID_HEADER,
"trace-openai-cli-local-timeout-inflight-123",
)
.body("{\"model\":\"gpt-5\",\"input\":\"first\",\"store\":false}")
.send()
.await
.expect("inflight request should complete")
});
wait_until(1_000, || {
*execution_runtime_hits.lock().expect("mutex should lock") >= 1
})
.await;
let pending_deadline = tokio::time::Instant::now() + std::time::Duration::from_millis(1_000);
loop {
let inflight_candidates = request_candidate_repository
.list_by_request_id("trace-openai-cli-local-timeout-inflight-123")
.await
.expect("inflight request candidate trace should read");
if inflight_candidates
.iter()
.any(|candidate| candidate.status == RequestCandidateStatus::Pending)
{
break;
}
assert!(
tokio::time::Instant::now() < pending_deadline,
"inflight request candidate did not become pending"
);
tokio::time::sleep(std::time::Duration::from_millis(10)).await;
}
let started_at = std::time::Instant::now();
let response = reqwest::Client::new()
let response = client
.post(format!("{gateway_url}/v1/responses"))
.header(http::header::CONTENT_TYPE, "application/json")
.header(
@@ -1281,44 +1296,40 @@ async fn gateway_returns_concurrency_limited_after_wait_budget_expires_for_opena
assert!(
started_at.elapsed() >= std::time::Duration::from_millis(100),
"request should wait for the bounded concurrency window before failing"
"request should wait for the bounded concurrency window before retrying"
);
assert_eq!(response.status(), StatusCode::SERVICE_UNAVAILABLE);
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response
.headers()
.get(EXECUTION_PATH_HEADER)
.and_then(|value| value.to_str().ok()),
Some(EXECUTION_PATH_LOCAL_API_KEY_CONCURRENCY_LIMITED)
Some(EXECUTION_PATH_EXECUTION_RUNTIME_SYNC)
);
assert_eq!(
response
.headers()
.get(LOCAL_EXECUTION_RUNTIME_MISS_REASON_HEADER)
.and_then(|value| value.to_str().ok()),
Some("auth_api_key_concurrency_limit_reached")
None
);
let payload: serde_json::Value = response.json().await.expect("body should parse");
assert_eq!(
payload["error"]["message"],
serde_json::Value::String("当前调用方 API Key 并发请求数已达上限,请稍后重试".to_string())
);
assert_eq!(payload["model"], "gpt-5-upstream");
let stored_candidates = request_candidate_repository
.list_by_request_id("trace-openai-cli-local-timeout-123")
.await
.expect("request candidate trace should read");
assert_eq!(stored_candidates.len(), 1);
assert_eq!(stored_candidates[0].status, RequestCandidateStatus::Skipped);
assert_eq!(
stored_candidates[0].skip_reason.as_deref(),
Some("auth_api_key_concurrency_limit_reached")
);
assert_eq!(stored_candidates[0].status, RequestCandidateStatus::Success);
assert_eq!(stored_candidates[0].skip_reason.as_deref(), None);
assert_eq!(
*execution_runtime_hits.lock().expect("mutex should lock"),
0
2
);
assert_eq!(*public_hits.lock().expect("mutex should lock"), 0);
let first_response = first_request.await.expect("inflight request should join");
assert_eq!(first_response.status(), StatusCode::OK);
gateway_handle.abort();
execution_runtime_handle.abort();
@@ -43,8 +43,15 @@ where
}
}
#[tokio::test]
async fn gateway_converts_openai_image_sync_to_gemini_image_provider() {
#[test]
fn gateway_converts_openai_image_sync_to_gemini_image_provider() {
run_image_sync_test(
"gateway_converts_openai_image_sync_to_gemini_image_provider",
gateway_converts_openai_image_sync_to_gemini_image_provider_impl,
);
}
async fn gateway_converts_openai_image_sync_to_gemini_image_provider_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
trace_id: String,
@@ -765,8 +772,15 @@ async fn gateway_converts_gemini_image_sync_to_openai_image_provider_impl() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_refresh() {
#[test]
fn gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_refresh() {
run_image_sync_test(
"gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_refresh",
gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_refresh_impl,
);
}
async fn gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_refresh_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
trace_id: String,
@@ -1271,8 +1285,15 @@ async fn gateway_executes_codex_image_sync_via_local_decision_gate_after_oauth_r
refresh_handle.abort();
}
#[tokio::test]
async fn gateway_plans_chatgpt_web_image_sync_with_internal_web_executor_url() {
#[test]
fn gateway_plans_chatgpt_web_image_sync_with_internal_web_executor_url() {
run_image_sync_test(
"gateway_plans_chatgpt_web_image_sync_with_internal_web_executor_url",
gateway_plans_chatgpt_web_image_sync_with_internal_web_executor_url_impl,
);
}
async fn gateway_plans_chatgpt_web_image_sync_with_internal_web_executor_url_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
trace_id: String,
+60 -8
View File
@@ -23,6 +23,30 @@ use aether_runtime_state::{
use crate::data::GatewayDataState;
const CONCURRENCY_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_concurrency_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(CONCURRENCY_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("concurrency test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn memory_runtime_semaphore(gate: &'static str, limit: usize) -> RuntimeSemaphore {
RuntimeState::memory(MemoryRuntimeStateConfig::default())
.semaphore(gate, limit, RuntimeSemaphoreConfig::default())
@@ -80,8 +104,15 @@ fn build_local_openai_gateway_state(
)
}
#[tokio::test]
async fn gateway_rejects_second_in_flight_stream_request_with_distributed_overload() {
#[test]
fn gateway_rejects_second_in_flight_stream_request_with_distributed_overload() {
run_concurrency_test(
"gateway_rejects_second_in_flight_stream_request_with_distributed_overload",
gateway_rejects_second_in_flight_stream_request_with_distributed_overload_impl,
);
}
async fn gateway_rejects_second_in_flight_stream_request_with_distributed_overload_impl() {
let execution_runtime_hits = Arc::new(AtomicUsize::new(0));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -175,8 +206,15 @@ async fn gateway_rejects_second_in_flight_stream_request_with_distributed_overlo
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_second_in_flight_stream_request_with_local_overload() {
#[test]
fn gateway_rejects_second_in_flight_stream_request_with_local_overload() {
run_concurrency_test(
"gateway_rejects_second_in_flight_stream_request_with_local_overload",
gateway_rejects_second_in_flight_stream_request_with_local_overload_impl,
);
}
async fn gateway_rejects_second_in_flight_stream_request_with_local_overload_impl() {
let execution_runtime_hits = Arc::new(AtomicUsize::new(0));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -262,8 +300,15 @@ async fn gateway_rejects_second_in_flight_stream_request_with_local_overload() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_exposes_request_concurrency_metrics() {
#[test]
fn gateway_exposes_request_concurrency_metrics() {
run_concurrency_test(
"gateway_exposes_request_concurrency_metrics",
gateway_exposes_request_concurrency_metrics_impl,
);
}
async fn gateway_exposes_request_concurrency_metrics_impl() {
let gateway = build_router_with_state(
AppState::new()
.expect("gateway state should build")
@@ -302,8 +347,15 @@ async fn gateway_exposes_request_concurrency_metrics() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_exposes_fallback_metrics() {
#[test]
fn gateway_exposes_fallback_metrics() {
run_concurrency_test(
"gateway_exposes_fallback_metrics",
gateway_exposes_fallback_metrics_impl,
);
}
async fn gateway_exposes_fallback_metrics_impl() {
let state = AppState::new().expect("gateway state should build");
let decision = sample_decision();
state.record_fallback_metric(
@@ -27,6 +27,30 @@ use crate::constants::{
};
use crate::data::GatewayDataState;
const PROVIDER_KEYS_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_provider_keys_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(PROVIDER_KEYS_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("provider keys test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
struct SummaryNullingProviderCatalogReadRepository {
inner: InMemoryProviderCatalogReadRepository,
}
@@ -879,8 +903,15 @@ async fn provider_key_concurrent_limit_reads_existing_list_response() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_fetches_allowed_models_immediately_when_creating_key_with_auto_fetch() {
#[test]
fn gateway_fetches_allowed_models_immediately_when_creating_key_with_auto_fetch() {
run_provider_keys_test(
"gateway_fetches_allowed_models_immediately_when_creating_key_with_auto_fetch",
gateway_fetches_allowed_models_immediately_when_creating_key_with_auto_fetch_impl,
);
}
async fn gateway_fetches_allowed_models_immediately_when_creating_key_with_auto_fetch_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -1759,8 +1790,15 @@ async fn provider_key_concurrent_limit_update_presence_semantics() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key_update() {
#[test]
fn gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key_update() {
run_provider_keys_test(
"gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key_update",
gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key_update_impl,
);
}
async fn gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key_update_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -1835,8 +1873,15 @@ async fn gateway_clears_allowed_models_when_disabling_auto_fetch_on_provider_key
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch() {
#[test]
fn gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch() {
run_provider_keys_test(
"gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch",
gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch_impl,
);
}
async fn gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -1948,8 +1993,16 @@ async fn gateway_overwrites_allowed_models_immediately_when_enabling_auto_fetch(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_from_empty_state() {
#[test]
fn gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_from_empty_state() {
run_provider_keys_test(
"gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_from_empty_state",
gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_from_empty_state_impl,
);
}
async fn gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_from_empty_state_impl()
{
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -2054,8 +2107,16 @@ async fn gateway_fetches_allowed_models_immediately_when_enabling_auto_fetch_fro
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_refreshes_allowed_models_when_updating_include_patterns_with_auto_fetch_enabled() {
#[test]
fn gateway_refreshes_allowed_models_when_updating_include_patterns_with_auto_fetch_enabled() {
run_provider_keys_test(
"gateway_refreshes_allowed_models_when_updating_include_patterns_with_auto_fetch_enabled",
gateway_refreshes_allowed_models_when_updating_include_patterns_with_auto_fetch_enabled_impl,
);
}
async fn gateway_refreshes_allowed_models_when_updating_include_patterns_with_auto_fetch_enabled_impl(
) {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -2158,8 +2219,16 @@ async fn gateway_refreshes_allowed_models_when_updating_include_patterns_with_au
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_refreshes_allowed_models_when_updating_exclude_patterns_with_auto_fetch_enabled() {
#[test]
fn gateway_refreshes_allowed_models_when_updating_exclude_patterns_with_auto_fetch_enabled() {
run_provider_keys_test(
"gateway_refreshes_allowed_models_when_updating_exclude_patterns_with_auto_fetch_enabled",
gateway_refreshes_allowed_models_when_updating_exclude_patterns_with_auto_fetch_enabled_impl,
);
}
async fn gateway_refreshes_allowed_models_when_updating_exclude_patterns_with_auto_fetch_enabled_impl(
) {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
File diff suppressed because it is too large Load Diff
@@ -32,16 +32,16 @@ use crate::constants::{
};
use crate::data::{GatewayDataConfig, GatewayDataState};
const SUB2API_PROVIDER_OPS_BALANCE_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
const PROVIDER_OPS_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_sub2api_provider_ops_balance_test<F, Fut>(test_name: &'static str, make_future: F)
fn run_provider_ops_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(SUB2API_PROVIDER_OPS_BALANCE_TEST_STACK_BYTES)
.stack_size(PROVIDER_OPS_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
@@ -49,7 +49,7 @@ where
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("sub2api provider ops balance test thread should spawn");
.expect("provider ops test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
@@ -117,8 +117,16 @@ fn assert_provider_ops_architectures_payload(payload: &serde_json::Value) {
assert_eq!(new_api["supported_auth_types"][0]["type"], "api_key");
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_architectures_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_architectures_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_architectures_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_architectures_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_architectures_locally_with_trusted_admin_principal_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -157,8 +165,15 @@ async fn gateway_handles_admin_provider_ops_architectures_locally_with_trusted_a
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_architectures_locally_with_bearer_admin_session() {
#[test]
fn gateway_handles_admin_provider_ops_architectures_locally_with_bearer_admin_session() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_architectures_locally_with_bearer_admin_session",
gateway_handles_admin_provider_ops_architectures_locally_with_bearer_admin_session_impl,
);
}
async fn gateway_handles_admin_provider_ops_architectures_locally_with_bearer_admin_session_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -197,8 +212,15 @@ async fn gateway_handles_admin_provider_ops_architectures_locally_with_bearer_ad
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_architecture_detail_locally_with_trusted_admin_principal(
#[test]
fn gateway_handles_admin_provider_ops_architecture_detail_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_architecture_detail_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_architecture_detail_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_architecture_detail_locally_with_trusted_admin_principal_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
@@ -241,8 +263,15 @@ async fn gateway_handles_admin_provider_ops_architecture_detail_locally_with_tru
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -328,8 +357,15 @@ async fn gateway_handles_admin_provider_ops_status_locally_with_trusted_admin_pr
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -427,8 +463,15 @@ async fn gateway_handles_admin_provider_ops_config_locally_with_trusted_admin_pr
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_principal() {
#[test]
fn gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_principal",
gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -592,8 +635,15 @@ async fn gateway_saves_admin_provider_ops_config_locally_with_trusted_admin_prin
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_principal() {
#[test]
fn gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_principal",
gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -688,8 +738,15 @@ async fn gateway_deletes_admin_provider_ops_config_locally_with_trusted_admin_pr
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_principal() {
#[test]
fn gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_principal",
gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -729,9 +786,16 @@ async fn gateway_disconnects_admin_provider_ops_locally_with_trusted_admin_princ
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_generic_api_with_trusted_admin_principal()
{
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_generic_api_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_generic_api_with_trusted_admin_principal",
gateway_verifies_admin_provider_ops_locally_for_generic_api_with_trusted_admin_principal_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_generic_api_with_trusted_admin_principal_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -830,8 +894,16 @@ async fn gateway_verifies_admin_provider_ops_locally_for_generic_api_with_truste
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_admin_principal() {
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_admin_principal",
gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_admin_principal_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_admin_principal_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -961,8 +1033,15 @@ async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_trusted_
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_auth_failure_message(
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_auth_failure_message() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_auth_failure_message",
gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_auth_failure_message_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_auth_failure_message_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
@@ -1052,8 +1131,16 @@ async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_with_cookie_a
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redirect_body_contains_arg1(
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redirect_body_contains_arg1()
{
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redirect_body_contains_arg1",
gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redirect_body_contains_arg1_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redirect_body_contains_arg1_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
@@ -1177,8 +1264,15 @@ async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_when_acw_redi
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode() {
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode",
gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode_impl() {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -1327,8 +1421,16 @@ async fn gateway_verifies_admin_provider_ops_locally_for_anyrouter_proxy_mode()
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_runtime_http1_only() {
#[test]
fn gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_runtime_http1_only() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_runtime_http1_only",
gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_runtime_http1_only_impl,
);
}
async fn gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_runtime_http1_only_impl(
) {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -1475,8 +1577,16 @@ async fn gateway_verifies_admin_provider_ops_sub2api_proxy_mode_via_execution_ru
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_admin_principal() {
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_admin_principal",
gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_admin_principal_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_admin_principal_impl()
{
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -1616,8 +1726,15 @@ async fn gateway_verifies_admin_provider_ops_locally_for_new_api_with_trusted_ad
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode() {
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode",
gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode_impl() {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -1741,8 +1858,15 @@ async fn gateway_verifies_admin_provider_ops_locally_for_new_api_proxy_node_mode
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_via_execution_runtime(
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_via_execution_runtime() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_via_execution_runtime",
gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_via_execution_runtime_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_via_execution_runtime_impl(
) {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
@@ -1844,8 +1968,16 @@ async fn gateway_verifies_admin_provider_ops_locally_for_new_api_without_proxy_v
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_admin_principal() {
#[test]
fn gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_admin_principal",
gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_admin_principal_impl,
);
}
async fn gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_admin_principal_impl()
{
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -1974,8 +2106,16 @@ async fn gateway_verifies_admin_provider_ops_locally_for_sub2api_with_trusted_ad
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base_url_has_path() {
#[test]
fn gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base_url_has_path() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base_url_has_path",
gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base_url_has_path_impl,
);
}
async fn gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base_url_has_path_impl()
{
let nested_refresh_hits = Arc::new(Mutex::new(0usize));
let nested_refresh_hits_clone = Arc::clone(&nested_refresh_hits);
let root_refresh_hits = Arc::new(Mutex::new(0usize));
@@ -2104,8 +2244,16 @@ async fn gateway_verifies_admin_provider_ops_sub2api_against_site_root_when_base
verify_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_without_refresh() {
#[test]
fn gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_without_refresh() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_without_refresh",
gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_without_refresh_impl,
);
}
async fn gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_without_refresh_impl()
{
let refresh_hits = Arc::new(Mutex::new(0usize));
let refresh_hits_clone = Arc::clone(&refresh_hits);
let ops = Router::new()
@@ -2233,8 +2381,15 @@ async fn gateway_verifies_admin_provider_ops_sub2api_with_cached_access_token_wi
ops_handle.abort();
}
#[tokio::test]
async fn gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_credentials() {
#[test]
fn gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_credentials() {
run_provider_ops_test(
"gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_credentials",
gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_credentials_impl,
);
}
async fn gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_credentials_impl() {
let ops = Router::new()
.route(
"/api/v1/auth/refresh",
@@ -2409,8 +2564,15 @@ async fn gateway_verifies_admin_provider_ops_sub2api_persists_rotated_runtime_cr
ops_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_principal() {
#[test]
fn gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_principal",
gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -2493,8 +2655,15 @@ async fn gateway_rejects_admin_provider_ops_connect_locally_with_trusted_admin_p
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -2624,8 +2793,15 @@ async fn gateway_handles_admin_provider_ops_balance_locally_with_trusted_admin_p
ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_balance_locally_for_generic_api_proxy_node_mode() {
#[test]
fn gateway_handles_admin_provider_ops_balance_locally_for_generic_api_proxy_node_mode() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_balance_locally_for_generic_api_proxy_node_mode",
gateway_handles_admin_provider_ops_balance_locally_for_generic_api_proxy_node_mode_impl,
);
}
async fn gateway_handles_admin_provider_ops_balance_locally_for_generic_api_proxy_node_mode_impl() {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -2774,8 +2950,16 @@ async fn gateway_handles_admin_provider_ops_balance_locally_for_generic_api_prox
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_execution_runtime() {
#[test]
fn gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_execution_runtime() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_execution_runtime",
gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_execution_runtime_impl,
);
}
async fn gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_execution_runtime_impl(
) {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -2913,8 +3097,15 @@ async fn gateway_handles_admin_provider_ops_balance_locally_without_proxy_via_ex
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_principal_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -3025,8 +3216,15 @@ async fn gateway_handles_admin_provider_ops_checkin_locally_with_trusted_admin_p
ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_proxy_node_mode() {
#[test]
fn gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_proxy_node_mode() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_proxy_node_mode",
gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_proxy_node_mode_impl,
);
}
async fn gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_proxy_node_mode_impl() {
let execution_plans = Arc::new(Mutex::new(Vec::<ExecutionPlan>::new()));
let execution_plans_clone = Arc::clone(&execution_plans);
let execution_runtime = Router::new().route(
@@ -3150,8 +3348,16 @@ async fn gateway_handles_admin_provider_ops_checkin_locally_for_generic_api_prox
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_admin_principal() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_admin_principal_impl(
) {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -3387,8 +3593,15 @@ async fn gateway_handles_admin_provider_ops_batch_balance_locally_with_trusted_a
ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_cookie() {
#[test]
fn gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_cookie() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_cookie",
gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_cookie_impl,
);
}
async fn gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_cookie_impl() {
let ops = Router::new()
.route(
"/",
@@ -3519,8 +3732,15 @@ async fn gateway_handles_admin_provider_ops_anyrouter_balance_with_auth_expired_
ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_redis() {
#[test]
fn gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_redis() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_redis",
gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_redis_impl,
);
}
async fn gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_redis_impl() {
let Some(redis) = start_managed_redis_or_skip().await else {
return;
};
@@ -3672,8 +3892,16 @@ async fn gateway_handles_admin_provider_ops_balance_cache_refresh_modes_with_red
ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_returns_live_payload_once_with_redis(
#[test]
fn gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_returns_live_payload_once_with_redis(
) {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_returns_live_payload_once_with_redis",
gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_returns_live_payload_once_with_redis_impl,
);
}
async fn gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_returns_live_payload_once_with_redis_impl(
) {
let Some(redis) = start_managed_redis_or_skip().await else {
return;
@@ -3801,8 +4029,15 @@ async fn gateway_handles_admin_provider_ops_balance_cache_miss_without_refresh_r
ops_handle.abort();
}
#[tokio::test]
async fn gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_redis() {
#[test]
fn gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_redis() {
run_provider_ops_test(
"gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_redis",
gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_redis_impl,
);
}
async fn gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_redis_impl() {
let Some(redis) = start_managed_redis_or_skip().await else {
return;
};
@@ -3989,8 +4224,15 @@ async fn gateway_clears_admin_provider_ops_balance_cache_after_config_save_with_
ops_v2_handle.abort();
}
#[tokio::test]
async fn gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_action_config() {
#[test]
fn gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_action_config() {
run_provider_ops_test(
"gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_action_config",
gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_action_config_impl,
);
}
async fn gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_action_config_impl() {
let Some(redis) = start_managed_redis_or_skip().await else {
return;
};
@@ -4222,8 +4464,15 @@ async fn gateway_verify_does_not_pollute_balance_cache_and_balance_uses_saved_ac
verify_ops_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hits_and_redis() {
#[test]
fn gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hits_and_redis() {
run_provider_ops_test(
"gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hits_and_redis",
gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hits_and_redis_impl,
);
}
async fn gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hits_and_redis_impl() {
let Some(redis) = start_managed_redis_or_skip().await else {
return;
};
@@ -4354,7 +4603,7 @@ async fn gateway_handles_admin_provider_ops_batch_balance_with_pending_cache_hit
#[test]
fn gateway_handles_admin_provider_ops_sub2api_balance_with_refresh_token_rotation() {
run_sub2api_provider_ops_balance_test(
run_provider_ops_test(
"gateway_handles_admin_provider_ops_sub2api_balance_with_refresh_token_rotation",
gateway_handles_admin_provider_ops_sub2api_balance_with_refresh_token_rotation_impl,
);
@@ -4566,7 +4815,7 @@ async fn gateway_handles_admin_provider_ops_sub2api_balance_with_refresh_token_r
#[test]
fn gateway_handles_admin_provider_ops_sub2api_balance_against_site_root_when_base_url_has_path() {
run_sub2api_provider_ops_balance_test(
run_provider_ops_test(
"gateway_handles_admin_provider_ops_sub2api_balance_against_site_root_when_base_url_has_path",
gateway_handles_admin_provider_ops_sub2api_balance_against_site_root_when_base_url_has_path_impl,
);
@@ -4782,7 +5031,7 @@ async fn gateway_handles_admin_provider_ops_sub2api_balance_against_site_root_wh
#[test]
fn gateway_handles_admin_provider_ops_sub2api_balance_with_session_login() {
run_sub2api_provider_ops_balance_test(
run_provider_ops_test(
"gateway_handles_admin_provider_ops_sub2api_balance_with_session_login",
gateway_handles_admin_provider_ops_sub2api_balance_with_session_login_impl,
);
@@ -29,6 +29,30 @@ use crate::constants::{
};
use crate::data::GatewayDataState;
const PROVIDER_QUERY_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_provider_query_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(PROVIDER_QUERY_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("provider query test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn crc32(data: &[u8]) -> u32 {
let mut crc = 0xffff_ffffu32;
for &byte in data {
@@ -122,8 +146,15 @@ async fn assert_admin_provider_query_route(
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_fetches_upstream_for_selected_key() {
#[test]
fn gateway_handles_admin_provider_query_models_fetches_upstream_for_selected_key() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_fetches_upstream_for_selected_key",
gateway_handles_admin_provider_query_models_fetches_upstream_for_selected_key_impl,
);
}
async fn gateway_handles_admin_provider_query_models_fetches_upstream_for_selected_key_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -244,8 +275,15 @@ async fn gateway_handles_admin_provider_query_models_fetches_upstream_for_select
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_fetches_windsurf_model_configs() {
#[test]
fn gateway_handles_admin_provider_query_models_fetches_windsurf_model_configs() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_fetches_windsurf_model_configs",
gateway_handles_admin_provider_query_models_fetches_windsurf_model_configs_impl,
);
}
async fn gateway_handles_admin_provider_query_models_fetches_windsurf_model_configs_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -382,8 +420,15 @@ async fn gateway_handles_admin_provider_query_models_fetches_windsurf_model_conf
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_with_openai_responses_endpoint() {
#[test]
fn gateway_handles_admin_provider_query_models_with_openai_responses_endpoint() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_with_openai_responses_endpoint",
gateway_handles_admin_provider_query_models_with_openai_responses_endpoint_impl,
);
}
async fn gateway_handles_admin_provider_query_models_with_openai_responses_endpoint_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -492,8 +537,15 @@ async fn gateway_handles_admin_provider_query_models_with_openai_responses_endpo
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_when_token_invalidated(
#[test]
fn gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_when_token_invalidated() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_when_token_invalidated",
gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_when_token_invalidated_impl,
);
}
async fn gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_when_token_invalidated_impl(
) {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
@@ -598,8 +650,15 @@ async fn gateway_handles_admin_provider_query_models_falls_back_to_codex_preset_
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_respecting_key_api_formats() {
#[test]
fn gateway_handles_admin_provider_query_models_respecting_key_api_formats() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_respecting_key_api_formats",
gateway_handles_admin_provider_query_models_respecting_key_api_formats_impl,
);
}
async fn gateway_handles_admin_provider_query_models_respecting_key_api_formats_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -729,8 +788,15 @@ async fn gateway_handles_admin_provider_query_models_respecting_key_api_formats(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_aggregating_active_keys() {
#[test]
fn gateway_handles_admin_provider_query_models_aggregating_active_keys() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_aggregating_active_keys",
gateway_handles_admin_provider_query_models_aggregating_active_keys_impl,
);
}
async fn gateway_handles_admin_provider_query_models_aggregating_active_keys_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -871,8 +937,15 @@ async fn gateway_handles_admin_provider_query_models_aggregating_active_keys() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_models_for_fixed_provider_without_endpoint() {
#[test]
fn gateway_handles_admin_provider_query_models_for_fixed_provider_without_endpoint() {
run_provider_query_test(
"gateway_handles_admin_provider_query_models_for_fixed_provider_without_endpoint",
gateway_handles_admin_provider_query_models_for_fixed_provider_without_endpoint_impl,
);
}
async fn gateway_handles_admin_provider_query_models_for_fixed_provider_without_endpoint_impl() {
let execution_runtime_hits = Arc::new(Mutex::new(0usize));
let execution_runtime_hits_clone = Arc::clone(&execution_runtime_hits);
let execution_runtime = Router::new().route(
@@ -946,8 +1019,16 @@ async fn gateway_handles_admin_provider_query_models_for_fixed_provider_without_
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_test_model_locally_with_trusted_admin_principal() {
#[test]
fn gateway_handles_admin_provider_query_test_model_locally_with_trusted_admin_principal() {
run_provider_query_test(
"gateway_handles_admin_provider_query_test_model_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_query_test_model_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_query_test_model_locally_with_trusted_admin_principal_impl()
{
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1056,8 +1137,15 @@ async fn gateway_handles_admin_provider_query_test_model_locally_with_trusted_ad
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_embedding_model_test() {
#[test]
fn gateway_handles_admin_provider_query_embedding_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_embedding_model_test",
gateway_handles_admin_provider_query_embedding_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_embedding_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1167,8 +1255,15 @@ async fn gateway_handles_admin_provider_query_embedding_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_doubao_text_embedding_model_test() {
#[test]
fn gateway_handles_admin_provider_query_doubao_text_embedding_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_doubao_text_embedding_model_test",
gateway_handles_admin_provider_query_doubao_text_embedding_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_doubao_text_embedding_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1281,8 +1376,15 @@ async fn gateway_handles_admin_provider_query_doubao_text_embedding_model_test()
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_gemini_embedding_model_test() {
#[test]
fn gateway_handles_admin_provider_query_gemini_embedding_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_gemini_embedding_model_test",
gateway_handles_admin_provider_query_gemini_embedding_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_gemini_embedding_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1396,8 +1498,15 @@ async fn gateway_handles_admin_provider_query_gemini_embedding_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test() {
#[test]
fn gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test",
gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1536,8 +1645,15 @@ async fn gateway_handles_admin_provider_query_vertex_gemini_embedding_model_test
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_jina_embedding_model_test() {
#[test]
fn gateway_handles_admin_provider_query_jina_embedding_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_jina_embedding_model_test",
gateway_handles_admin_provider_query_jina_embedding_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_jina_embedding_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1647,8 +1763,15 @@ async fn gateway_handles_admin_provider_query_jina_embedding_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_openai_rerank_model_test() {
#[test]
fn gateway_handles_admin_provider_query_openai_rerank_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_openai_rerank_model_test",
gateway_handles_admin_provider_query_openai_rerank_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_openai_rerank_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1765,8 +1888,15 @@ async fn gateway_handles_admin_provider_query_openai_rerank_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_rerank_model_test() {
#[test]
fn gateway_handles_admin_provider_query_rerank_model_test() {
run_provider_query_test(
"gateway_handles_admin_provider_query_rerank_model_test",
gateway_handles_admin_provider_query_rerank_model_test_impl,
);
}
async fn gateway_handles_admin_provider_query_rerank_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -1886,8 +2016,15 @@ async fn gateway_handles_admin_provider_query_rerank_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_maps_admin_provider_model_before_model_list_test_request() {
#[test]
fn gateway_maps_admin_provider_model_before_model_list_test_request() {
run_provider_query_test(
"gateway_maps_admin_provider_model_before_model_list_test_request",
gateway_maps_admin_provider_model_before_model_list_test_request_impl,
);
}
async fn gateway_maps_admin_provider_model_before_model_list_test_request_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2141,8 +2278,15 @@ async fn gateway_maps_admin_provider_model_before_model_list_test_request() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_test() {
#[test]
fn gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_test() {
run_provider_query_test(
"gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_test",
gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_test_impl,
);
}
async fn gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2247,8 +2391,15 @@ async fn gateway_streams_codex_openai_responses_upstream_for_admin_pool_model_te
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtime() {
#[test]
fn gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtime() {
run_provider_query_test(
"gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtime",
gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtime_impl,
);
}
async fn gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtime_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2385,8 +2536,15 @@ async fn gateway_routes_grok_responses_admin_pool_model_test_through_grok_runtim
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_streams_windsurf_connect_upstream_for_admin_model_test() {
#[test]
fn gateway_streams_windsurf_connect_upstream_for_admin_model_test() {
run_provider_query_test(
"gateway_streams_windsurf_connect_upstream_for_admin_model_test",
gateway_streams_windsurf_connect_upstream_for_admin_model_test_impl,
);
}
async fn gateway_streams_windsurf_connect_upstream_for_admin_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2501,8 +2659,15 @@ async fn gateway_streams_windsurf_connect_upstream_for_admin_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_pool_scheduler_order_for_admin_pool_model_test() {
#[test]
fn gateway_uses_pool_scheduler_order_for_admin_pool_model_test() {
run_provider_query_test(
"gateway_uses_pool_scheduler_order_for_admin_pool_model_test",
gateway_uses_pool_scheduler_order_for_admin_pool_model_test_impl,
);
}
async fn gateway_uses_pool_scheduler_order_for_admin_pool_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2649,8 +2814,15 @@ async fn gateway_uses_pool_scheduler_order_for_admin_pool_model_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_test_model_failover_locally_with_trusted_admin_principal(
#[test]
fn gateway_handles_admin_provider_query_test_model_failover_locally_with_trusted_admin_principal() {
run_provider_query_test(
"gateway_handles_admin_provider_query_test_model_failover_locally_with_trusted_admin_principal",
gateway_handles_admin_provider_query_test_model_failover_locally_with_trusted_admin_principal_impl,
);
}
async fn gateway_handles_admin_provider_query_test_model_failover_locally_with_trusted_admin_principal_impl(
) {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
@@ -2825,8 +2997,15 @@ async fn gateway_handles_admin_provider_query_test_model_failover_locally_with_t
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_test_model_for_kiro_locally() {
#[test]
fn gateway_handles_admin_provider_query_test_model_for_kiro_locally() {
run_provider_query_test(
"gateway_handles_admin_provider_query_test_model_for_kiro_locally",
gateway_handles_admin_provider_query_test_model_for_kiro_locally_impl,
);
}
async fn gateway_handles_admin_provider_query_test_model_for_kiro_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -2949,8 +3128,15 @@ async fn gateway_handles_admin_provider_query_test_model_for_kiro_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test() {
#[test]
fn gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test() {
run_provider_query_test(
"gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test",
gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test_impl,
);
}
async fn gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -3141,8 +3327,15 @@ async fn gateway_uses_kiro_mapped_model_name_for_explicit_model_mapping_test() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_test_model_failover_for_kiro_locally() {
#[test]
fn gateway_handles_admin_provider_query_test_model_failover_for_kiro_locally() {
run_provider_query_test(
"gateway_handles_admin_provider_query_test_model_failover_for_kiro_locally",
gateway_handles_admin_provider_query_test_model_failover_for_kiro_locally_impl,
);
}
async fn gateway_handles_admin_provider_query_test_model_failover_for_kiro_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -3298,8 +3491,15 @@ async fn gateway_handles_admin_provider_query_test_model_failover_for_kiro_local
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_retries_kiro_failover_after_http_error_without_message() {
#[test]
fn gateway_retries_kiro_failover_after_http_error_without_message() {
run_provider_query_test(
"gateway_retries_kiro_failover_after_http_error_without_message",
gateway_retries_kiro_failover_after_http_error_without_message_impl,
);
}
async fn gateway_retries_kiro_failover_after_http_error_without_message_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -3443,8 +3643,15 @@ async fn gateway_retries_kiro_failover_after_http_error_without_message() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_non_kiro_multi_model_failover_locally() {
#[test]
fn gateway_handles_non_kiro_multi_model_failover_locally() {
run_provider_query_test(
"gateway_handles_non_kiro_multi_model_failover_locally",
gateway_handles_non_kiro_multi_model_failover_locally_impl,
);
}
async fn gateway_handles_non_kiro_multi_model_failover_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -3558,8 +3765,15 @@ async fn gateway_handles_non_kiro_multi_model_failover_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_openai_responses_test_model_locally() {
#[test]
fn gateway_handles_openai_responses_test_model_locally() {
run_provider_query_test(
"gateway_handles_openai_responses_test_model_locally",
gateway_handles_openai_responses_test_model_locally_impl,
);
}
async fn gateway_handles_openai_responses_test_model_locally_impl() {
let prompt = "Tell me whether the CLI request preserved this prompt.";
let execution_runtime = Router::new().route(
"/v1/execute/sync",
@@ -3728,8 +3942,15 @@ async fn gateway_handles_openai_responses_test_model_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_openai_image_test_model_locally() {
#[test]
fn gateway_handles_openai_image_test_model_locally() {
run_provider_query_test(
"gateway_handles_openai_image_test_model_locally",
gateway_handles_openai_image_test_model_locally_impl,
);
}
async fn gateway_handles_openai_image_test_model_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -3846,8 +4067,15 @@ async fn gateway_handles_openai_image_test_model_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_reports_transport_unsupported_reason_for_non_kiro_provider() {
#[test]
fn gateway_reports_transport_unsupported_reason_for_non_kiro_provider() {
run_provider_query_test(
"gateway_reports_transport_unsupported_reason_for_non_kiro_provider",
gateway_reports_transport_unsupported_reason_for_non_kiro_provider_impl,
);
}
async fn gateway_reports_transport_unsupported_reason_for_non_kiro_provider_impl() {
let mut provider = sample_provider("provider-antigravity", "Antigravity", 10);
provider.provider_type = "antigravity".to_string();
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
@@ -3904,8 +4132,15 @@ async fn gateway_reports_transport_unsupported_reason_for_non_kiro_provider() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_handles_antigravity_endpoint_test_model_locally() {
#[test]
fn gateway_handles_antigravity_endpoint_test_model_locally() {
run_provider_query_test(
"gateway_handles_antigravity_endpoint_test_model_locally",
gateway_handles_antigravity_endpoint_test_model_locally_impl,
);
}
async fn gateway_handles_antigravity_endpoint_test_model_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4070,8 +4305,15 @@ async fn gateway_handles_antigravity_endpoint_test_model_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted() {
#[test]
fn gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted",
gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted_impl,
);
}
async fn gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4172,8 +4414,15 @@ async fn gateway_prefers_supported_non_kiro_endpoint_when_api_format_is_omitted(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_is_omitted() {
#[test]
fn gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_is_omitted",
gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_is_omitted_impl,
);
}
async fn gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_is_omitted_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4272,8 +4521,15 @@ async fn gateway_prefers_transport_supported_non_kiro_endpoint_when_api_format_i
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_api_format_is_omitted(
#[test]
fn gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_api_format_is_omitted",
gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_api_format_is_omitted_impl,
);
}
async fn gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_api_format_is_omitted_impl(
) {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
@@ -4368,8 +4624,15 @@ async fn gateway_prefers_supported_non_kiro_endpoint_with_compatible_key_when_ap
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted() {
#[test]
fn gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted",
gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted_impl,
);
}
async fn gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4463,8 +4726,16 @@ async fn gateway_uses_compatible_cli_endpoint_when_api_format_is_omitted() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_format_is_omitted() {
#[test]
fn gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_format_is_omitted",
gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_format_is_omitted_impl,
);
}
async fn gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_format_is_omitted_impl()
{
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4560,8 +4831,15 @@ async fn gateway_uses_runnable_cli_endpoint_after_chat_preference_when_api_forma
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_openai_responses_test_model_failover_locally() {
#[test]
fn gateway_handles_openai_responses_test_model_failover_locally() {
run_provider_query_test(
"gateway_handles_openai_responses_test_model_failover_locally",
gateway_handles_openai_responses_test_model_failover_locally_impl,
);
}
async fn gateway_handles_openai_responses_test_model_failover_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4653,8 +4931,15 @@ async fn gateway_handles_openai_responses_test_model_failover_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_claude_cli_test_model_locally() {
#[test]
fn gateway_handles_claude_cli_test_model_locally() {
run_provider_query_test(
"gateway_handles_claude_cli_test_model_locally",
gateway_handles_claude_cli_test_model_locally_impl,
);
}
async fn gateway_handles_claude_cli_test_model_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4744,8 +5029,15 @@ async fn gateway_handles_claude_cli_test_model_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted() {
#[test]
fn gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted",
gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted_impl,
);
}
async fn gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4831,8 +5123,15 @@ async fn gateway_uses_compatible_claude_cli_endpoint_when_api_format_is_omitted(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_claude_cli_test_model_failover_locally() {
#[test]
fn gateway_handles_claude_cli_test_model_failover_locally() {
run_provider_query_test(
"gateway_handles_claude_cli_test_model_failover_locally",
gateway_handles_claude_cli_test_model_failover_locally_impl,
);
}
async fn gateway_handles_claude_cli_test_model_failover_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -4924,8 +5223,15 @@ async fn gateway_handles_claude_cli_test_model_failover_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_gemini_cli_test_model_locally() {
#[test]
fn gateway_handles_gemini_cli_test_model_locally() {
run_provider_query_test(
"gateway_handles_gemini_cli_test_model_locally",
gateway_handles_gemini_cli_test_model_locally_impl,
);
}
async fn gateway_handles_gemini_cli_test_model_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5018,8 +5324,15 @@ async fn gateway_handles_gemini_cli_test_model_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_gemini_cli_test_model_with_oauth_header_fallback() {
#[test]
fn gateway_handles_gemini_cli_test_model_with_oauth_header_fallback() {
run_provider_query_test(
"gateway_handles_gemini_cli_test_model_with_oauth_header_fallback",
gateway_handles_gemini_cli_test_model_with_oauth_header_fallback_impl,
);
}
async fn gateway_handles_gemini_cli_test_model_with_oauth_header_fallback_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5137,8 +5450,15 @@ async fn gateway_handles_gemini_cli_test_model_with_oauth_header_fallback() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_model() {
#[test]
fn gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_model() {
run_provider_query_test(
"gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_model",
gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_model_impl,
);
}
async fn gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_model_impl() {
let seen_urls = Arc::new(Mutex::new(Vec::<String>::new()));
let seen_urls_clone = Arc::clone(&seen_urls);
let execution_runtime = Router::new().route(
@@ -5306,8 +5626,15 @@ async fn gateway_hydrates_gemini_cli_project_id_from_load_code_assist_for_test_m
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted() {
#[test]
fn gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted() {
run_provider_query_test(
"gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted",
gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted_impl,
);
}
async fn gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5393,8 +5720,15 @@ async fn gateway_uses_compatible_gemini_cli_endpoint_when_api_format_is_omitted(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_gemini_cli_test_model_failover_locally() {
#[test]
fn gateway_handles_gemini_cli_test_model_failover_locally() {
run_provider_query_test(
"gateway_handles_gemini_cli_test_model_failover_locally",
gateway_handles_gemini_cli_test_model_failover_locally_impl,
);
}
async fn gateway_handles_gemini_cli_test_model_failover_locally_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5486,8 +5820,15 @@ async fn gateway_handles_gemini_cli_test_model_failover_locally() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test() {
#[test]
fn gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test() {
run_provider_query_test(
"gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test",
gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test_impl,
);
}
async fn gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5613,8 +5954,16 @@ async fn gateway_unwraps_gemini_cli_v1internal_response_for_failover_model_test(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_handles_admin_provider_query_test_model_failover_with_single_model_name_alias() {
#[test]
fn gateway_handles_admin_provider_query_test_model_failover_with_single_model_name_alias() {
run_provider_query_test(
"gateway_handles_admin_provider_query_test_model_failover_with_single_model_name_alias",
gateway_handles_admin_provider_query_test_model_failover_with_single_model_name_alias_impl,
);
}
async fn gateway_handles_admin_provider_query_test_model_failover_with_single_model_name_alias_impl(
) {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5703,8 +6052,15 @@ async fn gateway_handles_admin_provider_query_test_model_failover_with_single_mo
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_retries_non_kiro_failover_after_http_error_without_message() {
#[test]
fn gateway_retries_non_kiro_failover_after_http_error_without_message() {
run_provider_query_test(
"gateway_retries_non_kiro_failover_after_http_error_without_message",
gateway_retries_non_kiro_failover_after_http_error_without_message_impl,
);
}
async fn gateway_retries_non_kiro_failover_after_http_error_without_message_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5825,8 +6181,15 @@ async fn gateway_retries_non_kiro_failover_after_http_error_without_message() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_retries_non_kiro_failover_after_success_status_without_body() {
#[test]
fn gateway_retries_non_kiro_failover_after_success_status_without_body() {
run_provider_query_test(
"gateway_retries_non_kiro_failover_after_success_status_without_body",
gateway_retries_non_kiro_failover_after_success_status_without_body_impl,
);
}
async fn gateway_retries_non_kiro_failover_after_success_status_without_body_impl() {
let execution_runtime = Router::new().route(
"/v1/execute/sync",
any(move |Json(plan): Json<ExecutionPlan>| async move {
@@ -5953,8 +6316,15 @@ async fn gateway_retries_non_kiro_failover_after_success_status_without_body() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_preserves_non_success_status_for_test_model_local_wrapper() {
#[test]
fn gateway_preserves_non_success_status_for_test_model_local_wrapper() {
run_provider_query_test(
"gateway_preserves_non_success_status_for_test_model_local_wrapper",
gateway_preserves_non_success_status_for_test_model_local_wrapper_impl,
);
}
async fn gateway_preserves_non_success_status_for_test_model_local_wrapper_impl() {
let gateway = build_router_with_state(AppState::new().expect("gateway should build"));
let (gateway_url, gateway_handle) = start_server(gateway).await;
@@ -5979,8 +6349,15 @@ async fn gateway_preserves_non_success_status_for_test_model_local_wrapper() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_admin_provider_query_invalid_json_body() {
#[test]
fn gateway_rejects_admin_provider_query_invalid_json_body() {
run_provider_query_test(
"gateway_rejects_admin_provider_query_invalid_json_body",
gateway_rejects_admin_provider_query_invalid_json_body_impl,
);
}
async fn gateway_rejects_admin_provider_query_invalid_json_body_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
@@ -6019,8 +6396,15 @@ async fn gateway_rejects_admin_provider_query_invalid_json_body() {
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_admin_provider_query_test_model_without_provider_id() {
#[test]
fn gateway_rejects_admin_provider_query_test_model_without_provider_id() {
run_provider_query_test(
"gateway_rejects_admin_provider_query_test_model_without_provider_id",
gateway_rejects_admin_provider_query_test_model_without_provider_id_impl,
);
}
async fn gateway_rejects_admin_provider_query_test_model_without_provider_id_impl() {
assert_admin_provider_query_route(
"/api/admin/provider-query/test-model",
json!({ "model": "gpt-4.1" }),
@@ -6032,8 +6416,15 @@ async fn gateway_rejects_admin_provider_query_test_model_without_provider_id() {
.await;
}
#[tokio::test]
async fn gateway_rejects_admin_provider_query_test_model_without_model() {
#[test]
fn gateway_rejects_admin_provider_query_test_model_without_model() {
run_provider_query_test(
"gateway_rejects_admin_provider_query_test_model_without_model",
gateway_rejects_admin_provider_query_test_model_without_model_impl,
);
}
async fn gateway_rejects_admin_provider_query_test_model_without_model_impl() {
assert_admin_provider_query_route(
"/api/admin/provider-query/test-model",
json!({ "provider_id": "provider-openai" }),
@@ -6045,8 +6436,15 @@ async fn gateway_rejects_admin_provider_query_test_model_without_model() {
.await;
}
#[tokio::test]
async fn gateway_rejects_admin_provider_query_test_model_failover_without_provider_id() {
#[test]
fn gateway_rejects_admin_provider_query_test_model_failover_without_provider_id() {
run_provider_query_test(
"gateway_rejects_admin_provider_query_test_model_failover_without_provider_id",
gateway_rejects_admin_provider_query_test_model_failover_without_provider_id_impl,
);
}
async fn gateway_rejects_admin_provider_query_test_model_failover_without_provider_id_impl() {
assert_admin_provider_query_route(
"/api/admin/provider-query/test-model-failover",
json!({ "failover_models": ["gpt-4.1"] }),
@@ -6058,8 +6456,15 @@ async fn gateway_rejects_admin_provider_query_test_model_failover_without_provid
.await;
}
#[tokio::test]
async fn gateway_rejects_admin_provider_query_test_model_failover_without_models() {
#[test]
fn gateway_rejects_admin_provider_query_test_model_failover_without_models() {
run_provider_query_test(
"gateway_rejects_admin_provider_query_test_model_failover_without_models",
gateway_rejects_admin_provider_query_test_model_failover_without_models_impl,
);
}
async fn gateway_rejects_admin_provider_query_test_model_failover_without_models_impl() {
assert_admin_provider_query_route(
"/api/admin/provider-query/test-model-failover",
json!({ "provider_id": "provider-openai", "failover_models": [] }),
@@ -264,8 +264,39 @@ fn sample_import_admin_user(user_id: &str) -> StoredUserAuthRecord {
.expect("admin user should build")
}
#[tokio::test]
async fn gateway_imports_admin_system_config_locally_and_persists_data() {
const ADMIN_SYSTEM_IMPORT_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_admin_system_import_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(ADMIN_SYSTEM_IMPORT_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("admin system import test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
#[test]
fn gateway_imports_admin_system_config_locally_and_persists_data() {
run_admin_system_import_test(
"gateway_imports_admin_system_config_locally_and_persists_data",
gateway_imports_admin_system_config_locally_and_persists_data_impl,
);
}
async fn gateway_imports_admin_system_config_locally_and_persists_data_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().fallback(any(move |_request: Request| {
@@ -499,8 +530,15 @@ async fn gateway_imports_admin_system_config_locally_and_persists_data() {
let _ = upstream_url;
}
#[tokio::test]
async fn gateway_imports_admin_system_config_openai_image_aliases() {
#[test]
fn gateway_imports_admin_system_config_openai_image_aliases() {
run_admin_system_import_test(
"gateway_imports_admin_system_config_openai_image_aliases",
gateway_imports_admin_system_config_openai_image_aliases_impl,
);
}
async fn gateway_imports_admin_system_config_openai_image_aliases_impl() {
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
Vec::new(),
Vec::new(),
@@ -566,8 +604,15 @@ async fn gateway_imports_admin_system_config_openai_image_aliases() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_returns_503_for_admin_system_config_import_when_local_data_is_unavailable() {
#[test]
fn gateway_returns_503_for_admin_system_config_import_when_local_data_is_unavailable() {
run_admin_system_import_test(
"gateway_returns_503_for_admin_system_config_import_when_local_data_is_unavailable",
gateway_returns_503_for_admin_system_config_import_when_local_data_is_unavailable_impl,
);
}
async fn gateway_returns_503_for_admin_system_config_import_when_local_data_is_unavailable_impl() {
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().fallback(any(move |_request: Request| {
@@ -603,8 +648,15 @@ async fn gateway_returns_503_for_admin_system_config_import_when_local_data_is_u
let _ = upstream_url;
}
#[tokio::test]
async fn gateway_imports_legacy_admin_system_config_versions_and_model_test_succeeds() {
#[test]
fn gateway_imports_legacy_admin_system_config_versions_and_model_test_succeeds() {
run_admin_system_import_test(
"gateway_imports_legacy_admin_system_config_versions_and_model_test_succeeds",
gateway_imports_legacy_admin_system_config_versions_and_model_test_succeeds_impl,
);
}
async fn gateway_imports_legacy_admin_system_config_versions_and_model_test_succeeds_impl() {
for (
fixture_name,
expected_provider_name,
@@ -828,8 +880,15 @@ async fn assert_legacy_admin_system_config_import_model_test_succeeds(
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_unknown_admin_system_config_import_versions() {
#[test]
fn gateway_rejects_unknown_admin_system_config_import_versions() {
run_admin_system_import_test(
"gateway_rejects_unknown_admin_system_config_import_versions",
gateway_rejects_unknown_admin_system_config_import_versions_impl,
);
}
async fn gateway_rejects_unknown_admin_system_config_import_versions_impl() {
let gateway = build_router_with_state(
AppState::new()
.expect("gateway should build")
@@ -867,8 +926,15 @@ async fn gateway_rejects_unknown_admin_system_config_import_versions() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_imports_admin_system_users_locally_and_persists_data() {
#[test]
fn gateway_imports_admin_system_users_locally_and_persists_data() {
run_admin_system_import_test(
"gateway_imports_admin_system_users_locally_and_persists_data",
gateway_imports_admin_system_users_locally_and_persists_data_impl,
);
}
async fn gateway_imports_admin_system_users_locally_and_persists_data_impl() {
let user_wallet_updated_at = "2024-05-06T07:08:09Z";
let standalone_wallet_updated_at = "2024-06-07T08:09:10Z";
let upstream_hits = Arc::new(Mutex::new(0usize));
@@ -1142,8 +1208,15 @@ async fn gateway_imports_admin_system_users_locally_and_persists_data() {
let _ = upstream_url;
}
#[tokio::test]
async fn gateway_overwrites_existing_admin_system_user_key_usage_totals() {
#[test]
fn gateway_overwrites_existing_admin_system_user_key_usage_totals() {
run_admin_system_import_test(
"gateway_overwrites_existing_admin_system_user_key_usage_totals",
gateway_overwrites_existing_admin_system_user_key_usage_totals_impl,
);
}
async fn gateway_overwrites_existing_admin_system_user_key_usage_totals_impl() {
let user_key_hash = hash_api_key("sk-existing-user-key");
let standalone_key_hash = hash_api_key("sk-existing-standalone-key");
let existing_user = StoredUserAuthRecord::new(
@@ -1347,8 +1420,15 @@ async fn gateway_overwrites_existing_admin_system_user_key_usage_totals() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_imports_admin_system_config_fixture_v22() {
#[test]
fn gateway_imports_admin_system_config_fixture_v22() {
run_admin_system_import_test(
"gateway_imports_admin_system_config_fixture_v22",
gateway_imports_admin_system_config_fixture_v22_impl,
);
}
async fn gateway_imports_admin_system_config_fixture_v22_impl() {
let gateway = build_router_with_state(
AppState::new()
.expect("gateway should build")
@@ -1374,8 +1454,15 @@ async fn gateway_imports_admin_system_config_fixture_v22() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_imports_admin_system_config_fixtures_from_legacy_exports() {
#[test]
fn gateway_imports_admin_system_config_fixtures_from_legacy_exports() {
run_admin_system_import_test(
"gateway_imports_admin_system_config_fixtures_from_legacy_exports",
gateway_imports_admin_system_config_fixtures_from_legacy_exports_impl,
);
}
async fn gateway_imports_admin_system_config_fixtures_from_legacy_exports_impl() {
for fixture in ["v20", "v21"] {
let gateway = build_router_with_state(
AppState::new()
@@ -1409,8 +1496,15 @@ async fn gateway_imports_admin_system_config_fixtures_from_legacy_exports() {
}
}
#[tokio::test]
async fn gateway_imports_python_cli_alias_export_and_model_test_smoke() {
#[test]
fn gateway_imports_python_cli_alias_export_and_model_test_smoke() {
run_admin_system_import_test(
"gateway_imports_python_cli_alias_export_and_model_test_smoke",
gateway_imports_python_cli_alias_export_and_model_test_smoke_impl,
);
}
async fn gateway_imports_python_cli_alias_export_and_model_test_smoke_impl() {
let seen_plan = Arc::new(Mutex::new(None::<ExecutionPlan>));
let seen_plan_clone = Arc::clone(&seen_plan);
let execution_runtime = Router::new().route(
@@ -1561,8 +1655,15 @@ async fn gateway_imports_python_cli_alias_export_and_model_test_smoke() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_legacy_user_import_string_bool_field() {
#[test]
fn gateway_rejects_legacy_user_import_string_bool_field() {
run_admin_system_import_test(
"gateway_rejects_legacy_user_import_string_bool_field",
gateway_rejects_legacy_user_import_string_bool_field_impl,
);
}
async fn gateway_rejects_legacy_user_import_string_bool_field_impl() {
let auth_repository = Arc::new(InMemoryAuthApiKeySnapshotRepository::default());
let state = AppState::new()
.expect("gateway should build")
@@ -1600,8 +1701,15 @@ async fn gateway_rejects_legacy_user_import_string_bool_field() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_reports_field_path_for_invalid_admin_system_config_import_shape() {
#[test]
fn gateway_reports_field_path_for_invalid_admin_system_config_import_shape() {
run_admin_system_import_test(
"gateway_reports_field_path_for_invalid_admin_system_config_import_shape",
gateway_reports_field_path_for_invalid_admin_system_config_import_shape_impl,
);
}
async fn gateway_reports_field_path_for_invalid_admin_system_config_import_shape_impl() {
let gateway = build_router_with_state(
AppState::new()
.expect("gateway should build")
@@ -1641,8 +1749,15 @@ async fn gateway_reports_field_path_for_invalid_admin_system_config_import_shape
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_imports_admin_system_config_with_numeric_string_prices() {
#[test]
fn gateway_imports_admin_system_config_with_numeric_string_prices() {
run_admin_system_import_test(
"gateway_imports_admin_system_config_with_numeric_string_prices",
gateway_imports_admin_system_config_with_numeric_string_prices_impl,
);
}
async fn gateway_imports_admin_system_config_with_numeric_string_prices_impl() {
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
Vec::new(),
Vec::new(),
@@ -1714,8 +1829,15 @@ async fn gateway_imports_admin_system_config_with_numeric_string_prices() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_imports_oauth_provider_key_credentials_from_admin_system_config() {
#[test]
fn gateway_imports_oauth_provider_key_credentials_from_admin_system_config() {
run_admin_system_import_test(
"gateway_imports_oauth_provider_key_credentials_from_admin_system_config",
gateway_imports_oauth_provider_key_credentials_from_admin_system_config_impl,
);
}
async fn gateway_imports_oauth_provider_key_credentials_from_admin_system_config_impl() {
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
Vec::new(),
Vec::new(),
@@ -1804,8 +1926,15 @@ async fn gateway_imports_oauth_provider_key_credentials_from_admin_system_config
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import() {
#[test]
fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import() {
run_admin_system_import_test(
"gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import",
gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_impl,
);
}
async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_impl() {
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
Vec::new(),
Vec::new(),
@@ -1898,8 +2027,12 @@ async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_imp
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_without_refresh(
#[test]
fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_without_refresh() {
run_admin_system_import_test("gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_without_refresh", gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_without_refresh_impl);
}
async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_import_without_refresh_impl(
) {
let seen_refresh = Arc::new(Mutex::new(false));
let seen_refresh_clone = Arc::clone(&seen_refresh);
@@ -2058,8 +2191,15 @@ async fn gateway_overwrites_oauth_provider_key_credentials_from_admin_system_imp
refresh_handle.abort();
}
#[tokio::test]
async fn gateway_skips_proxy_nodes_during_admin_system_config_import() {
#[test]
fn gateway_skips_proxy_nodes_during_admin_system_config_import() {
run_admin_system_import_test(
"gateway_skips_proxy_nodes_during_admin_system_config_import",
gateway_skips_proxy_nodes_during_admin_system_config_import_impl,
);
}
async fn gateway_skips_proxy_nodes_during_admin_system_config_import_impl() {
let gateway = build_router_with_state(
AppState::new()
.expect("gateway should build")
@@ -2103,8 +2243,15 @@ async fn gateway_skips_proxy_nodes_during_admin_system_config_import() {
gateway_handle.abort();
}
#[tokio::test]
async fn gateway_preserves_manual_proxy_configs_while_skipping_proxy_nodes_during_import() {
#[test]
fn gateway_preserves_manual_proxy_configs_while_skipping_proxy_nodes_during_import() {
run_admin_system_import_test(
"gateway_preserves_manual_proxy_configs_while_skipping_proxy_nodes_during_import",
gateway_preserves_manual_proxy_configs_while_skipping_proxy_nodes_during_import_impl,
);
}
async fn gateway_preserves_manual_proxy_configs_while_skipping_proxy_nodes_during_import_impl() {
let provider_catalog_repository = Arc::new(InMemoryProviderCatalogReadRepository::seed(
Vec::new(),
Vec::new(),
@@ -20,6 +20,30 @@ use crate::constants::{
};
use aether_data_contracts::repository::candidate_selection::StoredMinimalCandidateSelectionRow;
const EMBEDDING_PROXY_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_embedding_proxy_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(EMBEDDING_PROXY_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("embedding proxy test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn embedding_success_state(execution_runtime_url: String) -> AppState {
let mut snapshot =
sample_currently_usable_auth_snapshot("key-embedding-success", "user-embedding-success");
@@ -746,8 +770,15 @@ fn aliyun_embedding_execution_result(plan: &ExecutionPlan) -> ExecutionResult {
}
}
#[tokio::test]
async fn embeddings_route_accepts_openai_payload() {
#[test]
fn embeddings_route_accepts_openai_payload() {
run_embedding_proxy_test(
"embeddings_route_accepts_openai_payload",
embeddings_route_accepts_openai_payload_impl,
);
}
async fn embeddings_route_accepts_openai_payload_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(embedding_execution_runtime()).await;
let gateway = build_router_with_state(embedding_success_state(execution_runtime_url));
@@ -816,8 +847,15 @@ async fn embeddings_route_accepts_openai_payload() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_openai_payload_to_gemini_embedding_provider() {
#[test]
fn embeddings_route_converts_openai_payload_to_gemini_embedding_provider() {
run_embedding_proxy_test(
"embeddings_route_converts_openai_payload_to_gemini_embedding_provider",
embeddings_route_converts_openai_payload_to_gemini_embedding_provider_impl,
);
}
async fn embeddings_route_converts_openai_payload_to_gemini_embedding_provider_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(gemini_embedding_conversion_execution_runtime()).await;
let gateway = build_router_with_state(gemini_embedding_success_state(
@@ -867,8 +905,15 @@ async fn embeddings_route_converts_openai_payload_to_gemini_embedding_provider()
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_provider() {
#[test]
fn embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_provider() {
run_embedding_proxy_test(
"embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_provider",
embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_provider_impl,
);
}
async fn embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_provider_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(vertex_gemini_embedding_conversion_execution_runtime()).await;
let gateway =
@@ -911,8 +956,15 @@ async fn embeddings_route_converts_openai_payload_to_vertex_gemini_embedding_pro
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint() {
#[test]
fn embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint() {
run_embedding_proxy_test(
"embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint",
embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint_impl,
);
}
async fn embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(gemini_embedding_batch_conversion_execution_runtime()).await;
let gateway = build_router_with_state(gemini_embedding_success_state(
@@ -957,8 +1009,15 @@ async fn embeddings_route_converts_openai_batch_payload_to_gemini_batch_endpoint
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_text_payload_to_aliyun_embedding_provider() {
#[test]
fn embeddings_route_converts_text_payload_to_aliyun_embedding_provider() {
run_embedding_proxy_test(
"embeddings_route_converts_text_payload_to_aliyun_embedding_provider",
embeddings_route_converts_text_payload_to_aliyun_embedding_provider_impl,
);
}
async fn embeddings_route_converts_text_payload_to_aliyun_embedding_provider_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(aliyun_embedding_conversion_execution_runtime(
json!([{ "text": "hello" }]),
@@ -1006,8 +1065,15 @@ async fn embeddings_route_converts_text_payload_to_aliyun_embedding_provider() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provider() {
#[test]
fn embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provider() {
run_embedding_proxy_test(
"embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provider",
embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provider_impl,
);
}
async fn embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provider_impl() {
let expected_contents = json!([
{ "text": "white running shoes" },
{ "image": "https://example.com/shoe.png" },
@@ -1049,8 +1115,15 @@ async fn embeddings_route_converts_multimodal_payload_to_aliyun_embedding_provid
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_skips_openai_candidate_for_multimodal_payload() {
#[test]
fn embeddings_route_skips_openai_candidate_for_multimodal_payload() {
run_embedding_proxy_test(
"embeddings_route_skips_openai_candidate_for_multimodal_payload",
embeddings_route_skips_openai_candidate_for_multimodal_payload_impl,
);
}
async fn embeddings_route_skips_openai_candidate_for_multimodal_payload_impl() {
let expected_contents = json!([
{ "text": "white running shoes" },
{ "image": "https://example.com/shoe.png" }
@@ -1090,8 +1163,15 @@ async fn embeddings_route_skips_openai_candidate_for_multimodal_payload() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider() {
#[test]
fn embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider() {
run_embedding_proxy_test(
"embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider",
embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider_impl,
);
}
async fn embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider_impl() {
let expected_contents = json!([
{
"text": "white running shoes",
@@ -1134,8 +1214,15 @@ async fn embeddings_route_converts_fusion_payload_to_aliyun_embedding_provider()
execution_runtime_handle.abort();
}
#[tokio::test]
async fn gemini_embed_content_route_uses_native_gemini_embedding_provider() {
#[test]
fn gemini_embed_content_route_uses_native_gemini_embedding_provider() {
run_embedding_proxy_test(
"gemini_embed_content_route_uses_native_gemini_embedding_provider",
gemini_embed_content_route_uses_native_gemini_embedding_provider_impl,
);
}
async fn gemini_embed_content_route_uses_native_gemini_embedding_provider_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(gemini_embedding_native_execution_runtime()).await;
let gateway = build_router_with_state(gemini_embedding_success_state(
@@ -1188,8 +1275,15 @@ async fn gemini_embed_content_route_uses_native_gemini_embedding_provider() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_accepts_all_canonical_input_shapes() {
#[test]
fn embeddings_route_accepts_all_canonical_input_shapes() {
run_embedding_proxy_test(
"embeddings_route_accepts_all_canonical_input_shapes",
embeddings_route_accepts_all_canonical_input_shapes_impl,
);
}
async fn embeddings_route_accepts_all_canonical_input_shapes_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(embedding_execution_runtime()).await;
let gateway = build_router_with_state(embedding_success_state(execution_runtime_url));
@@ -1229,8 +1323,15 @@ async fn embeddings_route_accepts_all_canonical_input_shapes() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn embeddings_route_rejects_invalid_local_payloads() {
#[test]
fn embeddings_route_rejects_invalid_local_payloads() {
run_embedding_proxy_test(
"embeddings_route_rejects_invalid_local_payloads",
embeddings_route_rejects_invalid_local_payloads_impl,
);
}
async fn embeddings_route_rejects_invalid_local_payloads_impl() {
let gateway = build_router_with_state(AppState::new().expect("gateway should build"));
let (gateway_url, gateway_handle) = start_server(gateway).await;
let client = reqwest::Client::new();
@@ -1294,8 +1395,15 @@ async fn embeddings_route_rejects_invalid_local_payloads() {
gateway_handle.abort();
}
#[tokio::test]
async fn embeddings_route_rejects_non_json_content_type() {
#[test]
fn embeddings_route_rejects_non_json_content_type() {
run_embedding_proxy_test(
"embeddings_route_rejects_non_json_content_type",
embeddings_route_rejects_non_json_content_type_impl,
);
}
async fn embeddings_route_rejects_non_json_content_type_impl() {
let gateway = build_router_with_state(AppState::new().expect("gateway should build"));
let (gateway_url, gateway_handle) = start_server(gateway).await;
@@ -1317,8 +1425,15 @@ async fn embeddings_route_rejects_non_json_content_type() {
gateway_handle.abort();
}
#[tokio::test]
async fn embeddings_route_rejects_chat_only_model() {
#[test]
fn embeddings_route_rejects_chat_only_model() {
run_embedding_proxy_test(
"embeddings_route_rejects_chat_only_model",
embeddings_route_rejects_chat_only_model_impl,
);
}
async fn embeddings_route_rejects_chat_only_model_impl() {
let mut snapshot = sample_currently_usable_auth_snapshot("key-embedding-1", "user-embedding-1");
snapshot.user_allowed_api_formats = Some(vec!["openai:embedding".to_string()]);
snapshot.api_key_allowed_api_formats = Some(vec!["openai:embedding".to_string()]);
@@ -1366,8 +1481,15 @@ async fn embeddings_route_rejects_chat_only_model() {
gateway_handle.abort();
}
#[tokio::test]
async fn embeddings_route_rejects_chat_only_api_format() {
#[test]
fn embeddings_route_rejects_chat_only_api_format() {
run_embedding_proxy_test(
"embeddings_route_rejects_chat_only_api_format",
embeddings_route_rejects_chat_only_api_format_impl,
);
}
async fn embeddings_route_rejects_chat_only_api_format_impl() {
let mut snapshot = sample_currently_usable_auth_snapshot("key-embedding-2", "user-embedding-2");
snapshot.user_allowed_api_formats = Some(vec!["openai:chat".to_string()]);
snapshot.api_key_allowed_api_formats = Some(vec!["openai:chat".to_string()]);
@@ -20,6 +20,30 @@ use crate::constants::{
EXECUTION_PATH_LOCAL_AUTH_DENIED,
};
const RERANK_PROXY_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_rerank_proxy_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(RERANK_PROXY_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("rerank proxy test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn rerank_success_state(execution_runtime_url: String) -> AppState {
let mut snapshot =
sample_currently_usable_auth_snapshot("key-rerank-success", "user-rerank-success");
@@ -142,8 +166,15 @@ fn rerank_execution_result(plan: &ExecutionPlan) -> ExecutionResult {
}
}
#[tokio::test]
async fn rerank_route_accepts_openai_payload() {
#[test]
fn rerank_route_accepts_openai_payload() {
run_rerank_proxy_test(
"rerank_route_accepts_openai_payload",
rerank_route_accepts_openai_payload_impl,
);
}
async fn rerank_route_accepts_openai_payload_impl() {
let (execution_runtime_url, execution_runtime_handle) =
start_server(rerank_execution_runtime()).await;
let gateway = build_router_with_state(rerank_success_state(execution_runtime_url));
@@ -200,8 +231,15 @@ async fn rerank_route_accepts_openai_payload() {
execution_runtime_handle.abort();
}
#[tokio::test]
async fn rerank_route_rejects_invalid_local_payloads() {
#[test]
fn rerank_route_rejects_invalid_local_payloads() {
run_rerank_proxy_test(
"rerank_route_rejects_invalid_local_payloads",
rerank_route_rejects_invalid_local_payloads_impl,
);
}
async fn rerank_route_rejects_invalid_local_payloads_impl() {
let gateway = build_router_with_state(AppState::new().expect("gateway should build"));
let (gateway_url, gateway_handle) = start_server(gateway).await;
let client = reqwest::Client::new();
@@ -257,8 +295,15 @@ async fn rerank_route_rejects_invalid_local_payloads() {
gateway_handle.abort();
}
#[tokio::test]
async fn rerank_route_rejects_non_json_content_type() {
#[test]
fn rerank_route_rejects_non_json_content_type() {
run_rerank_proxy_test(
"rerank_route_rejects_non_json_content_type",
rerank_route_rejects_non_json_content_type_impl,
);
}
async fn rerank_route_rejects_non_json_content_type_impl() {
let gateway = build_router_with_state(AppState::new().expect("gateway should build"));
let (gateway_url, gateway_handle) = start_server(gateway).await;
@@ -280,8 +325,15 @@ async fn rerank_route_rejects_non_json_content_type() {
gateway_handle.abort();
}
#[tokio::test]
async fn rerank_route_rejects_chat_only_api_format() {
#[test]
fn rerank_route_rejects_chat_only_api_format() {
run_rerank_proxy_test(
"rerank_route_rejects_chat_only_api_format",
rerank_route_rejects_chat_only_api_format_impl,
);
}
async fn rerank_route_rejects_chat_only_api_format_impl() {
let mut snapshot = sample_currently_usable_auth_snapshot("key-rerank-2", "user-rerank-2");
snapshot.user_allowed_api_formats = Some(vec!["openai:chat".to_string()]);
snapshot.api_key_allowed_api_formats = Some(vec!["openai:chat".to_string()]);
+65 -10
View File
@@ -26,6 +26,30 @@ mod registry_cleanup;
mod stream;
mod sync;
const FILES_TEST_STACK_BYTES: usize = 16 * 1024 * 1024;
fn run_files_test<F, Fut>(test_name: &'static str, make_future: F)
where
F: FnOnce() -> Fut + Send + 'static,
Fut: std::future::Future<Output = ()> + 'static,
{
let handle = std::thread::Builder::new()
.name(test_name.to_string())
.stack_size(FILES_TEST_STACK_BYTES)
.spawn(move || {
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("test runtime should build");
runtime.block_on(make_future());
})
.expect("files test thread should spawn");
if let Err(payload) = handle.join() {
std::panic::resume_unwind(payload);
}
}
fn hash_api_key(value: &str) -> String {
let mut hasher = Sha256::new();
hasher.update(value.as_bytes());
@@ -167,8 +191,13 @@ fn sample_files_provider_catalog_key() -> StoredProviderCatalogKey {
.expect("key transport should build")
}
#[tokio::test]
async fn gateway_locally_denies_gemini_files_download_control_sync_even_with_opt_in_headers_when_execution_runtime_missing(
#[test]
fn gateway_locally_denies_gemini_files_download_control_sync_even_with_opt_in_headers_when_execution_runtime_missing(
) {
run_files_test("gateway_locally_denies_gemini_files_download_control_sync_even_with_opt_in_headers_when_execution_runtime_missing", gateway_locally_denies_gemini_files_download_control_sync_even_with_opt_in_headers_when_execution_runtime_missing_impl);
}
async fn gateway_locally_denies_gemini_files_download_control_sync_even_with_opt_in_headers_when_execution_runtime_missing_impl(
) {
let execute_hits = Arc::new(Mutex::new(0usize));
let execute_hits_clone = Arc::clone(&execute_hits);
@@ -237,8 +266,13 @@ async fn gateway_locally_denies_gemini_files_download_control_sync_even_with_opt
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_locally_denies_gemini_files_download_control_sync_without_opt_in_header_when_execution_runtime_missing(
#[test]
fn gateway_locally_denies_gemini_files_download_control_sync_without_opt_in_header_when_execution_runtime_missing(
) {
run_files_test("gateway_locally_denies_gemini_files_download_control_sync_without_opt_in_header_when_execution_runtime_missing", gateway_locally_denies_gemini_files_download_control_sync_without_opt_in_header_when_execution_runtime_missing_impl);
}
async fn gateway_locally_denies_gemini_files_download_control_sync_without_opt_in_header_when_execution_runtime_missing_impl(
) {
let execute_hits = Arc::new(Mutex::new(0usize));
let execute_hits_clone = Arc::clone(&execute_hits);
@@ -324,8 +358,15 @@ async fn gateway_locally_denies_gemini_files_download_control_sync_without_opt_i
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_skips_gemini_files_download_control_sync_without_opt_in_header() {
#[test]
fn gateway_skips_gemini_files_download_control_sync_without_opt_in_header() {
run_files_test(
"gateway_skips_gemini_files_download_control_sync_without_opt_in_header",
gateway_skips_gemini_files_download_control_sync_without_opt_in_header_impl,
);
}
async fn gateway_skips_gemini_files_download_control_sync_without_opt_in_header_impl() {
let execute_hits = Arc::new(Mutex::new(0usize));
let execute_hits_clone = Arc::clone(&execute_hits);
let public_hits = Arc::new(Mutex::new(0usize));
@@ -388,8 +429,15 @@ async fn gateway_skips_gemini_files_download_control_sync_without_opt_in_header(
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_gemini_files_get_via_local_decision_gate_with_local_planning_only() {
#[test]
fn gateway_executes_gemini_files_get_via_local_decision_gate_with_local_planning_only() {
run_files_test(
"gateway_executes_gemini_files_get_via_local_decision_gate_with_local_planning_only",
gateway_executes_gemini_files_get_via_local_decision_gate_with_local_planning_only_impl,
);
}
async fn gateway_executes_gemini_files_get_via_local_decision_gate_with_local_planning_only_impl() {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
method: String,
@@ -596,8 +644,15 @@ async fn gateway_executes_gemini_files_get_via_local_decision_gate_with_local_pl
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_rejects_non_post_gemini_upload_without_hitting_fallback_probe() {
#[test]
fn gateway_rejects_non_post_gemini_upload_without_hitting_fallback_probe() {
run_files_test(
"gateway_rejects_non_post_gemini_upload_without_hitting_fallback_probe",
gateway_rejects_non_post_gemini_upload_without_hitting_fallback_probe_impl,
);
}
async fn gateway_rejects_non_post_gemini_upload_without_hitting_fallback_probe_impl() {
let public_hits = Arc::new(Mutex::new(0usize));
let public_hits_clone = Arc::clone(&public_hits);
@@ -3,8 +3,15 @@ use aether_data::repository::gemini_file_mappings::{
GeminiFileMappingReadRepository, InMemoryGeminiFileMappingRepository, StoredGeminiFileMapping,
};
#[tokio::test]
async fn gateway_background_gemini_file_mapping_cleanup_deletes_expired_entries() {
#[test]
fn gateway_background_gemini_file_mapping_cleanup_deletes_expired_entries() {
super::run_files_test(
"gateway_background_gemini_file_mapping_cleanup_deletes_expired_entries",
gateway_background_gemini_file_mapping_cleanup_deletes_expired_entries_impl,
);
}
async fn gateway_background_gemini_file_mapping_cleanup_deletes_expired_entries_impl() {
fn sample_mapping(
id: &str,
file_name: &str,
+23 -6
View File
@@ -14,8 +14,13 @@ use super::{
TRACE_ID_HEADER,
};
#[tokio::test]
async fn gateway_executes_gemini_files_download_via_local_decision_gate_with_local_planning_only() {
#[test]
fn gateway_executes_gemini_files_download_via_local_decision_gate_with_local_planning_only() {
super::run_files_test("gateway_executes_gemini_files_download_via_local_decision_gate_with_local_planning_only", gateway_executes_gemini_files_download_via_local_decision_gate_with_local_planning_only_impl);
}
async fn gateway_executes_gemini_files_download_via_local_decision_gate_with_local_planning_only_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeStreamRequest {
method: String,
@@ -280,8 +285,13 @@ async fn gateway_executes_gemini_files_download_via_local_decision_gate_with_loc
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_headers_when_execution_runtime_missing(
#[test]
fn gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_headers_when_execution_runtime_missing(
) {
super::run_files_test("gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_headers_when_execution_runtime_missing", gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_headers_when_execution_runtime_missing_impl);
}
async fn gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_headers_when_execution_runtime_missing_impl(
) {
let execute_hits = Arc::new(Mutex::new(0usize));
let execute_hits_clone = Arc::clone(&execute_hits);
@@ -351,8 +361,15 @@ async fn gateway_locally_denies_gemini_files_upload_control_sync_with_opt_in_hea
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_locally_denies_gemini_files_upload_control_sync_without_opt_in_header() {
#[test]
fn gateway_locally_denies_gemini_files_upload_control_sync_without_opt_in_header() {
super::run_files_test(
"gateway_locally_denies_gemini_files_upload_control_sync_without_opt_in_header",
gateway_locally_denies_gemini_files_upload_control_sync_without_opt_in_header_impl,
);
}
async fn gateway_locally_denies_gemini_files_upload_control_sync_without_opt_in_header_impl() {
let execute_hits = Arc::new(Mutex::new(0usize));
let execute_hits_clone = Arc::clone(&execute_hits);
let public_hits = Arc::new(Mutex::new(0usize));
+30 -6
View File
@@ -10,8 +10,16 @@ use super::{
RequestCandidateStatus, Router, StatusCode, DEVELOPMENT_ENCRYPTION_KEY, TRACE_ID_HEADER,
};
#[tokio::test]
async fn gateway_executes_gemini_files_upload_via_local_decision_gate_with_local_planning_only() {
#[test]
fn gateway_executes_gemini_files_upload_via_local_decision_gate_with_local_planning_only() {
super::run_files_test(
"gateway_executes_gemini_files_upload_via_local_decision_gate_with_local_planning_only",
gateway_executes_gemini_files_upload_via_local_decision_gate_with_local_planning_only_impl,
);
}
async fn gateway_executes_gemini_files_upload_via_local_decision_gate_with_local_planning_only_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
method: String,
@@ -300,8 +308,16 @@ async fn gateway_executes_gemini_files_upload_via_local_decision_gate_with_local
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_gemini_files_list_via_local_decision_gate_with_local_planning_only() {
#[test]
fn gateway_executes_gemini_files_list_via_local_decision_gate_with_local_planning_only() {
super::run_files_test(
"gateway_executes_gemini_files_list_via_local_decision_gate_with_local_planning_only",
gateway_executes_gemini_files_list_via_local_decision_gate_with_local_planning_only_impl,
);
}
async fn gateway_executes_gemini_files_list_via_local_decision_gate_with_local_planning_only_impl()
{
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
method: String,
@@ -508,8 +524,16 @@ async fn gateway_executes_gemini_files_list_via_local_decision_gate_with_local_p
upstream_handle.abort();
}
#[tokio::test]
async fn gateway_executes_gemini_files_delete_via_local_decision_gate_with_local_planning_only() {
#[test]
fn gateway_executes_gemini_files_delete_via_local_decision_gate_with_local_planning_only() {
super::run_files_test(
"gateway_executes_gemini_files_delete_via_local_decision_gate_with_local_planning_only",
gateway_executes_gemini_files_delete_via_local_decision_gate_with_local_planning_only_impl,
);
}
async fn gateway_executes_gemini_files_delete_via_local_decision_gate_with_local_planning_only_impl(
) {
#[derive(Debug, Clone)]
struct SeenExecutionRuntimeSyncRequest {
method: String,