DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(composer-patch): 判定优先看原始语句,避免注释同形文本被误判成「上游已自修」
hairyfb0fe36b25487
diff --git a/src-tauri/src/service/patch/composer.rs b/src-tauri/src/service/patch/composer.rsindex ca644620..6a7a29d4 100644--- a/src-tauri/src/service/patch/composer.rs+++ b/src-tauri/src/service/patch/composer.rs@@ -20,7 +20,7 @@//!//! 幂等与容错://! - 已含标记即跳过;-//! - 上游将来自己放宽该判定(`chipTitle === void 0 && cwd === void 0`)时只补能力标记,+//! - 上游将来自己放宽该判定(inert 语句里已带 `&& cwd === void 0`)时只补能力标记,//! 不再改写源码——补丁随上游自动退休;//! - 锚点因上游布局变更而找不到 → 跳过并告警,不阻断启动(插件侧退级到功能禁用)。//!@@ -37,15 +37,11 @@ const PATCH_MARKER: &str = "dsh-tauri: composer stays usable for a session outsi/// `composer.workspace-less` 能力判据逐字一致,跨语言协议字面量)。const CAPABILITY_ATTRIBUTE: &str = "data-dsh-composer-cwd";-/// 官方 inert 判定(锚点绑定 0.1.5-rc.1 / rc.2 的压缩后源码)。-const INERT_ANCHOR: &str = "const inert = sessionId === void 0 || hero && chipTitle === void 0;";+/// 官方 inert 语句(锚点绑定 0.1.5-rc.1 / rc.2 的压缩后源码)。+const INERT_ORIGINAL: &str = "const inert = sessionId === void 0 || hero && chipTitle === void 0;";-/// 放宽后的 inert 判定:会话有 cwd 就不再算 inert。-const INERT_PATCHED: &str =- "const inert = sessionId === void 0 || hero && chipTitle === void 0 && cwd === void 0;";--/// 上游自己放宽后的形态(只用于判定「无需再改源码,只补能力标记」)。-const INERT_UPSTREAM_FIXED: &str = "chipTitle === void 0 && cwd === void 0";+/// 放宽后的语句:会话有 cwd 就不再算 inert。+const INERT_PATCHED: &str = "const inert = sessionId === void 0 || hero && chipTitle === void 0 && cwd === void 0;";/// 导出锚点的关键字(所在行的前导缩进随版本变化,不做硬编码)。const ANCHOR_KEYWORD: &str = "return module.exports;";@@ -55,14 +51,23 @@ const CONVERSATION_CLIENT_JS: &str ="node_modules/@deepseek-ai/dsh-client-ui-conversation/lib/client.js";/// 幂等补丁逻辑的纯函数部分(便于单测,不触碰文件系统)。+///+/// 判定优先看**原始语句**:只要它还在场就放宽它,只有它缺席、而放宽形态在场时才判定为+/// 「上游已自修」。反过来的优先级会让注释里的同形文本把补丁误判成「已修」而静默漏放宽+/// ——那正是「声明了能力、composer 却仍不可用」的半工作态。fn patch_source(source: &str) -> PatchOutcome {if source.contains(PATCH_MARKER) {return PatchOutcome::AlreadyPatched;}- let needs_relax = !source.contains(INERT_UPSTREAM_FIXED);- if needs_relax && !source.contains(INERT_ANCHOR) {- return PatchOutcome::AnchorMissing;+ let needs_relax = if source.contains(INERT_ORIGINAL) {+ true+ }+ else if source.contains(INERT_PATCHED) {+ false}+ else {+ return PatchOutcome::AnchorMissing;+ };let Some((line_start, indent)) = locate_return_module_exports(source) else {return PatchOutcome::AnchorMissing;};@@ -75,7 +80,7 @@ fn patch_source(source: &str) -> PatchOutcome {),);if needs_relax {- patched = patched.replacen(INERT_ANCHOR, INERT_PATCHED, 1);+ patched = patched.replacen(INERT_ORIGINAL, INERT_PATCHED, 1);}PatchOutcome::Patched(patched)}@@ -110,7 +115,7 @@ mod tests {/// 官方产物末尾片段(单 tab 缩进,与 renderer 补丁同一形状)。fn fixture() -> String {format!(- "\t\t\t{INERT_ANCHOR}\n\t\t\tconst heroWorkspaceRow = 1;\n\t\texports.apply = apply;\n\t\texports.inject = inject;\n\t\treturn module.exports;\n\t}}\n}});\n"+ "\t\t\t{INERT_ORIGINAL}\n\t\t\tconst heroWorkspaceRow = 1;\n\t\texports.apply = apply;\n\t\texports.inject = inject;\n\t\treturn module.exports;\n\t}}\n}});\n")}@@ -120,7 +125,7 @@ mod tests {panic!("expected Patched, got {:?}", patch_source(&fixture()));};assert!(patched.contains(INERT_PATCHED));- assert!(!patched.contains(INERT_ANCHOR));+ assert!(!patched.contains(INERT_ORIGINAL));assert!(patched.contains(&format!("\t\tif (typeof document !== \"undefined\") document.documentElement.setAttribute(\"{CAPABILITY_ATTRIBUTE}\", \"1\"); /* {PATCH_MARKER} */\n\t\treturn module.exports;\n")));@@ -136,22 +141,33 @@ mod tests {#[test]fn upstream_fix_only_declares_capability() {- let fixed = format!(- "\t\t\tconst inert = sessionId === void 0 || hero && chipTitle === void 0 && cwd === void 0;\n\t\treturn module.exports;\n"- );+ let fixed = format!("\t\t\t{INERT_PATCHED}\n\t\treturn module.exports;\n");let PatchOutcome::Patched(patched) = patch_source(&fixed) else {panic!("expected Patched");};// 不再改写源码,只补能力标记:补丁随上游退休。- assert!(patched.contains(INERT_UPSTREAM_FIXED));+ assert!(patched.contains(INERT_PATCHED));assert!(patched.contains(CAPABILITY_ATTRIBUTE));assert_eq!(patch_source(&patched), PatchOutcome::AlreadyPatched);}+ #[test]+ fn loose_substring_is_not_treated_as_upstream_fix() {+ // 注释或其它代码路径里出现放宽片段时,仍必须真的放宽当前语句。+ let source = format!(+ "\t\t\t// 说明:{INERT_PATCHED}\n\t\t\t{INERT_ORIGINAL}\n\t\treturn module.exports;\n"+ );+ let PatchOutcome::Patched(patched) = patch_source(&source) else {+ panic!("expected Patched");+ };+ assert!(!patched.contains(&format!("{INERT_ORIGINAL}\n")));+ assert_eq!(patched.matches(INERT_PATCHED).count(), 2);+ }+#[test]fn skips_when_anchor_missing() {assert_eq!(patch_source("\t\t\tconst inert = 1;\n"), PatchOutcome::AnchorMissing);- let no_return = format!("\t\t\t{INERT_ANCHOR}\n");+ let no_return = format!("\t\t\t{INERT_ORIGINAL}\n");assert_eq!(patch_source(&no_return), PatchOutcome::AnchorMissing);}}diff --git a/test/e2e/support/dsh.ts b/test/e2e/support/dsh.tsindex f1bf5df8..82c473fc 100644--- a/test/e2e/support/dsh.ts+++ b/test/e2e/support/dsh.ts@@ -291,10 +291,9 @@ const CONVERSATION_PACKAGE = 'dsh-client-ui-conversation'/** 客户端产物末尾的导出锚点;前导缩进由上游打包器决定,必须按实际行读取。 */const RENDERER_EXPORT_ANCHOR = 'return module.exports;'-/** composer 补丁的锚点与标记(与 `src-tauri/src/service/patch/composer.rs` 同源同语义)。 */-const COMPOSER_INERT_ANCHOR = 'const inert = sessionId === void 0 || hero && chipTitle === void 0;'+/** composer 补丁的语句锚点与标记(与 `src-tauri/src/service/patch/composer.rs` 同源同语义)。 */+const COMPOSER_INERT_ORIGINAL = 'const inert = sessionId === void 0 || hero && chipTitle === void 0;'const COMPOSER_INERT_PATCHED = 'const inert = sessionId === void 0 || hero && chipTitle === void 0 && cwd === void 0;'-const COMPOSER_INERT_UPSTREAM_FIXED = 'chipTitle === void 0 && cwd === void 0'const COMPOSER_PATCH_MARKER = 'dsh-tauri: composer stays usable for a session outside every workspace'/** 客户端插件探测本能力用的 DOM 标记(与 `dsh-tauri` 适配层的判据逐字一致)。 */const COMPOSER_CWD_ATTRIBUTE = 'data-dsh-composer-cwd'@@ -386,9 +385,12 @@ function patchComposerCwd(dshBin: string): void {if (source.includes(COMPOSER_PATCH_MARKER))return- const needsRelax = !source.includes(COMPOSER_INERT_UPSTREAM_FIXED)- if (needsRelax && !source.includes(COMPOSER_INERT_ANCHOR)) {- log(`⚠️ conversation 产物缺少 composer 锚点,跳过 composer 补丁:${target}`)+ // 优先看原始语句:只要它还在场就放宽它;只有它缺席、放宽形态在场时才算「上游已自修」。+ // 反过来的优先级会让注释里的同形文本把补丁误判成已修,声明了能力却漏放宽。+ const needsRelax = source.includes(COMPOSER_INERT_ORIGINAL)+ const upstreamFixed = !needsRelax && source.includes(COMPOSER_INERT_PATCHED)+ if (!needsRelax && !upstreamFixed) {+ log(`⚠️ conversation 产物缺少 composer 语句锚点,跳过 composer 补丁:${target}`)return}@@ -402,7 +404,7 @@ function patchComposerCwd(dshBin: string): void {const marker = `${indent}if (typeof document !== "undefined") document.documentElement.setAttribute("${COMPOSER_CWD_ATTRIBUTE}", "1"); /* ${COMPOSER_PATCH_MARKER} */\n`const withMarker = `${source.slice(0, lineStart)}${marker}${source.slice(lineStart)}`- writeFileSync(target, needsRelax ? withMarker.replace(COMPOSER_INERT_ANCHOR, COMPOSER_INERT_PATCHED) : withMarker)+ writeFileSync(target, needsRelax ? withMarker.replace(COMPOSER_INERT_ORIGINAL, COMPOSER_INERT_PATCHED) : withMarker)log(`🔧 已施加 composer 补丁:${target}`)}