From 5a05ad83fa0f24278f74bc456bdd866b65b15456 Mon Sep 17 00:00:00 2001 From: lzt404 <2596933790@qq.com> Date: Thu, 10 Sep 2026 17:00:59 +0800 Subject: [PATCH] refactor: remove unused agent configuration code and fix build warnings - Remove 3 unused functions and 2 unread fields - Gate test-only types and helpers with #[cfg(test)] - Verify all 403 Rust tests pass and check/release builds emit no warnings --- src-tauri/src/agents/discovery.rs | 22 +------- src-tauri/src/agents/state.rs | 89 +------------------------------ src-tauri/src/main.rs | 3 +- 3 files changed, 4 insertions(+), 110 deletions(-) diff --git a/src-tauri/src/agents/discovery.rs b/src-tauri/src/agents/discovery.rs index 45d71bd..47f2340 100644 --- a/src-tauri/src/agents/discovery.rs +++ b/src-tauri/src/agents/discovery.rs @@ -753,17 +753,6 @@ pub(crate) fn validate_codex_oauth_login_at(auth_path: &Path) -> Result<(), Stri } } -pub(crate) fn remove_codex_config_file(path: &Path) -> Result { - match fs::remove_file(path) { - Ok(()) => Ok(true), - Err(error) if error.kind() == std::io::ErrorKind::NotFound => Ok(false), - Err(error) => Err(format!( - "删除 Codex 配置文件失败 {}: {error}", - path_to_string(path) - )), - } -} - pub(crate) fn clear_codex_config_files(home: &Path) -> Result, String> { let paths = history_paths("codex",home)?; let before = history_images(&paths)?; @@ -1119,6 +1108,7 @@ pub(crate) fn agent_configuration_is_synchronized( configured } +#[cfg(test)] pub(crate) fn inspect_agent_application( client: AgentClient, home: &Path, @@ -1138,8 +1128,6 @@ pub(crate) fn inspect_agent_application( enabled: false, state: "unconfigured".to_string(), backup_available: false, - applied_model: None, - claude_desktop_model_mappings: None, warnings: Vec::new(), }; } @@ -1148,8 +1136,6 @@ pub(crate) fn inspect_agent_application( enabled: false, state: "invalid".to_string(), backup_available: false, - applied_model: None, - claude_desktop_model_mappings: None, warnings: vec![error], }; } @@ -1166,8 +1152,6 @@ pub(crate) fn inspect_agent_application( enabled: true, state: "applied".to_string(), backup_available, - applied_model: Some(state.model), - claude_desktop_model_mappings: state.claude_desktop_model_mappings, warnings, } } @@ -1175,16 +1159,12 @@ pub(crate) fn inspect_agent_application( enabled: false, state: "unconfigured".to_string(), backup_available: false, - applied_model: None, - claude_desktop_model_mappings: None, warnings: Vec::new(), }, Err(error) => AgentModificationInspection { enabled: false, state: "invalid".to_string(), backup_available: false, - applied_model: None, - claude_desktop_model_mappings: None, warnings: vec![error], }, } diff --git a/src-tauri/src/agents/state.rs b/src-tauri/src/agents/state.rs index 21824a7..fb6a57f 100644 --- a/src-tauri/src/agents/state.rs +++ b/src-tauri/src/agents/state.rs @@ -28,19 +28,6 @@ pub(crate) fn agent_managed_paths(client: AgentClient, home: &Path) -> Vec Vec { - serde_json::from_str::(state_content) - .ok() - .map(|record| { - record - .files - .into_iter() - .map(|file| file.backup_path) - .collect() - }) - .unwrap_or_default() -} - pub(crate) fn write_agent_applied_state( path: &Path, state: &AgentAppliedState, @@ -530,8 +517,6 @@ pub(crate) fn inspect_agent_modification( enabled: false, state: "inactive".to_string(), backup_available: false, - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: Vec::new(), } } @@ -571,8 +556,6 @@ pub(crate) fn inspect_agent_modification( enabled: true, state: state.to_string(), backup_available, - applied_model: Some(record.model), - claude_desktop_model_mappings: None, warnings, } } @@ -580,8 +563,6 @@ pub(crate) fn inspect_agent_modification( enabled: false, state: "inactive".to_string(), backup_available: false, - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: Vec::new(), }, Err(error) => AgentModificationInspection { @@ -591,8 +572,6 @@ pub(crate) fn inspect_agent_modification( .iter() .filter_map(|path| agent_backup_path(path).ok()) .any(|path| path.is_file()), - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: vec![error], }, }; @@ -601,13 +580,11 @@ pub(crate) fn inspect_agent_modification( if configured { if let Some(model) = current_model { match build_legacy_agent_record(client, home, port, model) { - Ok(Some(record)) => { + Ok(Some(_)) => { return AgentModificationInspection { enabled: true, state: "active".to_string(), backup_available: true, - applied_model: Some(record.model), - claude_desktop_model_mappings: None, warnings: vec![ "检测到旧版 CPA 配置和备份,可使用“清除修改”恢复原配置".to_string() ], @@ -618,8 +595,6 @@ pub(crate) fn inspect_agent_modification( enabled: false, state: "inactive".to_string(), backup_available: false, - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: vec!["检测到 CPA 配置,但缺少可安全恢复的原始备份".to_string()], } } @@ -628,8 +603,6 @@ pub(crate) fn inspect_agent_modification( enabled: false, state: "inactive".to_string(), backup_available: false, - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: vec![error], } } @@ -641,8 +614,6 @@ pub(crate) fn inspect_agent_modification( enabled: false, state: "inactive".to_string(), backup_available: false, - applied_model: current_model.map(str::to_string), - claude_desktop_model_mappings: None, warnings: Vec::new(), } } @@ -1233,63 +1204,6 @@ pub(crate) fn dated_agent_backup_path(path: &Path) -> Result { Ok(path.with_file_name(format!("{file_name}.{date}.bak"))) } -pub(crate) fn prepare_agent_session_backups( - client: AgentClient, - updates: &[AgentFileUpdate], -) -> Result, String> { - let mut backups: Vec = Vec::with_capacity(updates.len()); - let mut renamed = Vec::new(); - for update in updates { - let existed_before = update.path.is_file(); - let backup_path = dated_agent_backup_path(&update.path)?; - if existed_before { - if backup_path.exists() { - if client == AgentClient::DeepSeekHarness { - for backup in &backups { - if backup.existed_before { - let _ = fs::remove_file(&backup.backup_path); - } - } - } - for (path, backup) in renamed.iter().rev() { - let _ = fs::rename(backup, path); - } - return Err(format!( - "智能体备份文件已存在,无法覆盖: {}", - path_to_string(&backup_path) - )); - } - if client == AgentClient::DeepSeekHarness { - if let Err(error) = fs::copy(&update.path, &backup_path) { - for backup in &backups { - if backup.existed_before { - let _ = fs::remove_file(&backup.backup_path); - } - } - return Err(format!( - "备份 DeepSeek Harness 配置失败 {}: {error}", - path_to_string(&update.path) - )); - } - } else { - fs::rename(&update.path, &backup_path).map_err(|error| { - format!( - "重命名原智能体配置为备份失败 {}: {error}", - path_to_string(&update.path) - ) - })?; - renamed.push((update.path.clone(), backup_path.clone())); - } - } - backups.push(AgentAppliedBackupFile { - path: update.path.clone(), - backup_path, - existed_before, - }); - } - Ok(backups) -} - pub(crate) fn restore_agent_session_configuration( client: AgentClient, home: &Path, @@ -1396,6 +1310,7 @@ pub(crate) fn restore_agent_applied_state_configuration( Ok(()) } +#[cfg(test)] pub(crate) fn commit_agent_configuration( client: AgentClient, home: &Path, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index b8d3ac5..67377a3 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -1233,12 +1233,11 @@ struct AgentModificationFile { managed_sha256: String, } +#[cfg(test)] struct AgentModificationInspection { enabled: bool, state: String, backup_available: bool, - applied_model: Option, - claude_desktop_model_mappings: Option, warnings: Vec, }