Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

test(storage): add unfenced memory backend for default test workspace

Steven Enamakela7c4b84b8d11
diff --git a/crates/openhuman-core/src/storage/local.rs b/crates/openhuman-core/src/storage/local.rs
index 21d12d1ae2..c06cb5458d 100644
--- a/crates/openhuman-core/src/storage/local.rs
+++ b/crates/openhuman-core/src/storage/local.rs
@@ -188,7 +188,7 @@ async fn open_default_backend(_workspace_dir: PathBuf) -> Result<Arc<dyn Storage
#[cfg(test)]
{
let backend: Arc<dyn StorageBackend> =
- Arc::new(tinystoragedrivers_testkit::MemoryBackend::new());
+ Arc::new(super::test_support::UnfencedMemoryBackend::new());
super::boot::prepare_and_migrate(&backend).await?;
Ok(super::fenced_backend::wrap(backend))
}
diff --git a/crates/openhuman-core/src/storage/test_support.rs b/crates/openhuman-core/src/storage/test_support.rs
index 9ac69bf916..64ec010609 100644
--- a/crates/openhuman-core/src/storage/test_support.rs
+++ b/crates/openhuman-core/src/storage/test_support.rs
@@ -12,6 +12,45 @@ pub fn memory_backend() -> Arc<dyn StorageBackend> {
Arc::new(tinystoragedrivers_testkit::MemoryBackend::new())
}
+/// The in-memory backend a workspace opens by default under `cfg(test)`.
+///
+/// The TSD memory engine cannot evaluate a write condition, yet the session
+/// transcripts (lease-conditioned generation writes) and the state import
+/// claims ask every backend for a conditioned scope. In a unit test the one
+/// process is the only writer, so there is nothing to fence: this wrapper
+/// opens the plain handles for a conditioned scope. It exists only for the
+/// workspace default; tests of the conditions themselves use
+/// [`sqlite_backend`], which enforces them.
+#[derive(Debug)]
+pub(crate) struct UnfencedMemoryBackend(tinystoragedrivers_testkit::MemoryBackend);
+
+impl UnfencedMemoryBackend {
+ pub(crate) fn new() -> Self {
+ Self(tinystoragedrivers_testkit::MemoryBackend::new())
+ }
+}
+
+impl StorageBackend for UnfencedMemoryBackend {
+ fn capabilities(&self) -> tinystoragedrivers_types::Capabilities {
+ self.0.capabilities()
+ }
+
+ fn for_scope(
+ &self,
+ scope: &crate::storage::Scope,
+ ) -> Result<crate::storage::Storage, crate::storage::StorageError> {
+ self.0.for_scope(scope)
+ }
+
+ fn for_scope_conditioned(
+ &self,
+ scope: &crate::storage::Scope,
+ _condition: &tinystoragedrivers_types::WriteCondition,
+ ) -> Result<crate::storage::Storage, crate::storage::StorageError> {
+ self.0.for_scope(scope)
+ }
+}
+
static STORAGE_SLOT_TEST_LOCK: Mutex<()> = Mutex::new(());
/// Serializes a test that reads or mutates the process-wide installed storage