Skip to content

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

feat(flows): persist flow definitions in the store

Steven Enamakel4441a634d01b
diff --git a/crates/openhuman-core/src/flows/store.rs b/crates/openhuman-core/src/flows/store.rs
index 992e877c30..7e050d3a44 100644
--- a/crates/openhuman-core/src/flows/store.rs
+++ b/crates/openhuman-core/src/flows/store.rs
@@ -436,3 +436,7 @@ pub fn set_suggestion_status(config: &Config, id: &str, status: SuggestionStatus
let id = id.to_string();
run(async move { docs.set_suggestion_status(&id, status).await })
}
+
+#[cfg(test)]
+#[path = "store_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/flows/store_tests.rs b/crates/openhuman-core/src/flows/store_tests.rs
new file mode 100644
index 0000000000..7eaa430487
--- /dev/null
+++ b/crates/openhuman-core/src/flows/store_tests.rs
@@ -0,0 +1,76 @@
+//! The catalog's storage and the import of the files tinyflows used to write
+//! (`flows.db`, `checkpoints.db`, `drafts/*.json`) on first use.
+
+use super::*;
+use tinyflows::engine::Checkpointer;
+use tempfile::TempDir;
+
+fn fixture_workspace() -> std::path::PathBuf {
+ std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
+ .join("src/storage/import/fixtures/tinyflows/workspace")
+}
+
+fn copy_tree(from: &std::path::Path, to: &std::path::Path) {
+ std::fs::create_dir_all(to).unwrap();
+ for entry in std::fs::read_dir(from).unwrap() {
+ let entry = entry.unwrap();
+ let target = to.join(entry.file_name());
+ if entry.path().is_dir() {
+ copy_tree(&entry.path(), &target);
+ } else {
+ std::fs::copy(entry.path(), target).unwrap();
+ }
+ }
+}
+
+fn config(tmp: &TempDir) -> Config {
+ Config {
+ workspace_dir: tmp.path().to_path_buf(),
+ ..Config::default()
+ }
+}
+
+#[test]
+fn the_catalog_lives_in_its_own_workspace_database() {
+ let tmp = TempDir::new().unwrap();
+ let config = config(&tmp);
+ assert!(crate::storage::installed().is_none());
+ assert!(list_flows(&config).unwrap().0.is_empty());
+ assert_eq!(db_path(&config), tmp.path().join("flows/catalog.db"));
+ assert!(db_path(&config).is_file());
+}
+
+#[test]
+fn legacy_flows_drafts_and_checkpoints_are_imported_on_first_use_and_left_untouched() {
+ let tmp = TempDir::new().unwrap();
+ let config = config(&tmp);
+ copy_tree(&fixture_workspace(), tmp.path());
+ let flows_db = dir(&config).join("flows.db");
+ let before = std::fs::read(&flows_db).unwrap();
+
+ let (flows, _) = list_flows(&config).unwrap();
+ let mut ids: Vec<_> = flows.iter().map(|flow| flow.id.clone()).collect();
+ ids.sort();
+ assert_eq!(ids, ["flow-alpha", "flow-beta"]);
+ assert_eq!(super::super::draft_store::list_drafts(&config).unwrap().len(), 2);
+ assert_eq!(list_revisions(&config, "flow-alpha", 10).unwrap().len(), 2);
+ assert_eq!(get_flow_run(&config, "run-done").unwrap().unwrap().flow_id, "flow-alpha");
+
+ let checkpointer = crate::flows::tinyflows::open_flow_checkpointer(&config).unwrap();
+ let thread = crate::storage::block_on_anyhow(async move {
+ Ok(checkpointer.get_thread("run-1").await?.len())
+ })
+ .unwrap();
+ assert!(thread > 0, "the interrupted run's checkpoints came across");
+
+ assert_eq!(
+ std::fs::read(&flows_db).unwrap(),
+ before,
+ "flows.db was modified"
+ );
+
+ // Imported once: a flow removed afterwards stays removed after a restart.
+ remove_flow(&config, "flow-alpha").unwrap();
+ crate::storage::local::forget(&db_path(&config));
+ assert_eq!(list_flows(&config).unwrap().0.len(), 1);
+}
diff --git a/crates/openhuman-core/src/storage/import/tinyflows.rs b/crates/openhuman-core/src/storage/import/tinyflows.rs
index dadc1bfc88..7265223137 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows.rs
@@ -286,6 +286,6 @@ fn finish(domain: &'static str, outcome: Result<Outcome>) -> Report {
Report { domain, outcome }
}
-#[cfg(test)]
+#[cfg(all(test, feature = "flows"))]
#[path = "tinyflows_tests.rs"]
mod tests;