DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(plugin): registry 元数据拉取失败被判成供应链违规时重试并归类为网络错误
hairyf2926868b4286
diff --git a/src-tauri/src/service/plugin/install/diagnose.rs b/src-tauri/src/service/plugin/install/diagnose.rsindex bb0eaf9c..fe76858b 100644--- a/src-tauri/src/service/plugin/install/diagnose.rs+++ b/src-tauri/src/service/plugin/install/diagnose.rs@@ -111,6 +111,29 @@ pub(super) fn network_error_hint(output: &str) -> Option<&'static str> {.then_some("网络连接失败,请检查网络或代理设置后重试。")}+/// pnpm 的 lockfile supply-chain 校验(`minimumReleaseAge`)要按 registry 元数据核对+/// 每个条目的发布时间;元数据拉不到时 pnpm 会把条目**直接判成违规**并以+/// `ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION` 中止,输出里唯一的线索只有+/// `[WARN] GET https://registry.npmjs.org/<pkg> error (unknown)` —— 用户看到的+/// 「违反供应链策略」其实是网络问题(实测 `[email protected]` 已发布 21 天仍被判违规)。+/// 命中即说明重跑同一条命令大概率能过,调用方据此重试。+///+/// 真·发布时间违规(版本确实太新)不带任何拉取失败信号,绝不命中:那种失败重试无用,+/// 也不该把供应链信号降级成网络问题。+pub(super) fn policy_verification_network_failure(output: &str) -> bool {+ let lower = output.to_ascii_lowercase();+ if !lower.contains("err_pnpm_minimum_release_age_violation") {+ return false;+ }+ const FETCH_FAILURES: [&str; 4] = [+ "error (unknown)",+ "will retry in",+ "fetch failed",+ "failed to fetch",+ ];+ FETCH_FAILURES.iter().any(|signal| lower.contains(signal))+}+pub(super) fn git_transport_hint(output: &str) -> Option<&'static str> {const SIGNALS: &[(&str, &str)] = &[(@@ -292,6 +315,30 @@ mod tests {assert!(git_transport_hint(out).is_none());}+ // ---- lockfile supply-chain 校验因 registry 元数据拉取失败而误判违规 ----++ /// 用户实测(pnpm 11.7.0,`[email protected]` 已发布 21 天):判定违规的唯一线索是+ /// registry 元数据请求失败,而不是发布时间。+ const POLICY_VERIFICATION_FETCH_FAILURE: &str = "✗ Lockfile failed supply-chain policy check (4 entries in 2.7s) [ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION]\n1 lockfile entries failed verification:\n[WARN] GET https://registry.npmjs.org/undici error (unknown). Will retry in 10 seconds. 2 retries left.\n";++ #[test]+ fn policy_verification_failure_detects_registry_fetch_error() {+ assert!(policy_verification_network_failure(+ POLICY_VERIFICATION_FETCH_FAILURE+ ));+ }++ #[test]+ fn policy_verification_failure_ignores_real_release_age_violation() {+ // 真违规会给出发布时间与阈值、没有拉取失败信号:重试无用,也不该改判成网络问题。+ let real = "[ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION] [email protected] was published recently (released 5 minutes ago; minimumReleaseAge is 1440)\n";+ assert!(!policy_verification_network_failure(real));+ assert!(!policy_verification_network_failure(+ "ERR_PNPM_FETCH_404 registry error"+ ));+ assert!(!policy_verification_network_failure(""));+ }+// ---- pnpm store 布局不兼容(ERR_PNPM_UNEXPECTED_STORE 一族)----/// pnpm 的真实原始输出:档案由 pnpm 10 装好,当前 pnpm 11 解析出另一份 store。diff --git a/src-tauri/src/service/plugin/install/mod.rs b/src-tauri/src/service/plugin/install/mod.rsindex a27fd918..64d0fd00 100644--- a/src-tauri/src/service/plugin/install/mod.rs+++ b/src-tauri/src/service/plugin/install/mod.rs@@ -76,7 +76,7 @@ use allowlist::{add_allow_build_keys, parse_allowlist_keys};use artifact::{ensure_plugin_entry_built, verify_installed_products};use diagnose::{diagnostic_suffix, git_transport_hint, network_error_hint, pick_error_message,- store_mismatch_hint,+ policy_verification_network_failure, store_mismatch_hint,};use pnpm::ensure_pnpm;use spec::{bundled_dir_of, normalize_git_spec, preset_spec_for_install, spec_argument};@@ -106,6 +106,24 @@ fn transient_fs_retry_delay(retry: usize) -> std::time::Duration {std::time::Duration::from_secs(seconds)}+/// lockfile supply-chain 校验因 registry 元数据拉不到而误判违规时的重试上限+/// (见 [`policy_verification_network_failure`])。实测 registry 短暂不可用能让+/// 「已发布三周的 entry」连续失败数分钟:pnpm 自己重试两轮后放弃,这里再按退避+/// 把窗口拉到约一分钟以覆盖这类抖动;不设更大上限是因为每次重试都要重跑整条+/// `dsh plugin add`。+const POLICY_VERIFICATION_RETRIES: usize = 4;+/// 该重试的首次延迟;后续延迟按指数增长,最多 30 秒。+const POLICY_VERIFICATION_RETRY_DELAY: std::time::Duration = std::time::Duration::from_secs(5);++fn policy_verification_retry_delay(retry: usize) -> std::time::Duration {+ let seconds = POLICY_VERIFICATION_RETRY_DELAY+ .as_secs()+ .checked_shl(retry.saturating_sub(1) as u32)+ .unwrap_or(30)+ .min(30);+ std::time::Duration::from_secs(seconds)+}+pub async fn install(app_handle: &AppHandle, ids: &[String]) -> Result<(), String> {install_with_cancel(app_handle, ids, None, new_process_owner()).await}@@ -282,10 +300,17 @@ async fn install_with_cancel(if exit_code != 0 {log::error!("dsh plugin install failed with exit code {exit_code}");+ // 先无条件落一行 pnpm 原始诊断:后面的分类文案(网络 / store 指引)会丢掉细节,+ // 而用户贴进 issue 的日志必须能看到 pnpm 究竟报了什么。+ let detail = pick_error_message(&last_output, None);+ if !detail.is_empty() {+ log::error!("dsh plugin install diagnostic: {detail}");+ }// 区分 git 传输层失败与 allowBuilds 构建门禁:前者是 pnpm 走了 git+ssh// (用户环境无 SSH 配置),后者才是补充白名单可自愈的。传输层错误给出// 可读指引,避免用户被 dsh 那条 allowBuilds 提示误导。let network_error = network_error_hint(&last_output).is_some()+ || policy_verification_network_failure(&last_output)|| (exit_code == 3 && last_output.trim().is_empty());let hint = git_transport_hint(&last_output);let store_hint = store_mismatch_hint(&last_output);@@ -345,9 +370,6 @@ async fn install_with_cancel());}let detail = pick_error_message(&last_output, None);- if !detail.is_empty() {- log::error!("dsh plugin install diagnostic: {detail}");- }return Err(format!("PREINSTALL_FAILED: dsh plugin exited with code {exit_code}{}",diagnostic_suffix(&detail)@@ -481,11 +503,35 @@ async fn run_plugin_install_with_transient_retry(owner: ProcessOwner,) -> Result<(i32, String), String> {let mut attempt = 0usize;+ let mut policy_attempt = 0usize;loop {let (exit_code, output) = run_plugin_with_allow_build_retry(app_handle, node, args, cwd, envs, window, action, cancel, owner,).await?;+ // 先判网络类:pnpm 把「元数据拉不到」渲染成供应链违规,重跑整条命令最有效。+ if exit_code != 0+ && policy_attempt < POLICY_VERIFICATION_RETRIES+ && policy_verification_network_failure(&output)+ {+ policy_attempt += 1;+ let delay = policy_verification_retry_delay(policy_attempt);+ log::warn!(+ "dsh plugin {action} failed the lockfile supply-chain check because registry \+ metadata could not be fetched; retrying ({policy_attempt}/{POLICY_VERIFICATION_RETRIES}) \+ after {delay:?}"+ );+ let _ = window.emit(+ PREINSTALL_LOG_EVENT,+ PreinstallLogPayload {+ line: format!(+ "[harness] registry 元数据拉取失败,依赖校验未通过,正在重试({policy_attempt}/{POLICY_VERIFICATION_RETRIES})…"+ ),+ },+ );+ tokio::time::sleep(delay).await;+ continue;+ }if exit_code != 0&& attempt < TRANSIENT_FS_RETRIES&& is_transient_fs_install_failure(exit_code, &output)@@ -586,6 +632,22 @@ mod tests {);}+ #[test]+ fn policy_verification_retry_delay_uses_capped_exponential_backoff() {+ assert_eq!(+ policy_verification_retry_delay(1),+ std::time::Duration::from_secs(5)+ );+ assert_eq!(+ policy_verification_retry_delay(2),+ std::time::Duration::from_secs(10)+ );+ assert_eq!(+ policy_verification_retry_delay(4),+ std::time::Duration::from_secs(30)+ );+ }+#[test]fn transient_fs_failure_rejects_ordinary_failures() {assert!(!is_transient_fs_install_failure(diff --git a/src-tauri/src/service/plugin/install/single.rs b/src-tauri/src/service/plugin/install/single.rsindex 1e36cf79..c4dde1d3 100644--- a/src-tauri/src/service/plugin/install/single.rs+++ b/src-tauri/src/service/plugin/install/single.rs@@ -17,7 +17,8 @@ use crate::service::workflow;use super::artifact::{ensure_plugin_entry_built, installed_package_name};use super::build_plugin_envs;use super::diagnose::{- git_transport_hint, network_error_hint, pick_error_message, store_mismatch_hint,+ git_transport_hint, network_error_hint, pick_error_message,+ policy_verification_network_failure, store_mismatch_hint,};use super::errors;use super::installed_name;@@ -340,8 +341,11 @@ async fn run_single_plugin_command(if exit_code != 0 {log::error!("dsh plugin {action} failed for {id} with exit code {exit_code}");- let network_error =- network_error_hint(&output).is_some() || (exit_code == 3 && output.trim().is_empty());+ // lockfile 供应链校验因 registry 元数据拉取失败而误判违规时,对用户而言就是+ // 网络问题:给「检查网络后重试」而不是一条看不懂的供应链违规。+ let network_error = network_error_hint(&output).is_some()+ || policy_verification_network_failure(&output)+ || (exit_code == 3 && output.trim().is_empty());let store_hint = store_mismatch_hint(&output);let message = if network_error {"NETWORK_ERROR: plugin registry request failed; check network or proxy settings and retry."