Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .github/workflows/rust-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ jobs:

- name: Run Clippy
working-directory: src-tauri
run: cargo clippy --all-features -- -D warnings
continue-on-error: true # Don't fail the build on clippy warnings initially
run: cargo clippy --all-targets --all-features -- -D warnings

fmt:
name: Format
Expand Down
18 changes: 6 additions & 12 deletions src-tauri/src/commands/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,13 +329,11 @@ pub fn get_global_commands(
db: State<'_, Arc<Mutex<Database>>>,
) -> Result<Vec<GlobalCommand>, String> {
let db = db.lock().map_err(|e| e.to_string())?;
let query = format!(
"SELECT gc.id, gc.command_id, gc.is_enabled,
let query = "SELECT gc.id, gc.command_id, gc.is_enabled,
c.id, c.name, c.description, c.content, c.allowed_tools, c.argument_hint, c.model, c.tags, c.source, c.source_path, c.is_favorite, c.created_at, c.updated_at
FROM global_commands gc
JOIN commands c ON gc.command_id = c.id
ORDER BY c.name"
);
ORDER BY c.name".to_string();
let mut stmt = db.conn().prepare(&query).map_err(|e| e.to_string())?;

let commands = stmt
Expand Down Expand Up @@ -644,13 +642,11 @@ pub fn toggle_project_command(
.map_err(|e| e.to_string())?;

// Get the command and project path
let query = format!(
"SELECT c.id, c.name, c.description, c.content, c.allowed_tools, c.argument_hint, c.model, c.tags, c.source, c.source_path, c.is_favorite, c.created_at, c.updated_at, p.path
let query = "SELECT c.id, c.name, c.description, c.content, c.allowed_tools, c.argument_hint, c.model, c.tags, c.source, c.source_path, c.is_favorite, c.created_at, c.updated_at, p.path
FROM project_commands pc
JOIN commands c ON pc.command_id = c.id
JOIN projects p ON pc.project_id = p.id
WHERE pc.id = ?"
);
WHERE pc.id = ?".to_string();
let mut stmt = db_guard.conn().prepare(&query).map_err(|e| e.to_string())?;

let (command, project_path): (Command, String) = stmt
Expand Down Expand Up @@ -706,14 +702,12 @@ pub fn get_project_commands(
project_id: i64,
) -> Result<Vec<ProjectCommand>, String> {
let db = db.lock().map_err(|e| e.to_string())?;
let query = format!(
"SELECT pc.id, pc.command_id, pc.is_enabled,
let query = "SELECT pc.id, pc.command_id, pc.is_enabled,
c.id, c.name, c.description, c.content, c.allowed_tools, c.argument_hint, c.model, c.tags, c.source, c.source_path, c.is_favorite, c.created_at, c.updated_at
FROM project_commands pc
JOIN commands c ON pc.command_id = c.id
WHERE pc.project_id = ?
ORDER BY c.name"
);
ORDER BY c.name".to_string();
let mut stmt = db.conn().prepare(&query).map_err(|e| e.to_string())?;

let commands = stmt
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/commands/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn sync_global_config(db: State<'_, Arc<Mutex<Database>>>) -> Result<(), Str
}

/// Sync global config from database to disk (reusable helper without Tauri State)
#[allow(clippy::type_complexity)]
pub(crate) fn sync_global_config_from_db(db: &Database) -> Result<(), String> {
use crate::commands::settings::get_enabled_editors_from_db;
use crate::services::{
Expand Down
10 changes: 5 additions & 5 deletions src-tauri/src/commands/docker_hosts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn get_all_docker_hosts(
#[tauri::command]
pub fn create_docker_host(
db: State<'_, Arc<Mutex<Database>>>,
request: CreateDockerHostRequest,
_request: CreateDockerHostRequest,
) -> Result<DockerHost, String> {
let _db = db.lock().map_err(|e| e.to_string())?;
Err("Docker host feature not yet implemented".to_string())
Expand All @@ -23,20 +23,20 @@ pub fn create_docker_host(
#[tauri::command]
pub fn update_docker_host(
db: State<'_, Arc<Mutex<Database>>>,
id: i64,
request: CreateDockerHostRequest,
_id: i64,
_request: CreateDockerHostRequest,
) -> Result<DockerHost, String> {
let _db = db.lock().map_err(|e| e.to_string())?;
Err("Docker host feature not yet implemented".to_string())
}

#[tauri::command]
pub fn delete_docker_host(db: State<'_, Arc<Mutex<Database>>>, id: i64) -> Result<(), String> {
pub fn delete_docker_host(db: State<'_, Arc<Mutex<Database>>>, _id: i64) -> Result<(), String> {
let _db = db.lock().map_err(|e| e.to_string())?;
Err("Docker host feature not yet implemented".to_string())
}

#[tauri::command]
pub fn test_docker_host(id: i64) -> Result<bool, String> {
pub fn test_docker_host(_id: i64) -> Result<bool, String> {
Err("Docker host feature not yet implemented".to_string())
}
8 changes: 8 additions & 0 deletions src-tauri/src/commands/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,7 @@ pub fn duplicate_hook(
// ============================================================================

/// Create a hook in the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn create_hook_in_db(db: &Database, hook: &CreateHookRequest) -> Result<Hook, String> {
let tags_json = hook
.tags
Expand Down Expand Up @@ -939,6 +940,7 @@ pub(crate) fn create_hook_in_db(db: &Database, hook: &CreateHookRequest) -> Resu
}

/// Get a hook by ID from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_hook_by_id(db: &Database, id: i64) -> Result<Hook, String> {
let mut stmt = db
.conn()
Expand Down Expand Up @@ -971,6 +973,7 @@ pub(crate) fn get_all_hooks_from_db(db: &Database) -> Result<Vec<Hook>, String>
}

/// Update a hook in the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn update_hook_in_db(
db: &Database,
id: i64,
Expand Down Expand Up @@ -1020,6 +1023,7 @@ pub(crate) fn update_hook_in_db(
}

/// Delete a hook from the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn delete_hook_from_db(db: &Database, id: i64) -> Result<(), String> {
db.conn()
.execute("DELETE FROM hooks WHERE id = ?", [id])
Expand All @@ -1028,6 +1032,7 @@ pub(crate) fn delete_hook_from_db(db: &Database, id: i64) -> Result<(), String>
}

/// Add a hook to global hooks in the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn add_global_hook_in_db(db: &Database, hook_id: i64) -> Result<(), String> {
db.conn()
.execute(
Expand All @@ -1039,6 +1044,7 @@ pub(crate) fn add_global_hook_in_db(db: &Database, hook_id: i64) -> Result<(), S
}

/// Get all global hooks from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_global_hooks_from_db(db: &Database) -> Result<Vec<GlobalHook>, String> {
let mut stmt = db
.conn()
Expand Down Expand Up @@ -1068,6 +1074,7 @@ pub(crate) fn get_global_hooks_from_db(db: &Database) -> Result<Vec<GlobalHook>,
}

/// Toggle a global hook in the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn toggle_global_hook_in_db(
db: &Database,
id: i64,
Expand All @@ -1083,6 +1090,7 @@ pub(crate) fn toggle_global_hook_in_db(
}

/// Remove a global hook from the database (no file sync)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn remove_global_hook_from_db(db: &Database, hook_id: i64) -> Result<(), String> {
db.conn()
.execute("DELETE FROM global_hooks WHERE hook_id = ?", [hook_id])
Expand Down
9 changes: 8 additions & 1 deletion src-tauri/src/commands/mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ pub(crate) fn delete_mcp_impl(db: &Database, id: i64) -> Result<(), String> {
}

/// Duplicate an MCP in the database
#[allow(clippy::type_complexity)]
pub(crate) fn duplicate_mcp_impl(db: &Database, id: i64) -> Result<Mcp, String> {
// Get original
let mut stmt = db
Expand Down Expand Up @@ -319,18 +320,22 @@ pub(crate) fn generate_duplicate_name(name: &str) -> String {
}

// Convenience aliases (promoted from #[cfg(test)] for cross-module reuse)
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn create_mcp_in_db(db: &Database, mcp: &CreateMcpRequest) -> Result<Mcp, String> {
create_mcp_impl(db, mcp)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_mcp_by_id(db: &Database, id: i64) -> Result<Mcp, String> {
get_mcp_impl(db, id)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_all_mcps_from_db(db: &Database) -> Result<Vec<Mcp>, String> {
get_all_mcps_impl(db)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn update_mcp_in_db(
db: &Database,
id: i64,
Expand All @@ -339,10 +344,12 @@ pub(crate) fn update_mcp_in_db(
update_mcp_impl(db, id, mcp)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn delete_mcp_from_db(db: &Database, id: i64) -> Result<(), String> {
delete_mcp_impl(db, id)
}

#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn toggle_global_mcp_in_db(db: &Database, id: i64, enabled: bool) -> Result<(), String> {
toggle_global_mcp_impl(db, id, enabled)
}
Expand Down Expand Up @@ -708,7 +715,7 @@ mod tests {
let db = Database::in_memory().unwrap();
let req = sample_stdio_mcp();
let created = create_mcp_in_db(&db, &req).unwrap();
let original_updated = created.updated_at.clone();
let _original_updated = created.updated_at.clone();

// Small delay to ensure timestamp changes
std::thread::sleep(std::time::Duration::from_millis(10));
Expand Down
12 changes: 5 additions & 7 deletions src-tauri/src/commands/mcp_registry.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::db::Database;
use crate::services::mcp_registry::{EnvPlaceholder, RegistryClient, RegistryMcpEntry};
use crate::services::mcp_registry::{RegistryClient, RegistryMcpEntry};
use rusqlite::params;
use serde::{Deserialize, Serialize};
use std::sync::{Arc, Mutex};
Expand Down Expand Up @@ -94,18 +94,15 @@ pub fn import_mcp_from_registry_in_db(
let args_json = entry
.args
.as_ref()
.map(|a| serde_json::to_string(a).ok())
.flatten();
.and_then(|a| serde_json::to_string(a).ok());
let headers_json = entry
.headers
.as_ref()
.map(|h| serde_json::to_string(h).ok())
.flatten();
.and_then(|h| serde_json::to_string(h).ok());
let env_json = entry
.env
.as_ref()
.map(|e| serde_json::to_string(e).ok())
.flatten();
.and_then(|e| serde_json::to_string(e).ok());

db.conn()
.execute(
Expand Down Expand Up @@ -166,6 +163,7 @@ pub fn get_registry_mcp_by_id(db: &Database, id: i64) -> Result<RegistryMcpEntry
#[cfg(test)]
mod tests {
use super::*;
use crate::services::mcp_registry::EnvPlaceholder;
use std::collections::HashMap;

// =========================================================================
Expand Down
5 changes: 2 additions & 3 deletions src-tauri/src/commands/mcp_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
//! These commands allow the frontend to start/stop and configure the MCP server.

use crate::db::Database;
use crate::mcp_server::server::{
generate_self_mcp_entry, McpServerConfig, McpServerStatus, DEFAULT_MCP_SERVER_PORT,
};
use crate::mcp_server::server::{generate_self_mcp_entry, McpServerConfig, McpServerStatus};
use crate::mcp_server::McpServerState;
use log::info;
use serde_json::Value;
Expand Down Expand Up @@ -148,6 +146,7 @@ pub fn is_self_mcp_in_library(db: State<'_, Arc<Mutex<Database>>>) -> Result<boo
#[cfg(test)]
mod tests {
use super::*;
use crate::mcp_server::server::DEFAULT_MCP_SERVER_PORT;

#[test]
fn test_mcp_server_config_serde() {
Expand Down
2 changes: 2 additions & 0 deletions src-tauri/src/commands/mcp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct McpSessionData {
}

/// Extract MCP session data from the database (no Tauri State dependency)
#[allow(clippy::type_complexity)]
pub(crate) fn get_mcp_session_data_from_db(
db: &Database,
mcp_id: i64,
Expand Down Expand Up @@ -84,6 +85,7 @@ pub(crate) fn get_mcp_session_data_from_db(
}

/// Validate MCP session data before starting a session
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn validate_mcp_session_data(data: &McpSessionData) -> Result<(), String> {
if data.source == "system" {
if data.url.is_none() {
Expand Down
4 changes: 4 additions & 0 deletions src-tauri/src/commands/mcp_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use std::sync::{Arc, Mutex};
use tauri::State;

/// Extract MCP test data including source field from the database (no Tauri State dependency)
#[allow(clippy::type_complexity)]
pub fn get_mcp_test_data_with_source_from_db(
db: &Database,
mcp_id: i64,
Expand Down Expand Up @@ -163,6 +164,8 @@ pub fn test_mcp_config(
// ============================================================================

/// Extract MCP data from database for testing
#[cfg_attr(not(test), allow(dead_code))]
#[allow(clippy::type_complexity)]
pub fn get_mcp_test_data_from_db(
db: &Database,
mcp_id: i64,
Expand Down Expand Up @@ -217,6 +220,7 @@ pub fn get_mcp_test_data_from_db(
}

/// Validate MCP config before testing
#[cfg_attr(not(test), allow(dead_code))]
pub fn validate_mcp_config(
mcp_type: &str,
command: Option<&str>,
Expand Down
1 change: 1 addition & 0 deletions src-tauri/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod analytics;
pub mod claude_json;
pub mod claude_settings;
pub mod cloud_sync;
#[allow(clippy::module_inception)]
pub mod commands;
pub mod config;
pub mod containers;
Expand Down
3 changes: 2 additions & 1 deletion src-tauri/src/commands/permissions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ pub fn get_permission_templates(
}

/// Seed default permission templates (no Tauri State dependency)
#[allow(clippy::type_complexity)]
pub(crate) fn seed_permission_templates_impl(db: &Database) -> Result<(), String> {
// Check if templates already exist
let count: i64 = db
Expand Down Expand Up @@ -366,7 +367,7 @@ pub(crate) fn seed_permission_templates_impl(db: &Database) -> Result<(), String
),
];

let count = templates.len();
let _count = templates.len();
for (name, desc, category, rule, tool_name, tag) in templates {
let tags_json = serde_json::to_string(&vec![tag]).unwrap();
db.conn()
Expand Down
6 changes: 6 additions & 0 deletions src-tauri/src/commands/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ pub fn toggle_project_mcp(
}

#[tauri::command]
#[allow(clippy::type_complexity)]
pub fn sync_project_config(
db: State<'_, Arc<Mutex<Database>>>,
project_id: i64,
Expand Down Expand Up @@ -498,6 +499,7 @@ pub fn sync_project_config(
// ============================================================================

/// Create a project in the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn create_project_in_db(
db: &Database,
project: &CreateProjectRequest,
Expand All @@ -515,6 +517,7 @@ pub(crate) fn create_project_in_db(
}

/// Get a project by ID from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_project_by_id(db: &Database, id: i64) -> Result<Project, String> {
db.conn()
.query_row(
Expand All @@ -541,6 +544,7 @@ pub(crate) fn get_project_by_id(db: &Database, id: i64) -> Result<Project, Strin
}

/// Get a project by path from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_project_by_path(db: &Database, path: &str) -> Result<Project, String> {
db.conn()
.query_row(
Expand All @@ -567,6 +571,7 @@ pub(crate) fn get_project_by_path(db: &Database, path: &str) -> Result<Project,
}

/// Get all projects from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_all_projects_from_db(db: &Database) -> Result<Vec<Project>, String> {
let mut stmt = db
.conn()
Expand Down Expand Up @@ -765,6 +770,7 @@ pub(crate) fn toggle_project_mcp_in_db(
}

/// Get project MCP assignments from the database
#[cfg_attr(not(test), allow(dead_code))]
pub(crate) fn get_project_mcps_from_db(
db: &Database,
project_id: i64,
Expand Down
Loading
Loading