mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-25 13:45:03 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 55eec1e294 |
@@ -9,7 +9,51 @@ use super::DeepLinkImportRequest;
|
|||||||
use crate::AppType;
|
use crate::AppType;
|
||||||
use crate::{store::AppState, Database};
|
use crate::{store::AppState, Database};
|
||||||
use base64::prelude::*;
|
use base64::prelude::*;
|
||||||
use std::sync::Arc;
|
use std::{env, ffi::OsString, sync::Arc};
|
||||||
|
|
||||||
|
struct TestHomeGuard {
|
||||||
|
_dir: tempfile::TempDir,
|
||||||
|
original_home: Option<OsString>,
|
||||||
|
original_userprofile: Option<OsString>,
|
||||||
|
original_test_home: Option<OsString>,
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
// Parser Tests
|
||||||
@@ -477,8 +521,12 @@ fn test_build_claude_provider_without_config_unchanged() {
|
|||||||
// Prompt Tests
|
// 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]
|
#[test]
|
||||||
|
#[serial_test::serial]
|
||||||
fn test_import_prompt_allows_space_in_base64_content() {
|
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 url = "ccswitch://v1/import?resource=prompt&app=codex&name=PromptPlus&content=Pj4+";
|
||||||
let request = parse_deeplink_url(url).unwrap();
|
let request = parse_deeplink_url(url).unwrap();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user