fix(cas): exists 返回 Result 以区分不存在与存储故障

CasRepository::exists(core trait)与底层 Storage::exists 原返回裸 bool,
FileSystemStorage 用 try_exists(...).unwrap_or(false)、infra 适配层吞掉解析/
初始化错误返回 false,调用方无法区分“对象不存在”和权限/IO/初始化故障。

将整条链改为 Result<bool>:
- storage trait 与 FileSystemStorage:try_exists 的 IO 错误经 ? 传播;
- repository FileSystemCasRepository::exists 及 store/add_reference 内部调用;
- core CasRepository::exists trait;
- infra 适配层:解析失败→InvalidArgument、初始化/引擎错误经 map_error 传播。
Ok(false) 仅表示确实不存在。

新增单测:合法但不存在的对象返回 Ok(false),非法 ObjectId 返回 Err(而非静默
false);同步更新各层 exists 断言。

对应 issue #18 维护清单 2-1。

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-16 08:53:54 -07:00
co-authored by Claude Fable 5
parent c362fd80f4
commit 48ffc08cdf
6 changed files with 48 additions and 28 deletions
+5 -2
View File
@@ -153,11 +153,14 @@ pub trait CasRepository: Send + Sync {
/// # 示例
///
/// ```rust,ignore
/// if repository.exists(&object_id).await {
/// if repository.exists(&object_id).await? {
/// println!("Object exists");
/// }
/// ```
async fn exists(&self, id: &ObjectId) -> bool;
///
/// 返回 `Result` 以便调用方区分“对象不存在”(`Ok(false)`)与底层存储/IO 故障
/// (`Err`),而不是把故障静默当成不存在。
async fn exists(&self, id: &ObjectId) -> crate::Result<bool>;
/// 增加引用计数
///