Skip to content

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

test(e2e): improve file content assertion in session restart test

Steven Enamakel0aafafbb5d92
diff --git a/tests/native_channel_session_restart_e2e.rs b/tests/native_channel_session_restart_e2e.rs
index 9851dcc4c7..49e4f1a0d3 100644
--- a/tests/native_channel_session_restart_e2e.rs
+++ b/tests/native_channel_session_restart_e2e.rs
@@ -760,10 +760,23 @@ fn assert_model_received_file_content(request: &Value) {
"typed document carries the downloaded file bytes: {encoded}"
);
} else {
- assert!(
- content_has_text_block(content, std::str::from_utf8(NATIVE_FILE_BYTES).unwrap()),
- "unsupported Document input must reach the model as extracted literal text"
- );
+ if !content_has_text_block(content, std::str::from_utf8(NATIVE_FILE_BYTES).unwrap()) {
+ let serialized = serde_json::to_string(content).unwrap_or_default();
+ panic!(
+ "unsupported Document input must reach the model as extracted literal text; safe content shape: kind={} block_types={:?} staged_ref={} file_bytes_text={} file_bytes_base64={} caption={}",
+ match content {
+ Value::Array(_) => "array",
+ Value::Object(_) => "object",
+ Value::String(_) => "string",
+ _ => "other",
+ },
+ content_block_types(content),
+ serialized.contains("openhuman-staged://"),
+ serialized.contains(std::str::from_utf8(NATIVE_FILE_BYTES).unwrap()),
+ serialized.contains(&base64::engine::general_purpose::STANDARD.encode(NATIVE_FILE_BYTES)),
+ serialized.contains("file caption before media")
+ );
+ }
}
let text_blocks = collect_text_blocks(content);
let encoded = base64::engine::general_purpose::STANDARD.encode(NATIVE_FILE_BYTES);
@@ -809,6 +822,22 @@ fn find_block_type<'a>(value: &'a Value, expected: &str) -> Option<&'a Value> {
}
}
+fn content_block_types(value: &Value) -> Vec<String> {
+ match value {
+ Value::Array(items) => items.iter().flat_map(content_block_types).collect(),
+ Value::Object(fields) => {
+ let mut kinds = fields
+ .get("type")
+ .and_then(Value::as_str)
+ .map(|kind| vec![kind.to_owned()])
+ .unwrap_or_default();
+ kinds.extend(fields.values().flat_map(content_block_types));
+ kinds
+ }
+ _ => Vec::new(),
+ }
+}
+
fn content_has_text_block(value: &Value, expected: &str) -> bool {
match value {
Value::Array(items) => items