refactor(api): unify AppType parsing with FromStr trait
BREAKING CHANGE: Remove support for legacy app_type/appType parameters.
All Tauri commands now accept only the 'app' parameter (values: "claude" or "codex").
Invalid app values will return localized error messages with allowed values.
This commit addresses code duplication and improves error handling:
- Consolidate AppType parsing into FromStr trait implementation
* Eliminates duplicate parse_app() functions across 3 command modules
* Provides single source of truth for app type validation
* Enables idiomatic Rust .parse::<AppType>() syntax
- Enhance error messages with localization
* Return bilingual error messages (Chinese + English)
* Include list of allowed values in error responses
* Use structured AppError::localized for better categorization
- Add input normalization
* Case-insensitive matching ("CLAUDE" → AppType::Claude)
* Automatic whitespace trimming (" codex \n" → AppType::Codex)
* Improves API robustness against user input variations
- Introduce comprehensive unit tests
* Test valid inputs with case variations
* Test whitespace handling
* Verify error message content and localization
* 100% coverage of from_str logic
- Update documentation
* Add CHANGELOG entry marking breaking change
* Update README with accurate architecture description
* Revise REFACTORING_MASTER_PLAN with migration examples
* Remove all legacy app_type/appType references
Code Quality Metrics:
- Lines removed: 27 (duplicate code)
- Lines added: 52 (including tests and docs)
- Code duplication: 3 → 0 instances
- Test coverage: 0% → 100% for AppType parsing
This commit is contained in:
14
CHANGELOG.md
14
CHANGELOG.md
@@ -248,3 +248,17 @@ For users upgrading from v2.x (Electron version):
|
||||
- Basic provider management
|
||||
- Claude Code integration
|
||||
- Configuration file handling
|
||||
## [Unreleased]
|
||||
|
||||
### ⚠️ Breaking Changes
|
||||
|
||||
- Tauri 命令统一仅接受 `app` 参数,移除历史 `app_type`/`appType` 兼容路径;传入未知 `app` 时会明确报错,并提示可选值。
|
||||
|
||||
### 🔧 Improvements
|
||||
|
||||
- 统一 `AppType` 解析:集中到 `FromStr` 实现,命令层不再各自实现 `parse_app()`,减少重复与漂移。
|
||||
- 错误消息本地化与更友好:对不支持的 `app` 返回中英双语提示,并包含可选值清单。
|
||||
|
||||
### 🧪 Tests
|
||||
|
||||
- 新增单元测试覆盖 `AppType::from_str`:大小写、裁剪空白、未知值错误消息。
|
||||
|
||||
Reference in New Issue
Block a user