diff --git a/Cargo.lock b/Cargo.lock index 7ef96c99..cf8f6382 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1662,6 +1662,7 @@ dependencies = [ "serde", "serde_json", "signal-hook", + "tempfile", "thiserror", "tokio", "tokio-test", diff --git a/Cargo.toml b/Cargo.toml index a6f4b432..cf35a64c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ thiserror = "1.0" once_cell = "1.19" anyhow = "1.0" ctrlc = "3.4" +tempfile = "3.9" [dev-dependencies] wiremock = "0.5" diff --git a/src/main.rs b/src/main.rs index 2d0e94c6..42d8379e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,10 +11,10 @@ use crate::mcp::utilities::*; use clap::Parser; use rpc_router::{Error, Handler, Request, Router, RouterBuilder}; use serde_json::{json, Value}; -use std::fs::OpenOptions; use std::io; use std::io::Write; use std::thread; +use tempfile::NamedTempFile; // Platform-specific imports #[cfg(unix)] @@ -87,18 +87,13 @@ async fn main() { let mut line = String::new(); let input = io::stdin(); - // Use a platform-appropriate path for the log file - let log_path = if cfg!(windows) { - std::env::temp_dir().join("mcp.jsonl") - } else { - std::path::PathBuf::from("/tmp/mcp.jsonl") - }; + // Create a secure temporary file for logging + let logging_file = NamedTempFile::new().expect("Failed to create temporary log file"); + eprintln!("Log file created at: {}", logging_file.path().display()); + let mut logging_file = logging_file + .reopen() + .expect("Failed to reopen temporary log file"); - let mut logging_file = OpenOptions::new() - .append(true) - .create(true) - .open(log_path) - .unwrap(); while input.read_line(&mut line).unwrap() != 0 { let line = std::mem::take(&mut line); writeln!(logging_file, "{}", line).unwrap(); diff --git a/tests/helpers.rs b/tests/helpers.rs index 11e3b57d..094ddf96 100644 --- a/tests/helpers.rs +++ b/tests/helpers.rs @@ -8,7 +8,6 @@ pub fn load_fixture(filename: &str) -> String { } /// Get a mock SonarQube base URL for testing -#[allow(dead_code)] pub fn mock_base_url(mock_server: &wiremock::MockServer) -> String { mock_server.uri() } diff --git a/tests/main_tests.rs b/tests/main_tests.rs index 40ed4469..0936a4e0 100644 --- a/tests/main_tests.rs +++ b/tests/main_tests.rs @@ -1,5 +1,4 @@ use clap::Parser; -use std::str::FromStr; // Import the Args struct from main.rs // We can't directly import it as it's not public, so we recreate it here diff --git a/tests/sonarqube_types_tests.rs b/tests/sonarqube_types_tests.rs index f52d9831..24e5e2d5 100644 --- a/tests/sonarqube_types_tests.rs +++ b/tests/sonarqube_types_tests.rs @@ -1,6 +1,5 @@ mod helpers; -use serde_json::json; use sonarqube_mcp_server::mcp::sonarqube::types::*; #[test]