Skip to content

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

refactor(config): type document backend identity

Steven Enamakel4e6e7a5d8e1f
diff --git a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
index 1dd844517f..577eefc015 100644
--- a/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/concurrency_tests.rs
@@ -209,7 +209,7 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
let docs = Arc::clone(scoped(&storage, "tenant-source-b").documents());
let stored = docs
.get(
- super::super::CONFIG_COLLECTION,
+ super::super::storage_schema::CONFIG_COLLECTION,
&super::super::storage_schema::document_id("tenant-source-b").unwrap(),
)
.await
@@ -259,28 +259,45 @@ async fn config_snapshot_cannot_be_saved_into_a_different_tenant_scope() {
#[tokio::test]
async fn config_snapshot_is_bound_to_its_backend_instance() {
let tmp = tempfile::tempdir().unwrap();
- let storage = MemoryStorage::new();
- let seed = config_at(tmp.path(), "same-backend");
- let stale = {
+ let path = tmp.path().join("config.toml");
+ let workspace = tmp.path().join("workspace");
+ let storage_a = MemoryStorage::new();
+ let storage_b = MemoryStorage::new();
+ let config_a = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-backend-instance"),
- Scope::new("tenant-backend-instance").unwrap(),
+ scoped(&storage_a, "tenant-same-anchor"),
+ Scope::new("tenant-same-anchor").unwrap(),
keys(14),
);
- seed.save().await.unwrap();
- Config::load_from_config_path(&seed.config_path, &seed.workspace_dir)
- .await
- .unwrap()
+ config_at(tmp.path(), "backend-a").save().await.unwrap();
+ Config::load_from_config_path(&path, &workspace).await.unwrap()
+ };
+ let (config_b, version_b) = {
+ let _source = ForcedDocumentSource::new(
+ scoped(&storage_b, "tenant-same-anchor"),
+ Scope::new("tenant-same-anchor").unwrap(),
+ keys(14),
+ );
+ config_at(tmp.path(), "backend-b").save().await.unwrap();
+ let config = Config::load_from_config_path(&path, &workspace).await.unwrap();
+ let version = config.document_snapshot.lock().unwrap().version;
+ (config, version)
};
+ let version_a = config_a.document_snapshot.lock().unwrap().version;
+ assert_eq!(version_a, version_b, "fixture uses colliding document versions");
+ let anchor_a = config_a.document_snapshot.lock().unwrap().anchor.clone();
+ let anchor_b = config_b.document_snapshot.lock().unwrap().anchor.clone();
+ assert_ne!(anchor_a, anchor_b, "source anchors retain backend identity");
+
let error = {
let _source = ForcedDocumentSource::new(
- scoped(&storage, "tenant-backend-instance"),
- Scope::new("tenant-backend-instance").unwrap(),
+ scoped(&storage_b, "tenant-same-anchor"),
+ Scope::new("tenant-same-anchor").unwrap(),
keys(14),
);
- let mut stale = stale;
- stale.default_model = Some("must-not-cross-backend-instance".into());
- stale.save().await.unwrap_err()
+ let mut from_a = config_a;
+ from_a.default_model = Some("must-not-cross-backend-instance".into());
+ from_a.save().await.unwrap_err()
};
assert_typed_conflict(error);
}
diff --git a/crates/openhuman-core/src/config/schema/load/source/document.rs b/crates/openhuman-core/src/config/schema/load/source/document.rs
index 95453d9363..d093547132 100644
--- a/crates/openhuman-core/src/config/schema/load/source/document.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/document.rs
@@ -9,8 +9,8 @@ use tinystoragedrivers::secrets::{KeyProvider, crypto};
use tinystoragedrivers::{CollectionSpec, DocumentStore, Precondition};
use super::{
- ConfigRead, ConfigSource, ConfigSourceAnchor, FileConfigSource, apply_bootstrap,
- strip_bootstrap,
+ ConfigRead, ConfigSource, ConfigSourceAnchor, DocumentBackendIdentity, FileConfigSource,
+ apply_bootstrap, strip_bootstrap,
};
use crate::storage::Scope;
@@ -40,7 +40,7 @@ pub(crate) struct DocumentConfigSource {
keys: Arc<dyn KeyProvider>,
file: FileConfigSource,
observed_version: Mutex<Option<tinystoragedrivers::Version>>,
- backend_identity: usize,
+ backend_identity: DocumentBackendIdentity,
}
impl DocumentConfigSource {
@@ -49,7 +49,7 @@ impl DocumentConfigSource {
scope: Scope,
keys: Arc<dyn KeyProvider>,
file: FileConfigSource,
- backend_identity: usize,
+ backend_identity: DocumentBackendIdentity,
) -> Self {
Self {
docs,
diff --git a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs
index 8a79dc37dd..8f2f6e1a14 100644
--- a/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load/source/mod_tests.rs
@@ -29,7 +29,7 @@ fn document_source_keyed(
Scope::new(scope).unwrap(),
keys,
FileConfigSource::new(file),
- Arc::as_ptr(scoped(storage, scope).documents()) as *const () as usize,
+ super::DocumentBackendIdentity::Test(Arc::new(())),
)
}