From cd314742ade65aea9f0fb637f3ea468a892c012d Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Mon, 3 Aug 2026 23:47:43 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E4=BF=AE=E5=A4=8D=20anthropic=20?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E9=93=BE=E5=B5=8C=E5=A5=97=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=B8=BA=E7=9C=9F=E6=AD=A3=E7=9A=84=20source=20=E9=93=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 对抗性审查发现 test_format_error_chain_nested 是无效测试: 声称测嵌套错误链但实际没构造 source 链,inner 变量被 let _ 抑制。 改用 thiserror 构造真正的 #[source] 嵌套错误,验证 'caused by' 拼接。 --- src/providers/anthropic.rs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/providers/anthropic.rs b/src/providers/anthropic.rs index 249e0e6..cf3778f 100644 --- a/src/providers/anthropic.rs +++ b/src/providers/anthropic.rs @@ -614,15 +614,20 @@ mod tests { assert_eq!(chain, "single error"); } + /// 用 thiserror 构造真正的嵌套 source 链,验证 "caused by" 拼接 + #[derive(Debug, thiserror::Error)] + enum OuterError { + #[error("outer wrapper")] + Wrapped(#[source] std::io::Error), + } + #[test] fn test_format_error_chain_nested() { let inner = std::io::Error::new(std::io::ErrorKind::Other, "root cause"); - let outer = std::io::Error::new(std::io::ErrorKind::Other, "outer error"); - // std::io::Error 的 source 链需要手动构造,这里用 anyhow 风格的 context 模拟 - // 简化:验证无 source 时不拼接 "caused by" + let outer = OuterError::Wrapped(inner); let chain = format_error_chain(&outer); - assert!(chain.contains("outer error")); - assert!(!chain.contains("caused by")); - let _ = inner; // 抑制未使用警告 + assert!(chain.contains("outer wrapper")); + assert!(chain.contains("caused by")); + assert!(chain.contains("root cause")); } }