Skip to content

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

chore: files changed crates/openhuman-core/src/memory/import_tests.rs

Steven Enamakel7108644646a0
diff --git a/crates/openhuman-core/src/memory/import_tests.rs b/crates/openhuman-core/src/memory/import_tests.rs
index 0433cb8231..9fadea5f55 100644
--- a/crates/openhuman-core/src/memory/import_tests.rs
+++ b/crates/openhuman-core/src/memory/import_tests.rs
@@ -306,3 +306,221 @@ async fn starting_import_or_retry_while_a_peer_driver_runs_gives_mode_specific_g
}
}
}
+
+const HOST_LEGACY_MEMORY_DDL: &str = r#"
+CREATE TABLE memory_docs (
+ document_id TEXT PRIMARY KEY, namespace TEXT NOT NULL, key TEXT NOT NULL, title TEXT NOT NULL,
+ content TEXT NOT NULL, source_type TEXT NOT NULL, priority TEXT NOT NULL, tags_json TEXT NOT NULL,
+ metadata_json TEXT NOT NULL, category TEXT NOT NULL, session_id TEXT, created_at REAL NOT NULL,
+ updated_at REAL NOT NULL, markdown_rel_path TEXT NOT NULL, taint TEXT NOT NULL DEFAULT 'internal',
+ logical_namespace TEXT, UNIQUE(namespace, key));
+CREATE TABLE kv_global (key TEXT PRIMARY KEY, value_json TEXT NOT NULL, updated_at REAL NOT NULL);
+CREATE TABLE kv_namespace (namespace TEXT NOT NULL, key TEXT NOT NULL, value_json TEXT NOT NULL, updated_at REAL NOT NULL,
+ PRIMARY KEY(namespace, key));
+CREATE TABLE episodic_log (id INTEGER PRIMARY KEY AUTOINCREMENT, session_id TEXT NOT NULL, timestamp REAL NOT NULL,
+ role TEXT NOT NULL, content TEXT NOT NULL, lesson TEXT, tool_calls_json TEXT, cost_microdollars INTEGER DEFAULT 0);
+CREATE TABLE user_profile (facet_id TEXT PRIMARY KEY, facet_type TEXT NOT NULL, key TEXT NOT NULL, value TEXT NOT NULL,
+ confidence REAL NOT NULL DEFAULT 0.5, evidence_count INTEGER NOT NULL DEFAULT 1, source_segment_ids TEXT,
+ first_seen_at REAL NOT NULL, last_seen_at REAL NOT NULL, state TEXT NOT NULL DEFAULT 'active',
+ stability REAL NOT NULL DEFAULT 0.0, user_state TEXT NOT NULL DEFAULT 'auto', evidence_refs_json TEXT,
+ class TEXT, cue_families_json TEXT, UNIQUE(facet_type, key));
+"#;
+
+fn legacy_document(config: &Config, id: &str, title: &str, body: &str) {
+ let db = config.workspace_dir.join("memory/memory.db");
+ std::fs::create_dir_all(db.parent().unwrap()).unwrap();
+ let conn = crate::storage::rusqlite::Connection::open(db).unwrap();
+ conn.execute_batch(HOST_LEGACY_MEMORY_DDL).unwrap();
+ conn.execute(
+ "INSERT INTO memory_docs (document_id, namespace, key, title, content, source_type, priority,
+ tags_json, metadata_json, category, session_id, created_at, updated_at, markdown_rel_path,
+ taint, logical_namespace)
+ VALUES (?1, 'document_notes', ?1, ?2, ?3, 'chat', 'normal', '[]', '{}', 'core', NULL,
+ 1700000000.0, 1700000000.0, '', 'internal', NULL)",
+ crate::storage::rusqlite::params![id, title, body],
+ )
+ .unwrap();
+}
+
+async fn wait_for_host_import(config: &Config) -> ImportState {
+ for _ in 0..100_000 {
+ let state = status(config);
+ if state.phase == ImportPhase::Done && !is_running(&config.workspace_dir) {
+ return state;
+ }
+ tokio::task::yield_now().await;
+ }
+ panic!("the Host import did not finish and release its slot");
+}
+
+async fn assert_reference_contains(
+ engine: &tinymemory_api::conformance::ReferenceEngine,
+ text: &str,
+) {
+ use tinymemory_api::{ItemKind, MetaFilter};
+
+ let items = crate::memory::test_fixtures::stored(
+ engine,
+ MetaFilter {
+ kinds: vec![ItemKind::Document],
+ ..MetaFilter::default()
+ },
+ )
+ .await;
+ assert!(
+ items.iter().any(|item| item.text.contains(text)),
+ "{items:?}"
+ );
+}
+
+#[tokio::test]
+async fn a_real_legacy_document_imports_through_the_host_adapter() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ legacy_document(
+ &config,
+ "host-import-doc",
+ "Host import",
+ "real legacy body",
+ );
+
+ let started = start(&crate::core::runtime::DispatchCtx::ambient(), &config, true)
+ .await
+ .unwrap();
+ assert_eq!(started.phase, ImportPhase::Running);
+ assert_eq!(started.total, 1);
+
+ let done = wait_for_host_import(&config).await;
+ assert_eq!(done.imported, 1);
+ assert_eq!(done.failed, 0);
+ let file = FileCheckpointStore::new(&config.workspace_dir).load();
+ assert_eq!(
+ file.checkpoint.documents.as_deref(),
+ Some("host-import-doc")
+ );
+ assert!(file.failed.is_empty());
+ assert_reference_contains(&engine, "real legacy body").await;
+}
+
+#[tokio::test]
+async fn an_interrupted_import_resumes_through_the_host_adapter() {
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ legacy_document(
+ &config,
+ "host-resume-doc",
+ "Host resume",
+ "resumed legacy body",
+ );
+ let mut interrupted = ImportFile::default();
+ interrupted.state.phase = ImportPhase::Running;
+ interrupted.state.total = 1;
+ FileCheckpointStore::new(&config.workspace_dir)
+ .save(&interrupted)
+ .unwrap();
+
+ assert!(
+ resume_interrupted_with(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Arc::new(|| false),
+ Arc::new(|_: &Config| true),
+ )
+ .await
+ );
+
+ let done = wait_for_host_import(&config).await;
+ assert_eq!(done.imported, 1);
+ assert_eq!(done.failed, 0);
+ let file = FileCheckpointStore::new(&config.workspace_dir).load();
+ assert_eq!(
+ file.checkpoint.documents.as_deref(),
+ Some("host-resume-doc")
+ );
+ assert_reference_contains(&engine, "resumed legacy body").await;
+}
+
+#[tokio::test]
+async fn retry_failed_reimports_a_real_legacy_row_through_the_host_adapter() {
+ use tinymemory_integrations::import::FailedItem;
+
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ legacy_document(
+ &config,
+ "host-retry-doc",
+ "Host retry",
+ "retried legacy body",
+ );
+ let mut retry_state = ImportFile::default();
+ retry_state.state.phase = ImportPhase::Done;
+ retry_state.state.total = 1;
+ retry_state.state.failed = 1;
+ retry_state.failed.push(FailedItem {
+ id: "memory_docs:host-retry-doc".to_string(),
+ reason: "the prior engine refused this row".to_string(),
+ });
+ FileCheckpointStore::new(&config.workspace_dir)
+ .save(&retry_state)
+ .unwrap();
+
+ let started = retry_failed(&crate::core::runtime::DispatchCtx::ambient(), &config)
+ .await
+ .unwrap();
+ assert_eq!(started.phase, ImportPhase::Running);
+ let done = wait_for_host_import(&config).await;
+ assert_eq!(done.failed, 0);
+ assert_eq!(done.imported, 1);
+ let file = FileCheckpointStore::new(&config.workspace_dir).load();
+ assert!(file.failed.is_empty());
+ assert!(!file.retrying);
+ assert_reference_contains(&engine, "retried legacy body").await;
+}
+
+#[tokio::test]
+async fn an_interrupted_retry_resumes_its_real_legacy_row() {
+ use tinymemory_integrations::import::FailedItem;
+
+ let tmp = tempfile::tempdir().unwrap();
+ let config = config_in(&tmp);
+ let engine = bind_reference(&config);
+ legacy_document(
+ &config,
+ "host-retry-resume-doc",
+ "Host retry resume",
+ "resumed retry body",
+ );
+ let mut interrupted = ImportFile::default();
+ interrupted.state.phase = ImportPhase::Running;
+ interrupted.state.total = 1;
+ interrupted.state.failed = 1;
+ interrupted.retrying = true;
+ interrupted.failed.push(FailedItem {
+ id: "memory_docs:host-retry-resume-doc".to_string(),
+ reason: "the prior retry was interrupted".to_string(),
+ });
+ FileCheckpointStore::new(&config.workspace_dir)
+ .save(&interrupted)
+ .unwrap();
+
+ assert!(
+ resume_interrupted_with(
+ &crate::core::runtime::DispatchCtx::ambient(),
+ &config,
+ Arc::new(|| false),
+ Arc::new(|_: &Config| true),
+ )
+ .await
+ );
+
+ let done = wait_for_host_import(&config).await;
+ assert_eq!(done.failed, 0);
+ assert_eq!(done.imported, 1);
+ let file = FileCheckpointStore::new(&config.workspace_dir).load();
+ assert!(file.failed.is_empty());
+ assert!(!file.retrying);
+ assert_reference_contains(&engine, "resumed retry body").await;
+}