From bcebe1bccdfc5aeff341d3e2a3a0df2c83e2ec9f Mon Sep 17 00:00:00 2001 From: coso Date: Wed, 13 May 2026 12:33:03 +0800 Subject: [PATCH] test: exercise live skill prompt command install --- src-tauri/src/commands/skill_cmd.rs | 49 +++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/src-tauri/src/commands/skill_cmd.rs b/src-tauri/src/commands/skill_cmd.rs index 9250f8f3e..993cd35ab 100644 --- a/src-tauri/src/commands/skill_cmd.rs +++ b/src-tauri/src/commands/skill_cmd.rs @@ -1400,10 +1400,31 @@ mod tests { use super::*; use proptest::prelude::*; use std::collections::HashSet; + use std::ffi::OsString; use std::io::Write; use tempfile::TempDir; use zip::write::FileOptions; + struct EnvVarGuard { + key: &'static str, + original: Option, + } + + impl Drop for EnvVarGuard { + fn drop(&mut self) { + match &self.original { + Some(value) => std::env::set_var(self.key, value), + None => std::env::remove_var(self.key), + } + } + } + + fn set_test_env_var(key: &'static str, value: &Path) -> EnvVarGuard { + let original = std::env::var_os(key); + std::env::set_var(key, value); + EnvVarGuard { key, original } + } + /// 生成有效的 Skill 目录名(字母数字和连字符) fn skill_name_strategy() -> impl Strategy { "[a-z][a-z0-9-]{0,20}".prop_filter("non-empty", |s| !s.is_empty()) @@ -1897,16 +1918,26 @@ content"#, const DOWNLOAD_URL: &str = "https://limeai.run/skill-packages/viral-content-breakdown/latest/viral-content-breakdown.zip"; - let bytes = download_skill_package_zip(DOWNLOAD_URL) - .await - .expect("live skill package should download"); - assert!(!bytes.is_empty()); - println!("downloaded_bytes={}", bytes.len()); - let temp_dir = TempDir::new().unwrap(); - let target_root = temp_dir.path().join("skills"); - let result = install_skill_zip_bytes_into_root(&target_root, SKILL_NAME, &bytes) - .expect("live skill package should install into a temp skills root"); + // Isolate app paths so the command path never writes to the developer's real Lime data dir. + let _home = set_test_env_var("HOME", &temp_dir.path().join("home")); + let _xdg_data = set_test_env_var("XDG_DATA_HOME", &temp_dir.path().join("xdg-data")); + let _appdata = set_test_env_var("APPDATA", &temp_dir.path().join("appdata")); + let _local_appdata = + set_test_env_var("LOCALAPPDATA", &temp_dir.path().join("local-appdata")); + + let result = install_skill_from_download_url_for_app( + "lime".to_string(), + SkillDownloadInstallRequest { + skill_name: SKILL_NAME.to_string(), + download_url: DOWNLOAD_URL.to_string(), + }, + ) + .await + .expect("live website prompt package should install through the Lime command path"); + + let target_root = app_paths::resolve_skills_dir().expect("temp skills dir should resolve"); + assert!(target_root.starts_with(temp_dir.path())); let installed_dir = target_root.join(SKILL_NAME); let discovered = scan_installed_skills(&target_root);