Skip to content

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

test(session_host): add test module for permanent runtime session

Steven Enamakel6ca29f544ae9
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs
index be88b5d0cf..ce332bab5b 100644
--- a/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent.rs
@@ -56,3 +56,7 @@ impl OpenHumanTurnPrelude {
.or(preparation.prefix.take());
}
}
+
+#[cfg(test)]
+#[path = "permanent_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/agent/session_host/runtime_session/permanent_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent_tests.rs
new file mode 100644
index 0000000000..238a4315fb
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_host/runtime_session/permanent_tests.rs
@@ -0,0 +1,44 @@
+use super::*;
+use std::{collections::HashSet, sync::Arc};
+use tinyagents_session::transcript::{session_stem, SessionRef};
+use tinyinference_llm::message::Message;
+use tinytools::ToolSpec;
+
+fn spec(name: &str) -> Arc<ToolSpec> {
+ Arc::new(ToolSpec {
+ name: name.into(),
+ description: "d".into(),
+ parameters: serde_json::json!({"type": "object"}),
+ ..Default::default()
+ })
+}
+
+#[test]
+fn permanent_catalogue_uses_the_openhuman_marker_and_closing_tag() {
+ let prefix = PrefixSnapshot::new(vec![Message::system("host prefix")]);
+ let names: HashSet<String> = ["B_TOOL".to_string(), "A_TOOL".to_string()].into();
+ let refreshed = tinyagents_runtime::refresh_prefix(
+ &prefix,
+ &[spec("B_TOOL"), spec("A_TOOL"), spec("OTHER")],
+ &names,
+ "<openhuman-permanent-tools>\n",
+ "</openhuman-permanent-tools>",
+ )
+ .expect("catalogue is appended");
+ let last = refreshed.messages().last().unwrap().text();
+ assert!(last.starts_with("<openhuman-permanent-tools>\n"));
+ assert!(last.ends_with("</openhuman-permanent-tools>"));
+ assert!(last.find("A_TOOL").unwrap() < last.find("B_TOOL").unwrap());
+ assert!(!last.contains("OTHER"));
+ assert_eq!(refreshed.messages()[0].text(), "host prefix");
+}
+
+#[test]
+fn transcript_stem_for_a_thread_and_agent_is_stable_and_timestamp_free() {
+ let a = session_stem(&SessionRef::scoped("thread-1", "orchestrator"));
+ let b = session_stem(&SessionRef::scoped("thread-1", "orchestrator"));
+ assert_eq!(a, b);
+ assert_ne!(a, session_stem(&SessionRef::scoped("thread-2", "orchestrator")));
+ assert!(!a.chars().any(|c| c == '/' || c == '\\'));
+ println!("STEM={a}");
+}