mirror of
https://github.com/aljazceru/goose.git
synced 2025-12-18 14:44:21 +01:00
Fix clippy + test errors (#3120)
This commit is contained in:
@@ -116,7 +116,7 @@ async fn main() -> Result<()> {
|
|||||||
println!("\nCompletion Response:");
|
println!("\nCompletion Response:");
|
||||||
println!("{}", serde_json::to_string_pretty(&completion_response)?);
|
println!("{}", serde_json::to_string_pretty(&completion_response)?);
|
||||||
|
|
||||||
let tooltip = generate_tooltip(provider, provider_config.clone().into(), &messages).await?;
|
let tooltip = generate_tooltip(provider, provider_config.clone(), &messages).await?;
|
||||||
println!("\nTooltip: {}", tooltip);
|
println!("\nTooltip: {}", tooltip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ mod tests {
|
|||||||
.with_text("Hello, I'll help you with that.")
|
.with_text("Hello, I'll help you with that.")
|
||||||
.with_tool_request(
|
.with_tool_request(
|
||||||
"tool123",
|
"tool123",
|
||||||
Ok(ToolCall::new("test_tool", json!({"param": "value"})).into()),
|
Ok(ToolCall::new("test_tool", json!({"param": "value"}))),
|
||||||
);
|
);
|
||||||
|
|
||||||
let json_str = serde_json::to_string_pretty(&message).unwrap();
|
let json_str = serde_json::to_string_pretty(&message).unwrap();
|
||||||
|
|||||||
@@ -681,7 +681,7 @@ mod tests {
|
|||||||
Message::user().with_text("How are you?"),
|
Message::user().with_text("How are you?"),
|
||||||
Message::assistant().with_tool_request(
|
Message::assistant().with_tool_request(
|
||||||
"tool1",
|
"tool1",
|
||||||
Ok(ToolCall::new("example", json!({"param1": "value1"})).into()),
|
Ok(ToolCall::new("example", json!({"param1": "value1"}))),
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -801,7 +801,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data)?;
|
std::fs::write(&png_path, png_data)?;
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create message with image path
|
// Create message with image path
|
||||||
|
|||||||
@@ -674,7 +674,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data)?;
|
std::fs::write(&png_path, png_data)?;
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create message with image path
|
// Create message with image path
|
||||||
|
|||||||
@@ -277,7 +277,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data).unwrap();
|
std::fs::write(&png_path, png_data).unwrap();
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create a fake PNG (wrong magic numbers)
|
// Create a fake PNG (wrong magic numbers)
|
||||||
@@ -315,7 +315,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data).unwrap();
|
std::fs::write(&png_path, png_data).unwrap();
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create a fake PNG (wrong magic numbers)
|
// Create a fake PNG (wrong magic numbers)
|
||||||
|
|||||||
@@ -1695,7 +1695,7 @@ mod tests {
|
|||||||
std::env::set_current_dir(&temp_dir).unwrap();
|
std::env::set_current_dir(&temp_dir).unwrap();
|
||||||
|
|
||||||
// Create a DeveloperRouter with custom ignore patterns
|
// Create a DeveloperRouter with custom ignore patterns
|
||||||
let mut builder = GitignoreBuilder::new(temp_dir.path().to_path_buf());
|
let mut builder = GitignoreBuilder::new(temp_dir.path());
|
||||||
builder.add_line(None, "secret.txt").unwrap();
|
builder.add_line(None, "secret.txt").unwrap();
|
||||||
builder.add_line(None, "*.env").unwrap();
|
builder.add_line(None, "*.env").unwrap();
|
||||||
let ignore_patterns = builder.build().unwrap();
|
let ignore_patterns = builder.build().unwrap();
|
||||||
@@ -1747,7 +1747,7 @@ mod tests {
|
|||||||
std::env::set_current_dir(&temp_dir).unwrap();
|
std::env::set_current_dir(&temp_dir).unwrap();
|
||||||
|
|
||||||
// Create a DeveloperRouter with custom ignore patterns
|
// Create a DeveloperRouter with custom ignore patterns
|
||||||
let mut builder = GitignoreBuilder::new(temp_dir.path().to_path_buf());
|
let mut builder = GitignoreBuilder::new(temp_dir.path());
|
||||||
builder.add_line(None, "secret.txt").unwrap();
|
builder.add_line(None, "secret.txt").unwrap();
|
||||||
let ignore_patterns = builder.build().unwrap();
|
let ignore_patterns = builder.build().unwrap();
|
||||||
|
|
||||||
@@ -1807,7 +1807,7 @@ mod tests {
|
|||||||
std::env::set_current_dir(&temp_dir).unwrap();
|
std::env::set_current_dir(&temp_dir).unwrap();
|
||||||
|
|
||||||
// Create a DeveloperRouter with custom ignore patterns
|
// Create a DeveloperRouter with custom ignore patterns
|
||||||
let mut builder = GitignoreBuilder::new(temp_dir.path().to_path_buf());
|
let mut builder = GitignoreBuilder::new(temp_dir.path());
|
||||||
builder.add_line(None, "secret.txt").unwrap();
|
builder.add_line(None, "secret.txt").unwrap();
|
||||||
let ignore_patterns = builder.build().unwrap();
|
let ignore_patterns = builder.build().unwrap();
|
||||||
|
|
||||||
|
|||||||
@@ -66,23 +66,7 @@ async fn transcribe_handler(
|
|||||||
) -> Result<Json<TranscribeResponse>, StatusCode> {
|
) -> Result<Json<TranscribeResponse>, StatusCode> {
|
||||||
verify_secret_key(&headers, &state)?;
|
verify_secret_key(&headers, &state)?;
|
||||||
|
|
||||||
// Get the OpenAI API key from config
|
// Validate input first before checking API key configuration
|
||||||
let config = goose::config::Config::global();
|
|
||||||
let api_key: String = config
|
|
||||||
.get_secret("OPENAI_API_KEY")
|
|
||||||
.map_err(|_| StatusCode::PRECONDITION_FAILED)?;
|
|
||||||
|
|
||||||
// Get the OpenAI host from config (with default)
|
|
||||||
let openai_host = match config.get("OPENAI_HOST", false) {
|
|
||||||
Ok(value) => value
|
|
||||||
.as_str()
|
|
||||||
.map(|s| s.to_string())
|
|
||||||
.unwrap_or_else(|| "https://api.openai.com".to_string()),
|
|
||||||
Err(_) => "https://api.openai.com".to_string(),
|
|
||||||
};
|
|
||||||
|
|
||||||
tracing::debug!("Using OpenAI host: {}", openai_host);
|
|
||||||
|
|
||||||
// Decode the base64 audio data
|
// Decode the base64 audio data
|
||||||
let audio_bytes = BASE64
|
let audio_bytes = BASE64
|
||||||
.decode(&request.audio)
|
.decode(&request.audio)
|
||||||
@@ -110,6 +94,23 @@ async fn transcribe_handler(
|
|||||||
_ => return Err(StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
_ => return Err(StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Get the OpenAI API key from config (after input validation)
|
||||||
|
let config = goose::config::Config::global();
|
||||||
|
let api_key: String = config
|
||||||
|
.get_secret("OPENAI_API_KEY")
|
||||||
|
.map_err(|_| StatusCode::PRECONDITION_FAILED)?;
|
||||||
|
|
||||||
|
// Get the OpenAI host from config (with default)
|
||||||
|
let openai_host = match config.get("OPENAI_HOST", false) {
|
||||||
|
Ok(value) => value
|
||||||
|
.as_str()
|
||||||
|
.map(|s| s.to_string())
|
||||||
|
.unwrap_or_else(|| "https://api.openai.com".to_string()),
|
||||||
|
Err(_) => "https://api.openai.com".to_string(),
|
||||||
|
};
|
||||||
|
|
||||||
|
tracing::debug!("Using OpenAI host: {}", openai_host);
|
||||||
|
|
||||||
// Create a multipart form with the audio file
|
// Create a multipart form with the audio file
|
||||||
let part = reqwest::multipart::Part::bytes(audio_bytes)
|
let part = reqwest::multipart::Part::bytes(audio_bytes)
|
||||||
.file_name(format!("audio.{}", file_extension))
|
.file_name(format!("audio.{}", file_extension))
|
||||||
@@ -176,7 +177,35 @@ async fn transcribe_elevenlabs_handler(
|
|||||||
) -> Result<Json<TranscribeResponse>, StatusCode> {
|
) -> Result<Json<TranscribeResponse>, StatusCode> {
|
||||||
verify_secret_key(&headers, &state)?;
|
verify_secret_key(&headers, &state)?;
|
||||||
|
|
||||||
// Get the ElevenLabs API key from config
|
// Validate input first before checking API key configuration
|
||||||
|
// Decode the base64 audio data
|
||||||
|
let audio_bytes = BASE64
|
||||||
|
.decode(&request.audio)
|
||||||
|
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
||||||
|
|
||||||
|
// Check file size
|
||||||
|
if audio_bytes.len() > MAX_AUDIO_SIZE_BYTES {
|
||||||
|
tracing::warn!(
|
||||||
|
"Audio file too large: {} bytes (max: {} bytes)",
|
||||||
|
audio_bytes.len(),
|
||||||
|
MAX_AUDIO_SIZE_BYTES
|
||||||
|
);
|
||||||
|
return Err(StatusCode::PAYLOAD_TOO_LARGE);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine file extension and content type based on MIME type
|
||||||
|
let (file_extension, content_type) = match request.mime_type.as_str() {
|
||||||
|
"audio/webm" => ("webm", "audio/webm"),
|
||||||
|
"audio/mp4" => ("mp4", "audio/mp4"),
|
||||||
|
"audio/mpeg" => ("mp3", "audio/mpeg"),
|
||||||
|
"audio/mpga" => ("mp3", "audio/mpeg"),
|
||||||
|
"audio/m4a" => ("m4a", "audio/m4a"),
|
||||||
|
"audio/wav" => ("wav", "audio/wav"),
|
||||||
|
"audio/x-wav" => ("wav", "audio/wav"),
|
||||||
|
_ => return Err(StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get the ElevenLabs API key from config (after input validation)
|
||||||
let config = goose::config::Config::global();
|
let config = goose::config::Config::global();
|
||||||
|
|
||||||
// First try to get it as a secret
|
// First try to get it as a secret
|
||||||
@@ -216,33 +245,6 @@ async fn transcribe_elevenlabs_handler(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Decode the base64 audio data
|
|
||||||
let audio_bytes = BASE64
|
|
||||||
.decode(&request.audio)
|
|
||||||
.map_err(|_| StatusCode::BAD_REQUEST)?;
|
|
||||||
|
|
||||||
// Check file size
|
|
||||||
if audio_bytes.len() > MAX_AUDIO_SIZE_BYTES {
|
|
||||||
tracing::warn!(
|
|
||||||
"Audio file too large: {} bytes (max: {} bytes)",
|
|
||||||
audio_bytes.len(),
|
|
||||||
MAX_AUDIO_SIZE_BYTES
|
|
||||||
);
|
|
||||||
return Err(StatusCode::PAYLOAD_TOO_LARGE);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Determine file extension and content type based on MIME type
|
|
||||||
let (file_extension, content_type) = match request.mime_type.as_str() {
|
|
||||||
"audio/webm" => ("webm", "audio/webm"),
|
|
||||||
"audio/mp4" => ("mp4", "audio/mp4"),
|
|
||||||
"audio/mpeg" => ("mp3", "audio/mpeg"),
|
|
||||||
"audio/mpga" => ("mp3", "audio/mpeg"),
|
|
||||||
"audio/m4a" => ("m4a", "audio/m4a"),
|
|
||||||
"audio/wav" => ("wav", "audio/wav"),
|
|
||||||
"audio/x-wav" => ("wav", "audio/wav"),
|
|
||||||
_ => return Err(StatusCode::UNSUPPORTED_MEDIA_TYPE),
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create multipart form for ElevenLabs API
|
// Create multipart form for ElevenLabs API
|
||||||
let part = reqwest::multipart::Part::bytes(audio_bytes)
|
let part = reqwest::multipart::Part::bytes(audio_bytes)
|
||||||
.file_name(format!("audio.{}", file_extension))
|
.file_name(format!("audio.{}", file_extension))
|
||||||
|
|||||||
@@ -838,7 +838,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data)?;
|
std::fs::write(&png_path, png_data)?;
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create message with image path
|
// Create message with image path
|
||||||
|
|||||||
@@ -716,7 +716,7 @@ mod tests {
|
|||||||
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
0x0D, 0x0A, 0x1A, 0x0A, // PNG header
|
||||||
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
0x00, 0x00, 0x00, 0x0D, // Rest of fake PNG data
|
||||||
];
|
];
|
||||||
std::fs::write(&png_path, &png_data)?;
|
std::fs::write(&png_path, png_data)?;
|
||||||
let png_path_str = png_path.to_str().unwrap();
|
let png_path_str = png_path.to_str().unwrap();
|
||||||
|
|
||||||
// Create message with image path
|
// Create message with image path
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ async fn main() -> Result<()> {
|
|||||||
|
|
||||||
// Test broken transport
|
// Test broken transport
|
||||||
match test_transport(broken_stdio_transport().await?).await {
|
match test_transport(broken_stdio_transport().await?).await {
|
||||||
Ok(_) => assert!(false, "Expected an error but got success"),
|
Ok(_) => panic!("Expected an error but got success"),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
assert!(e
|
assert!(e
|
||||||
.to_string()
|
.to_string()
|
||||||
|
|||||||
Reference in New Issue
Block a user