Skip to content

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

test: cover legacy store import edge cases

Steven Enamakel78b96073a85d
diff --git a/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs b/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
index 04851ceca8..f57b2ef682 100644
--- a/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
+++ b/crates/openhuman-core/src/integrations/task_sources/store_import_tests.rs
@@ -119,3 +119,67 @@ fn legacy_sources_and_ledger_are_imported_once_through_the_public_api() {
forget(&db);
assert_eq!(live::list_sources(&default).unwrap().len(), 1);
}
+
+#[test]
+fn the_classic_opt_out_still_works_after_an_import() {
+ let (_dir, classic, default) = workspace();
+ live::add_source(
+ &classic,
+ ProviderSlug::Github,
+ None,
+ None,
+ filter(),
+ 600,
+ SourceTarget::AgentTodoProactive,
+ 10,
+ )
+ .unwrap();
+ assert_eq!(live::list_sources(&default).unwrap().len(), 1);
+ // The retired tables are gone from the legacy name; the legacy store
+ // starts again from a clean schema instead of trusting a stale version.
+ forget(&live::db_path(&default));
+ assert!(live::list_sources(&classic).unwrap().is_empty());
+ live::add_source(
+ &classic,
+ ProviderSlug::Github,
+ None,
+ None,
+ filter(),
+ 600,
+ SourceTarget::AgentTodoProactive,
+ 10,
+ )
+ .unwrap();
+}
+
+#[test]
+fn an_undecodable_source_row_keeps_the_legacy_table_in_service() {
+ let (_dir, classic, default) = workspace();
+ live::add_source(
+ &classic,
+ ProviderSlug::Github,
+ None,
+ None,
+ filter(),
+ 600,
+ SourceTarget::AgentTodoProactive,
+ 10,
+ )
+ .unwrap();
+ let db = live::db_path(&classic);
+ rusqlite::Connection::open(&db)
+ .unwrap()
+ .execute(
+ "INSERT INTO task_sources (id, provider, enabled, filter, interval_secs, target,
+ max_tasks_per_fetch, created_at)
+ VALUES ('bad', 'github', 1, 'not json', 600, '{}', 10, '2026-01-01T00:00:00Z')",
+ [],
+ )
+ .unwrap();
+ // The import fails, so nothing is retired and the store serves the
+ // legacy table (which cannot decode that row either).
+ assert!(live::list_sources(&default).is_err());
+ let tables = table_names(&db);
+ assert!(tables.contains(&"task_sources".to_string()));
+ assert!(!tables.contains(&"_legacy_task_sources".to_string()));
+}
diff --git a/crates/openhuman-core/src/security/approval/store_import_tests.rs b/crates/openhuman-core/src/security/approval/store_import_tests.rs
index f1355f1d21..02693e3bd5 100644
--- a/crates/openhuman-core/src/security/approval/store_import_tests.rs
+++ b/crates/openhuman-core/src/security/approval/store_import_tests.rs
@@ -141,3 +141,55 @@ fn the_classic_opt_out_keeps_the_legacy_tables() {
assert_eq!(live::list_pending(&classic).unwrap().len(), 1);
assert!(table_names(&live::db_path(&classic)).contains(&"pending_approvals".to_string()));
}
+
+#[test]
+fn an_old_schema_missing_a_table_is_imported_and_fully_retired() {
+ let (_dir, _classic, default) = workspace();
+ let db = live::db_path(&default);
+ std::fs::create_dir_all(db.parent().unwrap()).unwrap();
+ {
+ // The first schema: no audit/agent columns, and no flow_tool_trust.
+ let conn = rusqlite::Connection::open(&db).unwrap();
+ conn.execute_batch(
+ "CREATE TABLE pending_approvals (
+ request_id TEXT PRIMARY KEY, tool_name TEXT NOT NULL,
+ action_summary TEXT NOT NULL, args_redacted TEXT NOT NULL,
+ session_id TEXT NOT NULL, created_at TEXT NOT NULL,
+ expires_at TEXT, decided_at TEXT, decision TEXT);",
+ )
+ .unwrap();
+ conn.execute(
+ "INSERT INTO pending_approvals
+ (request_id, tool_name, action_summary, args_redacted, session_id, created_at)
+ VALUES ('old', 'composio', 'old row', '{}', 'a-credential-shaped-value', ?1)",
+ [Utc::now().to_rfc3339()],
+ )
+ .unwrap();
+ }
+ let pending = live::list_pending(&default).unwrap();
+ assert_eq!(pending.len(), 1);
+ assert_eq!(pending[0].request_id, "old");
+
+ // Both tables are retired, including the one the reader had to create, so
+ // a restart finds nothing to import and nothing alternates.
+ let tables = table_names(&db);
+ assert!(tables.contains(&"_legacy_pending_approvals".to_string()));
+ assert!(tables.contains(&"_legacy_flow_tool_trust".to_string()));
+ forget(&db);
+ assert_eq!(live::list_pending(&default).unwrap().len(), 1);
+ assert!(
+ !table_names(&db).iter().any(|t| t.ends_with("_2")),
+ "{:?}",
+ table_names(&db)
+ );
+ // The credential-shaped session id was scrubbed before it was read.
+ let conn = rusqlite::Connection::open(&db).unwrap();
+ let session: String = conn
+ .query_row(
+ "SELECT session_id FROM _legacy_pending_approvals",
+ [],
+ |r| r.get(0),
+ )
+ .unwrap();
+ assert_eq!(session, live::PRE_MIGRATION_SESSION_ID);
+}
diff --git a/tests/storage_default_import_e2e.rs b/tests/storage_default_import_e2e.rs
index dd7844556e..505b15c3a7 100644
--- a/tests/storage_default_import_e2e.rs
+++ b/tests/storage_default_import_e2e.rs
@@ -57,6 +57,17 @@ fn free_port() -> u16 {
}
fn start(home: &Path, workspace: &Path, url: Option<&str>) -> (Server, String) {
+ // The port is chosen, then released for the child to bind; if another
+ // process takes it in between, the child exits and a fresh port is tried.
+ for _attempt in 0..3 {
+ if let Some(started) = try_start(home, workspace, url) {
+ return started;
+ }
+ }
+ panic!("openhuman-core never started on a free port");
+}
+
+fn try_start(home: &Path, workspace: &Path, url: Option<&str>) -> Option<(Server, String)> {
let port = free_port();
// A debug build of the full product set needs more than the default 8 MiB
// main-thread stack to finish booting, so raise the limit first.
@@ -87,11 +98,11 @@ fn start(home: &Path, workspace: &Path, url: Option<&str>) -> (Server, String) {
loop {
if let Ok(response) = client.get(format!("{base}/health")).send() {
if response.status().is_success() {
- return (server, base);
+ return Some((server, base));
}
}
- if let Ok(Some(status)) = server.0.try_wait() {
- panic!("openhuman-core exited before serving: {status}");
+ if let Ok(Some(_)) = server.0.try_wait() {
+ return None;
}
assert!(
Instant::now() < deadline,