Skip to content

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

test(session_store): cover session store module behaviour

Steven Enamakel3fe9f20dd02f
diff --git a/crates/openhuman-core/src/agent/session_store/mod_tests.rs b/crates/openhuman-core/src/agent/session_store/mod_tests.rs
index 5b09fd1f70..84a97d1e45 100644
--- a/crates/openhuman-core/src/agent/session_store/mod_tests.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod_tests.rs
@@ -175,3 +175,54 @@ fn each_workspace_keeps_its_sessions_in_its_own_database() {
);
assert!(first.path().join("storage").join("storage.db").is_file());
}
+
+fn started(thread: &str, request: &str) -> tinyagents_session::turn_state::TurnState {
+ tinyagents_session::turn_state::TurnState::started(thread, request, 4, "2026-01-01T00:00:00Z")
+}
+
+#[tokio::test]
+async fn a_threads_turn_state_survives_a_restart_of_the_workspace_store() {
+ let dir = tempfile::tempdir().unwrap();
+ turn_states_for(dir.path())
+ .put(&started("thread-1", "req-1"))
+ .unwrap();
+
+ // A restart: every handle and cached default backend is dropped.
+ release_workspace_defaults();
+
+ let resumed = turn_states_for(dir.path())
+ .get("thread-1")
+ .unwrap()
+ .expect("the snapshot is read back from the backend");
+ assert_eq!(resumed.request_id, "req-1");
+ // The sweep a cold boot runs settles it as interrupted, and it persists.
+ let swept = default_turn_states_for(dir.path())
+ .mark_all_interrupted("2026-01-01T00:01:00Z")
+ .unwrap();
+ assert_eq!(swept, 1);
+ assert_eq!(
+ turn_states_for(dir.path())
+ .get("thread-1")
+ .unwrap()
+ .unwrap()
+ .lifecycle,
+ tinyagents_session::turn_state::TurnLifecycle::Interrupted
+ );
+}
+
+#[tokio::test]
+async fn a_stashed_attachment_survives_a_restart_of_the_workspace_store() {
+ let dir = tempfile::tempdir().unwrap();
+ let data_uri = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==";
+ let stash = attachment_stash_for(dir.path()).expect("a stash for the default tenant");
+ stash.write("att-1", data_uri).await.unwrap();
+
+ release_workspace_defaults();
+
+ let resumed = attachment_stash_for(dir.path()).expect("a stash after the restart");
+ assert_eq!(
+ resumed.read_data_uri("att-1").await.unwrap().as_deref(),
+ Some(data_uri)
+ );
+ assert!(resumed.read_data_uri("never-stashed").await.unwrap().is_none());
+}