Skip to content

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

test(memory): cover channel metadata stamping and legacy map quarantine

Steven Enamakel55486b132599
diff --git a/crates/openhuman-core/src/channels/controllers/ops/connect/memory_tests.rs b/crates/openhuman-core/src/channels/controllers/ops/connect/memory_tests.rs
index 7f62ea7330..6933f39100 100644
--- a/crates/openhuman-core/src/channels/controllers/ops/connect/memory_tests.rs
+++ b/crates/openhuman-core/src/channels/controllers/ops/connect/memory_tests.rs
@@ -194,8 +194,11 @@ async fn missing_or_corrupt_legacy_map_does_not_block_stamped_forget() {
assert_eq!(clear_channel_memory(&config, "discord").await.unwrap(), 1);
assert!(engine.is_empty());
if corrupt {
- assert_eq!(std::fs::read(&legacy_file).unwrap(), corrupt_bytes);
- assert!(!legacy_file.with_extension("json.corrupt").exists());
+ assert!(!legacy_file.exists());
+ assert_eq!(
+ std::fs::read(legacy_file.with_extension("json.corrupt")).unwrap(),
+ corrupt_bytes
+ );
} else {
assert!(!legacy_file.exists());
}
diff --git a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
index 51b73c890b..103e863154 100644
--- a/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/hooks_tests.rs
@@ -2,7 +2,7 @@ use super::*;
use tinymemory_api::{
Error as MemoryApiError, ItemKind, LearningKind, MemoryEngine, MemoryMeta, MetaFilter, Role,
- StoreItem,
+ StoreItem, Turn,
};
use tinymemory_tools::recall::SkipReason;
@@ -68,7 +68,7 @@ async fn run_post_turn(
identity: &tinymemory_tools::layout::identity::ResolvedIdentity,
(thread, index, text, calls, at): PostTurnArgs,
) {
- post_turn(config, identity, thread, index, text, calls, at).await;
+ post_turn(config, identity, thread, index, text, calls, at, None).await;
}
#[test]
@@ -77,6 +77,46 @@ fn turn_indices_follow_the_committed_transcript() {
assert_eq!(user_turn_index(3), 6);
}
+#[test]
+fn channel_metadata_does_not_change_stable_ids_for_either_conversation_turn_role() {
+ for role in [Role::User, Role::Assistant] {
+ let mut tagged = StoreItem::Conversation {
+ turns: vec![Turn::new(role.clone(), "same turn")],
+ meta: MemoryMeta::default(),
+ };
+ let untagged = tagged.clone();
+ tagged.meta_mut().channel = Some("telegram".into());
+
+ assert_eq!(untagged.fingerprint(), tagged.fingerprint());
+ }
+}
+
+#[tokio::test]
+async fn a_channel_reply_is_stamped_with_channel_metadata() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ let identity = tinymemory_tools::layout::identity::Identity::agent("channel-agent")
+ .resolve(&crate::memory::scope::identity_pins(&config));
+
+ post_turn(
+ &config,
+ &identity,
+ "channel-thread".into(),
+ 1,
+ "reply from telegram".into(),
+ Vec::new(),
+ Utc::now(),
+ Some("telegram".into()),
+ )
+ .await;
+
+ let turns = stored(&engine, MetaFilter::kinds([ItemKind::Conversation])).await;
+ assert_eq!(turns.len(), 1);
+ assert_eq!(turns[0].meta.channel.as_deref(), Some("telegram"));
+ assert!(turns[0].text.contains("assistant: reply from telegram"));
+}
+
#[test]
fn typed_skip_reasons_expose_only_account_wide_errors() {
let account_wide = [