Skip to content

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

refactor(cron): route test cron reads through the module client

Steven Enamakel2731a21bb36b
diff --git a/crates/openhuman-core/Cargo.toml b/crates/openhuman-core/Cargo.toml
index cc12ab65d6..a2bba49d6c 100644
--- a/crates/openhuman-core/Cargo.toml
+++ b/crates/openhuman-core/Cargo.toml
@@ -520,9 +520,9 @@ tinybox-core = { path = "../../vendor/tinybox/crates/tinybox-core" }
tinymemory-api = { path = "../../vendor/tinymemory/crates/tinymemory-api", features = ["conformance"] }
# The document catalog's `*_for_test` fixtures, which the flows store forwards
# in test builds.
-tinyflows-drivers = { path = "../../vendor/tinyflows/crates/tinyflows-drivers", default-features = false, features = ["schedule", "test-fixtures"] }
+tinyflows-drivers = { path = "../../vendor/tinyflows/crates/tinyflows-drivers", default-features = false, features = ["test-fixtures"] }
# The real tinyflows module, linked into the test binary (never the product) as
-# the fixture behind `modules::schedule::fixture`: the scheduler runtime, job
+# the fixture behind `modules::tinyflows::fixture`: the scheduler runtime, job
# store and schedule maths that `cron::` reaches over the bus.
tinyflows-module = { path = "../../vendor/tinyflows/crates/tinyflows-module", features = ["static-link"] }
# Test fixtures derive a known account from the BIP-39 vector phrase. Production
diff --git a/crates/openhuman-core/src/cron/client.rs b/crates/openhuman-core/src/cron/client.rs
index ace25691a7..aef0e1f14b 100644
--- a/crates/openhuman-core/src/cron/client.rs
+++ b/crates/openhuman-core/src/cron/client.rs
@@ -227,6 +227,62 @@ where
crate::storage::block_on_anyhow(f(config.clone()))
}
+/// Reading a scope's cron store straight through the module, for tests that
+/// stage a backend and check what an importer or another writer left in it.
+#[cfg(test)]
+pub(crate) mod testing {
+ use super::*;
+ use crate::storage::{Scope, StorageBackend};
+ use std::sync::Arc;
+ use tinyflows_bus::schedule::types::CronRun;
+
+ fn run<T: Send + 'static>(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ operation: StoreOperation,
+ ) -> Result<T>
+ where
+ T: DeserializeOwned,
+ {
+ let config = Config::default();
+ let scope = DocScope::on_backend(&config, Arc::clone(backend), scope.clone());
+ crate::storage::block_on_anyhow(async move { store_in(&config, &scope, operation).await })
+ }
+
+ pub(crate) fn list_jobs(backend: &Arc<dyn StorageBackend>, scope: &Scope) -> Result<Vec<CronJob>> {
+ run(backend, scope, StoreOperation::List)
+ }
+
+ pub(crate) fn get_job(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ job_id: &str,
+ ) -> Result<CronJob> {
+ run(
+ backend,
+ scope,
+ StoreOperation::Get {
+ job_id: job_id.to_string(),
+ },
+ )
+ }
+
+ pub(crate) fn list_runs(
+ backend: &Arc<dyn StorageBackend>,
+ scope: &Scope,
+ job_id: &str,
+ ) -> Result<Vec<CronRun>> {
+ run(
+ backend,
+ scope,
+ StoreOperation::ListRuns {
+ job_id: job_id.to_string(),
+ limit: 50,
+ },
+ )
+ }
+}
+
#[cfg(test)]
#[path = "client_tests.rs"]
mod tests;
diff --git a/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs
index 3318800db9..04a174e527 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows_cron_tests.rs
@@ -1,6 +1,6 @@
use super::*;
use crate::storage::MemoryStorage;
-use tinyflows_drivers::schedule::CronDocuments;
+use crate::cron::client::testing as cron_store;
fn copy_tree(from: &Path, to: &Path) {
std::fs::create_dir_all(to).unwrap();
@@ -38,9 +38,6 @@ fn run_with_imports_legacy_cron_jobs_whatever_the_flows_gate() {
Outcome::Imported { written, .. } => assert!(*written > 0),
other => panic!("expected the cron jobs to import, got {other:?}"),
}
- let docs = Arc::clone(backend.for_scope(&Scope::local()).unwrap().documents());
- let jobs =
- crate::storage::block_on_anyhow(async move { CronDocuments::new(docs).list_jobs().await })
- .unwrap();
+ let jobs = cron_store::list_jobs(&backend, &Scope::local()).unwrap();
assert!(!jobs.is_empty());
}
diff --git a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
index 048147a4a2..e7548894e4 100644
--- a/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
+++ b/crates/openhuman-core/src/storage/import/tinyflows_tests.rs
@@ -6,7 +6,7 @@ use std::collections::BTreeMap;
use tempfile::TempDir;
use tinyflows::engine::Checkpointer;
use tinyflows_drivers::catalog::FlowCatalogDocuments;
-use tinyflows_drivers::schedule::CronDocuments;
+use crate::cron::client::testing as cron_store;
use tinyflows_drivers::DriverCheckpointer;
fn fixtures() -> PathBuf {
@@ -190,32 +190,27 @@ fn cron_jobs_and_runs_come_across_with_their_fields() {
assert_eq!(written(outcome), 3 + 4);
let expected = expected()["cron"].clone();
- let cron = CronDocuments::new(documents(&backend, &Scope::local()));
- crate::storage::block_on_anyhow(async move {
- for legacy in expected["jobs"].as_array().unwrap() {
- let legacy_id = legacy["id"].as_str().unwrap();
- // A flow-schedule job is filed under an id derived from its flow.
- let new_id = if legacy["job_type"] == "flow" {
- format!("flow:{}", legacy["command"].as_str().unwrap())
- } else {
- legacy_id.to_string()
- };
- let job = cron.get_job(&new_id).await?;
- let mut got = json(&job);
- got.as_object_mut().unwrap().remove("id");
- let mut want = legacy.clone();
- want.as_object_mut().unwrap().remove("id");
- assert_eq!(got, want, "job {legacy_id}");
- let runs = cron.list_runs(&new_id, 50).await?;
- assert_eq!(
- runs.len(),
- expected["runs"][legacy_id].as_array().unwrap().len(),
- "runs of {legacy_id}"
- );
- }
- Ok(())
- })
- .unwrap();
+ for legacy in expected["jobs"].as_array().unwrap() {
+ let legacy_id = legacy["id"].as_str().unwrap();
+ // A flow-schedule job is filed under an id derived from its flow.
+ let new_id = if legacy["job_type"] == "flow" {
+ format!("flow:{}", legacy["command"].as_str().unwrap())
+ } else {
+ legacy_id.to_string()
+ };
+ let job = cron_store::get_job(&backend, &Scope::local(), &new_id).unwrap();
+ let mut got = json(&job);
+ got.as_object_mut().unwrap().remove("id");
+ let mut want = legacy.clone();
+ want.as_object_mut().unwrap().remove("id");
+ assert_eq!(got, want, "job {legacy_id}");
+ let runs = cron_store::list_runs(&backend, &Scope::local(), &new_id).unwrap();
+ assert_eq!(
+ runs.len(),
+ expected["runs"][legacy_id].as_array().unwrap().len(),
+ "runs of {legacy_id}"
+ );
+ }
assert_eq!(tree(dir.path()), before, "the legacy file was modified");
}
@@ -252,9 +247,7 @@ fn a_job_policy_kept_in_the_side_table_lands_on_the_job() {
let backend = backend();
import_cron(&backend, &Scope::local(), &config, dir.path(), "").unwrap();
- let cron = CronDocuments::new(documents(&backend, &Scope::local()));
- let job =
- crate::storage::block_on_anyhow(async move { cron.get_job(&shell_id).await }).unwrap();
+ let job = cron_store::get_job(&backend, &Scope::local(), &shell_id).unwrap();
assert_eq!(job.policy.retries, Some(0));
assert!(job.policy.single_flight);
}
@@ -359,10 +352,7 @@ fn an_agents_cron_database_lands_in_that_agents_scope() {
"{reports:?}"
);
- let count = |scope: Scope| {
- let cron = CronDocuments::new(documents(&backend, &scope));
- crate::storage::block_on_anyhow(async move { Ok(cron.list_jobs().await?.len()) }).unwrap()
- };
+ let count = |scope: Scope| cron_store::list_jobs(&backend, &scope).unwrap().len();
assert_eq!(count(Scope::local()), 3);
assert_eq!(count(crate::storage::scope_for_agent("alpha")), 3);
assert_eq!(count(crate::storage::scope_for_agent("beta")), 0);
diff --git a/scripts/ci/module-boundaries.json b/scripts/ci/module-boundaries.json
index aa126399e2..e0174a34bd 100644
--- a/scripts/ci/module-boundaries.json
+++ b/scripts/ci/module-boundaries.json
@@ -29,8 +29,6 @@
"tinysearch",
"tinysearch-core",
"cpal",
- "tinyflows-schedule",
- "tinyflows-drivers",
"tinyflows-module"
],
"implementationPrefixes": [