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/cron/documents_port_tests.rs

Steven Enamakel00ef3a66962c
diff --git a/crates/openhuman-core/src/cron/documents_port_tests.rs b/crates/openhuman-core/src/cron/documents_port_tests.rs
index 4699443cbf..354631c941 100644
--- a/crates/openhuman-core/src/cron/documents_port_tests.rs
+++ b/crates/openhuman-core/src/cron/documents_port_tests.rs
@@ -4,11 +4,20 @@ use serde_json::json;
use tinyflows_bus::schedule::{DOCUMENT_INTERFACE, DOCUMENT_METHOD};
async fn port() -> (tinybus::Proxy, CallbackAddress) {
+ let (proxy, address, _) = port_with_backend().await;
+ (proxy, address)
+}
+
+async fn port_with_backend() -> (
+ tinybus::Proxy,
+ CallbackAddress,
+ Arc<dyn StorageBackend>,
+) {
let config = Config::default();
// Start the module runtime and attach the module before touching the bus.
module::proxy(&config).await.expect("module attaches");
let backend: Arc<dyn StorageBackend> = Arc::new(MemoryStorage::new());
- let scope = DocScope::on_backend(&config, backend, Scope::local());
+ let scope = DocScope::on_backend(&config, Arc::clone(&backend), Scope::local());
let address = address(&scope).await.expect("port is served");
let runtime = crate::modules::runtime::runtime().await.unwrap();
let proxy = runtime
@@ -19,7 +28,7 @@ async fn port() -> (tinybus::Proxy, CallbackAddress) {
DOCUMENT_INTERFACE,
)
.expect("the contract's document interface is the one served");
- (proxy, address)
+ (proxy, address, backend)
}
async fn ask(proxy: &tinybus::Proxy, request: Value) -> Value {
@@ -31,6 +40,211 @@ async fn the_port_serves_the_contracts_document_interface_and_reports_capabiliti
let (proxy, _) = port().await;
let reply = ask(&proxy, json!({"op": "capabilities"})).await;
assert!(reply["value"]["transactions"].is_boolean(), "{reply}");
+ assert_eq!(reply["value"]["record_metadata"], true, "{reply}");
+}
+
+#[tokio::test]
+async fn schedule_store_migration_moves_legacy_jobs_runs_and_counter_before_reads() {
+ use tinyflows_bus::schedule::{
+ members, StoreBackend, StoreConfig, StoreOperation, StoreRequest,
+ };
+ use tinystoragedrivers::{DocumentStore, Precondition};
+
+ let config = Config::default();
+ let (port, callback, backend) = port_with_backend().await;
+ let scoped = backend.for_scope(&Scope::local()).unwrap();
+ let docs = scoped.documents();
+ for collection in ["cron_jobs", "cron_runs", "cron_counters"] {
+ docs.ensure_collection(&CollectionSpec::new(collection))
+ .await
+ .unwrap();
+ }
+ docs.put(
+ "cron_jobs",
+ "legacy-job",
+ json!({
+ "claim_generation": 3,
+ "expression": "0 9 * * *",
+ "command": "echo legacy",
+ "schedule": "{\"kind\":\"every\",\"every_ms\":3600000}",
+ "job_type": "shell",
+ "session_target": "isolated",
+ "enabled": true,
+ "delivery": "{\"mode\":\"none\",\"channel\":null,\"to\":null,\"best_effort\":true}",
+ "delete_after_run": false,
+ "created_at": "2026-03-04T05:06:07.123Z",
+ "created_ms": 1772600767123_i64,
+ "next_run": "2026-03-05T09:00:00Z",
+ "next_run_ms": 1772701200000_i64,
+ "next_run_ns": 1772701200000000000_i64,
+ "name": "legacy-job"
+ }),
+ Precondition::None,
+ )
+ .await
+ .unwrap();
+ docs.put(
+ "cron_runs",
+ "00000000000000000007",
+ json!({
+ "seq": 7,
+ "job_id": "legacy-job",
+ "started_at": "2026-03-04T09:00:00Z",
+ "started_ns": 1772614800000000000_i64,
+ "finished_at": "2026-03-04T09:00:02Z",
+ "status": "success",
+ "duration_ms": 2000,
+ "output": "legacy output"
+ }),
+ Precondition::None,
+ )
+ .await
+ .unwrap();
+ docs.put(
+ "cron_counters",
+ "runs",
+ json!({"next": 8}),
+ Precondition::None,
+ )
+ .await
+ .unwrap();
+
+ let storage = StoreConfig {
+ backend: StoreBackend::Documents {
+ callback: callback.clone(),
+ },
+ max_run_history: config.cron.max_run_history,
+ max_tasks: config.scheduler.max_tasks,
+ };
+ let request = StoreRequest {
+ storage: storage.clone(),
+ operation: serde_json::to_value(StoreOperation::Migrate).unwrap(),
+ };
+ let migrated: Value = module::proxy(&config)
+ .await
+ .unwrap()
+ .call(members::SCHEDULE_STORE, (request,))
+ .await
+ .unwrap();
+ assert!(migrated.get("report").is_some(), "{migrated}");
+
+ let list_request = StoreRequest {
+ storage: storage.clone(),
+ operation: serde_json::to_value(StoreOperation::List).unwrap(),
+ };
+ let listed: Value = module::proxy(&config)
+ .await
+ .unwrap()
+ .call(members::SCHEDULE_STORE, (list_request,))
+ .await
+ .unwrap();
+ let listed: Vec<tinyflows_bus::schedule::types::CronJob> =
+ serde_json::from_value(listed).unwrap();
+ assert_eq!(listed.len(), 1);
+ assert_eq!(listed[0].id, "legacy-job");
+ assert_eq!(listed[0].schedule, tinyflows_bus::schedule::types::Schedule::Every {
+ every_ms: 3_600_000
+ });
+
+ let runs_request = StoreRequest {
+ storage,
+ operation: serde_json::to_value(StoreOperation::ListRuns {
+ job_id: "legacy-job".into(),
+ limit: 10,
+ })
+ .unwrap(),
+ };
+ let runs: Value = module::proxy(&config)
+ .await
+ .unwrap()
+ .call(members::SCHEDULE_STORE, (runs_request,))
+ .await
+ .unwrap();
+ let runs: Vec<tinyflows_bus::schedule::types::CronRun> =
+ serde_json::from_value(runs).unwrap();
+ assert_eq!(runs.len(), 1);
+ assert_eq!(runs[0].output, "legacy output");
+}
+
+#[tokio::test]
+async fn shared_schedule_records_are_owner_scoped_and_never_scanned() {
+ use tinystoragedrivers::DocumentStore;
+
+ let (proxy, _, backend) = port_with_backend().await;
+ let scoped = backend.for_scope(&Scope::local()).unwrap();
+ let docs = scoped.documents();
+ for collection in ["tsd.counters", "tsd.leases", "tsd.migrations", "tsd.kv"] {
+ let ensured = ask(&proxy, json!({"op":"ensure","spec":{"name":collection}})).await;
+ assert!(ensured.get("error").is_none(), "{collection}: {ensured}");
+ }
+
+ let record = ask(
+ &proxy,
+ json!({
+ "op":"put",
+ "collection":"tsd.counters",
+ "id":"cron/runs",
+ "doc":{"next":7},
+ "precondition":{"kind":"none"}
+ }),
+ )
+ .await;
+ assert!(record.get("error").is_none(), "{record}");
+ assert!(docs.get("tsd.counters", "cron/runs").await.unwrap().is_some());
+
+ for request in [
+ json!({"op":"get","collection":"tsd.counters","id":"other/runs"}),
+ json!({"op":"put","collection":"tsd.leases","id":"other/lease","doc":{},"precondition":{"kind":"none"}}),
+ json!({"op":"get","collection":"tsd.migrations","id":"cron/unrelated/step"}),
+ json!({"op":"query","collection":"tsd.counters","query":{"filter":{"op":"all"}}}),
+ json!({"op":"count","collection":"tsd.leases","filter":{"op":"all"}}),
+ json!({"op":"delete_where","collection":"tsd.migrations","filter":{"op":"all"}}),
+ json!({"op":"get","collection":"tsd.kv","id":"cron/anything"}),
+ json!({"op":"atomic_batch","ops":[{"op":"delete","collection":"tsd.counters","id":"other/runs","precondition":{"kind":"none"}}]}),
+ ] {
+ let reply = ask(&proxy, request.clone()).await;
+ assert_eq!(reply["error"]["kind"], "invalid_input", "{request}: {reply}");
+ }
+
+ let exact_progress = ask(
+ &proxy,
+ json!({"op":"put","collection":"tsd.migrations","id":"cron/cron.jobs/jobs_v2","doc":{"done":true},"precondition":{"kind":"none"}}),
+ )
+ .await;
+ assert!(exact_progress.get("error").is_none(), "{exact_progress}");
+}
+
+#[tokio::test]
+async fn document_port_preserves_schedule_record_metadata_options() {
+ use tinystoragedrivers::DocumentStore;
+
+ let (proxy, _, backend) = port_with_backend().await;
+ let scoped = backend.for_scope(&Scope::local()).unwrap();
+ let docs = scoped.documents();
+ let ensured = ask(&proxy, json!({"op":"ensure","spec":{"name":"cron.jobs"}})).await;
+ assert!(ensured.get("error").is_none(), "{ensured}");
+
+ for (id, created_ms, schema) in [("zero", 0_i64, 2_u64), ("negative", -1_i64, 3_u64)] {
+ let reply = ask(
+ &proxy,
+ json!({
+ "op":"put",
+ "collection":"cron.jobs",
+ "id":id,
+ "doc":{"id":id},
+ "precondition":{"kind":"none"},
+ "schema":schema,
+ "created_ms":created_ms,
+ "expires_ms":9999999999999_i64
+ }),
+ )
+ .await;
+ assert!(reply.get("error").is_none(), "{id}: {reply}");
+ let stored = docs.get("cron.jobs", id).await.unwrap().unwrap();
+ assert_eq!(stored.meta.schema, schema as u32, "{id}");
+ assert_eq!(stored.meta.created_ms, created_ms, "{id}");
+ assert_eq!(stored.meta.expires_ms, Some(9999999999999_i64), "{id}");
+ }
}
#[tokio::test]