Files
cc-switch/tests/msw/state.ts

280 lines
6.6 KiB
TypeScript
Raw Permalink Normal View History

import type { AppId } from "@/lib/api/types";
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
2025-10-26 13:52:42 +08:00
import type { McpServer, Provider, Settings } from "@/types";
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
2025-10-25 16:48:43 +08:00
type ProvidersByApp = Record<AppId, Record<string, Provider>>;
type CurrentProviderState = Record<AppId, string>;
type McpConfigState = Record<AppId, Record<string, McpServer>>;
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
2025-10-25 16:48:43 +08:00
const createDefaultProviders = (): ProvidersByApp => ({
claude: {
"claude-1": {
id: "claude-1",
name: "Claude Default",
settingsConfig: {},
category: "official",
sortIndex: 0,
createdAt: Date.now(),
},
"claude-2": {
id: "claude-2",
name: "Claude Custom",
settingsConfig: {},
category: "custom",
sortIndex: 1,
createdAt: Date.now() + 1,
},
},
codex: {
"codex-1": {
id: "codex-1",
name: "Codex Default",
settingsConfig: {},
category: "official",
sortIndex: 0,
createdAt: Date.now(),
},
"codex-2": {
id: "codex-2",
name: "Codex Secondary",
settingsConfig: {},
category: "custom",
sortIndex: 1,
createdAt: Date.now() + 1,
},
},
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>
2025-11-12 10:47:34 +08:00
gemini: {
"gemini-1": {
id: "gemini-1",
name: "Gemini Default",
settingsConfig: {
env: {
GEMINI_API_KEY: "test-key",
GOOGLE_GEMINI_BASE_URL: "https://generativelanguage.googleapis.com",
},
},
category: "official",
sortIndex: 0,
createdAt: Date.now(),
},
},
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
2025-10-25 16:48:43 +08:00
});
const createDefaultCurrent = (): CurrentProviderState => ({
claude: "claude-1",
codex: "codex-1",
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>
2025-11-12 10:47:34 +08:00
gemini: "gemini-1",
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
2025-10-25 16:48:43 +08:00
});
let providers = createDefaultProviders();
let current = createDefaultCurrent();
let settingsState: Settings = {
showInTray: true,
minimizeToTrayOnClose: true,
enableClaudePluginIntegration: false,
claudeConfigDir: "/default/claude",
codexConfigDir: "/default/codex",
language: "zh",
};
let appConfigDirOverride: string | null = null;
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
2025-10-26 13:52:42 +08:00
let mcpConfigs: McpConfigState = {
claude: {
sample: {
id: "sample",
name: "Sample Claude Server",
enabled: true,
apps: { claude: true, codex: false, gemini: false },
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
2025-10-26 13:52:42 +08:00
server: {
type: "stdio",
command: "claude-server",
},
},
},
codex: {
httpServer: {
id: "httpServer",
name: "HTTP Codex Server",
enabled: false,
apps: { claude: false, codex: true, gemini: false },
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
2025-10-26 13:52:42 +08:00
server: {
type: "http",
url: "http://localhost:3000",
},
},
},
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>
2025-11-12 10:47:34 +08:00
gemini: {},
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
2025-10-26 13:52:42 +08:00
};
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
2025-10-25 16:48:43 +08:00
const cloneProviders = (value: ProvidersByApp) =>
JSON.parse(JSON.stringify(value)) as ProvidersByApp;
export const resetProviderState = () => {
providers = createDefaultProviders();
current = createDefaultCurrent();
settingsState = {
showInTray: true,
minimizeToTrayOnClose: true,
enableClaudePluginIntegration: false,
claudeConfigDir: "/default/claude",
codexConfigDir: "/default/codex",
language: "zh",
};
appConfigDirOverride = null;
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
2025-10-26 13:52:42 +08:00
mcpConfigs = {
claude: {
sample: {
id: "sample",
name: "Sample Claude Server",
enabled: true,
apps: { claude: true, codex: false, gemini: false },
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
2025-10-26 13:52:42 +08:00
server: {
type: "stdio",
command: "claude-server",
},
},
},
codex: {
httpServer: {
id: "httpServer",
name: "HTTP Codex Server",
enabled: false,
apps: { claude: false, codex: true, gemini: false },
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
2025-10-26 13:52:42 +08:00
server: {
type: "http",
url: "http://localhost:3000",
},
},
},
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>
2025-11-12 10:47:34 +08:00
gemini: {},
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
2025-10-26 13:52:42 +08:00
};
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
2025-10-25 16:48:43 +08:00
};
export const getProviders = (appType: AppId) =>
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
2025-10-25 16:48:43 +08:00
cloneProviders(providers)[appType] ?? {};
export const getCurrentProviderId = (appType: AppId) => current[appType] ?? "";
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
2025-10-25 16:48:43 +08:00
export const setCurrentProviderId = (appType: AppId, providerId: string) => {
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
2025-10-25 16:48:43 +08:00
current[appType] = providerId;
};
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.
2025-11-21 11:12:06 +08:00
export const updateProviders = (
appType: AppId,
data: Record<string, Provider>,
) => {
providers[appType] = cloneProviders({ [appType]: data } as ProvidersByApp)[
appType
];
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
2025-10-25 16:48:43 +08:00
};
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.
2025-11-21 11:12:06 +08:00
export const setProviders = (
appType: AppId,
data: Record<string, Provider>,
) => {
providers[appType] = JSON.parse(JSON.stringify(data)) as Record<
string,
Provider
>;
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
2025-10-25 16:48:43 +08:00
};
export const addProvider = (appType: AppId, provider: Provider) => {
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
2025-10-25 16:48:43 +08:00
providers[appType] = providers[appType] ?? {};
providers[appType][provider.id] = provider;
};
export const updateProvider = (appType: AppId, provider: Provider) => {
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
2025-10-25 16:48:43 +08:00
if (!providers[appType]) return;
providers[appType][provider.id] = {
...providers[appType][provider.id],
...provider,
};
};
export const deleteProvider = (appType: AppId, providerId: string) => {
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
2025-10-25 16:48:43 +08:00
if (!providers[appType]) return;
delete providers[appType][providerId];
if (current[appType] === providerId) {
const fallback = Object.keys(providers[appType])[0] ?? "";
current[appType] = fallback;
}
};
export const updateSortOrder = (
appType: AppId,
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
2025-10-25 16:48:43 +08:00
updates: { id: string; sortIndex: number }[],
) => {
if (!providers[appType]) return;
updates.forEach(({ id, sortIndex }) => {
const provider = providers[appType][id];
if (provider) {
providers[appType][id] = { ...provider, sortIndex };
}
});
};
export const listProviders = (appType: AppId) =>
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.
2025-11-21 11:12:06 +08:00
JSON.parse(JSON.stringify(providers[appType] ?? {})) as Record<
string,
Provider
>;
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
2025-10-25 16:48:43 +08:00
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.
2025-11-21 11:12:06 +08:00
export const getSettings = () =>
JSON.parse(JSON.stringify(settingsState)) as Settings;
export const setSettings = (data: Partial<Settings>) => {
settingsState = { ...settingsState, ...data };
};
export const getAppConfigDirOverride = () => appConfigDirOverride;
export const setAppConfigDirOverrideState = (value: string | null) => {
appConfigDirOverride = value;
};
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
2025-10-26 13:52:42 +08:00
export const getMcpConfig = (appType: AppId) => {
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
2025-10-26 13:52:42 +08:00
const servers = JSON.parse(
JSON.stringify(mcpConfigs[appType] ?? {}),
) as Record<string, McpServer>;
return {
configPath: `/mock/${appType}.mcp.json`,
servers,
};
};
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.
2025-11-21 11:12:06 +08:00
export const setMcpConfig = (
appType: AppId,
value: Record<string, McpServer>,
) => {
mcpConfigs[appType] = JSON.parse(JSON.stringify(value)) as Record<
string,
McpServer
>;
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
2025-10-26 13:52:42 +08:00
};
export const setMcpServerEnabled = (
appType: AppId,
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
2025-10-26 13:52:42 +08:00
id: string,
enabled: boolean,
) => {
if (!mcpConfigs[appType]?.[id]) return;
mcpConfigs[appType][id] = {
...mcpConfigs[appType][id],
enabled,
};
};
export const upsertMcpServer = (
appType: AppId,
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
2025-10-26 13:52:42 +08:00
id: string,
server: McpServer,
) => {
if (!mcpConfigs[appType]) {
mcpConfigs[appType] = {};
}
mcpConfigs[appType][id] = JSON.parse(JSON.stringify(server)) as McpServer;
};
export const deleteMcpServer = (appType: AppId, id: string) => {
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
2025-10-26 13:52:42 +08:00
if (!mcpConfigs[appType]) return;
delete mcpConfigs[appType][id];
};