commit 2c17ee2df7f24c3616356b211c3848cff1124dd0
parent b65d2bcad55bf3c7c55037f2bc1bbe2a6c6a6f61
Author: triesap <tyson@radroots.org>
Date: Thu, 6 Aug 2026 06:57:25 +0000
mobile: make sdk status mappings explicit
- define stable labels for every storage backend and open mode
- define stable labels for every shutdown and integrity state
- replace mobile Debug formatting with protocol-owned mappings
- cover the complete storage label matrix with focused tests
Diffstat:
2 files changed, 63 insertions(+), 4 deletions(-)
diff --git a/crates/mobile_core/src/runtime/sdk.rs b/crates/mobile_core/src/runtime/sdk.rs
@@ -49,10 +49,10 @@ impl RadrootsRuntime {
.await
.map_err(RadrootsAppError::from_sdk)?;
Ok(SdkStorageStatusRecord {
- backend: format!("{:?}", status.backend()).to_ascii_lowercase(),
- open_mode: format!("{:?}", status.open_mode()).to_ascii_lowercase(),
- shutdown: format!("{:?}", status.shutdown()).to_ascii_lowercase(),
- integrity: format!("{:?}", status.integrity().health()).to_ascii_lowercase(),
+ backend: status.backend().as_str().to_owned(),
+ open_mode: status.open_mode().as_str().to_owned(),
+ shutdown: status.shutdown().as_str().to_owned(),
+ integrity: status.integrity().health().as_str().to_owned(),
})
}
}
diff --git a/crates/storage/src/status.rs b/crates/storage/src/status.rs
@@ -18,6 +18,15 @@ pub enum StorageBackend {
Sqlite,
}
+impl StorageBackend {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Memory => "memory",
+ Self::Sqlite => "sqlite",
+ }
+ }
+}
+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -27,6 +36,16 @@ pub enum StorageOpenMode {
Create,
}
+impl StorageOpenMode {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::ReadOnly => "read_only",
+ Self::ReadWriteExisting => "read_write_existing",
+ Self::Create => "create",
+ }
+ }
+}
+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -44,6 +63,16 @@ pub enum ShutdownState {
Closed,
}
+impl ShutdownState {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Open => "open",
+ Self::Closing => "closing",
+ Self::Closed => "closed",
+ }
+ }
+}
+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
@@ -54,6 +83,17 @@ pub enum IntegrityHealth {
Unknown,
}
+impl IntegrityHealth {
+ pub const fn as_str(self) -> &'static str {
+ match self {
+ Self::Healthy => "healthy",
+ Self::Degraded => "degraded",
+ Self::Corrupt => "corrupt",
+ Self::Unknown => "unknown",
+ }
+ }
+}
+
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct IntegrityStatus {
@@ -251,6 +291,25 @@ impl EventStoreStatus {
mod tests {
use super::*;
+ #[test]
+ fn storage_status_labels_are_explicit_and_stable() {
+ assert_eq!(StorageBackend::Memory.as_str(), "memory");
+ assert_eq!(StorageBackend::Sqlite.as_str(), "sqlite");
+ assert_eq!(StorageOpenMode::ReadOnly.as_str(), "read_only");
+ assert_eq!(
+ StorageOpenMode::ReadWriteExisting.as_str(),
+ "read_write_existing"
+ );
+ assert_eq!(StorageOpenMode::Create.as_str(), "create");
+ assert_eq!(ShutdownState::Open.as_str(), "open");
+ assert_eq!(ShutdownState::Closing.as_str(), "closing");
+ assert_eq!(ShutdownState::Closed.as_str(), "closed");
+ assert_eq!(IntegrityHealth::Healthy.as_str(), "healthy");
+ assert_eq!(IntegrityHealth::Degraded.as_str(), "degraded");
+ assert_eq!(IntegrityHealth::Corrupt.as_str(), "corrupt");
+ assert_eq!(IntegrityHealth::Unknown.as_str(), "unknown");
+ }
+
fn integrity() -> IntegrityStatus {
IntegrityStatus::new(IntegrityHealth::Healthy, Some(1), 3, 0).unwrap()
}