Skip to content

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

test(agent): add round-trip tests for typed tool rows and image parts

Steven Enamakelcadf85042ec6
diff --git a/crates/openhuman-core/src/agent/messages_tests.rs b/crates/openhuman-core/src/agent/messages_tests.rs
index 9027c402cf..74fddecc4f 100644
--- a/crates/openhuman-core/src/agent/messages_tests.rs
+++ b/crates/openhuman-core/src/agent/messages_tests.rs
@@ -1,4 +1,5 @@
use super::*;
+use tinyagents_session::transcript::TranscriptPart;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize)]
@@ -11,7 +12,9 @@ struct Holder {
#[test]
fn history_wire_writes_only_role_and_content() {
- let mut row = TranscriptMessage::tool("{\"tool_call_id\":\"c1\",\"content\":\"ok\"}");
+ // A typed tool row is written as the flat envelope string files have
+ // always held.
+ let mut row = TranscriptMessage::tool_result("c1", "ok");
row.id = Some("c1".into());
row.cache_breakpoints = vec![3, 7];
row.extra_metadata = Some(serde_json::json!({"reasoning_content": "why"}));
@@ -49,3 +52,47 @@ fn history_wire_option_defaults_to_none_when_absent() {
let holder: Holder = serde_json::from_value(serde_json::json!({"rows": []})).unwrap();
assert!(holder.rows.is_empty() && holder.maybe.is_none());
}
+
+#[test]
+fn history_wire_lifts_flat_strings_into_typed_rows_and_hands_them_back_exactly() {
+ // Key order and `null` content are the writer's, not ours: the string a
+ // file held is the string it keeps.
+ let envelope = "{\"content\":null,\"tool_calls\":[{\"id\":\"c1\",\"name\":\"n\",\"arguments\":\"{}\"}]}";
+ let tool = "{\"tool_call_id\":\"c1\",\"content\":\"ok\"}";
+ let raw = serde_json::json!({
+ "rows": [
+ {"role": "assistant", "content": envelope},
+ {"role": "tool", "content": tool},
+ {"role": "user", "content": "see [IMAGE:data:image/png;base64,AA==] there"},
+ ],
+ "maybe": null,
+ });
+ let holder: Holder = serde_json::from_value(raw.clone()).unwrap();
+ assert_eq!(holder.rows[0].tool_calls.len(), 1);
+ assert_eq!(holder.rows[0].content, "");
+ assert_eq!(holder.rows[1].tool_call_id.as_deref(), Some("c1"));
+ assert_eq!(holder.rows[1].content, "ok");
+ // A host-marker image stays text on the wire (the lift to image blocks is
+ // the message bridge's).
+ assert!(holder.rows[2].parts.is_none());
+ assert_eq!(serde_json::to_value(&holder).unwrap(), raw);
+}
+
+#[test]
+fn history_wire_writes_image_parts_as_host_markers() {
+ let row = TranscriptMessage::user_with_parts(vec![
+ TranscriptPart::Text { text: "see ".into() },
+ TranscriptPart::Image {
+ url: "data:image/png;base64,AA==".into(),
+ },
+ TranscriptPart::Text { text: " there".into() },
+ ]);
+ let holder = Holder {
+ rows: vec![row],
+ maybe: None,
+ };
+ assert_eq!(
+ serde_json::to_value(&holder).unwrap()["rows"][0]["content"],
+ "see [IMAGE:data:image/png;base64,AA==] there"
+ );
+}