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
fix(context_tests): correct test assertion for context initialization
Steven Enamakel8eb5ce28a756
diff --git a/crates/openhuman-core/src/core/runtime/context_tests.rs b/crates/openhuman-core/src/core/runtime/context_tests.rsindex fbcb92d630..640ea6ea5a 100644--- a/crates/openhuman-core/src/core/runtime/context_tests.rs+++ b/crates/openhuman-core/src/core/runtime/context_tests.rs@@ -6,7 +6,6 @@ fn ctx(dir: &str) -> Arc<CoreContext> {host_kind: HostKind::Cli,workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {workspace_dir: Some(PathBuf::from(dir)),- memory_subsystem: Default::default(),}))),domains: crate::core::runtime::DomainSet::full(),tool_groups: Default::default(),@@ -36,7 +35,6 @@ fn ctx_with_config(config: crate::config::Config) -> Arc<CoreContext> {host_kind: HostKind::Cli,workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {workspace_dir: Some(config.workspace_dir.clone()),- memory_subsystem: Default::default(),}))),domains: crate::core::runtime::DomainSet::full(),tool_groups: Default::default(),@@ -329,26 +327,12 @@ async fn nested_scope_overrides_then_restores() {assert_eq!(outer, PathBuf::from("/tmp/ctx-a"));}-// The Phase 3 exit criterion, at the store level: two contexts over distinct-// workspaces resolve isolated per-domain stores, and one context always-// The three people-based context tests that stood here are gone with-// `CoreContext::people()`. They proved per-context workspace isolation-// using the people store as the example, and that property is proved-// unchanged by `memory_binding_is_isolated_per_context_workspace` and-// `rebind_workspace_updates_context_memory_binding` below — which is what-// people now resolves through. The third,-// `people_rpc_uses_scoped_context_store`, asserted that a scoped-// `people_resolve` wrote workspace A and not B by reading both stores-// directly; there is no second reader to check against any more, and the-// isolation it tested is the binding's.-#[test]fn degraded_context_rejects_workspace_bound_stores() {let ctx = CoreContext {host_kind: HostKind::Cli,workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {workspace_dir: None,- memory_subsystem: Default::default(),}))),domains: crate::core::runtime::DomainSet::full(),tool_groups: Default::default(),@@ -370,351 +354,3 @@ fn degraded_context_rejects_workspace_bound_stores() {"unexpected error: {err}");}--// ---- memory driver binding (M2b) ------------------------------------------fn untrusted_external_memory_cfg() -> crate::config::schema::MemorySubsystemConfig {- use crate::config::schema::{MemoryDriverConfig, MemorySubsystemConfig};- let mut cfg = MemorySubsystemConfig {- driver: "supermemory".into(),- ..Default::default()- };- cfg.drivers.insert(- "supermemory".into(),- MemoryDriverConfig {- class: Some("external".into()),- ..Default::default()- },- );- cfg-}--/// Same proof as `people_store_is_isolated_per_context_workspace`, one layer-/// up: the memory binding is per-workspace, not per-process.-#[test]-fn memory_binding_is_isolated_per_context_workspace() {- let dir_a = tempfile::tempdir().unwrap();- let dir_b = tempfile::tempdir().unwrap();- let a = Arc::new(CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_a.path().to_path_buf()),- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- });- let b = Arc::new(CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_b.path().to_path_buf()),- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- });-- let bind_a = a.memory_binding().expect("bind workspace A");- let bind_b = b.memory_binding().expect("bind workspace B");- assert!(!Arc::ptr_eq(&bind_a, &bind_b));-- let bind_a_again = a.memory_binding().expect("re-resolve workspace A");- assert!(Arc::ptr_eq(&bind_a, &bind_a_again));-}--/// The per-workspace rebinding requirement, proven without any explicit-/// "rebind memory" call: switching the active user re-points-/// `workspace_dir`, and the accessor keys on that.-#[test]-fn rebind_workspace_updates_context_memory_binding() {- let dir_a = tempfile::tempdir().unwrap();- let dir_b = tempfile::tempdir().unwrap();- let ctx = CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_a.path().to_path_buf()),- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- };-- let bind_a = ctx.memory_binding().expect("bind workspace A");- ctx.rebind_workspace(dir_b.path(), Default::default())- .expect("rebind context workspace");-- assert_eq!(ctx.workspace_dir().unwrap(), dir_b.path());- let bind_b = ctx.memory_binding().expect("bind workspace B");- assert!(!Arc::ptr_eq(&bind_a, &bind_b));-}--/// The subsystem-config refresh half of the rebind requirement: a rebind-/// that passes a `[subsystems.memory] driver = "null"` config must make the-/// accessor report the null driver, not the default embedded one captured-/// before the user switch.-#[test]-fn rebind_workspace_refreshes_memory_subsystem_config() {- let dir_a = tempfile::tempdir().unwrap();- let ctx = CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_a.path().to_path_buf()),- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- };-- let bind_a = ctx.memory_binding().expect("bind workspace A");- let expected = if cfg!(feature = "modules") {- crate::core::subsystem::DriverClass::Module- } else {- crate::core::subsystem::DriverClass::Null- };- assert_eq!(bind_a.class(), expected);-- let null_cfg = crate::config::schema::MemorySubsystemConfig {- driver: "null".to_string(),- ..Default::default()- };- // This is the dangerous case: changing only the memory config for an- // already-bound workspace must replace the complete snapshot, so the- // binding cache sees the new (workspace, config) pair.- ctx.rebind_workspace(dir_a.path(), null_cfg)- .expect("rebind context subsystem config");-- let bind_b = ctx.memory_binding().expect("bind workspace B");- assert_eq!(bind_b.class(), crate::core::subsystem::DriverClass::Null);-}--/// `memory::global`'s clear-on-failed-rebind property, preserved-/// structurally: a workspace whose configured driver is refused resolves to-/// the fallback, never to another workspace's driver.-#[test]-fn failed_bind_never_returns_previous_workspace_binding() {- let dir_a = tempfile::tempdir().unwrap();- let dir_b = tempfile::tempdir().unwrap();- let a = CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_a.path().to_path_buf()),- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- };- let b = CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: Some(dir_b.path().to_path_buf()),- memory_subsystem: untrusted_external_memory_cfg(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- };-- let bind_a = a.memory_binding().expect("bind workspace A");- assert_eq!(bind_a.driver_id(), "tinymemory");- assert!(bind_a.fallback().is_none());-- let bind_b = b.memory_binding().expect("workspace B falls back");- assert_eq!(- bind_b.driver_id(),- "null",- "a refused driver must fall back, not inherit another workspace's"- );- let fallback = bind_b.fallback().expect("fallback provenance recorded");- assert_eq!(fallback.configured_driver, "supermemory");- assert!(!Arc::ptr_eq(&bind_a, &bind_b));-}--/// The single most important default in this step: no binding ⇒ the FULL-/// capability set, mirroring `core::all::group_allowed` with no context.-#[test]-fn memory_capabilities_defaults_open_without_a_workspace() {- let ctx = CoreContext {- host_kind: HostKind::Cli,- workspace_binding: RwLock::new(Arc::new(RwLock::new(WorkspaceBinding {- workspace_dir: None,- memory_subsystem: Default::default(),- }))),- domains: crate::core::runtime::DomainSet::full(),- tool_groups: Default::default(),- embedder_config: None,- user_skill_roots: true,- backend_transport: None,- };- assert!(ctx.memory_binding().is_err(), "no workspace ⇒ no binding");- assert_eq!(- ctx.memory_capabilities(),- tinymemory_api::capabilities::Capabilities::all(),- "a context with no binding must not deny any capability"- );-}--/// The no-context arm of `current_memory_capabilities`. Asserted through-/// the value the fallback branch yields rather than by calling it with an-/// empty `DEFAULT_CONTEXT`: that global is process-wide and another test in-/// the same binary may have set it, which would make a bare-/// `assert_eq!(current_memory_capabilities(), all())` order-dependently-/// flaky.-#[test]-fn current_memory_capabilities_defaults_open_without_a_context() {- assert_eq!(- crate::memory::binding::unbound_default_capabilities(),- tinymemory_api::capabilities::Capabilities::all()- );- // And when a context *is* ambient, the call resolves through it rather- // than erroring.- let ctx = CoreContext::for_test(crate::core::runtime::DomainSet::full(), None);- assert_eq!(- ctx.memory_capabilities(),- tinymemory_api::capabilities::Capabilities::all()- );-}--/// The DomainSet axis and the capability axis are independent (kernel.md-/// §3.7's three axes): a narrowed `DomainSet` must not narrow capabilities.-#[test]-fn capabilities_are_open_under_a_harness_domain_set() {- let ctx = CoreContext::for_test(crate::core::runtime::DomainSet::harness(), None);- assert_eq!(- ctx.memory_capabilities(),- tinymemory_api::capabilities::Capabilities::all()- );-}--fn overlay_for(workspace: &str, driver: Option<&str>) -> ContextOverlay {- let mut config = crate::config::Config::default();- config.workspace_dir = PathBuf::from(workspace);- if let Some(driver) = driver {- config.subsystems.memory.driver = driver.to_string();- }- ContextOverlay::new(- config,- crate::core::runtime::DomainSet::kernel(),- crate::tools::toolpacks::ToolGroups::none(),- )-}--#[test]-fn a_derived_context_without_a_memory_override_follows_the_parents_engine_switch() {- let parent = ctx("/tmp/share-ws");- let child = parent.derive_with(overlay_for("/tmp/share-ws", None));-- let mut switched = crate::config::schema::MemorySubsystemConfig::default();- switched.driver = "null".to_string();- parent- .set_memory_subsystem(std::path::Path::new("/tmp/share-ws"), switched.clone())- .unwrap();-- let child_driver = child- .workspace_binding- .read()- .unwrap()- .read()- .unwrap()- .memory_subsystem- .driver- .clone();- assert_eq!(- child_driver, "null",- "a rebind must reach the derived context"- );-}--#[test]-fn a_derived_context_with_its_own_memory_config_keeps_the_override() {- let parent = ctx("/tmp/override-ws");- let child = parent.derive_with(overlay_for("/tmp/override-ws", Some("null")));-- let mut switched = crate::config::schema::MemorySubsystemConfig::default();- switched.driver = "tinymemory".to_string();- parent- .set_memory_subsystem(std::path::Path::new("/tmp/override-ws"), switched)- .unwrap();- assert_eq!(- child- .workspace_binding- .read()- .unwrap()- .read()- .unwrap()- .memory_subsystem- .driver,- "null",- "a deliberate per-agent memory config is not overwritten by the parent"- );-}--#[test]-fn a_derived_context_on_another_workspace_is_not_shared() {- let parent = ctx("/tmp/parent-only-ws");- let child = parent.derive_with(overlay_for("/tmp/child-only-ws", None));- let mut switched = crate::config::schema::MemorySubsystemConfig::default();- switched.driver = "null".to_string();- parent- .set_memory_subsystem(std::path::Path::new("/tmp/parent-only-ws"), switched)- .unwrap();- assert_ne!(- child- .workspace_binding- .read()- .unwrap()- .read()- .unwrap()- .memory_subsystem- .driver,- "null"- );-}--#[test]-fn a_parent_workspace_rebind_does_not_move_a_derived_context() {- let parent = ctx("/tmp/shared-before-rebind");- let child = parent.derive_with(overlay_for("/tmp/shared-before-rebind", None));- let mut next_memory = crate::config::schema::MemorySubsystemConfig::default();- next_memory.driver = "null".to_string();-- parent- .rebind_workspace(std::path::Path::new("/tmp/next-user"), next_memory)- .unwrap();-- assert_eq!(- parent.workspace_dir().unwrap(),- PathBuf::from("/tmp/next-user")- );- assert_eq!(- child.workspace_dir().unwrap(),- PathBuf::from("/tmp/shared-before-rebind")- );- assert_eq!(- child- .workspace_binding- .read()- .unwrap()- .read()- .unwrap()- .memory_subsystem- .driver,- "tinycortex"- );-}