0.5.1-pre.002

This commit is contained in:
2026-08-09 19:34:08 +02:00
parent 816eee59a9
commit 6a680767ae
767 changed files with 12257 additions and 12195 deletions

View File

@@ -0,0 +1,58 @@
// file: ks-store/src/contracts/health.rs
// version: 2
//! Backend-neutral health contracts for storage implementations.
/// Store backend health status.
#[derive(Clone, Copy, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub enum StoreHealthStatus {
/// Health is not known yet.
Unknown,
/// Backend is reachable and usable.
Healthy,
/// Backend is reachable but not fully usable.
Degraded,
/// Backend is not usable.
Unhealthy,
}
/// Store backend health snapshot.
#[derive(Clone, Debug, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
pub struct StoreHealthSnapshot {
/// Stable backend code such as `postgres` or `sqlite`.
pub backend: std::string::String,
/// Current health status.
pub status: StoreHealthStatus,
/// Optional human-readable diagnostic message.
pub message: std::option::Option<std::string::String>,
}
impl StoreHealthSnapshot {
/// Builds a store health snapshot after minimal validation.
pub fn new(
backend: impl std::convert::Into<std::string::String>,
status: StoreHealthStatus,
message: std::option::Option<std::string::String>,
) -> ks_core::Result<Self> {
let backend_value = backend.into();
if backend_value.trim().is_empty() {
return std::result::Result::Err(ks_core::Error::db(
"store health backend must not be empty",
));
}
return std::result::Result::Ok(Self { backend: backend_value, status, message });
}
}
#[cfg(test)]
mod tests {
#[test]
fn health_snapshot_rejects_empty_backend() {
let result = crate::StoreHealthSnapshot::new(
" ",
crate::StoreHealthStatus::Unknown,
std::option::Option::None,
);
assert!(result.is_err());
}
}