Skip to content

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

test(ci): cover computer status serialization

Steven Enamakel306da7b168d8
diff --git a/crates/openhuman-core/src/modules/schemas.rs b/crates/openhuman-core/src/modules/schemas.rs
index 622ee16c42..0848aad26a 100644
--- a/crates/openhuman-core/src/modules/schemas.rs
+++ b/crates/openhuman-core/src/modules/schemas.rs
@@ -201,11 +201,14 @@ fn handle_computer_status(params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let load = params.get("load").and_then(Value::as_bool).unwrap_or(false);
let config = config_rpc::load_config_with_timeout().await?;
- serde_json::to_value(super::computer::status(&config, load).await)
- .map_err(|error| error.to_string())
+ controller_value(super::computer::status(&config, load).await)
})
}
+fn controller_value(value: impl serde::Serialize) -> Result<Value, String> {
+ serde_json::to_value(value).map_err(|error| error.to_string())
+}
+
fn handle_list(_params: Map<String, Value>) -> ControllerFuture {
Box::pin(async move {
let config = config_rpc::load_config_with_timeout().await?;
diff --git a/crates/openhuman-core/src/modules/schemas_tests.rs b/crates/openhuman-core/src/modules/schemas_tests.rs
index 9b04a078f2..ed365dfac1 100644
--- a/crates/openhuman-core/src/modules/schemas_tests.rs
+++ b/crates/openhuman-core/src/modules/schemas_tests.rs
@@ -1,4 +1,8 @@
-use super::{all_controller_schemas, all_registered_controllers, schemas, string_param};
+use super::{
+ all_controller_schemas, all_registered_controllers, controller_value, schemas, string_param,
+};
+use crate::core::runtime::context::CoreContext;
+use crate::core::runtime::DomainSet;
use serde_json::{Map, Value};
#[test]
@@ -40,3 +44,26 @@ fn a_blank_or_missing_id_is_not_a_parameter() {
params.insert("id".to_string(), Value::String(" tinydocs ".to_string()));
assert_eq!(string_param(&params, "id"), Some("tinydocs".to_string()));
}
+
+#[test]
+fn controller_value_reports_serialization_errors() {
+ let invalid_object_key = std::collections::HashMap::from([(vec![1, 2], true)]);
+
+ let error = controller_value(invalid_object_key).unwrap_err();
+
+ assert!(error.contains("key must be a string"));
+}
+
+#[tokio::test]
+async fn computer_status_handler_returns_serialized_status() {
+ let ctx =
+ CoreContext::for_test_with_config(DomainSet::full(), crate::config::Config::default());
+
+ let status = CoreContext::scope(ctx, async {
+ super::handle_computer_status(Map::new()).await
+ })
+ .await
+ .expect("computer status should serialize");
+
+ assert!(status.get("decision_model").is_some());
+}