refactor(backend): phase 3 - unify error handling and fix backup timestamp bug

Key improvements:
- Extract switch_provider_internal() returning AppError for better testability
- Fix backup mtime inheritance: use read+write instead of fs::copy to ensure latest backup survives cleanup
- Add 15+ integration tests covering provider commands, atomic writes, and rollback scenarios
- Expose write_codex_live_atomic, AppState, and test hooks in public API
- Extract tests/support.rs with isolated HOME and mutex utilities

Test coverage:
- Provider switching with live config backfill and MCP sync
- Codex atomic write success and failure rollback
- Backup retention policy with proper mtime ordering
- Negative cases: missing auth field, invalid provider ID
This commit is contained in:
Jason
2025-10-28 09:55:10 +08:00
parent 10abdfa096
commit 8e980e6974
7 changed files with 450 additions and 81 deletions

View File

@@ -16,15 +16,16 @@ mod store;
mod usage_script;
pub use app_config::{AppType, MultiAppConfig};
pub use codex_config::{get_codex_auth_path, get_codex_config_path};
pub use codex_config::{get_codex_auth_path, get_codex_config_path, write_codex_live_atomic};
pub use config::{get_claude_mcp_path, get_claude_settings_path, read_json_file};
pub use import_export::{create_backup, sync_current_providers_to_live};
pub use provider::Provider;
pub use settings::{update_settings, AppSettings};
pub use mcp::{import_from_claude, import_from_codex, sync_enabled_to_claude, sync_enabled_to_codex};
pub use error::AppError;
pub use store::AppState;
pub use commands::*;
use store::AppState;
use tauri::{
menu::{CheckMenuItem, Menu, MenuBuilder, MenuItem},
tray::{TrayIconBuilder, TrayIconEvent},