Add optimized auto-save function for General tab settings.
- Add autoSaveSettings method for non-destructive auto-save
- Only trigger system APIs when values actually change
- Avoid unnecessary auto-launch and plugin config updates
- Update tests to cover new functionality
- Add postChangeSync.ts utility with Result pattern for graceful error handling
- Replace try-catch with syncCurrentProvidersLiveSafe in useImportExport
- Add directory-change-triggered sync in useSettings to maintain SSOT
- Introduce partial-success status to distinguish import success from sync failures
- Add test coverage for sync behavior in different scenarios
This refactoring ensures config.json changes are reliably synced to live
files while providing better user feedback for edge cases.
useSettings Tests:
- Add test for null settings state protection
- Returns null immediately without calling APIs
- Prevents null pointer errors in save flow
- Add test for save mutation failure
- Verifies error propagates to caller
- Ensures restart flag remains untouched on failure
- Validates no side effects when save fails
useProviderActions Tests:
- Add error propagation tests for CRUD operations
- updateProvider: propagates errors to caller
- addProvider: propagates errors to caller
- deleteProvider: propagates errors to caller
- Add switch mutation error handling tests
- Claude switch: handles errors silently (no throw)
- Codex switch: skips plugin sync when mutation fails
- Verifies plugin sync APIs not called on failure
- Add loading state verification
- Test all mutations pending scenario (existing)
- Test all mutations idle scenario (new)
- Ensures isLoading flag accuracy
useImportExport Edge Case Tests (new file):
- Add test for user cancelling file dialog
- File dialog returns null (user cancelled)
- State remains unchanged (selectedFile: "", status: "idle")
- No error toast shown
- Add test for resetStatus behavior
- Clears error message and status
- Preserves selected file path for retry
- Resets backupId to null
All tests passing: 79/79 (10 new tests)
SettingsDialog Integration Tests:
- Add test for directory browsing and reset functionality
- Verify app config directory browse/reset flow
- Verify Claude config directory manual change, browse, and reset
- Test multiple directory inputs with getAllByTitle pattern
- Add test for export failure error handling
- User cancels file selection (save_file_dialog returns null)
- Export operation fails (disk full scenario)
- Use server.use() to dynamically override MSW handlers
- Verify toast error messages match i18n keys
MSW Handler Extension:
- Add pick_directory handler to support directory selection API
- Consistent with select_config_directory mock strategy
useSettings Hook Unit Tests:
- Add comprehensive tests for settings save logic
- Test restart flag when app config directory changes
- Test no restart when directory unchanged
- Verify space trimming and empty string to undefined conversion
- Test Claude plugin sync failure tolerance
- Add test for settings reset functionality
- Verify form/language/directories reset with server data
- Use factory functions for mock creation (reusability)
- Complete dependency isolation with mock hooks
All tests passing: 9/9 (5 integration + 4 unit tests)