DeepSeek Harness Tauri 桌面版 | Only 8mb installer, zero environment setup, preset plugins, Windows / macOS / Linux.
fix(plugin): keep !!js expressions when the desktop rewrites cordis.patch.yml (#1180)
Zuyang Liufa12e97c72be
diff --git a/src-tauri/src/service/plugin/disable.rs b/src-tauri/src/service/plugin/disable.rsindex 8ff68eb7..7bb1e685 100644--- a/src-tauri/src/service/plugin/disable.rs+++ b/src-tauri/src/service/plugin/disable.rs@@ -15,7 +15,7 @@ use tauri::AppHandle;use crate::service::plugin::installed::profile_dir;use crate::service::plugin::recovery::{is_core_package, is_package_name, patch_entry_targets};-use crate::service::plugin::{process, watch};+use crate::service::plugin::{parse_patch_layer, process, render_patch_layer, watch};/// profile 层的 patch 覆盖文件。const PATCH_FILE: &str = "cordis.patch.yml";@@ -208,18 +208,18 @@ pub(crate) fn add_patch_disable(profile: &Path, id: &str) -> Result<bool, String};let mut entries = match content.trim() {"" => Vec::new(),- raw => match serde_yaml::from_str::<serde_yaml::Value>(raw)- .map_err(|e| format!("DISABLE_PATCH_PARSE_FAILED: {e}"))?- {- serde_yaml::Value::Sequence(seq) => seq,- serde_yaml::Value::Null => Vec::new(),- _ => {- return Err(- "DISABLE_PATCH_UNSUPPORTED_SHAPE: cordis.patch.yml top level is not a list"- .to_string(),- )+ raw => {+ match parse_patch_layer(raw).map_err(|e| format!("DISABLE_PATCH_PARSE_FAILED: {e}"))? {+ serde_yaml::Value::Sequence(seq) => seq,+ serde_yaml::Value::Null => Vec::new(),+ _ => {+ return Err(+ "DISABLE_PATCH_UNSUPPORTED_SHAPE: cordis.patch.yml top level is not a list"+ .to_string(),+ )+ }}- },+ }};let names = plugin_target_names(profile, id);let disabled_key = || serde_yaml::Value::String(DISABLED_KEY.to_string());@@ -285,7 +285,7 @@ pub(crate) fn add_patch_disable(profile: &Path, id: &str) -> Result<bool, Stringif !changed {return Ok(false);}- let rendered = serde_yaml::to_string(&serde_yaml::Value::Sequence(entries))+ let rendered = render_patch_layer(&serde_yaml::Value::Sequence(entries)).map_err(|e| format!("DISABLE_PATCH_RENDER_FAILED: {e}"))?;super::atomic_write::write_patch_layer_atomically(&path, &rendered).map_err(|e| format!("DISABLE_PATCH_WRITE_FAILED: {e}"))?;@@ -305,8 +305,8 @@ pub(crate) fn strip_patch_disable(profile: &Path, id: &str) -> Result<bool, StriErr(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(false),Err(error) => return Err(format!("ENABLE_PATCH_READ_FAILED: {error}")),};- let mut doc: serde_yaml::Value =- serde_yaml::from_str(&content).map_err(|e| format!("ENABLE_PATCH_PARSE_FAILED: {e}"))?;+ let mut doc =+ parse_patch_layer(&content).map_err(|e| format!("ENABLE_PATCH_PARSE_FAILED: {e}"))?;let Some(entries) = doc.as_sequence_mut() else {return Ok(false);};@@ -337,7 +337,7 @@ pub(crate) fn strip_patch_disable(profile: &Path, id: &str) -> Result<bool, Striif !changed {return Ok(false);}- let rendered = serde_yaml::to_string(&serde_yaml::Value::Sequence(kept))+ let rendered = render_patch_layer(&serde_yaml::Value::Sequence(kept)).map_err(|e| format!("ENABLE_PATCH_RENDER_FAILED: {e}"))?;super::atomic_write::write_patch_layer_atomically(&path, &rendered).map_err(|e| format!("ENABLE_PATCH_WRITE_FAILED: {e}"))?;@@ -734,6 +734,38 @@ mod tests {let _ = fs::remove_dir_all(&profile);}+ #[test]+ fn disable_keeps_js_expressions_of_other_entries() {+ let profile = build_profile("js-disable", "p");+ write_patch(+ &profile,+ "- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n",+ );+ disable_plugin_at(&profile, "dsh-better-sidebar").unwrap();++ assert_eq!(+ read_patch(&profile),+ "- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n- id: dsh-better-sidebar\n disabled: true\n"+ );+ let _ = fs::remove_dir_all(&profile);+ }++ #[test]+ fn enable_keeps_js_expressions_of_other_entries() {+ let profile = build_profile("js-enable", "q");+ write_patch(+ &profile,+ "- id: dsh-better-sidebar\n disabled: true\n- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n",+ );+ enable_plugin_at(&profile, "dsh-better-sidebar").unwrap();++ assert_eq!(+ read_patch(&profile),+ "- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n"+ );+ let _ = fs::remove_dir_all(&profile);+ }+#[test]fn disable_internal_plugin_is_rejected() {let profile = build_profile("internal-reject", "f");diff --git a/src-tauri/src/service/plugin/internal/mod.rs b/src-tauri/src/service/plugin/internal/mod.rsindex 95f59f36..832e32f5 100644--- a/src-tauri/src/service/plugin/internal/mod.rs+++ b/src-tauri/src/service/plugin/internal/mod.rs@@ -249,7 +249,7 @@ fn repair_loader_state(return Err(format!("{code}: {}: {error}", patch_path.display()));}};- let mut patch = serde_yaml::from_str::<serde_yaml::Value>(&raw).map_err(|e| {+ let mut patch = super::parse_patch_layer(&raw).map_err(|e| {format!("INTERNAL_PLUGIN_PATCH_PARSE_FAILED: {}: {e}",patch_path.display()@@ -260,7 +260,7 @@ fn repair_loader_state(pending = true;continue;}- let rendered = serde_yaml::to_string(&patch)+ let rendered = super::render_patch_layer(&patch).map_err(|e| format!("INTERNAL_PLUGIN_PATCH_RENDER_FAILED: {e}"))?;super::atomic_write::write_patch_layer_atomically(&patch_path, &rendered).map_err(|e| {@@ -1408,6 +1408,43 @@ mod tests {assert!(profile.join("cordis.patch.yml").is_dir());}+ #[test]+ fn loader_repair_keeps_js_expressions_in_patch_layers() {+ let temp = tempfile::tempdir().unwrap();+ let profile = temp.path().join("profiles/tauri");+ std::fs::create_dir_all(&profile).unwrap();+ let patch = profile.join("cordis.patch.yml");+ std::fs::write(+ &patch,+ "- insert:\n - id: builtin\n - id: user-plugin\n config:\n token: !!js process.env.TOKEN\n",+ )+ .unwrap();+ let builtin = PreinstallPluginInfo {+ id: "builtin".into(),+ spec: "builtin".into(),+ internal: true,+ package: None,+ version: None,+ name: "builtin".into(),+ description: String::new(),+ repo_url: String::new(),+ recommended: false,+ fix: false,+ default_checked: false,+ default_unchecked: false,+ win_only: false,+ };++ assert_eq!(+ repair_loader_state(&profile, temp.path(), &[&builtin], &mut None, true),+ Ok(false)+ );+ assert_eq!(+ std::fs::read_to_string(&patch).unwrap(),+ "- insert:\n - id: user-plugin\n config:\n token: !!js process.env.TOKEN\n"+ );+ }+#[test]fn early_prepare_uses_normal_kernel_and_defers_repairs_without_installing() {let root = tempfile::tempdir().unwrap();diff --git a/src-tauri/src/service/plugin/mod.rs b/src-tauri/src/service/plugin/mod.rsindex 0411a6d2..a843e8e0 100644--- a/src-tauri/src/service/plugin/mod.rs+++ b/src-tauri/src/service/plugin/mod.rs@@ -44,6 +44,7 @@ mod installed;mod internal;mod patch_entries;mod patch_guard;+mod patch_yaml;mod preset;mod process;pub mod recovery;@@ -81,6 +82,7 @@ pub(crate) use patch_guard::{patch_layer_paths, quarantine_active_patch_layers, quarantine_failure_message,quarantine_patch_layers_in, PatchQuarantineReport,};+pub(crate) use patch_yaml::{parse_patch_layer, render_patch_layer};pub use preset::repo_url_of;pub(crate) use preset::{bundled_plugin_dir, bundled_plugin_dir_from, current_preset_hash, load_presets,diff --git a/src-tauri/src/service/plugin/patch_entries.rs b/src-tauri/src/service/plugin/patch_entries.rsindex 6eb1b23a..e25590ec 100644--- a/src-tauri/src/service/plugin/patch_entries.rs+++ b/src-tauri/src/service/plugin/patch_entries.rs@@ -25,6 +25,7 @@ use tauri::AppHandle;use super::atomic_write::write_patch_layer_atomically;use super::installed::ProfilePackageJson;use super::patch_guard::{backup_path, now_stamp, patch_layer_paths};+use super::patch_yaml::{parse_patch_layer, render_patch_layer};/// 启动失败错误串的前缀;前端据此识别并渲染「移除悬空条目」入口。pub(crate) const PATCH_ENTRY_UNRESOLVED: &str = "PATCH_LAYER_ENTRY_UNRESOLVED";@@ -110,7 +111,7 @@ pub(crate) fn strip_unresolved_entries_in(let Ok(raw) = std::fs::read_to_string(&layer) else {continue;};- let Ok(doc) = serde_yaml::from_str::<Value>(&raw) else {+ let Ok(doc) = parse_patch_layer(&raw) else {continue;};let Some(entries) = doc.as_sequence() else {@@ -124,7 +125,7 @@ pub(crate) fn strip_unresolved_entries_in(let backup = backup_path(&layer, "bak", &stamp);std::fs::copy(&layer, &backup).map_err(|e| format!("PATCH_LAYER_STRIP_BACKUP_FAILED: {}: {e}", backup.display()))?;- let rendered = serde_yaml::to_string(&Value::Sequence(kept))+ let rendered = render_patch_layer(&Value::Sequence(kept)).map_err(|e| format!("PATCH_LAYER_STRIP_RENDER_FAILED: {e}"))?;write_patch_layer_atomically(&layer, &rendered).map_err(|error| {format!(@@ -157,7 +158,7 @@ fn scan_layer(return Vec::new();};// 解析不了的补丁层交给 patch_guard 的语法错误路径,不在这里重复报错。- let Ok(doc) = serde_yaml::from_str::<Value>(&raw) else {+ let Ok(doc) = parse_patch_layer(&raw) else {return Vec::new();};let Some(entries) = doc.as_sequence() else {@@ -218,6 +219,7 @@ fn dangling_package<'a>() -> Option<&'a str> {item.as_mapping().and_then(|item| map_get(item, "name"))+ .filter(|name| !matches!(name, Value::Tagged(_))).and_then(Value::as_str).filter(|name| {is_bare_package_name(name) && !package_resolvable(profile_dir, install_anchor, name)@@ -555,7 +557,7 @@ mod tests {let home = tmp_dir("non-bare-home");std::fs::write(profile.join("cordis.patch.yml"),- "- insert:\n - id: local\n name: ./plugins/local\n - id: abs\n name: file:///tmp/plugin.js\n",+ "- insert:\n - id: local\n name: ./plugins/local\n - id: abs\n name: file:///tmp/plugin.js\n - id: env\n name: !!js process.env.PLUGIN\n",).unwrap();@@ -657,6 +659,27 @@ mod tests {let _ = std::fs::remove_dir_all(&home);}+ #[test]+ fn strip_keeps_js_expressions_of_kept_entries() {+ let profile = tmp_dir("js-strip-profile");+ let home = tmp_dir("js-strip-home");+ std::fs::write(+ profile.join("cordis.patch.yml"),+ "- insert:\n - id: file-edit\n name: dsh-file-edit\n- id: market\n config:\n token: !!js process.env.TOKEN\n",+ )+ .unwrap();++ let report = strip_unresolved_entries_in(&profile, &home, None).unwrap();++ assert_eq!(report.layers[0].removed, 1);+ assert_eq!(+ std::fs::read_to_string(profile.join("cordis.patch.yml")).unwrap(),+ "- id: market\n config:\n token: !!js process.env.TOKEN\n"+ );+ let _ = std::fs::remove_dir_all(&profile);+ let _ = std::fs::remove_dir_all(&home);+ }+/// insert 被清空且条目再无其它字段时整个条目移除,补丁层回落成空数组。#[test]fn strip_drops_an_entry_left_empty() {diff --git a/src-tauri/src/service/plugin/patch_yaml.rs b/src-tauri/src/service/plugin/patch_yaml.rsnew file mode 100644index 00000000..aa306989--- /dev/null+++ b/src-tauri/src/service/plugin/patch_yaml.rs@@ -0,0 +1,139 @@+//! 补丁层 YAML 的整份读写。serde_yaml 把 `!!js` 解析成 `tag:yaml.org,2002:js`,+//! 既不当核心类型也不留成 `Value::Tagged`,直接降成普通字符串,回写后 loader 只会+//! 拿到字面量。解析时把 `!!` 句柄映射到私有前缀,只给 `!!js` 节点保留标签,写回时还原。++use serde_yaml::Value;++const SECONDARY_HANDLE: &str = "%TAG !! !dsh-secondary-\n";+const JS_TAG: &str = "!dsh-secondary-js";++pub(crate) fn parse_patch_layer(raw: &str) -> Result<Value, serde_yaml::Error> {+ let plain = serde_yaml::from_str(raw)?;+ if !raw.contains("!!") {+ return Ok(plain);+ }+ let body = raw.strip_prefix('\u{feff}').unwrap_or(raw);+ let explicit_start = body+ .lines()+ .find(|line| !line.trim().is_empty() && !line.trim_start().starts_with('#'))+ .is_some_and(|line| {+ line.starts_with('%')+ || line+ .strip_prefix("---")+ .is_some_and(|rest| rest.is_empty() || rest.starts_with([' ', '\t']))+ });+ let remapped = if explicit_start {+ format!("{SECONDARY_HANDLE}{body}")+ } else {+ format!("{SECONDARY_HANDLE}---\n{body}")+ };+ Ok(keep_js_tags(plain, serde_yaml::from_str(&remapped)?))+}++pub(crate) fn render_patch_layer(value: &Value) -> Result<String, serde_yaml::Error> {+ serde_yaml::to_string(value).map(|rendered| rendered.replace(JS_TAG, "!!js"))+}++fn keep_js_tags(plain: Value, tagged: Value) -> Value {+ match (plain, tagged) {+ (plain, Value::Tagged(mut node)) if node.tag == JS_TAG => {+ node.value = plain;+ Value::Tagged(node)+ }+ (Value::Sequence(plain), Value::Sequence(tagged)) => Value::Sequence(+ plain+ .into_iter()+ .zip(tagged)+ .map(|(plain, tagged)| keep_js_tags(plain, tagged))+ .collect(),+ ),+ (Value::Mapping(plain), Value::Mapping(tagged)) => Value::Mapping(+ plain+ .into_iter()+ .zip(tagged)+ .map(|((key, plain), (_, tagged))| (key, keep_js_tags(plain, tagged)))+ .collect(),+ ),+ (Value::Tagged(mut plain), Value::Tagged(tagged)) => {+ plain.value = keep_js_tags(plain.value, tagged.value);+ Value::Tagged(plain)+ }+ (plain, _) => plain,+ }+}++#[cfg(test)]+mod tests {+ use super::*;++ fn rewrite(raw: &str) -> String {+ render_patch_layer(&parse_patch_layer(raw).unwrap()).unwrap()+ }++ #[test]+ fn rewrite_keeps_js_expressions() {+ assert_eq!(+ rewrite("- id: x\n name: !!js \"process.env.X ? 'a' : 'b'\"\n config:\n token: !!js process.env.TOKEN\n port: !!js 0x10\n dirs:\n - !!js process.cwd()\n"),+ "- id: x\n name: !!js 'process.env.X ? ''a'' : ''b'''\n config:\n token: !!js process.env.TOKEN\n port: !!js '0x10'\n dirs:\n - !!js process.cwd()\n"+ );+ }++ #[test]+ fn other_secondary_tags_keep_plain_values() {+ let parsed = parse_patch_layer("- !!str 123\n- !!int '7'\n").unwrap();+ assert_eq!(+ parsed,+ Value::Sequence(vec![Value::String("123".into()), Value::Number(7.into())])+ );+ }++ #[test]+ fn local_tags_keep_nested_js_expressions() {+ assert_eq!(+ rewrite("- !custom {a: !!js y}\n"),+ "- !custom\n a: !!js y\n"+ );+ }++ #[test]+ fn document_markers_and_bom_keep_js_expressions() {+ for raw in [+ "---\n- !!js a\n",+ "# c\n--- # start\n- !!js a\n",+ "%YAML 1.1\n---\n- !!js a\n",+ "\u{feff}- !!js a\n",+ "\u{feff}# c\n---\n- !!js a\n",+ ] {+ assert_eq!(rewrite(raw), "- !!js a\n", "{raw:?}");+ }+ }++ #[test]+ fn layers_without_secondary_tags_parse_like_serde_yaml() {+ for raw in [+ "# comment only\n",+ "[]\n",+ "- !custom {a: 1}\n",+ "- id: x\n",+ ] {+ assert_eq!(+ parse_patch_layer(raw).unwrap(),+ serde_yaml::from_str::<Value>(raw).unwrap(),+ "{raw:?}"+ );+ }+ }++ #[test]+ fn syntax_errors_report_the_original_line() {+ let error =+ parse_patch_layer("- id: a\n config:\n token: !!js process.env.T ? a : b\n")+ .unwrap_err();+ assert_eq!(error.location().map(|location| location.line()), Some(3));+ }++ #[test]+ fn redefined_secondary_handle_is_refused() {+ assert!(parse_patch_layer("%TAG !! tag:yaml.org,2002:\n---\n- !!js a\n").is_err());+ }+}diff --git a/src-tauri/src/service/plugin/recovery/uninstall.rs b/src-tauri/src/service/plugin/recovery/uninstall.rsindex 2074a03e..8a5745df 100644--- a/src-tauri/src/service/plugin/recovery/uninstall.rs+++ b/src-tauri/src/service/plugin/recovery/uninstall.rs@@ -8,6 +8,7 @@ use std::os::windows::fs::FileTypeExt;use std::path::Path;use crate::service::fs_guard;+use crate::service::plugin::{parse_patch_layer, render_patch_layer};/// 从 manifest 中移除指定插件(`dependencies` + `dsh.profile.bundles`),返回是否有改动。pub(super) fn remove_plugin_from_manifest(manifest: &mut serde_json::Value, id: &str) -> bool {@@ -131,7 +132,7 @@ pub(super) fn strip_cordis_patch_for(profile: &Path, id: &str) {let Ok(content) = fs::read_to_string(&path) else {return;};- let Ok(doc) = serde_yaml::from_str::<serde_yaml::Value>(&content) else {+ let Ok(doc) = parse_patch_layer(&content) else {return;};let Some(entries) = doc.as_sequence() else {@@ -145,7 +146,7 @@ pub(super) fn strip_cordis_patch_for(profile: &Path, id: &str) {if kept.len() == entries.len() {return;}- if let Ok(rendered) = serde_yaml::to_string(&serde_yaml::Value::Sequence(kept)) {+ if let Ok(rendered) = render_patch_layer(&serde_yaml::Value::Sequence(kept)) {let _ = fs::write(&path, rendered);log::info!("Stripped cordis.patch.yml entries for plugin {id}");}@@ -413,4 +414,22 @@ mod tests {assert!(kept_doc.contains("dsh-web-ui-all"));assert!(!kept_doc.contains("dsh-better-sidebar"));}++ #[test]+ fn patch_strip_keeps_js_expressions_of_other_entries() {+ let profile = tempfile::tempdir().unwrap();+ let patch = profile.path().join("cordis.patch.yml");+ std::fs::write(+ &patch,+ "- id: dsh-better-sidebar\n foo: 1\n- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n",+ )+ .unwrap();++ strip_cordis_patch_for(profile.path(), "dsh-better-sidebar");++ assert_eq!(+ std::fs::read_to_string(&patch).unwrap(),+ "- id: dshmarket\n config:\n token: !!js process.env.TOKEN\n"+ );+ }}diff --git a/src-tauri/src/service/profile/migrate.rs b/src-tauri/src/service/profile/migrate.rsindex 9ff2cb74..b1fe471a 100644--- a/src-tauri/src/service/profile/migrate.rs+++ b/src-tauri/src/service/profile/migrate.rs@@ -20,7 +20,10 @@ use tauri::AppHandle;use crate::config;use crate::service::fs_guard;use crate::service::plugin::compat::{self, PluginInspect};-use crate::service::plugin::{inspect_specs, load_presets, packument, watch, ProfilePackageJson};+use crate::service::plugin::{+ inspect_specs, load_presets, packument, parse_patch_layer, render_patch_layer, watch,+ ProfilePackageJson,+};/// 发布时长策略豁免键(与 `profile::profile_release_age_excludes` 同源)。const POLICY_KEY: &str = "minimumReleaseAgeExclude";@@ -319,7 +322,7 @@ fn patch_covered(source: &[Value], target: &Path) -> bool {/// 补丁层文件的顶层数组;文件缺失、读不出或不是数组时返回 `None`。fn patch_layer_entries(path: &Path) -> Option<Vec<Value>> {let content = fs::read_to_string(path).ok()?;- let document: Value = serde_yaml::from_str(&content).ok()?;+ let document = parse_patch_layer(&content).ok()?;Some(document.as_sequence()?.clone())}@@ -382,7 +385,7 @@ fn merge_patch(source: &Path, target: &Path) -> Result<bool, String> {if !added {return Ok(false);}- let rendered = serde_yaml::to_string(&Value::Sequence(entries))+ let rendered = render_patch_layer(&Value::Sequence(entries)).map_err(|e| format!("PROFILE_MIGRATION_PATCH_RENDER: {e}"))?;fs::write(target.join(PATCH_FILE), rendered).map_err(|e| format!("PROFILE_MIGRATION_PATCH_WRITE: {e}"))?;@@ -635,6 +638,31 @@ mod tests {let _ = fs::remove_dir_all(&target);}+ #[test]+ fn merge_patch_keeps_js_expressions() {+ let source = workspace("js-source");+ let target = workspace("js-target");+ fs::write(+ source.join(PATCH_FILE),+ "- id: new\n config:\n token: !!js process.env.TOKEN\n",+ )+ .unwrap();+ fs::write(+ target.join(PATCH_FILE),+ "- id: local\n name: !!js process.env.LOCAL_PLUGIN\n",+ )+ .unwrap();++ assert!(merge_patch(&source, &target).unwrap());++ assert_eq!(+ fs::read_to_string(target.join(PATCH_FILE)).unwrap(),+ "- id: local\n name: !!js process.env.LOCAL_PLUGIN\n- id: new\n config:\n token: !!js process.env.TOKEN\n"+ );+ let _ = fs::remove_dir_all(&source);+ let _ = fs::remove_dir_all(&target);+ }+/// 目标档案已完全包含源的内容时迁移是空操作,界面据此禁用勾选。#[test]fn data_items_marks_fully_contained_entries_as_covered() {diff --git a/src-tauri/src/service/workflow/win_inspector.rs b/src-tauri/src/service/workflow/win_inspector.rsindex 7ac31f52..b92c8095 100644--- a/src-tauri/src/service/workflow/win_inspector.rs+++ b/src-tauri/src/service/workflow/win_inspector.rs@@ -13,6 +13,8 @@ mod imp {use std::fs;use std::path::{Path, PathBuf};+ use crate::service::plugin::{parse_patch_layer, render_patch_layer};+/// 历史注入块的自识别标记。const PATCH_MARKER: &str = "dsh-win-terminal-inspector";@@ -68,7 +70,7 @@ mod imp {let retained: Vec<serde_yaml::Value> =seq.into_iter().filter(|el| !block_is_ours(el)).collect();- let out = serde_yaml::to_string(&serde_yaml::Value::Sequence(retained))+ let out = render_patch_layer(&serde_yaml::Value::Sequence(retained)).map_err(|e| format!("PATCH_RENDER_FAILED: {e}"))?;write_file(&patch_path, &out).map_err(|e| format!("PATCH_PRUNE_FAILED: {e}"))}@@ -78,8 +80,7 @@ mod imp {if content.trim().is_empty() {return Ok(serde_yaml::Value::Sequence(Vec::new()));}- let doc: serde_yaml::Value =- serde_yaml::from_str(content).map_err(|e| format!("PATCH_PARSE_FAILED: {e}"))?;+ let doc = parse_patch_layer(content).map_err(|e| format!("PATCH_PARSE_FAILED: {e}"))?;match &doc {serde_yaml::Value::Sequence(_) => Ok(doc),serde_yaml::Value::Null => Ok(serde_yaml::Value::Sequence(Vec::new())),@@ -206,6 +207,26 @@ mod imp {std::fs::remove_dir_all(&dir).ok();}+ #[test]+ fn patch_prune_keeps_js_expressions() {+ let dir = temp_dir("l");+ std::fs::create_dir_all(&dir).unwrap();+ let patch = dir.join("cordis.patch.yml");+ std::fs::write(+ &patch,+ "- insert:\n - id: win-terminal-inspector\n name: dsh-win-terminal-inspector\n- id: some-row\n config:\n token: !!js process.env.TOKEN\n",+ )+ .unwrap();++ apply_at(&dir).unwrap();+ assert_eq!(+ std::fs::read_to_string(&patch).unwrap(),+ "- id: some-row\n config:\n token: !!js process.env.TOKEN\n"+ );++ std::fs::remove_dir_all(&dir).ok();+ }+#[test]fn git_bash_dirs_follow_finder() {match find_git_bash() {