* feat(providers): add notes field for provider management - Add notes field to Provider model (backend and frontend) - Display notes with higher priority than URL in provider card - Style notes as non-clickable text to differentiate from URLs - Add notes input field in provider form - Add i18n support (zh/en) for notes field * chore: format code and clean up unused props - Run cargo fmt on Rust backend code - Format TypeScript imports and code style - Remove unused appId prop from ProviderPresetSelector - Clean up unused variables in tests - Integrate notes field handling in provider dialogs * feat(deeplink): implement ccswitch:// protocol for provider import Add deep link support to enable one-click provider configuration import via ccswitch:// URLs. Backend: - Implement URL parsing and validation (src-tauri/src/deeplink.rs) - Add Tauri commands for parse and import (src-tauri/src/commands/deeplink.rs) - Register ccswitch:// protocol in macOS Info.plist - Add comprehensive unit tests (src-tauri/tests/deeplink_import.rs) Frontend: - Create confirmation dialog with security review UI (src/components/DeepLinkImportDialog.tsx) - Add API wrapper (src/lib/api/deeplink.ts) - Integrate event listeners in App.tsx Configuration: - Update Tauri config for deep link handling - Add i18n support for Chinese and English - Include test page for deep link validation (deeplink-test.html) Files: 15 changed, 1312 insertions(+) * chore(deeplink): integrate deep link handling into app lifecycle Wire up deep link infrastructure with app initialization and event handling. Backend Integration: - Register deep link module and commands in mod.rs - Add URL handling in app setup (src-tauri/src/lib.rs:handle_deeplink_url) - Handle deep links from single instance callback (Windows/Linux CLI) - Handle deep links from macOS system events - Add tauri-plugin-deep-link dependency (Cargo.toml) Frontend Integration: - Listen for deeplink-import/deeplink-error events in App.tsx - Update DeepLinkImportDialog component imports Configuration: - Enable deep link plugin in tauri.conf.json - Update Cargo.lock for new dependencies Localization: - Add Chinese translations for deep link UI (zh.json) - Add English translations for deep link UI (en.json) Files: 9 changed, 359 insertions(+), 18 deletions(-) * refactor(deeplink): enhance Codex provider template generation Align deep link import with UI preset generation logic by: - Adding complete config.toml template matching frontend defaults - Generating safe provider name from sanitized input - Including model_provider, reasoning_effort, and wire_api settings - Removing minimal template that only contained base_url - Cleaning up deprecated test file deeplink-test.html * style: fix clippy uninlined_format_args warnings Apply clippy --fix to use inline format arguments in: - src/mcp.rs (8 fixes) - src/services/env_manager.rs (10 fixes) * style: apply code formatting and cleanup - Format TypeScript files with Prettier (App.tsx, EnvWarningBanner.tsx, formatters.ts) - Organize Rust imports and module order alphabetically - Add newline at end of JSON files (en.json, zh.json) - Update Cargo.lock for dependency changes * feat: add model name configuration support for Codex and fix Gemini model handling - Add visual model name input field for Codex providers - Add model name extraction and update utilities in providerConfigUtils - Implement model name state management in useCodexConfigState hook - Add conditional model field rendering in CodexFormFields (non-official only) - Integrate model name sync with TOML config in ProviderForm - Fix Gemini deeplink model injection bug - Correct environment variable name from GOOGLE_GEMINI_MODEL to GEMINI_MODEL - Add test cases for Gemini model injection (with/without model) - All tests passing (9/9) - Fix Gemini model field binding in edit mode - Add geminiModel state to useGeminiConfigState hook - Extract model value during initialization and reset - Sync model field with geminiEnv state to prevent data loss on submit - Fix missing model value display when editing Gemini providers Changes: - 6 files changed, 245 insertions(+), 13 deletions(-)
122 lines
4.0 KiB
Rust
122 lines
4.0 KiB
Rust
use std::sync::RwLock;
|
|
|
|
use cc_switch_lib::{
|
|
import_provider_from_deeplink, parse_deeplink_url, AppState, AppType, MultiAppConfig,
|
|
};
|
|
|
|
#[path = "support.rs"]
|
|
mod support;
|
|
use support::{ensure_test_home, reset_test_fs, test_mutex};
|
|
|
|
#[test]
|
|
fn deeplink_import_claude_provider_persists_to_config() {
|
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
|
reset_test_fs();
|
|
let home = ensure_test_home();
|
|
|
|
let url = "ccswitch://v1/import?resource=provider&app=claude&name=DeepLink%20Claude&homepage=https%3A%2F%2Fexample.com&endpoint=https%3A%2F%2Fapi.example.com%2Fv1&apiKey=sk-test-claude-key&model=claude-sonnet-4";
|
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
|
|
|
let mut config = MultiAppConfig::default();
|
|
config.ensure_app(&AppType::Claude);
|
|
|
|
let state = AppState {
|
|
config: RwLock::new(config),
|
|
};
|
|
|
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
|
.expect("import provider from deeplink");
|
|
|
|
// 验证内存状态
|
|
let guard = state.config.read().expect("read config");
|
|
let manager = guard
|
|
.get_manager(&AppType::Claude)
|
|
.expect("claude manager should exist");
|
|
let provider = manager
|
|
.providers
|
|
.get(&provider_id)
|
|
.expect("provider created via deeplink");
|
|
assert_eq!(provider.name, request.name);
|
|
assert_eq!(
|
|
provider.website_url.as_deref(),
|
|
Some(request.homepage.as_str())
|
|
);
|
|
let auth_token = provider
|
|
.settings_config
|
|
.pointer("/env/ANTHROPIC_AUTH_TOKEN")
|
|
.and_then(|v| v.as_str());
|
|
let base_url = provider
|
|
.settings_config
|
|
.pointer("/env/ANTHROPIC_BASE_URL")
|
|
.and_then(|v| v.as_str());
|
|
assert_eq!(auth_token, Some(request.api_key.as_str()));
|
|
assert_eq!(base_url, Some(request.endpoint.as_str()));
|
|
drop(guard);
|
|
|
|
// 验证配置已持久化
|
|
let config_path = home.join(".cc-switch").join("config.json");
|
|
assert!(
|
|
config_path.exists(),
|
|
"importing provider from deeplink should persist config.json"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn deeplink_import_codex_provider_builds_auth_and_config() {
|
|
let _guard = test_mutex().lock().expect("acquire test mutex");
|
|
reset_test_fs();
|
|
let home = ensure_test_home();
|
|
|
|
let url = "ccswitch://v1/import?resource=provider&app=codex&name=DeepLink%20Codex&homepage=https%3A%2F%2Fopenai.example&endpoint=https%3A%2F%2Fapi.openai.example%2Fv1&apiKey=sk-test-codex-key&model=gpt-4o";
|
|
let request = parse_deeplink_url(url).expect("parse deeplink url");
|
|
|
|
let mut config = MultiAppConfig::default();
|
|
config.ensure_app(&AppType::Codex);
|
|
|
|
let state = AppState {
|
|
config: RwLock::new(config),
|
|
};
|
|
|
|
let provider_id = import_provider_from_deeplink(&state, request.clone())
|
|
.expect("import provider from deeplink");
|
|
|
|
let guard = state.config.read().expect("read config");
|
|
let manager = guard
|
|
.get_manager(&AppType::Codex)
|
|
.expect("codex manager should exist");
|
|
let provider = manager
|
|
.providers
|
|
.get(&provider_id)
|
|
.expect("provider created via deeplink");
|
|
assert_eq!(provider.name, request.name);
|
|
assert_eq!(
|
|
provider.website_url.as_deref(),
|
|
Some(request.homepage.as_str())
|
|
);
|
|
let auth_value = provider
|
|
.settings_config
|
|
.pointer("/auth/OPENAI_API_KEY")
|
|
.and_then(|v| v.as_str());
|
|
let config_text = provider
|
|
.settings_config
|
|
.get("config")
|
|
.and_then(|v| v.as_str())
|
|
.unwrap_or_default();
|
|
assert_eq!(auth_value, Some(request.api_key.as_str()));
|
|
assert!(
|
|
config_text.contains(request.endpoint.as_str()),
|
|
"config.toml content should contain endpoint"
|
|
);
|
|
assert!(
|
|
config_text.contains("model = \"gpt-4o\""),
|
|
"config.toml content should contain model setting"
|
|
);
|
|
drop(guard);
|
|
|
|
let config_path = home.join(".cc-switch").join("config.json");
|
|
assert!(
|
|
config_path.exists(),
|
|
"importing provider from deeplink should persist config.json"
|
|
);
|
|
}
|