Skip to content

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

test(memory): add engine and scope memory tests

Steven Enamakelf4da7497dd83
diff --git a/crates/openhuman-core/src/memory/engine_tests.rs b/crates/openhuman-core/src/memory/engine_tests.rs
index 0509ced2d4..2bd98309a2 100644
--- a/crates/openhuman-core/src/memory/engine_tests.rs
+++ b/crates/openhuman-core/src/memory/engine_tests.rs
@@ -246,7 +246,7 @@ fn layout_v3_binds_its_own_engine_beside_legacy() {
// The migration holds both at once, whatever the setting says.
let explicit_legacy = bind_with_root(&config, None).unwrap();
- let explicit_v3 = bind_with_root(&config, Some("user:6512ab0f6512ab0f6512ab0f")).unwrap();
+ let explicit_v3 = bind_with_root(&config, Some("org:6512ab0f6512ab0f6512ab0f")).unwrap();
assert!(Arc::ptr_eq(&explicit_legacy.engine, &legacy.engine));
assert!(Arc::ptr_eq(&explicit_v3.engine, &v3.engine));
}
@@ -293,15 +293,51 @@ fn an_installed_engine_has_one_layout_unless_one_is_installed_per_root() {
#[test]
fn a_root_sets_the_scope_root_its_owner_and_the_cache_key() {
- let (settings, key) = rooted(EngineSettings::default(), Some("user:42"));
- assert_eq!(settings.scope_root.as_deref(), Some("user:42"));
+ // CortexDB's own API: `org:<id>` is the root, owned by the actor.
+ let (settings, key) = rooted(EngineSettings::default(), Some("org:42"), false, false);
+ assert_eq!(settings.scope_root.as_deref(), Some("org:42"));
assert_eq!(settings.scope_owner.as_deref(), Some("user:42"));
- assert_eq!(key, "|root=user:42");
- let (settings, key) = rooted(EngineSettings::default(), None);
+ assert!(!settings.tenant_root);
+ assert_eq!(settings.retired_scope_root, None);
+ assert_eq!(key, "|root=org:42|tenant=false|retired=-");
+ let (settings, key) = rooted(EngineSettings::default(), None, false, true);
assert_eq!(settings.scope_root, None);
+ assert_eq!(settings.retired_scope_root, None);
assert_eq!(key, "|root=legacy");
}
+#[test]
+fn the_hosted_wire_sends_no_root_and_legacy_read_names_the_user_segment() {
+ // TinyHumans: the backend pins `org:<id>`; no root, no `user:` segment.
+ let (settings, key) = rooted(EngineSettings::default(), Some("org:42"), true, false);
+ assert!(settings.tenant_root);
+ assert_eq!(settings.scope_root, None);
+ assert_eq!(settings.scope_owner, None);
+ assert_eq!(settings.retired_scope_root, None);
+ // During the move, the earlier `user:<id>` root is read and forgotten.
+ let (settings, read_too) = rooted(EngineSettings::default(), Some("org:42"), true, true);
+ assert_eq!(settings.retired_scope_root.as_deref(), Some("user:42"));
+ assert_ne!(key, read_too, "the flag rebuilds the engine");
+ let (settings, _) = rooted(EngineSettings::default(), Some("org:42"), false, true);
+ assert_eq!(settings.retired_scope_root.as_deref(), Some("user:42"));
+}
+
+#[test]
+fn legacy_user_segment_read_is_on_by_default_and_written_only_when_off() {
+ let config = crate::config::MemoryConfig::default();
+ assert!(config.legacy_user_segment_read);
+ let on = toml::to_string(&config).unwrap();
+ assert!(!on.contains("legacy_user_segment_read"), "{on}");
+ let off = crate::config::MemoryConfig {
+ legacy_user_segment_read: false,
+ ..config
+ };
+ let written = toml::to_string(&off).unwrap();
+ assert!(written.contains("legacy_user_segment_read = false"), "{written}");
+ let read: crate::config::MemoryConfig = toml::from_str("").unwrap();
+ assert!(read.legacy_user_segment_read);
+}
+
#[tokio::test]
async fn switching_to_v3_persists_and_rebinds_the_persons_own_config() {
let tmp = tempfile::tempdir().unwrap();
diff --git a/crates/openhuman-core/src/memory/scope_tests.rs b/crates/openhuman-core/src/memory/scope_tests.rs
index adb4192aac..76d4e481f2 100644
--- a/crates/openhuman-core/src/memory/scope_tests.rs
+++ b/crates/openhuman-core/src/memory/scope_tests.rs
@@ -116,11 +116,12 @@ fn validate_root_accepts_nodes_and_refuses_junk() {
fn a_user_root_is_the_account_id_or_a_hashed_local_id() {
assert_eq!(
user_root_for("6512AB0F6512ab0f6512ab0f").as_deref(),
- Some("user:6512ab0f6512ab0f6512ab0f")
+ Some("org:6512ab0f6512ab0f6512ab0f")
);
let local = user_root_for("local-megamind-macbook").unwrap();
- assert!(local.starts_with("user:local-"), "{local}");
- assert_eq!(local.len(), "user:local-".len() + 16);
+ assert!(local.starts_with("org:local-"), "{local}");
+ assert_eq!(local.len(), "org:local-".len() + 16);
+ assert!(!local.contains("user:"), "{local}");
assert!(!local.contains("megamind"), "no device name: {local}");
assert_eq!(Some(local), user_root_for("local-megamind-macbook"));
assert_eq!(user_root_for(crate::config::PRE_LOGIN_USER_ID), None);
@@ -133,7 +134,7 @@ fn the_user_root_is_read_from_where_the_config_lives() {
config.config_path = "/h/.openhuman/users/6512ab0f6512ab0f6512ab0f/config.toml".into();
assert_eq!(
user_root(&config).as_deref(),
- Some("user:6512ab0f6512ab0f6512ab0f")
+ Some("org:6512ab0f6512ab0f6512ab0f")
);
config.config_path = "/h/.openhuman/users/local/config.toml".into();
assert_eq!(user_root(&config), None);
@@ -167,3 +168,16 @@ fn layout_v3_pools_every_agents_chats_at_ws_main() {
let team = MemoryIdentity::team_member("acme", "writer").resolve(&config);
assert_eq!(chat_node(&team.layout), ns("team:acme/ws:main"));
}
+
+#[test]
+fn a_roots_actor_is_its_user_spelling() {
+ assert_eq!(actor_of_root("org:6512ab0f6512ab0f6512ab0f"), "user:6512ab0f6512ab0f6512ab0f");
+ assert_eq!(actor_of_root("org:local-0011223344556677"), "user:local-0011223344556677");
+ // The actor of the earlier root is the same account.
+ assert_eq!(
+ actor_of_root(&user_root_for("local-megamind-macbook").unwrap()),
+ user_root_for("local-megamind-macbook")
+ .unwrap()
+ .replacen("org:", "user:", 1)
+ );
+}