Skip to content

DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.

fix(plugin): fix plugin dependency exception caused by Windows extension path

hairyf68a8a822a9d0
diff --git a/src-tauri/src/service/plugin/internal.rs b/src-tauri/src/service/plugin/internal.rs
index b3581cd5..dd4c8ea9 100644
--- a/src-tauri/src/service/plugin/internal.rs
+++ b/src-tauri/src/service/plugin/internal.rs
@@ -14,7 +14,9 @@ use std::collections::HashMap;
use tauri::{AppHandle, Emitter};
use super::installed::{installed_name, profile_dir, ProfilePackageJson};
-use super::preset::{bundled_dep_spec, bundled_plugin_dir, load_presets, PreinstallPluginInfo};
+use super::preset::{
+ bundled_dep_spec, bundled_plugin_dir, load_presets, strip_verbatim_path, PreinstallPluginInfo,
+};
/// 核对并强制安装缺失/路径不正确/被卸载的内置插件,在服务进程启动前调用。
///
@@ -125,7 +127,13 @@ fn dep_matches_spec(actual: &str, expected: &str) -> bool {
.strip_prefix("link:")
.or_else(|| spec.strip_prefix("file:"))
.unwrap_or(spec);
- stripped.replace('\\', "/").trim_end_matches('/').to_string()
+ // 剥离 Windows 扩展长度路径前缀(`\\?\`,见 preset::strip_verbatim_path):
+ // 期望值已经由 bundled_dep_spec 归一化掉前缀,若历史命中的实值仍带
+ // `//?/` 前缀(旧版 or 含 `\\?\` 的联接目标),先归一化再比对,保证幂等
+ // (避免旧值一次次触发不必要的重装)。
+ strip_verbatim_path(stripped)
+ .trim_end_matches('/')
+ .to_string()
};
let actual = norm(actual);
let expected = norm(expected);
@@ -165,6 +173,12 @@ mod tests {
"file:C:/Apps/dsh/resources/preset-plugins/dsh-tauri",
expected
));
+ // 实值仍带 Windows 扩展长度前缀(`\\?\`,见 preset::strip_verbatim_path)
+ // 与归一化掉前缀的期望值仍视为同一路径(幂等,避免不必要的重装)
+ assert!(dep_matches_spec(
+ "link://?/C:/Apps/dsh/resources/preset-plugins/dsh-tauri",
+ expected
+ ));
}
#[test]
diff --git a/src-tauri/src/service/plugin/preset.rs b/src-tauri/src/service/plugin/preset.rs
index d4d14cab..476f71d2 100644
--- a/src-tauri/src/service/plugin/preset.rs
+++ b/src-tauri/src/service/plugin/preset.rs
@@ -162,11 +162,38 @@ fn parse_dev_internal_dir(content: &str) -> Option<PathBuf> {
/// 路径解析并建立目录联接(junction,改源码重启服务即热更新)。pnpm 按传入
/// 形式把 `link:` 依赖写入 profile 的 package.json;安装(`install.rs`)与启动
/// 自愈(`internal.rs`)共用这一规范形比对路径是否正确。
+///
+/// 生成前先剥离 Windows 扩展长度路径前缀(`\\?\` verbatim):`resource_dir()`
+/// 在部分 Windows 环境返回 verbatim 形式,直接拼进 `link:` 会得到 `link://?/G:/...`,
+/// pnpm 会把 `//?/G:/...` 当作相对路径解析并生成 `..\?\G:\...` 的坏联接
+/// (内置插件重装死循环的根因),因此此处统一转成常规绝对路径。
pub(crate) fn bundled_dep_spec(dir: &std::path::Path) -> String {
- let normalized = dir.to_string_lossy().replace('\\', "/");
+ let normalized = strip_verbatim_path(&dir.to_string_lossy());
format!("link:{}", normalized.trim_end_matches('/'))
}
+/// 剥离 Windows 扩展长度路径前缀(`\\?\` verbatim)并统一分隔符为正斜杠。
+///
+/// Windows 文件的 verbatim 路径形如 `\\?\C:\...`(`canonicalize` 或部分环境下
+/// `resource_dir()` 会返回该形式)。文件系统 API 对两者等价,但把它写进依赖
+/// spec(`link:`)时 pnpm 会误把 `//?/` 当相对路径,必须剥掉,保证 pnpm 按常规
+/// 绝对路径解析并建立正确联接。
+///
+/// - 常规路径:分隔符统一为正斜杠,原样返回;
+/// - 盘符 verbatim(`\\?\G:\...`):剥离 `\\?\`;
+/// - UNC verbatim(`\\?\UNC\server\share`):转成常规 UNC(`\\server\share`,
+/// 即在 `//server/share` 形式下保留双斜杠)。
+pub(crate) fn strip_verbatim_path(path: &str) -> String {
+ let s = path.replace('\\', "/");
+ if let Some(rest) = s.strip_prefix("//?/UNC/") {
+ format!("//{rest}")
+ } else if let Some(rest) = s.strip_prefix("//?/") {
+ rest.to_string()
+ } else {
+ s
+ }
+}
+
/// 解析预设清单 JSON
fn parse_presets(json: &str) -> Result<Vec<PreinstallPluginInfo>, String> {
serde_json::from_str(json).map_err(|e| format!("PRESET_PLUGINS_INVALID_JSON: {e}"))
@@ -371,6 +398,41 @@ mod tests {
);
}
+ #[test]
+ fn bundled_dep_spec_strips_verbatim_prefix() {
+ // 回归:Windows 扩展长度路径前缀(`\\?\`)不该进入 link: spec。
+ // `resource_dir()` 返回 verbatim 路径时,未剥离会导致 pnpm 把
+ // `//?/G:/...` 当相对路径解析、生成 `..\?\G:\...` 的坏联接而安装失败。
+ let dir = std::path::Path::new(
+ r"\\?\G:\Deepseek Harness Desktop\resources\preset-plugins\dsh-tauri",
+ );
+ assert_eq!(
+ bundled_dep_spec(dir),
+ "link:G:/Deepseek Harness Desktop/resources/preset-plugins/dsh-tauri"
+ );
+ }
+
+ #[test]
+ fn strip_verbatim_path_variants() {
+ // 常规路径:仅统一切换分隔符
+ assert_eq!(
+ strip_verbatim_path("C:\\Apps\\dsh\\plugins\\x"),
+ "C:/Apps/dsh/plugins/x"
+ );
+ // 盘符 verbatim:剥离 `\\?\`
+ assert_eq!(
+ strip_verbatim_path(r"\\?\G:\Apps\dsh\plugins\x"),
+ "G:/Apps/dsh/plugins/x"
+ );
+ // UNC verbatim:转成常规 UNC(保留 `//`)
+ assert_eq!(
+ strip_verbatim_path(r"\\?\UNC\server\share\plugins\x"),
+ "//server/share/plugins/x"
+ );
+ // 已是无 verbatim 前缀的(Unix 或正斜杠)原样保留
+ assert_eq!(strip_verbatim_path("/opt/dsh/plugins/x"), "/opt/dsh/plugins/x");
+ }
+
#[cfg(debug_assertions)]
#[test]
fn dev_internal_dir_parses_plain_and_quoted_values() {