Skip to content

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

test(threads): add transcript test module

Steven Enamakelae3c1cd7c1f1
diff --git a/crates/openhuman-core/src/threads/ops/transcript.rs b/crates/openhuman-core/src/threads/ops/transcript.rs
index 6482304fa6..76c3f99f6a 100644
--- a/crates/openhuman-core/src/threads/ops/transcript.rs
+++ b/crates/openhuman-core/src/threads/ops/transcript.rs
@@ -62,3 +62,7 @@ pub async fn transcript_get(
});
Ok(envelope(page, Some(counts), pagination))
}
+
+#[cfg(test)]
+#[path = "transcript_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/threads/ops/transcript_tests.rs b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
new file mode 100644
index 0000000000..9809454d1a
--- /dev/null
+++ b/crates/openhuman-core/src/threads/ops/transcript_tests.rs
@@ -0,0 +1,187 @@
+//! `threads.transcript_get` and `threads.token_usage` read a thread through
+//! the session store, under the key the request's own context resolves.
+
+use super::*;
+use crate::core::runtime::{ContextOverlay, CoreContext, DispatchCtx, DomainSet};
+use tinyagents_session::transcript::{
+ MessageUsage, SessionRef, TranscriptMessage, TranscriptMeta, TranscriptTurn, TurnUsage,
+};
+
+const THREAD: &str = "thread-store";
+
+fn ctx_for(workspace: &std::path::Path, profile: Option<&str>) -> DispatchCtx {
+ let mut config = crate::config::Config::default();
+ config.workspace_dir = workspace.to_path_buf();
+ let mut overlay = ContextOverlay::new(
+ config,
+ DomainSet::kernel(),
+ crate::tools::toolpacks::ToolGroups::none(),
+ );
+ if let Some(profile) = profile {
+ overlay = overlay.profile(profile);
+ }
+ DispatchCtx::new(CoreContext::for_test(DomainSet::full(), None).derive_with(overlay))
+}
+
+fn meta(agent: &str, agent_type: &str) -> TranscriptMeta {
+ TranscriptMeta {
+ agent_name: agent.into(),
+ agent_id: Some(agent.into()),
+ agent_type: Some(agent_type.into()),
+ dispatcher: "native".into(),
+ provider: Some("openhuman".into()),
+ model: Some("test-model".into()),
+ created: "2026-10-15T00:00:00Z".into(),
+ updated: "2026-10-15T00:00:00Z".into(),
+ turn_count: 1,
+ prefix_message_count: None,
+ input_tokens: 0,
+ output_tokens: 0,
+ cached_input_tokens: 0,
+ charged_amount_usd: 0.0,
+ thread_id: Some(THREAD.into()),
+ task_id: None,
+ session_id: None,
+ parent_session_id: None,
+ }
+}
+
+fn usage(input: u64, output: u64) -> TurnUsage {
+ TurnUsage {
+ provider: "openhuman".into(),
+ model: "test-model".into(),
+ usage: MessageUsage {
+ input,
+ output,
+ context_window: 200_000,
+ ..Default::default()
+ },
+ ts: "2026-10-15T00:00:01Z".into(),
+ reasoning_content: None,
+ tool_calls: Vec::new(),
+ iteration: 1,
+ }
+}
+
+/// A root turn and one sub-agent run of [`THREAD`], written where the session
+/// host and the sub-agent runner write them: `ctx`'s transcript store.
+async fn write_thread(ctx: &DispatchCtx) {
+ let locator = super::super::support::transcript_store(ctx)
+ .await
+ .expect("store")
+ .locator();
+ let root_meta = meta("orchestrator", "root");
+ let turn = vec![
+ TranscriptMessage::user("hello"),
+ TranscriptMessage::assistant("hi there"),
+ ];
+ locator
+ .open_session(
+ &SessionRef::scoped(THREAD, "orchestrator"),
+ root_meta.clone(),
+ )
+ .unwrap()
+ .append_turn(TranscriptTurn {
+ prev: &[],
+ next: &turn,
+ meta: &root_meta,
+ turn_usage: Some(&usage(100, 10)),
+ request_id: Some("req-1"),
+ tools: None,
+ })
+ .unwrap();
+ let child_meta = meta("researcher", "subagent");
+ let child = vec![
+ TranscriptMessage::user("look it up"),
+ TranscriptMessage::assistant("found it"),
+ ];
+ locator
+ .open_stem("1700000000_orchestrator__researcher", child_meta.clone())
+ .unwrap()
+ .append_turn(TranscriptTurn {
+ prev: &[],
+ next: &child,
+ meta: &child_meta,
+ turn_usage: Some(&usage(40, 4)),
+ request_id: None,
+ tools: None,
+ })
+ .unwrap();
+}
+
+#[tokio::test]
+async fn a_profiles_thread_is_read_from_its_own_store() {
+ let dir = tempfile::tempdir().unwrap();
+ let profile = ctx_for(dir.path(), Some("profile-t"));
+ write_thread(&profile).await;
+
+ let page = transcript_get(
+ &profile,
+ TranscriptGetRequest {
+ thread_id: THREAD.into(),
+ cursor: None,
+ limit: None,
+ },
+ )
+ .await
+ .expect("transcript page")
+ .value
+ .data
+ .expect("page data");
+ assert!(page.has_transcript, "the profile reads its own transcript");
+ assert!(!page.items.is_empty());
+
+ let spend = super::super::usage::token_usage(
+ &profile,
+ super::super::usage::ThreadTokenUsageRequest {
+ thread_id: THREAD.into(),
+ },
+ )
+ .await
+ .expect("usage")
+ .value
+ .data
+ .expect("usage data");
+ assert!(spend.has_usage);
+ assert_eq!(
+ spend.input_tokens, 140,
+ "root and sub-agent are both counted"
+ );
+ assert_eq!(spend.output_tokens, 14);
+ assert_eq!(spend.subagents.len(), 1);
+ assert_eq!(spend.subagents[0].agent_id, "researcher");
+
+ // The same workspace without the profile resolves another key, and so
+ // never sees the profile's thread.
+ let desktop = ctx_for(dir.path(), None);
+ let page = transcript_get(
+ &desktop,
+ TranscriptGetRequest {
+ thread_id: THREAD.into(),
+ cursor: None,
+ limit: None,
+ },
+ )
+ .await
+ .unwrap()
+ .value
+ .data
+ .unwrap();
+ assert!(!page.has_transcript);
+}
+
+#[tokio::test]
+async fn a_blank_thread_id_is_refused() {
+ let dir = tempfile::tempdir().unwrap();
+ let err = transcript_get(
+ &ctx_for(dir.path(), None),
+ TranscriptGetRequest {
+ thread_id: " ".into(),
+ cursor: None,
+ limit: None,
+ },
+ )
+ .await
+ .expect_err("blank thread id");
+ assert!(err.contains("thread_id is required"));
+}