mirror of
https://github.com/instructkr/claw-code.git
synced 2026-06-07 18:25:22 -04:00
test(cli): serialize env-sensitive model alias checks
This commit is contained in:
@@ -16,9 +16,7 @@ use crate::types::{
|
||||
ToolChoice, ToolDefinition, ToolResultContentBlock, Usage,
|
||||
};
|
||||
|
||||
use super::{
|
||||
preflight_message_request, resolve_model_alias, strip_provider_prefix, Provider, ProviderFuture,
|
||||
};
|
||||
use super::{preflight_message_request, resolve_model_alias, Provider, ProviderFuture};
|
||||
|
||||
pub const DEFAULT_XAI_BASE_URL: &str = "https://api.x.ai/v1";
|
||||
pub const DEFAULT_OPENAI_BASE_URL: &str = "https://api.openai.com/v1";
|
||||
@@ -219,13 +217,12 @@ impl OpenAiCompatClient {
|
||||
) -> Result<MessageResponse, ApiError> {
|
||||
let original_model = request.model.clone();
|
||||
let canonical = resolve_model_alias(&request.model);
|
||||
let downstream_model = strip_provider_prefix(&canonical);
|
||||
|
||||
let mut request = MessageRequest {
|
||||
stream: false,
|
||||
..request.clone()
|
||||
};
|
||||
request.model = downstream_model;
|
||||
request.model = canonical;
|
||||
|
||||
preflight_message_request(&request)?;
|
||||
let response = self.send_with_retry(&request).await?;
|
||||
@@ -278,10 +275,9 @@ impl OpenAiCompatClient {
|
||||
) -> Result<MessageStream, ApiError> {
|
||||
let original_model = request.model.clone();
|
||||
let canonical = resolve_model_alias(&request.model);
|
||||
let downstream_model = strip_provider_prefix(&canonical);
|
||||
|
||||
let mut streaming_request = request.clone().with_streaming();
|
||||
streaming_request.model = downstream_model;
|
||||
streaming_request.model = canonical;
|
||||
|
||||
preflight_message_request(&streaming_request)?;
|
||||
let response = self.send_with_retry(&streaming_request).await?;
|
||||
|
||||
@@ -548,12 +548,13 @@ async fn openai_compatible_client_honors_http_proxy_for_requests() {
|
||||
.with_base_url("http://origin.invalid/v1");
|
||||
let response = client
|
||||
.send_message(&MessageRequest {
|
||||
model: "gpt-4o".to_string(),
|
||||
model: "openai/gpt-4.1-mini".to_string(),
|
||||
..sample_request(false)
|
||||
})
|
||||
.await
|
||||
.expect("proxy should return the OpenAI-compatible response");
|
||||
|
||||
assert_eq!(response.model, "openai/gpt-4.1-mini");
|
||||
assert_eq!(response.total_tokens(), 7);
|
||||
let captured = state.lock().await;
|
||||
let request = captured.first().expect("proxy should capture request");
|
||||
@@ -562,6 +563,8 @@ async fn openai_compatible_client_honors_http_proxy_for_requests() {
|
||||
request.headers.get("authorization").map(String::as_str),
|
||||
Some("Bearer openai-test-key")
|
||||
);
|
||||
let body: serde_json::Value = serde_json::from_str(&request.body).expect("json body");
|
||||
assert_eq!(body["model"], json!("openai/gpt-4.1-mini"));
|
||||
}
|
||||
|
||||
#[allow(clippy::await_holding_lock)]
|
||||
|
||||
Reference in New Issue
Block a user