Commit Graph

12 Commits

  • test: update test suites to match component refactoring
    Comprehensive test updates to align with recent component refactoring
    and new auto-launch functionality.
    
    Component Tests:
    - AddProviderDialog.test.tsx (10 lines):
      * Updated test cases for new dialog behavior
      * Enhanced mock data for preset selection
      * Improved assertions for validation
    
    - ImportExportSection.test.tsx (16 lines):
      * Updated for new settings page integration
      * Enhanced test coverage for error scenarios
      * Better mock state management
    
    - McpFormModal.test.tsx (60 lines):
      * Extensive updates for form refactoring
      * New test cases for multi-app selection
      * Enhanced validation testing
      * Better coverage of stdio/http server types
    
    - ProviderList.test.tsx (11 lines):
      * Updated for new card layout
      * Enhanced drag-and-drop testing
    
    - SettingsDialog.test.tsx (96 lines):
      * Major updates for SettingsPage migration
      * New test cases for auto-launch functionality
      * Enhanced integration test coverage
      * Better async operation testing
    
    Hook Tests:
    - useDirectorySettings.test.tsx (32 lines):
      * Updated for refactored hook logic
      * Enhanced test coverage for edge cases
    
    - useDragSort.test.tsx (36 lines):
      * Simplified test cases
      * Better mock implementation
      * Improved assertions
    
    - useImportExport tests (16 lines total):
      * Updated for new error handling
      * Enhanced test coverage
    
    - useMcpValidation.test.tsx (23 lines):
      * Updated validation test cases
      * Better coverage of error scenarios
    
    - useProviderActions.test.tsx (48 lines):
      * Extensive updates for hook refactoring
      * New test cases for provider operations
      * Enhanced mock data
    
    - useSettings.test.tsx (12 lines):
      * New test cases for auto-launch
      * Enhanced settings state testing
      * Better async operation coverage
    
    Integration Tests:
    - App.test.tsx (41 lines):
      * Updated for new routing logic
      * Enhanced navigation testing
      * Better component integration coverage
    
    - SettingsDialog.test.tsx (88 lines):
      * Complete rewrite for SettingsPage
      * New integration test scenarios
      * Enhanced user workflow testing
    
    Mock Infrastructure:
    - handlers.ts (117 lines):
      * Major updates for MSW handlers
      * New handlers for auto-launch commands
      * Enhanced error simulation
      * Better request/response mocking
    
    - state.ts (37 lines):
      * Updated mock state structure
      * New state for auto-launch
      * Enhanced state reset functionality
    
    - tauriMocks.ts (10 lines):
      * Updated mock implementations
      * Better type safety
    
    - server.ts & testQueryClient.ts:
      * Minor cleanup (2 lines removed)
    
    Test Infrastructure Improvements:
    - Better test isolation
    - Enhanced mock data consistency
    - Improved async operation testing
    - Better error scenario coverage
    - Enhanced integration test patterns
    
    Coverage Improvements:
    - Net increase of 195 lines of test code
    - Better coverage of edge cases
    - Enhanced error path testing
    - Improved integration test scenarios
    - Better mock infrastructure
    
    All tests now pass with the refactored components while maintaining
    comprehensive coverage of functionality and edge cases.
  • feat(frontend): implement unified MCP panel for v3.7.0
    Complete Phase 3 (P0) frontend implementation for unified MCP management:
    
    **New Files:**
    - src/hooks/useMcp.ts: React Query hooks for unified MCP operations
    - src/components/mcp/UnifiedMcpPanel.tsx: Unified MCP management panel
    - src/components/ui/checkbox.tsx: Checkbox component from shadcn/ui
    
    **Features:**
    - Unified panel with three-column layout: server info + app checkboxes + actions
    - Multi-app control: Claude/Codex/Gemini checkboxes for each server
    - Real-time stats: Show enabled server counts per app
    - Full CRUD operations: Add, edit, delete, sync all servers
    
    **Integration:**
    - Replace old app-specific McpPanel with UnifiedMcpPanel in App.tsx
    - Update McpFormModal to support unified mode with apps field
    - Add i18n support: mcp.unifiedPanel namespace (zh/en)
    
    **Type Safety:**
    - Ensure McpServer.apps field always initialized
    - Fix all test files to include apps field
    - TypeScript type check passes 
    
    **Architecture:**
    - Single source of truth: mcp.servers manages all MCP configs
    - Per-server app control: apps.claude/codex/gemini boolean flags
    - Backward compatible: McpFormModal supports both unified and legacy modes
    
    Next: P1 tasks (import dialogs, sub-components, tests)
  • feat(gemini): add Gemini provider integration (#202)
    * feat(gemini): add Gemini provider integration
    
    - Add gemini_config.rs module for .env file parsing
    - Extend AppType enum to support Gemini
    - Implement GeminiConfigEditor and GeminiFormFields components
    - Add GeminiIcon with standardized 1024x1024 viewBox
    - Add Gemini provider presets configuration
    - Update i18n translations for Gemini support
    - Extend ProviderService and McpService for Gemini
    
    * fix(gemini): resolve TypeScript errors, add i18n support, and fix MCP logic
    
    **Critical Fixes:**
    - Fix TS2741 errors in tests/msw/state.ts by adding missing Gemini type definitions
    - Fix ProviderCard.extractApiUrl to support GOOGLE_GEMINI_BASE_URL display
    - Add missing apps.gemini i18n keys (zh/en) for proper app name display
    - Fix MCP service Gemini cross-app duplication logic to prevent self-copy
    
    **Technical Details:**
    - tests/msw/state.ts: Add gemini default providers, current ID, and MCP config
    - ProviderCard.tsx: Check both ANTHROPIC_BASE_URL and GOOGLE_GEMINI_BASE_URL
    - services/mcp.rs: Skip Gemini in sync_other_side logic with unreachable!() guards
    - Run pnpm format to auto-fix code style issues
    
    **Verification:**
    -  pnpm typecheck passes
    -  pnpm format completed
    
    * feat(gemini): enhance authentication and config parsing
    
    - Add strict and lenient .env parsing modes
    - Implement PackyCode partner authentication detection
    - Support Google OAuth official authentication
    - Auto-configure security.auth.selectedType for PackyCode
    - Add comprehensive test coverage for all auth types
    - Update i18n for OAuth hints and Gemini config
    
    ---------
    
    Co-authored-by: Jason <farion1231@gmail.com>
  • refactor: migrate all Tauri commands to camelCase parameters
    This commit addresses parameter naming inconsistencies caused by Tauri v2's
    requirement for camelCase parameter names in IPC commands.
    
    Backend changes (Rust):
    - Updated all command parameters from snake_case to camelCase
    - Commands affected:
      * provider.rs: providerId (×4), timeoutSecs
      * import_export.rs: filePath (×2), defaultName
      * config.rs: defaultPath
    - Added #[allow(non_snake_case)] attributes for camelCase parameters
    - Removed unused QueryUsageParams struct
    
    Frontend changes (TypeScript):
    - Removed redundant snake_case parameters from all invoke() calls
    - Updated API files:
      * usage.ts: removed debug logs, unified to providerId
      * vscode.ts: updated 8 functions (providerId, timeoutSecs, filePath, defaultName)
      * settings.ts: updated 4 functions (defaultPath, filePath, defaultName)
    - Ensured all parameters now use camelCase exclusively
    
    Test updates:
    - Updated MSW handlers to accept both old and new parameter formats during transition
    - Added i18n mock compatibility for tests
    
    Root cause:
    The issue stemmed from Tauri v2 strictly requiring camelCase for command
    parameters, while the codebase was using snake_case. This caused parameters
    like 'provider_id' to not be recognized by the backend, resulting in
    "missing providerId parameter" errors.
    
    BREAKING CHANGE: All Tauri command invocations now require camelCase parameters.
    Any external tools or scripts calling these commands must be updated accordingly.
    
    Fixes: Usage query always failing with "missing providerId" error
    Fixes: Custom endpoint management not receiving provider ID
    Fixes: Import/export dialogs not respecting default paths
  • refactor(types): rename AppType to AppId for semantic clarity
    Rename `AppType` to `AppId` across the entire frontend codebase to better
    reflect its purpose as an application identifier rather than a type category.
    This aligns frontend naming with backend command parameter conventions.
    
    Changes:
    - Rename type `AppType` to `AppId` in src/lib/api/types.ts
    - Remove `AppType` export from src/lib/api/index.ts
    - Update all component props from `appType` to `appId` (43 files)
    - Update all variable names from `appType` to `appId`
    - Synchronize documentation (CHANGELOG, refactoring plans)
    - Update test files and MSW mocks
    
    BREAKING CHANGE: `AppType` type is no longer exported. Use `AppId` instead.
    All component props have been renamed from `appType` to `appId`.
  • refactor(api): simplify app type parameter handling to single required parameter
    Replace the previous dual-parameter approach (app_type/app/appType) with a single required `app: String` parameter across all Tauri commands. This change:
    
    - Introduces unified `parse_app()` helper replacing complex `resolve_app_type()` logic
    - Updates all backend commands in config, mcp, and provider modules
    - Aligns frontend API calls to use consistent `app` parameter naming
    - Simplifies MSW test handlers by removing optional parameter handling
    
    This improves API clarity and reduces parameter ambiguity while maintaining backward compatibility through error handling.
  • test: add dual-parameter support and sync mocks for import/export tests
    Update test infrastructure to support the dual app type parameter pattern
    (app_type enum + app string) introduced in 590be4e:
    
    - Add toast.warning mock for partial-success status handling
    - Add syncCurrentProvidersLive mock to test post-import sync behavior
    - Update MSW handlers to accept both app_type and app parameters with
      fallback resolution (app ?? app_type) across 7 provider endpoints
    - Add sync_current_providers_live endpoint mock returning success
    
    This ensures test compatibility during the app_type → app parameter
    migration and enables testing of the new partial-success import flow.
  • fix: resolve TypeScript type errors in test files
    - Add vitest/globals to tsconfig.json types array to provide type
      definitions for global test functions (describe, it, expect, vi)
    - Fix vi.fn type parameter in useDirectorySettings.test.tsx from
      <[], Promise<string>> to <() => Promise<string>>
    - Remove unused setMcpConfig import from MSW handlers
    - Add type assertions for mock.calls access in McpFormModal tests
      to resolve union type inference issues
    
    This ensures pnpm typecheck passes without errors while maintaining
    test functionality with vitest globals: true configuration.
  • test: add comprehensive MCP UI test coverage with MSW infrastructure
    ## MSW Infrastructure Enhancement
    - Add 5 MCP API handlers to tests/msw/handlers.ts:
      - get_mcp_config: Fetch MCP configuration for app type
      - import_mcp_from_claude/codex: Mock import operations (returns count: 1)
      - set_mcp_enabled: Toggle MCP server enabled state
      - upsert_mcp_server_in_config: Create/update MCP server
      - delete_mcp_server_in_config: Remove MCP server
    - Add MCP state management to tests/msw/state.ts:
      - McpConfigState type with per-app server storage
      - Default test data (stdio server for Claude, http server for Codex)
      - CRUD functions: getMcpConfig, setMcpServerEnabled, upsertMcpServer, deleteMcpServer
      - Immutable state operations with deep cloning
    
    ## McpFormModal Component Tests (4 tests)
    - Test preset application: Verify ID and config JSON auto-fill from preset selection
    - Test conflict detection: Async validation shows warning when syncing to conflicting ID
    - Test field sanitization: Verify trim whitespace, split tags, clean URLs before save
    - Test validation errors: Block submit and show toast error for invalid stdio config (missing command)
    
    ## McpPanel Integration Tests (3 tests)
    - Test toggle enabled state: Click toggle button triggers useMcpActions.toggleEnabled with correct params
    - Test create server flow: Open form → submit → saveServer called with syncOtherSide option
    - Test delete server flow: Click delete → confirm dialog → deleteServer called with ID
    
    ## Test Utilities
    - Add createTestQueryClient helper with retry: false for faster test execution
    
    ## Test Coverage
    - Test files: 15 → 17 (+2)
    - Total tests: 105 → 112 (+6.7%)
    - All 112 tests passing
    - Execution time: 3.15s
  • test: add directory browsing/reset and useSettings hook 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)
  • test: add SettingsDialog integration tests and enhance MSW infrastructure
    - Add comprehensive SettingsDialog integration tests with 3 test cases:
      * Load default settings from MSW
      * Import configuration and trigger success callback
      * Save settings and handle restart prompt
    - Extend MSW handlers with settings-related endpoints:
      * get_settings/save_settings for settings management
      * app_config_dir_override for custom config directory
      * apply_claude_plugin_config for plugin integration
      * import/export config file operations
      * file/directory dialog mocks
    - Add settings state management to MSW mock state:
      * Settings state with default values
      * appConfigDirOverride state
      * Reset logic in resetProviderState()
    - Mock @tauri-apps/api/path for DirectorySettings tests
    - Refactor App.test.tsx to focus on happy path scenarios:
      * Remove delete functionality test (covered in useProviderActions unit tests)
      * Reorganize test flow: settings → switch → usage → create → edit → switch → duplicate
      * Remove unnecessary state verifications
      * Simplify event testing
    
    All tests passing: 4 integration tests + 12 unit tests
  • test: migrate to MSW testing architecture for App integration test
    Major testing infrastructure upgrade from manual mocks to Mock Service Worker (MSW):
    
    New MSW infrastructure (tests/msw/):
    - Add state.ts: In-memory state manager with full CRUD operations
      - Manage providers and current selections per app type (Claude/Codex)
      - Auto-switch current provider when deleted
      - Deep clone to prevent reference pollution
    - Add handlers.ts: HTTP request handlers for 10 Tauri API endpoints
      - Mock get_providers, switch_provider, add/update/delete_provider
      - Mock update_sort_order, update_tray_menu, import_default_config
      - Support error scenarios (404 for non-existent providers)
    - Add tauriMocks.ts: Tauri API mock layer
      - Transparently convert invoke() calls to HTTP requests
      - Mock event listener system with emitTauriEvent helper
      - Use cross-fetch for Node.js environment
    - Add server.ts: MSW server setup for Node.js test environment
    
    Refactor App.test.tsx (-170 lines, -43%):
    - Remove 23 manual mocks (useProvidersQuery, useProviderActions, etc.)
    - Run real hooks with MSW-backed API calls instead of mock implementations
    - Test real state changes instead of mock call counts
    - Add comprehensive flow: duplicate → create → edit → delete → event listening
    - Verify actual provider list changes and current selection updates
    
    Setup integration:
    - Add MSW server lifecycle to tests/setupTests.ts
      - Start server before all tests
      - Reset handlers and state after each test
      - Close server after all tests complete
    - Clear all mocks in afterEach for test isolation
    
    Dependencies:
    - Add msw@^2.11.6 for API mocking
    - Add cross-fetch@^4.1.0 for fetch polyfill in Node.js
    
    Type fixes:
    - Add missing imports (AppType, Provider) in handlers.ts
    - Fix HttpResponse.json generic constraint with as any (MSW best practice)
    - Change invalid category "default" to "official" in state.ts
    
    Test results: All 50 tests passing across 8 files, 0 TypeScript errors