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/agent/session_db/schemas_tests.rs

Steven Enamakel7bbf4c2fee6d
diff --git a/crates/openhuman-core/src/agent/session_db/schemas_tests.rs b/crates/openhuman-core/src/agent/session_db/schemas_tests.rs
index e07bdf5564..15e4655606 100644
--- a/crates/openhuman-core/src/agent/session_db/schemas_tests.rs
+++ b/crates/openhuman-core/src/agent/session_db/schemas_tests.rs
@@ -74,3 +74,91 @@ fn new_correlation_id_is_eight_hex_chars() {
assert_eq!(cid.len(), 8);
assert!(cid.chars().all(|c| c.is_ascii_hexdigit()));
}
+
+#[test]
+fn an_unknown_function_gets_the_error_schema() {
+ let s = schema_for("no_such_function");
+ assert_eq!(s.namespace, "run_ledger");
+ assert_eq!(s.function, "unknown");
+ assert_eq!(s.outputs[0].name, "error");
+}
+
+/// Runs `handler` with the configured workspace pointed at a scratch
+/// directory, so the ledger it reads is empty and nothing touches the
+/// operator's home.
+async fn with_scratch_workspace<F, Fut>(handler: F) -> Result<Value, String>
+where
+ F: FnOnce() -> Fut,
+ Fut: std::future::Future<Output = Result<Value, String>>,
+{
+ let _env_lock = crate::config::TEST_ENV_LOCK.lock().await;
+ let tmp = tempfile::tempdir().expect("tempdir");
+ // SAFETY: serialised by `TEST_ENV_LOCK`.
+ unsafe {
+ std::env::set_var("OPENHUMAN_WORKSPACE", tmp.path());
+ }
+ let result = handler().await;
+ // SAFETY: serialised by `TEST_ENV_LOCK`.
+ unsafe {
+ std::env::remove_var("OPENHUMAN_WORKSPACE");
+ }
+ result
+}
+
+fn params(value: Value) -> Map<String, Value> {
+ value.as_object().cloned().unwrap_or_default()
+}
+
+#[tokio::test]
+async fn listing_an_empty_ledger_returns_no_runs() {
+ let value = with_scratch_workspace(|| handle_run_ledger_list(Map::new()))
+ .await
+ .expect("list answers on an empty ledger");
+ let text = value.to_string();
+ assert!(text.contains("runs") || text.contains("items"), "{text}");
+}
+
+#[tokio::test]
+async fn listing_rejects_malformed_params() {
+ let err = with_scratch_workspace(|| {
+ handle_run_ledger_list(params(serde_json::json!({ "limit": "many" })))
+ })
+ .await
+ .expect_err("a non-numeric limit is refused");
+ assert!(err.contains("invalid run ledger list params"), "{err}");
+}
+
+#[tokio::test]
+async fn getting_an_unknown_run_answers_null() {
+ let value = with_scratch_workspace(|| {
+ handle_run_ledger_get(params(serde_json::json!({ "id": "no-such-run" })))
+ })
+ .await
+ .expect("get answers for an unknown id");
+ assert!(value.to_string().contains("null"), "{value}");
+}
+
+#[tokio::test]
+async fn getting_a_run_requires_an_id() {
+ let err = with_scratch_workspace(|| handle_run_ledger_get(Map::new()))
+ .await
+ .expect_err("id is required");
+ assert!(err.contains("missing required param: id"), "{err}");
+}
+
+#[tokio::test]
+async fn events_of_an_unknown_run_are_empty() {
+ with_scratch_workspace(|| {
+ handle_run_ledger_events(params(serde_json::json!({ "runId": "no-such-run" })))
+ })
+ .await
+ .expect("events answer for an unknown run");
+}
+
+#[tokio::test]
+async fn events_reject_malformed_params() {
+ let err = with_scratch_workspace(|| handle_run_ledger_events(Map::new()))
+ .await
+ .expect_err("runId is required");
+ assert!(err.contains("invalid run ledger events params"), "{err}");
+}