Skip to content

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

test(subagent_sessions): cover per-workspace legacy import markers

Steven Enamakel8121dcc24372
diff --git a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
index 1c628aa36e..3daca14f75 100644
--- a/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
+++ b/crates/openhuman-core/src/agent/orchestration/subagent_sessions/store.rs
@@ -20,7 +20,10 @@ impl SubagentSessionStore {
/// so it stays byte-identical. A missing file is the common case and a
/// no-op.
fn import_legacy(&self, docs: &super::store_documents::Docs) -> Result<(), String> {
- if docs.legacy_imported(&self.workspace_dir).map_err(|err| format!("{err:#}"))? {
+ if docs
+ .legacy_imported(&self.workspace_dir)
+ .map_err(|err| format!("{err:#}"))?
+ {
return Ok(());
}
let path = self.legacy_path();
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
index fc25962d73..f6b5ab215a 100644
--- 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
@@ -169,3 +169,21 @@ fn a_legacy_session_file_is_imported_once_and_left_byte_identical() {
assert_eq!(again.len(), 1);
assert_eq!(again[0].subagent_session_id, "legacy-1");
}
+
+#[test]
+fn workspaces_sharing_a_backend_each_import_their_own_legacy_file() {
+ let docs = docs_in(&MemoryStorage::new(), "local");
+ let (one, two) = (
+ std::path::Path::new("/ws/one"),
+ std::path::Path::new("/ws/two"),
+ );
+ assert!(!docs.legacy_imported(one).unwrap());
+ docs.import_legacy(one, &[session("from-one")]).unwrap();
+ assert!(docs.legacy_imported(one).unwrap());
+ assert!(
+ !docs.legacy_imported(two).unwrap(),
+ "importing one workspace must not suppress another's import"
+ );
+ docs.import_legacy(two, &[session("from-two")]).unwrap();
+ assert_eq!(docs.load().unwrap().len(), 2);
+}
diff --git a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs b/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
index 9f31d23b69..6a580ade1f 100644
--- a/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
+++ b/crates/openhuman-core/src/threads/store/legacy_import_tests.rs
@@ -149,3 +149,32 @@ fn threads_round_trip_through_the_backend_store() {
assert!(store.delete_thread("t", "2026-01-02T00:00:00Z").unwrap());
assert!(store.list_threads().unwrap().is_empty());
}
+
+#[test]
+fn legacy_import_marker_is_per_source_workspace() {
+ let a = crate::storage::source_key(Path::new("/ws/a"));
+ let b = crate::storage::source_key(Path::new("/ws/b"));
+ assert_ne!(a, b);
+ assert_eq!(a, crate::storage::source_key(Path::new("/ws/a")));
+}
+
+#[cfg(unix)]
+#[test]
+fn an_unreadable_legacy_log_is_an_error_not_an_empty_store() {
+ use std::os::unix::fs::PermissionsExt;
+ let dir = tempfile::tempdir().unwrap();
+ let root = backend::legacy_root(dir.path());
+ std::fs::create_dir_all(&root).unwrap();
+ std::fs::write(root.join("threads.jsonl"), "").unwrap();
+ std::fs::set_permissions(&root, std::fs::Permissions::from_mode(0o000)).unwrap();
+ // Root bypasses permission bits; only assert when the stat truly fails.
+ let blocked = std::fs::metadata(root.join("threads.jsonl")).is_err();
+ let result = ConversationStore::new(dir.path().to_path_buf()).list_threads();
+ std::fs::set_permissions(&root, std::fs::Permissions::from_mode(0o755)).unwrap();
+ if blocked {
+ assert!(
+ result.is_err(),
+ "a stat failure must surface so a retry can import"
+ );
+ }
+}