Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix tauri test

Dinh Long Nguyen9a72a2d5d588
diff --git a/src-tauri/src/core/mcp/tests.rs b/src-tauri/src/core/mcp/tests.rs
index 636a2ccb8..d973ce647 100644
--- a/src-tauri/src/core/mcp/tests.rs
+++ b/src-tauri/src/core/mcp/tests.rs
@@ -38,6 +38,7 @@ async fn test_run_mcp_commands() {
std::fs::remove_file(&config_path).expect("Failed to remove config file");
}
+#[test]
fn test_add_server_config_new_file() {
let app = mock_app();
let app_path = get_jan_data_folder_path(app.handle().clone());
@@ -151,7 +152,14 @@ fn test_add_server_config_existing_servers() {
fn test_add_server_config_missing_config_file() {
let app = mock_app();
let app_path = get_jan_data_folder_path(app.handle().clone());
- let config_path = app_path.join("nonexistent_config.json");
+
+ // Ensure the directory exists
+ if let Some(parent) = app_path.parent() {
+ std::fs::create_dir_all(parent).ok();
+ }
+ std::fs::create_dir_all(&app_path).ok();
+
+ let config_path = app_path.join("mcp_config.json");
// Ensure the file doesn't exist
if config_path.exists() {
diff --git a/src-tauri/src/core/threads/commands.rs b/src-tauri/src/core/threads/commands.rs
index a9012193a..7f16371a7 100644
--- a/src-tauri/src/core/threads/commands.rs
+++ b/src-tauri/src/core/threads/commands.rs
@@ -148,6 +148,9 @@ pub async fn create_message<R: Runtime>(
let data = serde_json::to_string(&message).map_err(|e| e.to_string())?;
writeln!(file, "{}", data).map_err(|e| e.to_string())?;
+
+ // Explicitly flush to ensure data is written before returning
+ file.flush().map_err(|e| e.to_string())?;
}
Ok(message)
diff --git a/src-tauri/src/core/threads/tests.rs b/src-tauri/src/core/threads/tests.rs
index 5b4aaec57..7a918e46f 100644
--- a/src-tauri/src/core/threads/tests.rs
+++ b/src-tauri/src/core/threads/tests.rs
@@ -82,7 +82,7 @@ async fn test_create_and_list_messages() {
let messages = list_messages(app.handle().clone(), thread_id.clone())
.await
.unwrap();
- assert!(messages.len() > 0);
+ assert!(messages.len() > 0, "Expected at least one message, but got none. Thread ID: {}", thread_id);
assert_eq!(messages[0]["role"], "user");
// Clean up