The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(flows): cover catalog storage profile scoping and CAS metadata
Steven Enamakel2ae9165e1799
diff --git a/crates/openhuman-core/src/flows/catalog_storage_tests.rs b/crates/openhuman-core/src/flows/catalog_storage_tests.rsindex 6d13e6ff4a..d331145a0c 100644--- a/crates/openhuman-core/src/flows/catalog_storage_tests.rs+++ b/crates/openhuman-core/src/flows/catalog_storage_tests.rs@@ -1,6 +1,33 @@use super::*;use serde_json::json;+fn context(config: &Config, profile: &str) -> DispatchCtx {+ use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet};+ use crate::tools::toolpacks::ToolGroups;++ let root = CoreContext::for_test_with_config(DomainSet::full(), config.clone());+ DispatchCtx::new(root.derive_with(+ ContextOverlay::new(config.clone(), DomainSet::full(), ToolGroups::default())+ .profile(profile),+ ))+}++async fn callback_proxy(+ registration: &CatalogStorageRegistration,+) -> tinybus::Proxy {+ let runtime = crate::modules::runtime::runtime()+ .await+ .expect("module runtime is available");+ runtime+ .connection()+ .proxy(+ ®istration.address.destination,+ ®istration.address.object_path,+ catalog::STORAGE_INTERFACE,+ )+ .expect("CatalogStorage callback address is valid")+}+#[test]fn storage_paths_are_stable_and_unambiguous_for_workspace_and_scope() {let key = RegistrationKey {@@ -64,20 +91,12 @@ fn graph_query_and_delete_filters_are_confined_to_the_flows_namespace() {#[tokio::test]async fn cancelling_the_caller_after_serve_keeps_one_cached_registration() {- use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};- use crate::tools::toolpacks::ToolGroups;-let workspace = tempfile::tempdir().expect("isolated workspace");let config = Config {workspace_dir: workspace.path().to_path_buf(),..Config::default()};- let root = CoreContext::for_test_with_config(DomainSet::full(), config.clone());- let core = root.derive_with(- ContextOverlay::new(config.clone(), DomainSet::full(), ToolGroups::default())- .profile("catalog-storage-cancellation-test"),- );- let context = DispatchCtx::new(core);+ let context = context(&config, "catalog-storage-cancellation-test");let scope = crate::storage::scope_for_profile("catalog-storage-cancellation-test");let key = RegistrationKey {workspace_dir: config.workspace_dir.clone(),@@ -139,3 +158,268 @@ async fn cancelling_the_caller_after_serve_keeps_one_cached_registration() {.expect("cached callback remains served");assert!(matches!(reply, CatalogStorageReply::Value { .. }));}++#[tokio::test]+async fn catalog_module_uses_captured_profile_and_storage_preserves_cas_metadata() {+ use tinyflows_bus::catalog::{+ self, CatalogDocumentPrecondition, CatalogStorageReply, PutWorkflowRequest,+ PutWorkflowResponse,+ };++ let workspace = tempfile::tempdir().expect("isolated workspace");+ let config = Config {+ workspace_dir: workspace.path().to_path_buf(),+ ..Config::default()+ };+ let alice = context(&config, "catalog-storage-alice");+ let bob = context(&config, "catalog-storage-bob");+ let alice_registration = register(&alice, &config).await.unwrap();+ let bob_registration = register(&bob, &config).await.unwrap();+ assert_ne!(+ alice_registration.address.object_path,+ bob_registration.address.object_path+ );++ let catalog_proxy = module::catalog_proxy(&config).await.unwrap();+ let graph = json!({+ "nodes": [{"id":"trigger","name":"Trigger","kind":"trigger","config":{"trigger_kind":"manual"}}],+ "edges": []+ });+ let create = PutWorkflowRequest::Create {+ storage: alice_registration.storage(),+ name: "Alice scoped catalog entry".into(),+ graph,+ require_approval: false,+ };+ let response: PutWorkflowResponse = catalog_proxy+ .call(catalog::members::PUT_WORKFLOW, &(create,))+ .await+ .unwrap();+ let PutWorkflowResponse::Ok(created) = response else {+ panic!("valid test workflow should be created");+ };+ let flow_id = created.workflow.id;++ let alice_list: catalog::ListWorkflowsResult = catalog_proxy+ .call(+ catalog::members::LIST_WORKFLOWS,+ &(alice_registration.storage(),),+ )+ .await+ .unwrap();+ let bob_list: catalog::ListWorkflowsResult = catalog_proxy+ .call(+ catalog::members::LIST_WORKFLOWS,+ &(bob_registration.storage(),),+ )+ .await+ .unwrap();+ assert_eq!(alice_list.workflows.len(), 1);+ assert!(bob_list.workflows.is_empty());++ let alice_bus = callback_proxy(&alice_registration).await;+ let bob_bus = callback_proxy(&bob_registration).await;+ let get = catalog::DocGetRequest {+ collection: "flows.definitions".into(),+ id: flow_id.clone(),+ };+ let reply: CatalogStorageReply = alice_bus+ .call(catalog::storage::GET, &(get.clone(),))+ .await+ .unwrap();+ let CatalogStorageReply::Value { value } = reply else {+ panic!("created record is readable");+ };+ let record: Option<CatalogVersionedDocument> = serde_json::from_value(value).unwrap();+ let record = record.unwrap();+ assert!(record.meta.created_ms > 0);+ assert!(record.meta.updated_ms > 0);+ let old_version = record.version;++ let put = DocPutRequest {+ collection: "flows.definitions".into(),+ id: flow_id.clone(),+ doc: record.doc.clone(),+ precondition: CatalogDocumentPrecondition::Version(old_version),+ schema: record.meta.schema,+ expires_ms: record.meta.expires_ms,+ created_ms: Some(record.meta.created_ms),+ };+ let updated: CatalogStorageReply = alice_bus+ .call(catalog::storage::PUT, &(put.clone(),))+ .await+ .unwrap();+ assert!(matches!(updated, CatalogStorageReply::Value { .. }));++ let stale: CatalogStorageReply = alice_bus+ .call(catalog::storage::PUT, &(put,))+ .await+ .unwrap();+ assert!(matches!(+ stale,+ CatalogStorageReply::Error { ref error } if error.kind == "conflict"+ ));++ let foreign: CatalogStorageReply = bob_bus+ .call(catalog::storage::GET, &(get,))+ .await+ .unwrap();+ assert!(matches!(+ foreign,+ CatalogStorageReply::Value { value } if value.is_null()+ ));++}++#[tokio::test]+async fn catalog_storage_resolves_the_current_backend_and_confines_graph_namespace_queries() {+ use tinyflows_bus::catalog::{+ CatalogCollectionSpec, CatalogDocumentPrecondition, CatalogFilter, CatalogQuery,+ CatalogStorageReply, DocDeleteWhereRequest,+ };++ let workspace = tempfile::tempdir().expect("isolated workspace");+ let config = Config {+ workspace_dir: workspace.path().to_path_buf(),+ ..Config::default()+ };+ let context = context(&config, "catalog-storage-rebind");+ let registration = register(&context, &config).await.unwrap();+ let proxy = callback_proxy(®istration).await;++ let backend_a: Arc<dyn StorageBackend> = Arc::new(crate::storage::MemoryStorage::new());+ let previous = crate::storage::install(Arc::clone(&backend_a));+ struct RestoreBackend(Option<Arc<dyn StorageBackend>>);+ impl Drop for RestoreBackend {+ fn drop(&mut self) {+ if let Some(previous) = self.0.take() {+ crate::storage::install(previous);+ } else {+ crate::storage::clear();+ }+ }+ }+ let _restore = RestoreBackend(previous);++ let result: CatalogStorageReply = proxy+ .call(+ catalog::storage::ENSURE,+ &(DocEnsureRequest {+ spec: CatalogCollectionSpec {+ name: "graph.threads".into(),+ indexes: Vec::new(),+ ttl_field: None,+ search: None,+ },+ },),+ )+ .await+ .unwrap();+ assert!(matches!(result, CatalogStorageReply::Value { .. }));++ let scope = crate::storage::scope_for_profile("catalog-storage-rebind");+ let first = backend_a.for_scope(&scope).unwrap();+ first+ .documents()+ .put(+ "graph.threads",+ "flows/alice-thread",+ json!({"ns":"flows","thread":"alice-thread","next":1}),+ Precondition::Absent,+ )+ .await+ .unwrap();+ first+ .documents()+ .put(+ "graph.threads",+ "other/bob-thread",+ json!({"ns":"other","thread":"bob-thread","next":1}),+ Precondition::Absent,+ )+ .await+ .unwrap();++ let query: CatalogStorageReply = proxy+ .call(+ catalog::storage::QUERY,+ &(catalog::DocQueryRequest {+ collection: "graph.threads".into(),+ query: CatalogQuery::default(),+ },),+ )+ .await+ .unwrap();+ let CatalogStorageReply::Value { value } = query else {+ panic!("query succeeds");+ };+ let page: catalog::CatalogDocumentPage = serde_json::from_value(value).unwrap();+ assert_eq!(page.items.len(), 1);+ assert_eq!(page.items[0].doc["ns"], "flows");++ let delete: CatalogStorageReply = proxy+ .call(+ catalog::storage::DELETE_WHERE,+ &(DocDeleteWhereRequest {+ collection: "graph.threads".into(),+ filter: CatalogFilter::All,+ },),+ )+ .await+ .unwrap();+ assert!(matches!(delete, CatalogStorageReply::Value { .. }));+ let foreign = first+ .documents()+ .get("graph.threads", "other/bob-thread")+ .await+ .unwrap();+ assert!(foreign.is_some(), "flow deletion leaves the other namespace intact");++ let forbidden_get: CatalogStorageReply = proxy+ .call(+ catalog::storage::GET,+ &(catalog::DocGetRequest {+ collection: "graph.threads".into(),+ id: "other/bob-thread".into(),+ },),+ )+ .await+ .unwrap();+ assert!(matches!(+ forbidden_get,+ CatalogStorageReply::Error { ref error } if error.kind == "invalid_input"+ ));++ let backend_b: Arc<dyn StorageBackend> = Arc::new(crate::storage::MemoryStorage::new());+ crate::storage::install(Arc::clone(&backend_b));+ let ensured: CatalogStorageReply = proxy+ .call(+ catalog::storage::ENSURE,+ &(DocEnsureRequest {+ spec: CatalogCollectionSpec {+ name: "graph.threads".into(),+ indexes: Vec::new(),+ ttl_field: None,+ search: None,+ },+ },),+ )+ .await+ .unwrap();+ assert!(matches!(ensured, CatalogStorageReply::Value { .. }));+ let rebound = proxy+ .call::<CatalogStorageReply, _>(+ catalog::storage::GET,+ &(catalog::DocGetRequest {+ collection: "graph.threads".into(),+ id: "flows/alice-thread".into(),+ },),+ )+ .await+ .unwrap();+ assert!(matches!(+ rebound,+ CatalogStorageReply::Value { ref value } if value.is_null()+ ));+ assert_eq!(registration.address.object_path, registration.storage().callback.object_path);+}diff --git a/crates/openhuman-core/src/flows/store.rs b/crates/openhuman-core/src/flows/store.rsindex a72131c012..8ea7f900f6 100644--- a/crates/openhuman-core/src/flows/store.rs+++ b/crates/openhuman-core/src/flows/store.rs@@ -90,7 +90,7 @@ fn put_result(response: PutWorkflowResponse) -> Result<Flow> {}}-/// Save a workflow through the module's Catalog contract.+/// Seed a caller-chosen id through CatalogStorage for host tests.#[cfg(test)]pub fn upsert_flow(config: &Config, flow: &Flow) -> Result<()> {test_seed_flow(config, flow)@@ -163,7 +163,7 @@ pub fn create_flow(name: String,graph: tinyflows::model::WorkflowGraph,require_approval: bool,- _enabled: bool,+ enabled: bool,) -> Result<Flow> {let storage = super::catalog_storage::register_blocking(config)?;let request = PutWorkflowRequest::Create {@@ -173,7 +173,12 @@ pub fn create_flow(require_approval,};let response: PutWorkflowResponse = call_catalog(config, catalog::members::PUT_WORKFLOW, (request,))?;- put_result(response)+ let flow = put_result(response)?;+ if !enabled && flow.enabled {+ set_enabled(config, &flow.id, false)+ } else {+ Ok(flow)+ }}/// Read one workflow by id.