Skip to content

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

test(storage): add controller schema tests and share jobs fixture helper

Steven Enamakel6d486c74529a
diff --git a/crates/openhuman-core/src/storage/layout/legacy_tests.rs b/crates/openhuman-core/src/storage/layout/legacy_tests.rs
index 764d5f4e63..c1ab0fd4cc 100644
--- a/crates/openhuman-core/src/storage/layout/legacy_tests.rs
+++ b/crates/openhuman-core/src/storage/layout/legacy_tests.rs
@@ -1,6 +1,5 @@
use super::*;
use crate::storage::layout::test_fixtures::{fixture_docs, v1_profile};
-use crate::storage::state_kv::StateKv;
#[tokio::test(flavor = "multi_thread")]
async fn the_import_brings_legacy_files_into_the_v1_database() {
@@ -9,15 +8,7 @@ async fn the_import_brings_legacy_files_into_the_v1_database() {
assert_eq!(summary.memory_state, vec!["jobs".to_owned()]);
assert!(summary.domains >= 3, "approval, devices, ... ran: {summary:?}");
- let url = v1_url(&fx.target);
- let jobs = crate::storage::block_on(async move {
- let backend = storage::open(&url).await?;
- let scoped = backend.for_scope(&storage::Scope::local())?;
- Ok(StateKv::over(&scoped, "memory", "state")
- .get::<serde_json::Value>("jobs")
- .unwrap_or_else(|e| panic!("kv get: {e:#}")))
- })
- .unwrap();
+ let jobs = crate::storage::layout::test_fixtures::jobs_value(&v1_db(&fx.target));
assert_eq!(jobs, Some(serde_json::json!({"jobs": [1, 2, 3]})));
// the sources are only read
assert!(fx.workspace().join("memory/jobs.json").is_file());
diff --git a/crates/openhuman-core/src/storage/layout/run_tests.rs b/crates/openhuman-core/src/storage/layout/run_tests.rs
index 087ad8404d..e8f0b7d637 100644
--- a/crates/openhuman-core/src/storage/layout/run_tests.rs
+++ b/crates/openhuman-core/src/storage/layout/run_tests.rs
@@ -1,7 +1,6 @@
use super::*;
use crate::storage::layout::state::STATE_FILE;
use crate::storage::layout::test_fixtures::{fixture_docs, tree, v1_profile, write, Fixture};
-use crate::storage::state_kv::StateKv;
fn opts() -> Options {
Options::default()
@@ -38,13 +37,7 @@ fn assert_migrated(fx: &Fixture) {
assert!(!exists(&profile.join(STATE_FILE)), "the progress file is removed last");
// the database came across
assert_eq!(fixture_docs(&fx.target.storage_db()).len(), 3);
- let url = format!("sqlite:{}", fx.target.storage_db().display());
- let jobs = crate::storage::block_on(async move {
- let backend = crate::storage::open(&url).await?;
- let scoped = backend.for_scope(&crate::storage::Scope::local())?;
- Ok(StateKv::over(&scoped, "memory", "state").get::<serde_json::Value>("jobs").ok().flatten())
- })
- .unwrap();
+ let jobs = crate::storage::layout::test_fixtures::jobs_value(&fx.target.storage_db());
assert_eq!(jobs, Some(serde_json::json!({"jobs": [1, 2, 3]})), "imported state is in the v2 database");
// user files moved
assert_eq!(std::fs::read_to_string(files.join("skills/s1/SKILL.md")).unwrap(), "# skill one\n");
diff --git a/crates/openhuman-core/src/storage/layout/schemas_tests.rs b/crates/openhuman-core/src/storage/layout/schemas_tests.rs
index 4563e55b7b..a3836b6cba 100644
--- a/crates/openhuman-core/src/storage/layout/schemas_tests.rs
+++ b/crates/openhuman-core/src/storage/layout/schemas_tests.rs
@@ -1 +1,14 @@
use super::*;
+
+#[test]
+fn the_three_controllers_are_registered_under_storage() {
+ let names: Vec<_> = all_registered_controllers()
+ .iter()
+ .map(|c| (c.schema.namespace, c.schema.function))
+ .collect();
+ assert_eq!(names, vec![("storage", "migrate"), ("storage", "status"), ("storage", "restore")]);
+ assert_eq!(all_controller_schemas().len(), 3);
+ assert!(schemas("restore").inputs.iter().any(|f| f.name == "archive" && f.required));
+ assert!(schemas("migrate").inputs.iter().any(|f| f.name == "dry_run" && !f.required));
+ assert_eq!(schemas("nope").function, "unknown");
+}
diff --git a/crates/openhuman-core/src/storage/layout/test_fixtures.rs b/crates/openhuman-core/src/storage/layout/test_fixtures.rs
index 5256334a3e..f95cffedad 100644
--- a/crates/openhuman-core/src/storage/layout/test_fixtures.rs
+++ b/crates/openhuman-core/src/storage/layout/test_fixtures.rs
@@ -119,3 +119,16 @@ pub fn fixture_docs(db: &Path) -> BTreeMap<String, serde_json::Value> {
})
.unwrap()
}
+
+/// The imported `memory/state/jobs` value of the database file `db`.
+pub fn jobs_value(db: &Path) -> Option<serde_json::Value> {
+ let url = format!("sqlite:{}", db.display());
+ let scoped = storage::block_on(async move {
+ let backend = storage::open(&url).await?;
+ backend.for_scope(&Scope::local())
+ })
+ .unwrap();
+ crate::storage::state_kv::StateKv::over(&scoped, "memory", "state")
+ .get::<serde_json::Value>("jobs")
+ .unwrap()
+}