Skip to content

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

test(orchestration): add subagent session store document tests

Steven Enamakelfe662137c85c
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
new file mode 100644
index 0000000000..52dc239587
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store_documents_tests.rs
@@ -0,0 +1,70 @@
+use super::*;
+use crate::agent::orchestration::subagent_sessions::types::SubagentSessionStore;
+use crate::agent::orchestration::subagent_sessions::types::DurableSubagentStatus;
+use crate::storage::{MemoryStorage, Scope, StorageBackend};
+
+fn docs_in(storage: &MemoryStorage, scope: &str) -> Docs {
+ Docs::over(&storage.for_scope(&Scope::new(scope).unwrap()).unwrap())
+}
+
+fn session(id: &str) -> DurableSubagentSession {
+ serde_json::from_value(json!({
+ "subagentSessionId": id,
+ "parentSession": "parent",
+ "parentThreadId": "thread",
+ "workerThreadId": null,
+ "agentId": "researcher",
+ "displayName": null,
+ "model": null,
+ "sandboxMode": "workspace",
+ "actionRoot": null,
+ "taskKey": "task",
+ "taskTitle": "Task",
+ "currentTaskId": null,
+ "status": "idle",
+ "reusable": true,
+ "latestHistory": null,
+ "latestError": null,
+ "createdAt": "2026-01-01T00:00:00Z",
+ "updatedAt": "2026-01-01T00:00:00Z",
+ "lastUsedAt": "2026-01-01T00:00:00Z",
+ }))
+ .unwrap()
+}
+
+#[test]
+fn a_missing_list_loads_empty() {
+ assert!(docs_in(&MemoryStorage::new(), "local").load().unwrap().is_empty());
+}
+
+#[test]
+fn save_replaces_the_whole_list() {
+ let docs = docs_in(&MemoryStorage::new(), "local");
+ docs.save(&[session("a"), session("b")]).unwrap();
+ let loaded = docs.load().unwrap();
+ assert_eq!(loaded.len(), 2);
+ assert_eq!(loaded[0].subagent_session_id, "a");
+ assert_eq!(loaded[1].status, DurableSubagentStatus::Idle);
+ docs.save(&[session("c")]).unwrap();
+ let loaded = docs.load().unwrap();
+ assert_eq!(loaded.len(), 1);
+ assert_eq!(loaded[0].subagent_session_id, "c");
+}
+
+#[test]
+fn scopes_do_not_see_each_others_sessions() {
+ let storage = MemoryStorage::new();
+ docs_in(&storage, "alice").save(&[session("a")]).unwrap();
+ assert!(docs_in(&storage, "bob").load().unwrap().is_empty());
+ assert_eq!(docs_in(&storage, "alice").load().unwrap().len(), 1);
+}
+
+#[test]
+fn the_file_store_still_works_with_no_backend() {
+ let dir = tempfile::tempdir().unwrap();
+ let store = SubagentSessionStore::new(dir.path().to_path_buf());
+ assert!(store.load().unwrap().is_empty());
+ store.save(&[session("a")]).unwrap();
+ assert!(dir.path().join(".openhuman/subagent_sessions.json").exists());
+ assert_eq!(store.load().unwrap().len(), 1);
+}