Skip to content

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

test(storage): cover memory driver in cross-process url suite

Steven Enamakelbb681c16e0ae
diff --git a/tests/cli_storage_url_e2e.rs b/tests/cli_storage_url_e2e.rs
index 292da0f0dd..696b9f28f3 100644
--- a/tests/cli_storage_url_e2e.rs
+++ b/tests/cli_storage_url_e2e.rs
@@ -5,6 +5,12 @@
use std::process::Command;
+#[macro_use]
+#[path = "support/storage_drivers.rs"]
+mod storage_drivers;
+
+use storage_drivers::UrlCase;
+
fn core(workspace: &std::path::Path, url: Option<&str>, args: &[&str]) -> std::process::Output {
let mut cmd = Command::new(env!("CARGO_BIN_EXE_openhuman-core"));
cmd.args(args)
@@ -56,69 +62,60 @@ fn one_shot(url: &str, args: &[&str]) -> (std::process::Output, tempfile::TempDi
(output, workspace)
}
-#[test]
-fn a_second_process_reads_what_a_one_shot_wrote_to_the_backend() {
- let data = tempfile::tempdir().unwrap();
- // (url, whether this build carries the driver for it)
- let candidates = [
- (
- format!("sqlite:{}", data.path().join("shared.db").display()),
- cfg!(feature = "storage-sqlite"),
- ),
- (
- format!("file:{}", data.path().join("shared-files").display()),
- cfg!(feature = "storage-file"),
- ),
+/// Every driver is asked the same thing: write a job in one process, list in
+/// another. A durable driver shows it to the second process; `memory` keeps
+/// nothing between processes, so it must not.
+fn a_second_process_reads_what_a_one_shot_wrote_to_the_backend(case: UrlCase) {
+ let args = [
+ "cron",
+ "add",
+ "--name",
+ "storage-probe",
+ "--schedule",
+ r#"{"kind":"every","every_ms":3600000}"#,
+ "--command",
+ "echo probe",
];
- let mut tested = 0;
- for (url, driver_built) in &candidates {
- if !driver_built {
- continue;
- }
- let (added, _first) = one_shot(
- url,
- &[
- "cron",
- "add",
- "--name",
- "storage-probe",
- "--schedule",
- r#"{"kind":"every","every_ms":3600000}"#,
- "--command",
- "echo probe",
- ],
- );
- let stderr = String::from_utf8_lossy(&added.stderr);
- assert!(added.status.success(), "cron add against {url}: {stderr}");
+ let (added, _first) = one_shot(&case.url, &args);
+ let stderr = String::from_utf8_lossy(&added.stderr);
+ assert!(
+ added.status.success(),
+ "cron add against {}: {stderr}",
+ case.driver.name()
+ );
- // A different workspace: only the backend can hold the job.
- let (listed, _second) = one_shot(url, &["cron", "list"]);
- assert!(
- listed.status.success(),
- "{}",
- String::from_utf8_lossy(&listed.stderr)
- );
- let stdout = String::from_utf8_lossy(&listed.stdout);
+ // A different workspace: only the backend can hold the job.
+ let (listed, _second) = one_shot(&case.url, &["cron", "list"]);
+ assert!(
+ listed.status.success(),
+ "{}",
+ String::from_utf8_lossy(&listed.stderr)
+ );
+ let stdout = String::from_utf8_lossy(&listed.stdout);
+ if case.driver.is_durable() {
assert!(
stdout.contains("storage-probe"),
"second process sees the job: {stdout}"
);
-
- // And without the URL the same fresh workspace has nothing.
- let workspace = tempfile::tempdir().unwrap();
- let classic = core(workspace.path(), None, &["cron", "list"]);
+ } else {
assert!(
- classic.status.success(),
- "{}",
- String::from_utf8_lossy(&classic.stderr)
+ !stdout.contains("storage-probe"),
+ "memory keeps nothing between processes: {stdout}"
);
- assert!(
- !String::from_utf8_lossy(&classic.stdout).contains("storage-probe"),
- "the job lives in the backend, not in files"
- );
- tested += 1;
- }
- if tested == 0 {
- eprintln!("skipped: no storage driver compiled in (enable storage-sqlite or storage-file)");
}
+
+ // And without the URL the same fresh workspace has nothing.
+ let workspace = tempfile::tempdir().unwrap();
+ let classic = core(workspace.path(), None, &["cron", "list"]);
+ assert!(
+ classic.status.success(),
+ "{}",
+ String::from_utf8_lossy(&classic.stderr)
+ );
+ assert!(
+ !String::from_utf8_lossy(&classic.stdout).contains("storage-probe"),
+ "the job lives in the backend, not in files"
+ );
}
+
+driver_cases!(url a_second_process_reads_what_a_one_shot_wrote_to_the_backend);
diff --git a/tests/support/storage_drivers.rs b/tests/support/storage_drivers.rs
index c89e65cd79..4794e202e1 100644
--- a/tests/support/storage_drivers.rs
+++ b/tests/support/storage_drivers.rs
@@ -23,7 +23,8 @@
//!
//! Include with `#[macro_use] mod storage_drivers;` and declare the body with
//! `driver_cases!(sync body)` (or `async body`), where `body` is
-//! `fn(Case)` (or `async fn(Case)`).
+//! `fn(Case)` (or `async fn(Case)`); `driver_cases!(url body)` takes a
+//! `fn(UrlCase)` for suites that spawn `openhuman-core` against the URL.
#![allow(dead_code)]
@@ -193,6 +194,28 @@ impl Drop for Case {
}
}
+/// A driver's URL for suites that hand it to a spawned `openhuman-core`
+/// process instead of opening the backend in the test process.
+pub struct UrlCase {
+ pub driver: Driver,
+ pub url: String,
+ pub data_dir: tempfile::TempDir,
+}
+
+/// Runs a body that only needs the driver's URL (`driver_cases!(url body)`).
+pub fn run_url(driver: Driver, body: fn(UrlCase)) {
+ let data_dir = tempfile::tempdir().expect("temp dir");
+ let Some(url) = driver.url(data_dir.path()) else {
+ eprintln!("skipped {}: {MONGO_URL_VAR} is not set", driver.name());
+ return;
+ };
+ body(UrlCase {
+ driver,
+ url,
+ data_dir,
+ });
+}
+
/// Runs a synchronous case body on `driver`.
pub fn run_sync(driver: Driver, body: fn(Case)) {
if let Some(case) = Case::open(driver) {
@@ -229,6 +252,9 @@ macro_rules! driver_cases {
(async $body:ident) => {
driver_cases!(@each run_async $body);
};
+ (url $body:ident) => {
+ driver_cases!(@each run_url $body);
+ };
(@each $runner:ident $body:ident) => {
mod memory {
#[test]