diff --git a/src-tauri/src/deeplink/tests.rs b/src-tauri/src/deeplink/tests.rs index 7d814e794..7a04be2d2 100644 --- a/src-tauri/src/deeplink/tests.rs +++ b/src-tauri/src/deeplink/tests.rs @@ -9,7 +9,51 @@ use super::DeepLinkImportRequest; use crate::AppType; use crate::{store::AppState, Database}; use base64::prelude::*; -use std::sync::Arc; +use std::{env, ffi::OsString, sync::Arc}; + +struct TestHomeGuard { + _dir: tempfile::TempDir, + original_home: Option, + original_userprofile: Option, + original_test_home: Option, +} + +impl TestHomeGuard { + fn new() -> Self { + let dir = tempfile::tempdir().expect("create isolated test home"); + let original_home = env::var_os("HOME"); + let original_userprofile = env::var_os("USERPROFILE"); + let original_test_home = env::var_os("CC_SWITCH_TEST_HOME"); + + env::set_var("HOME", dir.path()); + env::set_var("USERPROFILE", dir.path()); + env::set_var("CC_SWITCH_TEST_HOME", dir.path()); + + Self { + _dir: dir, + original_home, + original_userprofile, + original_test_home, + } + } +} + +impl Drop for TestHomeGuard { + fn drop(&mut self) { + match &self.original_test_home { + Some(value) => env::set_var("CC_SWITCH_TEST_HOME", value), + None => env::remove_var("CC_SWITCH_TEST_HOME"), + } + match &self.original_userprofile { + Some(value) => env::set_var("USERPROFILE", value), + None => env::remove_var("USERPROFILE"), + } + match &self.original_home { + Some(value) => env::set_var("HOME", value), + None => env::remove_var("HOME"), + } + } +} // ============================================================================= // Parser Tests @@ -477,8 +521,12 @@ fn test_build_claude_provider_without_config_unchanged() { // Prompt Tests // ============================================================================= +// Integration-style unit test: prompt import reaches PromptService and resolves +// live config file paths, so HOME must be isolated before it runs. #[test] +#[serial_test::serial] fn test_import_prompt_allows_space_in_base64_content() { + let _test_home = TestHomeGuard::new(); let url = "ccswitch://v1/import?resource=prompt&app=codex&name=PromptPlus&content=Pj4+"; let request = parse_deeplink_url(url).unwrap();