DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix: prevent Unix shim recursion and stalled core downloads (#829)
SkanderBotb39e4dd20186
diff --git a/src-tauri/src/service/cli/shim/build.rs b/src-tauri/src/service/cli/shim/build.rsindex 991f30bc..f0134425 100644--- a/src-tauri/src/service/cli/shim/build.rs+++ b/src-tauri/src/service/cli/shim/build.rs@@ -1222,7 +1222,7 @@ mod tests {{let content = build_sh_shim(&sample_shim_paths(), &sample_dsh_home());assert!(content.contains(r#"exec "$dir/dsh" "$@""#));- assert!(content.contains("SELF_DIR"));+ assert!(content.contains(r#"[ "$dir/dsh" -ef "$0" ]"#));// 用户 dsh 优先 > 注入 DSH_HOMElet user_at = content.find(r#""$dir/dsh""#).unwrap();let home_at = content.find("export DSH_HOME").unwrap();diff --git a/src-tauri/src/service/cli/shim/templates.rs b/src-tauri/src/service/cli/shim/templates.rsindex 48db06c9..2da0fa4a 100644--- a/src-tauri/src/service/cli/shim/templates.rs+++ b/src-tauri/src/service/cli/shim/templates.rs@@ -183,15 +183,117 @@ if ($userDsh) {pub(super) const SH_USER_DSH_PRECEDENCE: &str = r#"# Prefer a user-installed dsh on PATH (skip our own shim dir), fall back to bundled.# This preserves your own dsh binary and its $DSH_HOME config; nothing is overwritten.-SELF_DIR=$(cd "$(dirname "$0")" && pwd)-IFS=:-for dir in $PATH; do- if [ "$dir" = "$SELF_DIR" ]; then+remaining_path=${PATH-}:+while [ -n "$remaining_path" ]; do+ dir=${remaining_path%%:*}+ remaining_path=${remaining_path#*:}+ dir=${dir:-.}+ if [ "$dir/dsh" -ef "$0" ]; thencontinuefiif [ -x "$dir/dsh" ]; thenexec "$dir/dsh" "$@"fidone-unset IFS+unset remaining_path"#;++#[cfg(all(test, unix))]+mod tests {+ use super::SH_USER_DSH_PRECEDENCE;+ use std::os::unix::fs::{symlink, PermissionsExt};+ use std::path::PathBuf;+ use std::time::{Duration, SystemTime, UNIX_EPOCH};++ struct Scratch(PathBuf);++ impl Drop for Scratch {+ fn drop(&mut self) {+ let _ = std::fs::remove_dir_all(&self.0);+ }+ }++ #[tokio::test]+ async fn dsh_shim_skips_aliases_and_preserves_user_command_arguments_and_status() {+ let scratch = Scratch(std::env::temp_dir().join(format!(+ "dsh-shim-alias-{}-{}",+ std::process::id(),+ SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_nanos()+ )));+ let root = &scratch.0;+ let bin = root.join("shim bin");+ std::fs::create_dir_all(&bin).unwrap();+ let shim = bin.join("dsh");+ std::fs::write(+ &shim,+ format!("#!/bin/sh\n{SH_USER_DSH_PRECEDENCE}\nprintf 'FALLBACK\\n'\n"),+ )+ .unwrap();+ std::fs::set_permissions(&shim, std::fs::Permissions::from_mode(0o755)).unwrap();+ let alias = root.join("alias");+ symlink(&bin, &alias).unwrap();+ let file_alias = root.join("file-alias");+ std::fs::create_dir_all(&file_alias).unwrap();+ symlink(&shim, file_alias.join("dsh")).unwrap();+ let hard_link = root.join("hard-link");+ std::fs::create_dir_all(&hard_link).unwrap();+ std::fs::hard_link(&shim, hard_link.join("dsh")).unwrap();++ for prefix in [+ bin.display().to_string(),+ format!("{}/", bin.display()),+ format!("{}:{}", bin.display(), alias.display()),+ file_alias.display().to_string(),+ hard_link.display().to_string(),+ ".".into(),+ String::new(),+ ] {+ let output = tokio::time::timeout(+ Duration::from_secs(2),+ tokio::process::Command::new(&shim)+ .current_dir(&bin)+ .env_clear()+ .env("PATH", format!("{prefix}:{}", root.join("missing").display()))+ .kill_on_drop(true)+ .output(),+ )+ .await+ .expect("shim must not re-execute itself")+ .unwrap();+ assert!(output.status.success(), "PATH prefix: {prefix}");+ assert_eq!(output.stdout, b"FALLBACK\n", "PATH prefix: {prefix}");+ }++ let user_bin = root.join("user[bin]");+ std::fs::create_dir_all(&user_bin).unwrap();+ let user_dsh = user_bin.join("dsh");+ std::fs::write(&user_dsh, "#!/bin/sh\nprintf '%s\\n' \"$@\"\nexit 7\n").unwrap();+ std::fs::set_permissions(&user_dsh, std::fs::Permissions::from_mode(0o755)).unwrap();+ let decoy = root.join("userb");+ std::fs::create_dir_all(&decoy).unwrap();+ let decoy_dsh = decoy.join("dsh");+ std::fs::write(&decoy_dsh, "#!/bin/sh\nexit 99\n").unwrap();+ std::fs::set_permissions(&decoy_dsh, std::fs::Permissions::from_mode(0o755)).unwrap();+ for path in [+ format!("{}:{}", bin.display(), user_bin.display()),+ format!("{}:", root.join("missing").display()),+ String::new(),+ ] {+ let output = tokio::time::timeout(+ Duration::from_secs(2),+ tokio::process::Command::new(&shim)+ .current_dir(&user_bin)+ .env_clear()+ .env("PATH", &path)+ .args(["two words", "*"])+ .kill_on_drop(true)+ .output(),+ )+ .await+ .expect("user command must finish")+ .unwrap();+ assert_eq!(output.status.code(), Some(7), "PATH: {path}");+ assert_eq!(output.stdout, b"two words\n*\n", "PATH: {path}");+ }+ }+}diff --git a/src-tauri/src/service/core/runtime.rs b/src-tauri/src/service/core/runtime.rsindex 31d22150..d1d8d63a 100644--- a/src-tauri/src/service/core/runtime.rs+++ b/src-tauri/src/service/core/runtime.rs@@ -598,6 +598,14 @@ fn link_required_plugins(app_handle: &AppHandle, core_root: &Path) -> Result<(),}let source = profile.join("node_modules").join(&name);if !source.join("package.json").is_file() {+ if read_package_name(&core_node_modules.join(&name).join("package.json"))+ .ok()+ .flatten()+ .as_deref()+ == Some(name.as_str())+ {+ continue;+ }log::warn!("CORE_PLUGIN_PROFILE_ENTRY_MISSING: {} is referenced by {}, source {} is unavailable",name,diff --git a/src-tauri/src/service/download/core.rs b/src-tauri/src/service/download/core.rsindex 5cf00111..fdf2aa09 100644--- a/src-tauri/src/service/download/core.rs+++ b/src-tauri/src/service/download/core.rs@@ -86,6 +86,7 @@ async fn download_with_retry<'a, R: Runtime>(let client = reqwest::Client::builder().user_agent("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (deepseek-harness-desktop)").connect_timeout(std::time::Duration::from_secs(20))+ .read_timeout(Duration::from_secs(30)).build().map_err(|e| {log::error!("Failed to create HTTP client: {}", e);@@ -213,7 +214,6 @@ async fn download_attempt<'a, R: Runtime>(res.content_length().unwrap_or(0)};log::debug!("File size: {} bytes", total_size);- let mut downloaded: u64 = 0;let mut stream = res.bytes_stream();while let Some(chunk) = stream.next().await {let chunk = chunk.map_err(|e| {@@ -221,8 +221,7 @@ async fn download_attempt<'a, R: Runtime>(e.to_string()})?;buffer.extend_from_slice(&chunk);- downloaded += chunk.len() as u64;- let received_total = resume_from + downloaded;+ let received_total = buffer.len() as u64;// 未知总长(服务器未给 Content-Length/分块传输)时进度取 -1,// 避免 `received / 0 = +inf` 或 NaN 进度传给前端let progress_pct = download_progress_percent(received_total, total_size);