Skip to content

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

test(goals): strengthen tool result assertions with structured payload checks

Steven Enamakel3dce23d18e0a
diff --git a/crates/openhuman-core/src/agent/goals/tools_tests.rs b/crates/openhuman-core/src/agent/goals/tools_tests.rs
index 680ffc7a0b..b6c8cc3808 100644
--- a/crates/openhuman-core/src/agent/goals/tools_tests.rs
+++ b/crates/openhuman-core/src/agent/goals/tools_tests.rs
@@ -9,6 +9,12 @@ impl ToolRunContext for ThreadContext {
}
}
+/// Every goal tool answers with `{ goal, text }`: the structured goal the UI
+/// reads and the rendered block the transcript shows.
+fn payload(res: &tinytools::ToolResult) -> serde_json::Value {
+ serde_json::from_str(&res.text()).unwrap_or_else(|e| panic!("goal payload is JSON: {e}: {}", res.text()))
+}
+
#[tokio::test]
async fn set_get_complete_via_tools_in_thread_scope() {
let tmp = tempfile::tempdir().unwrap();
@@ -24,21 +30,33 @@ async fn set_get_complete_via_tools_in_thread_scope() {
.await
.unwrap();
assert!(!res.is_error, "{}", res.text());
- assert!(res.text().contains("land the PR"));
+ let set_payload = payload(&res);
+ assert_eq!(set_payload["goal"]["objective"], "land the PR");
+ assert_eq!(set_payload["goal"]["status"], "active");
+ assert_eq!(set_payload["goal"]["tokenBudget"], 5000);
+ assert_eq!(set_payload["goal"]["tokensUsed"], 0);
+ let text = set_payload["text"].as_str().unwrap();
+ assert!(text.starts_with("Goal set."), "{text}");
+ assert!(text.contains("objective: land the PR"), "{text}");
let get = GoalGetTool::new(dir.clone());
let res = get
.execute_with_context(json!({}), ToolCallOptions::default(), Some(&context))
.await
.unwrap();
- assert!(res.text().contains("status: active"));
+ let get_payload = payload(&res);
+ assert_eq!(get_payload["goal"]["status"], "active");
+ assert_eq!(get_payload["goal"]["goalId"], set_payload["goal"]["goalId"]);
+ assert!(get_payload["text"].as_str().unwrap().contains("status: active"));
let done = GoalCompleteTool::new(dir.clone());
let res = done
.execute_with_context(json!({}), ToolCallOptions::default(), Some(&context))
.await
.unwrap();
- assert!(res.text().contains("status: complete"));
+ let done_payload = payload(&res);
+ assert_eq!(done_payload["goal"]["status"], "complete");
+ assert!(done_payload["text"].as_str().unwrap().starts_with("Goal marked complete."));
}
#[tokio::test]
@@ -61,5 +79,7 @@ async fn get_reports_absent_goal() {
.execute_with_context(json!({}), ToolCallOptions::default(), Some(&context))
.await
.unwrap();
- assert!(res.text().contains("no goal set"));
+ let absent = payload(&res);
+ assert!(absent["goal"].is_null(), "{absent}");
+ assert_eq!(absent["text"], "no goal set for this thread");
}