Skip to content

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

fix(windows): 避免缓存失败导致静默退出并提示低完整性启动 (#892)

SkanderBotee95af2119b4
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index a3ec88f8..0bbade9e 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -266,3 +266,11 @@ jobs:
- name: Run tests
run: cargo test --all-features --locked
working-directory: src-tauri
+
+ - name: Check startup regression stability
+ shell: bash
+ run: |
+ for iteration in 1 2 3 4 5; do
+ cargo test --all-features --locked desktop::startup::tests:: -- --test-threads=1 || exit 1
+ done
+ working-directory: src-tauri
diff --git a/README.en.md b/README.en.md
index b903ddeb..b7f4738b 100644
--- a/README.en.md
+++ b/README.en.md
@@ -104,6 +104,8 @@ brew install dsh-tauri/desktop/deepseek-harness
## Runtime
+On Windows, `STARTUP_LOW_INTEGRITY` means the process is running below Medium integrity and cannot write normal user data. This can happen when an installation folder has an inherited Low integrity label: a replacement executable can inherit it during an update. Inspect the folder and executable with `icacls`; restore the trusted installation's labels to Medium, or reinstall into a normal folder. Running the same Low-labeled executable as administrator does not remove its integrity restriction. Keep sessions and `DSH_HOME` unchanged. Startup failures now show a native Windows dialog with the underlying error.
+
| Current baseline | Version |
| --- | --- |
| Desktop | `0.20.0-beta.1` |
diff --git a/README.md b/README.md
index e5d2a044..e1a3001c 100644
--- a/README.md
+++ b/README.md
@@ -104,6 +104,8 @@ brew install dsh-tauri/desktop/deepseek-harness
## 运行方式
+Windows 上出现 `STARTUP_LOW_INTEGRITY` 表示进程以低于 Medium 的完整性级别运行,无法写入正常用户的数据目录。安装目录若带有可继承的 Low 标签,更新替换的可执行文件可能继承该标签。可用 `icacls` 检查安装目录及可执行文件,将可信安装的标签恢复为 Medium,或重新安装到正常目录。以管理员身份运行同一个 Low 标签程序不会移除其完整性限制。无需删除会话或修改 `DSH_HOME`;启动失败时会通过原生 Windows 对话框显示具体错误。
+
| 当前基线 | 版本 |
| --- | --- |
| 桌面端 | `0.20.0-beta.1` |
diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock
index e6763b6c..96563a31 100644
--- a/src-tauri/Cargo.lock
+++ b/src-tauri/Cargo.lock
@@ -790,29 +790,10 @@ version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87"
dependencies = [
- "percent-encoding",
"time",
"version_check",
]
-[[package]]
-name = "cookie_store"
-version = "0.22.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "15b2c103cf610ec6cae3da84a766285b42fd16aad564758459e6ecf128c75206"
-dependencies = [
- "cookie",
- "document-features",
- "idna",
- "log",
- "publicsuffix",
- "serde",
- "serde_derive",
- "serde_json",
- "time",
- "url",
-]
-
[[package]]
name = "core-foundation"
version = "0.7.0"
@@ -1123,6 +1104,7 @@ dependencies = [
"tauri-plugin-single-instance",
"tauri-plugin-store",
"tauri-plugin-wdio-webdriver",
+ "tempfile",
"time",
"tokio",
"tracing",
@@ -1315,15 +1297,6 @@ dependencies = [
"const-random",
]
-[[package]]
-name = "document-features"
-version = "0.2.12"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d4b8a88685455ed29a21542a33abd9cb6510b6b129abadabdcef0f4c55bc8f61"
-dependencies = [
- "litrs",
-]
-
[[package]]
name = "dom_query"
version = "0.27.0"
@@ -2862,12 +2835,6 @@ version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae"
-[[package]]
-name = "litrs"
-version = "1.0.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "11d3d7f243d5c5a8b9bb5d6dd2b1602c0cb0b9db1621bafc7ed66e35ff9fe092"
-
[[package]]
name = "lock_api"
version = "0.4.14"
@@ -3909,22 +3876,6 @@ dependencies = [
"unicode-ident",
]
-[[package]]
-name = "psl-types"
-version = "2.0.11"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "33cb294fe86a74cbcf50d4445b37da762029549ebeea341421c7c70370f86cac"
-
-[[package]]
-name = "publicsuffix"
-version = "2.3.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6f42ea446cab60335f76979ec15e12619a2165b5ae2c12166bef27d283a9fadf"
-dependencies = [
- "idna",
- "psl-types",
-]
-
[[package]]
name = "pxfm"
version = "0.1.30"
@@ -4214,8 +4165,6 @@ checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147"
dependencies = [
"base64 0.22.1",
"bytes",
- "cookie",
- "cookie_store",
"encoding_rs",
"futures-core",
"futures-util",
@@ -5382,8 +5331,6 @@ version = "2.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7241a0c762649be8fba7dd4cc84684d0e409f26b335a978ef4dd5fe78da74ce6"
dependencies = [
- "bytes",
- "cookie_store",
"data-url",
"http",
"regex",
diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml
index 72fabc6e..8e6735d0 100644
--- a/src-tauri/Cargo.toml
+++ b/src-tauri/Cargo.toml
@@ -54,7 +54,13 @@ tauri-plugin-autostart = "2"
# 桌宠素材直连远端:插件版 HTTP 从 Rust 发起请求,绕开 githubusercontent 的 CORS。
# 版本须与 package.json 的 @tauri-apps/plugin-http(catalog:tauri,^2.6.0)保持同一 minor:
# tauri CLI 会在构建前校验 NPM 包与 Rust crate 的 major/minor 是否一致,不一致直接退出。
-tauri-plugin-http = "2.6"
+# 公开桌宠素材不需要 cookie;禁用持久化,避免缓存不可写时阻断整个应用启动。
+tauri-plugin-http = { version = "2.6", default-features = false, features = [
+ "rustls-tls",
+ "http2",
+ "charset",
+ "system-proxy"
+] }
# 前端读取系统版本(`@tauri-apps/plugin-os` 的 `type()` / `version()`)用于缩放的平台判定。
# 版本须与 package.json 的 @tauri-apps/plugin-os(catalog:tauri,^2.3.2)保持同一 minor:
# tauri CLI 会在构建前校验 NPM 包与 Rust crate 的 major/minor 是否一致,不一致直接退出。
@@ -96,6 +102,8 @@ sysinfo = { version = "0.39.6", default-features = false, features = [ "system"
[dev-dependencies]
auto-launch = "0.5"
+tauri = { version = "2", features = [ "test" ] }
+tempfile = "3"
[target.'cfg(target_os = "macos")'.dependencies]
objc2-app-kit = { version = "=0.3.2", default-features = false, features = [
diff --git a/src-tauri/build.rs b/src-tauri/build.rs
index aa63a3f4..c6a3a70e 100644
--- a/src-tauri/build.rs
+++ b/src-tauri/build.rs
@@ -1,5 +1,19 @@
fn main() {
#[cfg(target_os = "macos")]
println!("cargo:rustc-link-arg=-Wl,-rpath,/usr/lib/swift");
- tauri_build::build()
+ let attributes = tauri_build::Attributes::new();
+ let attributes = if std::env::var("CARGO_CFG_TARGET_OS").as_deref() == Ok("windows")
+ && std::env::var("CARGO_CFG_TARGET_ENV").as_deref() == Ok("msvc")
+ {
+ let manifest = std::path::PathBuf::from(std::env::var_os("CARGO_MANIFEST_DIR").unwrap())
+ .join("windows-app-manifest.xml");
+ // tauri-build 默认只给应用嵌入清单;测试程序也需要 Common Controls v6。
+ println!("cargo:rerun-if-changed={}", manifest.display());
+ println!("cargo:rustc-link-arg=/MANIFEST:EMBED");
+ println!("cargo:rustc-link-arg=/MANIFESTINPUT:{}", manifest.display());
+ attributes.windows_attributes(tauri_build::WindowsAttributes::new_without_app_manifest())
+ } else {
+ attributes
+ };
+ tauri_build::try_build(attributes).expect("failed to build Tauri resources")
}
diff --git a/src-tauri/src/desktop/mod.rs b/src-tauri/src/desktop/mod.rs
index 07859336..ce4e4a36 100644
--- a/src-tauri/src/desktop/mod.rs
+++ b/src-tauri/src/desktop/mod.rs
@@ -12,6 +12,7 @@ pub mod payload;
pub mod pet;
pub mod pet_mouse;
pub mod plugin_boot;
+pub mod startup;
#[cfg(windows)]
pub mod tauri_internals;
pub mod window;
diff --git a/src-tauri/src/desktop/startup.rs b/src-tauri/src/desktop/startup.rs
new file mode 100644
index 00000000..7e26be6b
--- /dev/null
+++ b/src-tauri/src/desktop/startup.rs
@@ -0,0 +1,278 @@
+pub(crate) fn verify() -> Result<(), String> {
+ #[cfg(windows)]
+ {
+ let level = process_integrity_level()
+ .map_err(|error| format!("STARTUP_INTEGRITY_CHECK_FAILED: {error}"))?;
+ let executable = std::env::current_exe()
+ .map_err(|error| format!("STARTUP_EXECUTABLE_PATH_FAILED: {error}"))?;
+ if let Some(error) = integrity_error(level, &executable) {
+ return Err(error);
+ }
+ }
+ Ok(())
+}
+
+pub fn report(message: &str) {
+ eprintln!("{message}");
+ log::error!("{message}");
+ #[cfg(windows)]
+ rfd::MessageDialog::new()
+ .set_title("DeepSeek Harness Desktop — 启动失败 / Startup failed")
+ .set_description(message)
+ .set_level(rfd::MessageLevel::Error)
+ .show();
+}
+
+#[cfg(any(windows, test))]
+fn integrity_error(level: u32, executable: &std::path::Path) -> Option<String> {
+ (level < 0x2000).then(|| {
+ format!(
+ "STARTUP_LOW_INTEGRITY (RID {level})\n\n\
+ 当前进程的 Windows 完整性级别低于 Medium,无法安全写入正常用户的数据目录。\n\
+ 请检查可信安装目录及可执行文件的完整性标签,恢复为 Medium,或重新安装到正常目录后启动。\n\
+ 无需删除会话或修改 DSH_HOME。\n\n\
+ This process runs below Medium integrity and cannot write normal user data.\n\
+ Check the trusted installation folder and executable integrity labels; restore them to Medium or reinstall in a normal folder.\n\
+ Do not delete sessions or change DSH_HOME.\n\n\
+ Executable: {}",
+ executable.display()
+ )
+ })
+}
+
+#[cfg(windows)]
+fn process_integrity_level() -> std::io::Result<u32> {
+ use std::os::windows::io::{AsRawHandle, FromRawHandle, OwnedHandle};
+ use windows_sys::Win32::Security::{
+ GetSidSubAuthority, GetSidSubAuthorityCount, GetTokenInformation, IsValidSid,
+ TokenIntegrityLevel, TOKEN_MANDATORY_LABEL, TOKEN_QUERY,
+ };
+ use windows_sys::Win32::System::Threading::{GetCurrentProcess, OpenProcessToken};
+
+ unsafe {
+ let mut token = std::ptr::null_mut();
+ if OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &mut token) == 0 {
+ return Err(std::io::Error::last_os_error());
+ }
+ let token = OwnedHandle::from_raw_handle(token);
+ let mut required = 0;
+ GetTokenInformation(
+ token.as_raw_handle(),
+ TokenIntegrityLevel,
+ std::ptr::null_mut(),
+ 0,
+ &mut required,
+ );
+ if required < std::mem::size_of::<TOKEN_MANDATORY_LABEL>() as u32 {
+ return Err(std::io::Error::last_os_error());
+ }
+ // TOKEN_MANDATORY_LABEL 含指针,缓冲区必须满足其对齐要求。
+ let mut buffer = vec![0usize; (required as usize).div_ceil(std::mem::size_of::<usize>())];
+ if GetTokenInformation(
+ token.as_raw_handle(),
+ TokenIntegrityLevel,
+ buffer.as_mut_ptr().cast(),
+ required,
+ &mut required,
+ ) == 0
+ {
+ return Err(std::io::Error::last_os_error());
+ }
+ let sid = (*buffer.as_ptr().cast::<TOKEN_MANDATORY_LABEL>()).Label.Sid;
+ if IsValidSid(sid) == 0 {
+ return Err(std::io::Error::other("invalid process integrity SID"));
+ }
+ let count = *GetSidSubAuthorityCount(sid);
+ if count == 0 {
+ return Err(std::io::Error::other("empty process integrity SID"));
+ }
+ Ok(*GetSidSubAuthority(sid, u32::from(count - 1)))
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use tauri::test::{mock_builder, mock_context, noop_assets};
+
+ fn initialize_http(
+ cache: &std::path::Path,
+ ) -> tauri::Result<tauri::App<tauri::test::MockRuntime>> {
+ let mut context = mock_context(noop_assets());
+ context.config_mut().identifier = cache.to_string_lossy().into_owned();
+ mock_builder()
+ .plugin(tauri_plugin_http::init())
+ .build(context)
+ }
+
+ #[test]
+ fn public_asset_http_does_not_require_a_writable_cache_directory() {
+ let scratch = tempfile::tempdir().unwrap();
+ let cache = scratch.path().join("blocked-cache");
+ std::fs::write(&cache, b"preserve this file").unwrap();
+ let result = initialize_http(&cache);
+ assert!(
+ result.is_ok(),
+ "HTTP initialization failed: {:?}",
+ result.err()
+ );
+ assert_eq!(std::fs::read(cache).unwrap(), b"preserve this file");
+ }
+
+ #[test]
+ fn public_asset_http_does_not_create_a_cookie_store() {
+ let scratch = tempfile::tempdir().unwrap();
+ let cache = scratch.path().join("unused-cache");
+ let _app = initialize_http(&cache).unwrap();
+ assert!(!cache.exists(), "public asset HTTP created a cookie cache");
+ }
+
+ #[test]
+ fn only_below_medium_integrity_requires_repair() {
+ let executable = std::path::Path::new("F:/Tool/DeepSeek Harness Desktop/app.exe");
+ for level in [0, 0x1000, 0x1fff] {
+ let error = integrity_error(level, executable).unwrap();
+ assert!(error.starts_with("STARTUP_LOW_INTEGRITY"));
+ assert!(error.contains(&executable.display().to_string()));
+ assert!(error.contains("Do not delete sessions or change DSH_HOME"));
+ }
+ for level in [0x2000, 0x2010, 0x2100, 0x3000, 0x4000] {
+ assert_eq!(integrity_error(level, executable), None);
+ }
+ }
+
+ #[cfg(windows)]
+ #[test]
+ fn real_low_integrity_process_shows_an_actionable_error_before_app_setup() {
+ use std::os::windows::process::CommandExt;
+ use windows_sys::core::BOOL;
+ use windows_sys::Win32::Foundation::{HWND, LPARAM};
+ use windows_sys::Win32::UI::WindowsAndMessaging::{
+ EnumWindows, GetWindowTextW, GetWindowThreadProcessId, IsWindowVisible, PostMessageW,
+ WM_CLOSE,
+ };
+
+ unsafe extern "system" fn dismiss_error(window: HWND, parameter: LPARAM) -> BOOL {
+ let probe = &mut *(parameter as *mut (u32, bool));
+ let mut process = 0;
+ GetWindowThreadProcessId(window, &mut process);
+ if process == probe.0 && IsWindowVisible(window) != 0 {
+ let mut title = [0u16; 256];
+ let length = GetWindowTextW(window, title.as_mut_ptr(), title.len() as i32);
+ let title = String::from_utf16_lossy(&title[..length as usize]);
+ if title.contains("DeepSeek Harness Desktop") && title.contains("Startup failed") {
+ probe.1 = PostMessageW(window, WM_CLOSE, 0, 0) != 0;
+ return 0;
+ }
+ }
+ 1
+ }
+
+ let home = tempfile::tempdir().unwrap();
+ let local = home.path().join("AppData/Local");
+ let roaming = home.path().join("AppData/Roaming");
+ std::fs::create_dir_all(&local).unwrap();
+ std::fs::create_dir_all(&roaming).unwrap();
+ let mut child = std::process::Command::new(std::env::current_exe().unwrap())
+ .args([
+ "--exact",
+ "desktop::startup::tests::low_integrity_child",
+ "--nocapture",
+ ])
+ .env("DSH_TEST_LOW_INTEGRITY_CHILD", "1")
+ .env("DSH_E2E_HOME", home.path())
+ .env("USERPROFILE", home.path())
+ .env("HOME", home.path())
+ .env("LOCALAPPDATA", local)
+ .env("APPDATA", roaming)
+ .creation_flags(0x08000000)
+ .stdout(std::process::Stdio::piped())
+ .stderr(std::process::Stdio::piped())
+ .spawn()
+ .unwrap();
+ let deadline = std::time::Instant::now() + std::time::Duration::from_secs(30);
+ let mut probe = (child.id(), false);
+ while child.try_wait().unwrap().is_none() {
+ if !probe.1 {
+ unsafe {
+ EnumWindows(Some(dismiss_error), std::ptr::addr_of_mut!(probe) as LPARAM);
+ }
+ }
+ if std::time::Instant::now() >= deadline {
+ child.kill().unwrap();
+ let _ = child.wait();
+ panic!("low-integrity startup did not return within 30 seconds");
+ }
+ std::thread::sleep(std::time::Duration::from_millis(25));
+ }
+ let output = child.wait_with_output().unwrap();
+ assert!(
+ output.status.success(),
+ "child failed: {}\n{}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ assert!(String::from_utf8_lossy(&output.stdout).contains("LOW_INTEGRITY_GUARD_VERIFIED"));
+ assert!(
+ probe.1,
+ "the low-integrity process did not display a native error dialog"
+ );
+ }
+
+ #[cfg(windows)]
+ #[test]
+ fn low_integrity_child() {
+ if std::env::var("DSH_TEST_LOW_INTEGRITY_CHILD").as_deref() != Ok("1") {
+ return;
+ }
+ use std::os::windows::io::{AsRawHandle, FromRawHandle, OwnedHandle};
+ use windows_sys::Win32::Security::{
+ SetTokenInformation, TokenIntegrityLevel, SID, SID_AND_ATTRIBUTES,
+ SID_IDENTIFIER_AUTHORITY, TOKEN_ADJUST_DEFAULT, TOKEN_MANDATORY_LABEL, TOKEN_QUERY,
+ };
+ use windows_sys::Win32::System::SystemServices::SE_GROUP_INTEGRITY;
+ use windows_sys::Win32::System::Threading::{GetCurrentProcess, OpenProcessToken};
+ unsafe {
+ let mut token = std::ptr::null_mut();
+ assert_ne!(
+ OpenProcessToken(
+ GetCurrentProcess(),
+ TOKEN_QUERY | TOKEN_ADJUST_DEFAULT,
+ &mut token
+ ),
+ 0
+ );
+ let token = OwnedHandle::from_raw_handle(token);
+ let mut sid = SID {
+ Revision: 1,
+ SubAuthorityCount: 1,
+ IdentifierAuthority: SID_IDENTIFIER_AUTHORITY {
+ Value: [0, 0, 0, 0, 0, 16],
+ },
+ SubAuthority: [0x1000],
+ };
+ let label = TOKEN_MANDATORY_LABEL {
+ Label: SID_AND_ATTRIBUTES {
+ Sid: std::ptr::addr_of_mut!(sid).cast(),
+ Attributes: SE_GROUP_INTEGRITY as u32,
+ },
+ };
+ assert_ne!(
+ SetTokenInformation(
+ token.as_raw_handle(),
+ TokenIntegrityLevel,
+ std::ptr::addr_of!(label).cast(),
+ (std::mem::size_of_val(&label) + std::mem::size_of_val(&sid)) as u32
+ ),
+ 0,
+ "{}",
+ std::io::Error::last_os_error()
+ );
+ }
+ assert_eq!(process_integrity_level().unwrap(), 0x1000);
+ let error = crate::run().unwrap_err();
+ assert!(error.starts_with("STARTUP_LOW_INTEGRITY"), "{error}");
+ report(&error);
+ println!("LOW_INTEGRITY_GUARD_VERIFIED");
+ }
+}
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 428b9ffe..0342eb7c 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -16,7 +16,8 @@ pub fn patch_core_dir(core_dir: &std::path::Path) -> Result<(), String> {
/// 应用入口:先做 Wayland 环境兼容(见 `should_apply_wayland_egl_workaround` 与
/// `should_restore_wayland_backend`),再初始化日志、装配桌面端并进入事件循环。
-pub fn run() {
+pub fn run() -> Result<(), String> {
+ desktop::startup::verify()?;
// Wayland EGL workaround:仅 AppImage 需要(见 `should_apply_wayland_egl_workaround`)。
if should_apply_wayland_egl_workaround(
&std::env::var("XDG_SESSION_TYPE").unwrap_or_default(),
@@ -75,7 +76,7 @@ pub fn run() {
desktop::builder()
.invoke_handler(desktop::handler())
.build(tauri::generate_context!())
- .expect("error while building tauri application")
+ .map_err(|error| format!("STARTUP_FAILED: {error}"))?
.run(|app_handle, event| match event {
#[cfg(target_os = "macos")]
tauri::RunEvent::WindowEvent { event, .. } => {
@@ -118,6 +119,7 @@ pub fn run() {
}
_ => {}
});
+ Ok(())
}
/// Wayland EGL workaround 是否生效:仅 AppImage 需要。
diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs
index 6575f83b..dd28a819 100644
--- a/src-tauri/src/main.rs
+++ b/src-tauri/src/main.rs
@@ -16,5 +16,8 @@ fn main() {
}
return;
}
- main::run()
+ if let Err(error) = main::run() {
+ main::desktop::startup::report(&error);
+ std::process::exit(1);
+ }
}
diff --git a/src-tauri/windows-app-manifest.xml b/src-tauri/windows-app-manifest.xml
new file mode 100644
index 00000000..2d510ed3
--- /dev/null
+++ b/src-tauri/windows-app-manifest.xml
@@ -0,0 +1,14 @@
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity
+ type="win32"
+ name="Microsoft.Windows.Common-Controls"
+ version="6.0.0.0"
+ processorArchitecture="*"
+ publicKeyToken="6595b64144ccf1df"
+ language="*"
+ />
+ </dependentAssembly>
+ </dependency>
+</assembly>