fix(test): 修复 anthropic 错误链嵌套测试为真正的 source 链
对抗性审查发现 test_format_error_chain_nested 是无效测试: 声称测嵌套错误链但实际没构造 source 链,inner 变量被 let _ 抑制。 改用 thiserror 构造真正的 #[source] 嵌套错误,验证 'caused by' 拼接。
This commit is contained in:
parent
e6b2fcfb6d
commit
cd314742ad
@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user