The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(flows): rework parked-run sweep test to use module-created runs
Steven Enamakelf8775e6e59cb
diff --git a/crates/openhuman-core/src/flows/ops_resume_checkpoint_tests.rs b/crates/openhuman-core/src/flows/ops_resume_checkpoint_tests.rsindex 36c0ce574d..c3bc2a5e69 100644--- a/crates/openhuman-core/src/flows/ops_resume_checkpoint_tests.rs+++ b/crates/openhuman-core/src/flows/ops_resume_checkpoint_tests.rs@@ -2,7 +2,7 @@ use super::*;/// Rewrite a module-created run document only for the migration fixture below./// All normal run setup and execution still go through the TinyFlows bus.-fn update_parked_run_document_for_test(+pub(super) fn update_parked_run_document_for_test(config: &Config,run_id: &str,update: impl FnOnce(&mut Value),diff --git a/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs b/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rsindex ed0eaf5c18..46afae2e56 100644--- a/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs+++ b/crates/openhuman-core/src/flows/ops_validate_warnings_and_connections_tests.rs@@ -1,97 +1,7 @@use super::*;-#[tokio::test]-async fn flows_cancel_run_of_a_completed_with_warnings_run_errors() {- // A settled `completed_with_warnings` run (run honesty, PR2) must be just- // as terminal as a plain `completed` run — otherwise `flows_cancel_run`- // falls through to its not-in-flight path and overwrites the row (and the- // flow summary) as `"cancelled"`, silently discarding the warning status- // the run already recorded.- let tmp = TempDir::new().unwrap();- let config = test_config(&tmp);- let created = flows_create(&config, "demo".to_string(), trigger_only_graph(), false)- .await- .unwrap();-- let run = flows_run(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- &created.value.id,- json!({}),- serde_json::Map::new(),- FlowRunTrigger::Rpc,- )- .await- .unwrap();- let thread_id = run.value["thread_id"].as_str().unwrap().to_string();-- // Force the settled row to the warning status directly — an end-to-end- // null-binding graph isn't needed to exercise this guard.- // Fixture-only forcing write: the run above already settled `completed`, so- // `finish_flow_run`'s liveness guard (correctly) refuses a terminal →- // terminal transition. Staging a row at an arbitrary terminal status is a- // test concern, not a production one.- store::force_run_status_for_test(&config, &thread_id, "completed_with_warnings", None).unwrap();-- let err = flows_cancel_run(&config, &thread_id)- .await- .expect_err("cancelling a completed_with_warnings run must be a clear error");- assert!(err.contains("already terminal"), "got: {err}");-- // And the row must still read back as the warning status, not overwritten.- let run_row = flows_get_run(&config, &thread_id).await.unwrap();- assert_eq!(run_row.value.status, "completed_with_warnings");-}--#[tokio::test]-async fn flows_cancel_run_of_an_interrupted_run_errors() {- // An `interrupted` run (bug B42 — reconciled by the drop-guard / boot- // sweep) is terminal: cancelling it must be a clear error, never fall- // through to the not-in-flight path and clobber the row to `"cancelled"`,- // discarding the interruption reason it already carries.- let tmp = TempDir::new().unwrap();- let config = test_config(&tmp);- let created = flows_create(&config, "demo".to_string(), trigger_only_graph(), false)- .await- .unwrap();-- let run = flows_run(- &crate::core::runtime::DispatchCtx::ambient(),- &config,- &created.value.id,- json!({}),- serde_json::Map::new(),- FlowRunTrigger::Rpc,- )- .await- .unwrap();- let thread_id = run.value["thread_id"].as_str().unwrap().to_string();-- // Force the settled row to `interrupted` directly.- // Fixture-only forcing write — see the sibling test above: the run has- // already settled, and `finish_flow_run` now (correctly) refuses a- // terminal -> terminal transition.- store::force_run_status_for_test(- &config,- &thread_id,- "interrupted",- Some("interrupted mid-flight"),- )- .unwrap();-- let err = flows_cancel_run(&config, &thread_id)- .await- .expect_err("cancelling an interrupted run must be a clear error");- assert!(err.contains("already terminal"), "got: {err}");-- // And the row must still read back as `interrupted`, not overwritten.- let run_row = flows_get_run(&config, &thread_id).await.unwrap();- assert_eq!(run_row.value.status, "interrupted");- assert_eq!(- run_row.value.error.as_deref(),- Some("interrupted mid-flight")- );-}+// The module owns terminal status classification; the public cancel boundary+// is covered by real module-created completed runs in ops_run_rows_and_notifications_tests.rs.#[tokio::test]async fn flows_cancel_run_missing_run_errors() {@@ -112,27 +22,30 @@ async fn parked_run_ttl_sweep_expires_stale_runs_but_spares_fresh_ones() {let created = flows_create(&config, "gated".to_string(), approval_gated_graph(), false).await.unwrap();+ let ctx = crate::core::runtime::DispatchCtx::ambient();- // Seed a parked run whose "parked since" (finished_at) is far in the past,- // so it is well beyond the TTL.- let stale_id = format!("flow:{}:stale-run", created.value.id);- let ancient = "2000-01-01T00:00:00+00:00";- store::insert_flow_run(&config, &stale_id, &created.value.id, &stale_id, ancient).unwrap();- store::finish_flow_run(+ // Start both rows through TinyFlows, then age only the parked timestamp on+ // one module-created document to model an approval left behind across TTL.+ let stale = flows_run(+ &ctx,&config,- &stale_id,- "pending_approval",- ancient,- &[],- &["gate".to_string()],- None,- None,+ &created.value.id,+ json!({}),+ serde_json::Map::new(),+ FlowRunTrigger::Rpc,)+ .await.unwrap();+ let stale_id = stale.value["thread_id"].as_str().unwrap().to_string();+ let ancient_ms = (Utc::now() - chrono::Duration::days(365 * 20)).timestamp_millis();+ super::resume_checkpoint_tests::update_parked_run_document_for_test(+ &config,+ &stale_id,+ |document| document["finished_ms"] = json!(ancient_ms),+ );- // A genuinely fresh parked run (just paused now) must survive the sweep.let fresh = flows_run(- &crate::core::runtime::DispatchCtx::ambient(),+ &ctx,&config,&created.value.id,json!({}),@@ -143,25 +56,24 @@ async fn parked_run_ttl_sweep_expires_stale_runs_but_spares_fresh_ones() {.unwrap();let fresh_id = fresh.value["thread_id"].as_str().unwrap().to_string();- let swept = sweep_expired_parked_runs(&config).await;+ let swept = crate::flows::recovery::expire_parked_runs(&ctx, &config).await;assert_eq!(swept, 1, "only the stale parked run should be swept");- let stale_row = store::get_flow_run(&config, &stale_id).unwrap().unwrap();+ let stale_row = flows_get_run(&config, &stale_id).await.unwrap().value;assert_eq!(stale_row.status, "cancelled");assert!(stale_row.error.unwrap_or_default().contains("expired"),"an expired run's error must note the TTL expiry");- let fresh_row = store::get_flow_run(&config, &fresh_id).unwrap().unwrap();+ let fresh_row = flows_get_run(&config, &fresh_id).await.unwrap().value;assert_eq!(fresh_row.status, "pending_approval","a run parked within the TTL must not be swept");- // The swept run is no longer resumable.let err = flows_resume(- &crate::core::runtime::DispatchCtx::ambient(),+ &ctx,&config,&created.value.id,&stale_id,@@ -170,7 +82,7 @@ async fn parked_run_ttl_sweep_expires_stale_runs_but_spares_fresh_ones() {).await.expect_err("an expired parked run must not be resumable");- assert!(err.contains("not pending approval") || err.contains("no paused run"));+ assert!(err.contains("not waiting for approval"));}#[tokio::test]