Jason
6a9aa7aeb5
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
2025-10-27 22:30:57 +08:00
Jason
9f5c2b427f
refactor(backend): phase 2 - split commands.rs by domain (100%)
...
Split monolithic commands.rs (1525 lines) into 7 domain-focused modules
to improve maintainability and readability while preserving the external API.
## Changes
### Module Structure
Created `commands/` directory with domain-based organization:
- **provider.rs** (946 lines, 15 commands)
- Provider CRUD operations (get, add, update, delete, switch)
- Usage query integration
- Endpoint speed testing and custom endpoint management
- Sort order management
- Largest file but highly cohesive (all provider-related)
- **mcp.rs** (235 lines, 13 commands)
- Claude MCP management (~/.claude.json)
- SSOT MCP config management (config.json)
- Sync operations (Claude ↔ Codex)
- Import/export functionality
- **config.rs** (153 lines, 8 commands)
- Config path queries (Claude/Codex)
- Directory operations (open, pick)
- Config status checks
- Parameter compatibility layer (app_type/app/appType)
- **settings.rs** (40 lines, 5 commands)
- App settings management
- App restart functionality
- app_config_dir override (Store integration)
- **plugin.rs** (36 lines, 4 commands)
- Claude plugin management (~/.claude/config.json)
- Plugin status and config operations
- **misc.rs** (45 lines, 3 commands)
- External link handling
- Update checks
- Portable mode detection
- **mod.rs** (15 lines)
- Module exports via `pub use`
- Preserves flat API structure
### API Preservation
- Used `pub use` pattern to maintain external API
- All commands still accessible as `commands::function_name`
- Zero breaking changes for frontend code
- lib.rs invoke_handler unchanged (48 commands registered)
## Statistics
- Files: 1 → 7 (modular organization)
- Lines: 1525 → 1470 (net -55 lines, -3.6%)
- Commands: 48 → 48 (all preserved)
- Average file size: 210 lines (excluding provider.rs)
- Compilation: ✅ Success (6.92s, 0 warnings)
- Tests: ✅ 4/4 passed
## Benefits
- **Maintainability**: Easier to locate and modify domain-specific code
- **Readability**: Smaller files (~200 lines) vs monolithic 1500+ lines
- **Testability**: Can unit test individual modules in isolation
- **Scalability**: Clear pattern for adding new command groups
- **Zero Risk**: No API changes, all tests passing
## Design Decisions
1. **Domain-based split**: Organized by business domain (provider, mcp, config)
rather than technical layers (crud, query, sync)
2. **Preserved provider.rs size**: Kept at 946 lines to maintain high cohesion
(all provider-related operations together). Can be further split in Phase 2.1
if needed.
3. **Parameter compatibility**: Retained multiple parameter names (app_type, app,
appType) for backward compatibility with different frontend call styles
## Phase 2 Status: ✅ 100% Complete
Ready for Phase 3: Adding integration tests.
Co-authored-by: Claude <noreply@anthropic.com >
2025-10-27 22:18:05 +08:00
Jason
c01e495eea
refactor(backend): phase 1 - unified error handling with thiserror
...
Introduce AppError enum to replace Result<T, String> pattern across
the codebase, improving error context preservation and type safety.
## Changes
### Core Infrastructure
- Add src/error.rs with AppError enum using thiserror
- Add thiserror dependency to Cargo.toml
- Implement helper functions: io(), json(), toml() for ergonomic error creation
- Implement From<PoisonError> for automatic lock error conversion
- Implement From<AppError> for String to maintain Tauri command compatibility
### Module Migrations (60% complete)
- config.rs: Full migration to AppError
- read_json_file, write_json_file, atomic_write
- archive_file, copy_file, delete_file
- claude_mcp.rs: Full migration to AppError
- get_mcp_status, read_mcp_json, upsert_mcp_server
- delete_mcp_server, validate_command_in_path
- set_mcp_servers_map
- codex_config.rs: Full migration to AppError
- write_codex_live_atomic with rollback support
- read_and_validate_codex_config_text
- validate_config_toml
- app_config.rs: Partial migration
- MultiAppConfig::load, MultiAppConfig::save
- store.rs: Partial migration
- AppState::save now returns Result<(), AppError>
- commands.rs: Minimal changes
- Use .map_err(Into::into) for compatibility
- mcp.rs: Minimal changes
- sync_enabled_to_claude uses Into::into conversion
### Documentation
- Add docs/BACKEND_REFACTOR_PLAN.md with detailed refactoring roadmap
## Benefits
- Type-safe error handling with preserved error chains
- Better error messages with file paths and context
- Reduced boilerplate code (118 Result<T, String> instances to migrate)
- Automatic error conversion for seamless integration
## Testing
- All existing tests pass (4/4)
- Compilation successful with no warnings
- Build time: 0.61s (no performance regression)
## Remaining Work
- claude_plugin.rs (7 functions)
- migration.rs, import_export.rs
- Add unit tests for error.rs
- Complete commands.rs migration after dependent modules
Co-authored-by: Claude <claude@anthropic.com >
2025-10-27 16:29:11 +08:00
Jason
bbf830a1da
test: add frontend testing infrastructure with vitest
...
- Introduce Vitest + React Testing Library + jsdom environment
- Add useDragSort hook unit tests covering:
* Sorting logic (sortIndex → createdAt → name)
* Successful drag operation (API call + cache invalidation)
* Failed drag operation (error toast display)
* Edge case (no valid target, no API call)
- Configure global test setup (i18n mock, auto cleanup)
- Update TypeScript configs to include tests/ directory
- Add test development plan documentation
Test Coverage:
✓ Provider drag-and-drop sorting core logic
✓ React Query cache refresh
✓ Toast notification display
✓ Boundary condition handling
Test Results: 4/4 passed (671ms)
Next Steps: Sprint 2 - component tests with MSW mock layer
2025-10-25 10:08:06 +08:00
Jason
bb48f4f6af
refactor: consolidate provider form components
...
This commit completes Stage 2.5-2.6 of the refactoring plan by:
- Consolidating 8 provider form files (1941+ lines) into a single
unified ProviderForm component (353 lines), reducing code by ~82%
- Implementing modern form management with react-hook-form and zod
- Adding preset provider categorization with grouped select UI
- Supporting dual-mode operation for both Claude and Codex configs
- Removing redundant subcomponents:
- ApiKeyInput.tsx (72 lines)
- ClaudeConfigEditor.tsx (205 lines)
- CodexConfigEditor.tsx (667 lines)
- EndpointSpeedTest.tsx (636 lines)
- KimiModelSelector.tsx (195 lines)
- PresetSelector.tsx (119 lines)
Key improvements:
- Type-safe form values with ProviderFormValues extension
- Automatic template value application for presets
- Better internationalization coverage
- Cleaner separation of concerns
- Enhanced UX with categorized preset groups
Updates AddProviderDialog and EditProviderDialog to pass appType prop
and handle preset category metadata.
2025-10-16 13:02:38 +08:00
Jason
f3e7412a14
feat: complete stage 4 cleanup and code formatting
...
This commit completes stage 4 of the refactoring plan, focusing on cleanup
and optimization of the modernized codebase.
## Key Changes
### Code Cleanup
- Remove legacy `src/lib/styles.ts` (no longer needed)
- Remove old modal components (`ImportProgressModal.tsx`, `ProviderList.tsx`)
- Streamline `src/lib/tauri-api.ts` from 712 lines to 17 lines (-97.6%)
- Remove global `window.api` pollution
- Keep only event listeners (`tauriEvents.onProviderSwitched`)
- All API calls now use modular `@/lib/api/*` layer
### Type System
- Clean up `src/vite-env.d.ts` (remove 156 lines of outdated types)
- Remove obsolete global type declarations
- All TypeScript checks pass with zero errors
### Code Formatting
- Format all source files with Prettier (82 files)
- Fix formatting issues in 15 files:
- App.tsx and core components
- MCP management components
- Settings module components
- Provider management components
- UI components
### Documentation Updates
- Update `REFACTORING_CHECKLIST.md` with stage 4 progress
- Mark completed tasks in `REFACTORING_MASTER_PLAN.md`
## Impact
**Code Reduction:**
- Total: -1,753 lines, +384 lines (net -1,369 lines)
- tauri-api.ts: 712 → 17 lines (-97.6%)
- Removed styles.ts: -82 lines
- Removed vite-env.d.ts declarations: -156 lines
**Quality Improvements:**
- ✅ Zero TypeScript errors
- ✅ Zero TODO/FIXME comments
- ✅ 100% Prettier compliant
- ✅ Zero `window.api` references
- ✅ Fully modular API layer
## Testing
- [x] TypeScript compilation passes
- [x] Code formatting validated
- [x] No linting errors
Stage 4 completion: 100%
Ready for stage 5 (testing and bug fixes)
2025-10-16 12:13:51 +08:00
Jason
2b45af118f
feat: complete stage 3 settings refactor
2025-10-16 11:40:02 +08:00
Jason
b88eb88608
feat: complete stage 2 core refactor
2025-10-16 10:49:56 +08:00
Jason
cc0b7053aa
feat: complete stage 1 infrastructure
2025-10-16 10:00:22 +08:00
Jason
95e2d84655
docs: add comprehensive refactoring documentation
...
Add three key documents to guide the project restructure:
- REFACTORING_MASTER_PLAN.md: Complete refactoring roadmap with 6 stages
- REFACTORING_CHECKLIST.md: Detailed task checklist for tracking progress
- REFACTORING_REFERENCE.md: Technical reference and implementation guide
This refactoring aims to modernize the codebase with React Query,
react-hook-form, zod validation, and shadcn/ui components while
maintaining the current Tailwind CSS 4.x stack.
🤖 Generated with [Claude Code](https://claude.com/claude-code )
Co-Authored-By: Claude <noreply@anthropic.com >
2025-10-16 09:38:41 +08:00
Jason
60e8351f60
chore: bump version to v3.5.0 and update roadmap
...
Version Changes:
- Update version to 3.5.0 in package.json, Cargo.toml, and tauri.conf.json
Changelog Updates:
- Add v3.5.0 release notes with comprehensive feature list
- Document MCP management system implementation
- Document configuration import/export functionality
- Document endpoint speed testing feature
- List all improvements, bug fixes, and technical enhancements
Roadmap Updates:
- Mark MCP manager as completed ✅
- Mark i18n (internationalization) as completed ✅
- Add new planned features: memory management, cloud sync
- Reorganize feature priorities
2025-10-12 22:27:02 +08:00
Jason
e0908701b4
Remove deprecated VS Code Codex integration
2025-10-03 20:03:55 +08:00
Jason
7435a34c66
update roadmap
2025-09-26 21:57:38 +08:00
Jason
186c361a79
refactor: reorganize documentation structure
...
- Remove docs/ from .gitignore to track documentation files
- Delete completed plan documents (encrypted-config-plan.md, updater-plan.md)
- Add roadmap.md with project milestones and future features
2025-09-25 23:51:48 +08:00
Jason
a1a16be2aa
feat(updater): 前端 Updater 封装与设置页接入\n\n- 新增 src/lib/updater.ts(check→download→install→relaunch 封装与类型)\n- SettingsModal 按钮优先走 Updater,失败回退打开 Releases\n- 依赖:@tauri-apps/plugin-updater、@tauri-apps/plugin-process\n- 文档:精简并重写 docs/updater-plan.md(明确接口/流程/配置)
2025-09-08 16:48:24 +08:00
Jason
c0d9d0296d
feat(ui): implement dark mode with system preference support
...
- Add useDarkMode hook for managing theme state and persistence
- Integrate dark mode toggle button in app header
- Update all components with dark variant styles using Tailwind v4
- Create centralized style utilities for consistent theming
- Support system color scheme preference as fallback
- Store user preference in localStorage for persistence
2025-09-08 15:38:06 +08:00
Jason
ab6be1d510
docs(cleanup): remove 'current' as special provider; align UI/messages and migration naming to 'default' and one-time import rule
...
- App: update auto-import message to '默认供应商'
- README: clarify default import only when providers are empty
- Plan doc: replace 'current entry' wording with current pointer (manager.current)
- Migration: name live-imported item 'default' instead of 'current'
2025-09-05 15:16:03 +08:00
Jason
33753c72cd
docs: update plan to use 'current' instead of 'default' for initial import\n\n- Aligns documentation with implementation across migration and import flows
2025-09-04 22:39:03 +08:00
Jason
25c112856d
feat(ssot): backfill live config and write from in-memory settings during switch\n\n- Stop relying on provider backup files for switching (Claude/Codex)\n- Backfill current live config into the active provider before switching\n- Write target provider settings directly to app main config\n- Avoid writing provider copies when importing default provider
2025-09-04 15:59:28 +08:00