migrate ai format conversion to responses adapters

This commit is contained in:
fawney19
2026-04-26 20:32:55 +08:00
parent e36fb8c07a
commit 5b914aa78c
183 changed files with 13539 additions and 3401 deletions

View File

@@ -197,7 +197,7 @@ async fn gateway_refreshes_admin_provider_quota_locally_for_codex_with_trusted_a
);
assert_eq!(
seen_execution_runtime_request.provider_api_format,
"openai:cli"
"openai:responses"
);
assert_eq!(seen_execution_runtime_request.total_ms, Some(30_000));

View File

@@ -566,7 +566,7 @@ async fn gateway_handles_admin_default_body_rules_locally_with_trusted_admin_pri
let upstream_hits = Arc::new(Mutex::new(0usize));
let upstream_hits_clone = Arc::clone(&upstream_hits);
let upstream = Router::new().route(
"/api/admin/endpoints/defaults/openai:cli/body-rules",
"/api/admin/endpoints/defaults/openai:responses/body-rules",
any(move |_request: Request| {
let upstream_hits_inner = Arc::clone(&upstream_hits_clone);
async move {
@@ -582,7 +582,7 @@ async fn gateway_handles_admin_default_body_rules_locally_with_trusted_admin_pri
let response = reqwest::Client::new()
.get(format!(
"{gateway_url}/api/admin/endpoints/defaults/openai:cli/body-rules?provider_type=codex"
"{gateway_url}/api/admin/endpoints/defaults/openai:responses/body-rules?provider_type=codex"
))
.header(crate::constants::GATEWAY_HEADER, "rust-phase3b")
.header(TRUSTED_ADMIN_USER_ID_HEADER, "admin-user-123")
@@ -594,7 +594,7 @@ async fn gateway_handles_admin_default_body_rules_locally_with_trusted_admin_pri
assert_eq!(response.status(), StatusCode::OK);
let payload: serde_json::Value = response.json().await.expect("json body should parse");
assert_eq!(payload["api_format"], "openai:cli");
assert_eq!(payload["api_format"], "openai:responses");
let rules = payload["body_rules"]
.as_array()
.expect("body_rules should be an array");

View File

@@ -329,16 +329,17 @@ async fn gateway_handles_admin_provider_query_models_with_openai_responses_endpo
assert_eq!(response.status(), StatusCode::OK);
let payload: serde_json::Value = response.json().await.expect("json body should parse");
assert_eq!(payload["success"], json!(false));
assert_eq!(
payload["data"]["error"],
json!("No active endpoints found for this provider")
);
assert_eq!(payload["success"], json!(true));
assert_eq!(payload["data"]["error"], serde_json::Value::Null);
assert_eq!(payload["data"]["from_cache"], json!(false));
assert_eq!(payload["data"]["models"], json!([]));
assert_eq!(payload["data"]["models"][0]["id"], json!("gpt-4.1"));
assert_eq!(
payload["data"]["models"][0]["api_formats"],
json!(["openai:responses"])
);
assert_eq!(
*execution_runtime_hits.lock().expect("mutex should lock"),
0
1
);
gateway_handle.abort();
@@ -465,7 +466,7 @@ async fn gateway_handles_admin_provider_query_models_respecting_key_api_formats(
assert_eq!(payload["data"]["from_cache"], json!(false));
assert_eq!(
payload["data"]["models"][0]["api_formats"],
json!(["openai:cli"])
json!(["openai:responses"])
);
assert_eq!(
*execution_runtime_hits.lock().expect("mutex should lock"),
@@ -1596,7 +1597,7 @@ async fn gateway_handles_openai_cli_test_model_locally() {
"choices": [{
"message": {
"role": "assistant",
"content": "Hello from OpenAI CLI"
"content": "Hello from OpenAI Responses"
}
}]
}
@@ -1660,7 +1661,7 @@ async fn gateway_handles_openai_cli_test_model_locally() {
assert_eq!(payload["success"], json!(true));
assert_eq!(
payload["data"]["response"]["choices"][0]["message"]["content"],
json!("Hello from OpenAI CLI")
json!("Hello from OpenAI Responses")
);
gateway_handle.abort();
@@ -2236,7 +2237,7 @@ async fn gateway_handles_openai_cli_test_model_failover_locally() {
"choices": [{
"message": {
"role": "assistant",
"content": "OpenAI CLI failover path succeeded"
"content": "OpenAI Responses failover path succeeded"
}
}]
}
@@ -2299,7 +2300,7 @@ async fn gateway_handles_openai_cli_test_model_failover_locally() {
assert_eq!(payload["total_attempts"], json!(1));
assert_eq!(
payload["data"]["response"]["choices"][0]["message"]["content"],
json!("OpenAI CLI failover path succeeded")
json!("OpenAI Responses failover path succeeded")
);
gateway_handle.abort();

View File

@@ -943,20 +943,20 @@ async fn gateway_creates_admin_provider_locally_with_trusted_admin_principal() {
.await
.expect("endpoints should list");
assert_eq!(endpoints.len(), 3);
let cli_endpoint = endpoints
let responses_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:cli")
.expect("cli endpoint should exist");
.find(|endpoint| endpoint.api_format == "openai:responses")
.expect("responses endpoint should exist");
let compact_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:compact")
.find(|endpoint| endpoint.api_format == "openai:responses:compact")
.expect("compact endpoint should exist");
let image_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:image")
.expect("image endpoint should exist");
assert_eq!(
cli_endpoint.base_url,
responses_endpoint.base_url,
"https://chatgpt.com/backend-api/codex"
);
assert_eq!(
@@ -967,11 +967,11 @@ async fn gateway_creates_admin_provider_locally_with_trusted_admin_principal() {
image_endpoint.base_url,
"https://chatgpt.com/backend-api/codex"
);
assert_eq!(cli_endpoint.max_retries, Some(7));
assert_eq!(responses_endpoint.max_retries, Some(7));
assert_eq!(compact_endpoint.max_retries, Some(7));
assert_eq!(image_endpoint.max_retries, Some(7));
assert_eq!(
cli_endpoint
responses_endpoint
.config
.as_ref()
.and_then(|value| value.get("upstream_stream_policy"))
@@ -986,7 +986,7 @@ async fn gateway_creates_admin_provider_locally_with_trusted_admin_principal() {
.and_then(serde_json::Value::as_str),
Some("force_stream")
);
assert!(cli_endpoint.body_rules.is_none());
assert!(responses_endpoint.body_rules.is_none());
assert!(compact_endpoint.body_rules.is_none());
assert!(image_endpoint.body_rules.is_none());
assert_eq!(*upstream_hits.lock().expect("mutex should lock"), 0);
@@ -1079,24 +1079,24 @@ async fn gateway_updates_fixed_provider_and_reconciles_template_managed_endpoint
.await
.expect("endpoints should list");
assert_eq!(endpoints.len(), 3);
let cli_endpoint = endpoints
let responses_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:cli")
.expect("cli endpoint should exist");
.find(|endpoint| endpoint.api_format == "openai:responses")
.expect("responses endpoint should exist");
let compact_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:compact")
.find(|endpoint| endpoint.api_format == "openai:responses:compact")
.expect("compact endpoint should exist");
let image_endpoint = endpoints
.iter()
.find(|endpoint| endpoint.api_format == "openai:image")
.expect("image endpoint should exist");
assert_eq!(cli_endpoint.max_retries, Some(9));
assert_eq!(responses_endpoint.max_retries, Some(9));
assert_eq!(compact_endpoint.max_retries, Some(9));
assert_eq!(image_endpoint.max_retries, Some(9));
assert_eq!(
cli_endpoint
responses_endpoint
.config
.as_ref()
.and_then(|value| value.get("_aether_fixed_provider_template"))