From 02d5bc537e6f8e6323bfb47318b78fb4659b4863 Mon Sep 17 00:00:00 2001 From: Yuyi-Oak <1722157266@qq.com> Date: Thu, 16 Jul 2026 08:00:31 -0700 Subject: [PATCH] =?UTF-8?q?fix(patch):=20=E5=8D=A0=E4=BD=8D=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E8=BF=94=E5=9B=9E=E6=9C=AA=E5=AE=9E=E7=8E=B0=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E8=80=8C=E9=9D=9E=E7=A9=BA=E7=BB=93=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit apply_patch / apply_json_patch 原返回 Ok(空 Vec/空 String),调用方会把未实现 的占位误当成一次成功的补丁应用。改为返回 PatchError::ApplyFailed,让占位状态 显式可见。新增单测确认返回错误。 对应 issue #18 维护清单 2-4。 Co-Authored-By: Claude Fable 5 --- crates/bat-patch/src/binary.rs | 20 ++++++++++++++++++-- crates/bat-patch/src/json.rs | 20 ++++++++++++++++++-- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/crates/bat-patch/src/binary.rs b/crates/bat-patch/src/binary.rs index 3acf3e4..53c66a8 100644 --- a/crates/bat-patch/src/binary.rs +++ b/crates/bat-patch/src/binary.rs @@ -1,6 +1,22 @@ //! Binary Patch 模块占位 -/// Binary Patch 应用(待实现) +/// Binary Patch 应用(尚未实现)。 +/// +/// 返回 [`crate::PatchError::ApplyFailed`] 而非空结果,避免调用方把未实现的 +/// 占位当成一次成功的补丁应用。 pub fn apply_patch(_old: &[u8], _patch: &[u8]) -> crate::Result> { - Ok(Vec::new()) + Err(crate::PatchError::ApplyFailed( + "binary patch 尚未实现".to_string(), + )) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn apply_patch_reports_not_implemented() { + let error = apply_patch(b"old", b"patch").unwrap_err(); + assert!(matches!(error, crate::PatchError::ApplyFailed(_))); + } } diff --git a/crates/bat-patch/src/json.rs b/crates/bat-patch/src/json.rs index ccac569..8088a8d 100644 --- a/crates/bat-patch/src/json.rs +++ b/crates/bat-patch/src/json.rs @@ -1,6 +1,22 @@ //! JSON Patch 模块占位 -/// JSON Patch 应用(待实现) +/// JSON Patch 应用(尚未实现)。 +/// +/// 返回 [`crate::PatchError::ApplyFailed`] 而非空字符串,避免调用方把未实现的 +/// 占位当成一次成功的补丁应用。 pub fn apply_json_patch(_doc: &str, _patch: &str) -> crate::Result { - Ok(String::new()) + Err(crate::PatchError::ApplyFailed( + "json patch 尚未实现".to_string(), + )) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn apply_json_patch_reports_not_implemented() { + let error = apply_json_patch("{}", "[]").unwrap_err(); + assert!(matches!(error, crate::PatchError::ApplyFailed(_))); + } }