refactor(backend): phase 3 - expand integration tests for Codex and MCP sync

Expand test suite from 3 to 11 integration tests, adding comprehensive coverage
for Codex dual-file atomicity and bidirectional MCP synchronization:

New Codex sync tests:
- sync_codex_provider_writes_auth_and_config: validates atomic write of auth.json
  and config.toml, plus SSOT backfill of latest toml content
- sync_enabled_to_codex_writes_enabled_servers: MCP projection to config.toml
- sync_enabled_to_codex_removes_servers_when_none_enabled: cleanup when all disabled
- sync_enabled_to_codex_returns_error_on_invalid_toml: error handling for malformed TOML

New Codex MCP import tests:
- import_from_codex_adds_servers_from_mcp_servers_table: imports new servers from live config
- import_from_codex_merges_into_existing_entries: smart merge preserving SSOT server configs

New Claude MCP tests:
- sync_claude_enabled_mcp_projects_to_user_config: enabled/disabled filtering for .claude.json
- import_from_claude_merges_into_config: intelligent merge preserving existing configurations

Expand lib.rs API exports:
- Codex paths: get_codex_auth_path, get_codex_config_path
- Claude MCP: get_claude_mcp_path
- MCP sync: sync_enabled_to_claude, sync_enabled_to_codex
- MCP import: import_from_claude, import_from_codex
- Error type: AppError (for test assertions)

Test infrastructure improvements:
- Enhanced reset_test_fs() to clean .claude.json
- All tests use isolated HOME directory with sequential execution via mutex

Test results: 11/11 passed
Files changed: 3 (+394/-6 lines)

Next steps: Command layer integration tests and error recovery scenarios
This commit is contained in:
Jason
2025-10-27 23:26:42 +08:00
parent 6a9aa7aeb5
commit 10abdfa096
3 changed files with 394 additions and 6 deletions

View File

@@ -77,9 +77,9 @@
- 每个文件聚焦单一功能域供应商、MCP、配置、设置、杂项、插件命令函数平均 150-250 行,可读性与后续维护性显著提升。
- 相关依赖调整后 `cargo check` 通过,静态巡检确认无重复定义或未注册命令。
- **阶段 3补充测试 🚧**
- 新增 `tests/import_export_sync.rs` 集成测试,覆盖配置备份Claude 供应商 live 同步路径(使用隔离 HOME 目录避免污染真实环境
- 扩展 `lib.rs` 对核心数据结构与错误处理 API 的导出,便于后续服务层测试复用
- 当前覆盖率聚焦配置导入导出模块,后续待补充 MCP 同步、供应商切换等跨模块场景
- `tests/import_export_sync.rs` 集成测试盖配置备份Claude/Codex live 同步、MCP 投影与 Codex/Claude 双向导入流程,并新增启用项清理、非法 TOML 抛错等失败场景验证;统一使用隔离 HOME 目录避免污染真实用户环境。
- 扩展 `lib.rs` re-export暴露 `AppType``MultiAppConfig``AppError`、配置 IO 以及 Codex/Claude MCP 路径与同步函数,方便服务层测试直接复用核心逻辑
- 当前覆盖配置、Codex/Claude MCP 核心路径及关键错误分支,后续仍需补齐命令层边界与导入导出异常回滚测试
## 渐进式重构路线