refactor(backend): phase 3 - add integration tests for config sync (partial)

Add integration test suite with isolated test environment:
- New test file: tests/import_export_sync.rs (149 lines, 3 test cases)
  * sync_claude_provider_writes_live_settings: validates SSOT sync to live settings
  * create_backup_skips_missing_file: edge case handling for missing config
  * create_backup_generates_snapshot_file: verifies backup snapshot creation
- Test infrastructure:
  * OnceLock-based isolated HOME directory in temp folder
  * Mutex guard to ensure sequential test execution (avoid file system race)
  * Automatic cleanup between test runs

Export core APIs for testing (lib.rs):
- AppType, MultiAppConfig, Provider (data structures)
- get_claude_settings_path, read_json_file (config utilities)
- create_backup, sync_current_providers_to_live (sync operations)
- update_settings, AppSettings (settings management)

Adjust visibility:
- import_export::sync_current_providers_to_live: fn -> pub fn

Update documentation:
- Mark Phase 3 as in-progress (🚧) in BACKEND_REFACTOR_PLAN.md
- Document current test coverage scope and pending scenarios

Test results: 7/7 passed (4 unit + 3 integration)
Build time: 0.16s

Next steps:
- Add Codex sync tests (auth.json + config.toml atomic writes)
- Add MCP sync integration tests
- Add end-to-end provider switching tests
This commit is contained in:
Jason
2025-10-27 22:30:57 +08:00
parent 9f5c2b427f
commit 6a9aa7aeb5
4 changed files with 159 additions and 1 deletions

View File

@@ -76,6 +76,10 @@
- 已将单一 `src-tauri/src/commands.rs` 拆分为 `commands/{provider,mcp,config,settings,misc,plugin}.rs` 并通过 `commands/mod.rs` 统一导出,保持对外 API 不变。
- 每个文件聚焦单一功能域供应商、MCP、配置、设置、杂项、插件命令函数平均 150-250 行,可读性与后续维护性显著提升。
- 相关依赖调整后 `cargo check` 通过,静态巡检确认无重复定义或未注册命令。
- **阶段 3补充测试 🚧**
- 新增 `tests/import_export_sync.rs` 集成测试,覆盖配置备份与 Claude 供应商 live 同步路径(使用隔离的 HOME 目录,避免污染真实环境)。
- 扩展 `lib.rs` 对核心数据结构与错误处理 API 的导出,便于后续服务层测试复用。
- 当前覆盖率聚焦配置导入导出模块,后续待补充 MCP 同步、供应商切换等跨模块场景。
## 渐进式重构路线