Skip to content

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

test(tools): add content-type detection tests for web fetch

Steven Enamakelac1c035462a7
diff --git a/crates/openhuman-core/src/tools/impl/network/web_fetch_tests.rs b/crates/openhuman-core/src/tools/impl/network/web_fetch_tests.rs
index af8c64653f..30fbdcb77a 100644
--- a/crates/openhuman-core/src/tools/impl/network/web_fetch_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/network/web_fetch_tests.rs
@@ -106,3 +106,60 @@ fn test_web_fetch_truncation_utf8() {
assert_eq!(cut, 6);
assert_eq!(&body[..cut], "Hello ");
}
+
+// --- content extraction ----------------------------------------------------
+
+#[test]
+fn an_explicit_html_content_type_selects_markdown_conversion() {
+ assert!(is_html("<p>hi</p>", Some("text/html; charset=utf-8")));
+ assert!(is_html("<p>hi</p>", Some("application/xhtml+xml")));
+}
+
+#[test]
+fn an_explicit_non_html_content_type_is_taken_at_its_word() {
+ // A JSON API that happens to quote markup must come back verbatim —
+ // the server said what it sent, so we don't second-guess it by sniffing.
+ let body = r#"{"html": "<div><p>one</p><span>two</span><a href=\"#\">x</a></div>"}"#;
+ assert!(!is_html(body, Some("application/json")));
+ assert!(!is_html("<p>x</p>", Some("text/plain")));
+}
+
+#[test]
+fn a_missing_content_type_falls_back_to_content_detection() {
+ assert!(is_html(
+ "<!DOCTYPE html><html><body><p>hi</p></body></html>",
+ None
+ ));
+ assert!(!is_html("# Just a README\n\nSome prose.\n", None));
+}
+
+#[test]
+fn an_empty_content_type_does_not_veto_detection() {
+ assert!(is_html("<!DOCTYPE html><html><body>x</body></html>", Some("")));
+}
+
+#[test]
+fn the_schema_offers_the_raw_escape_hatch() {
+ let tool = WebFetchTool::new(Arc::new(SecurityPolicy::default()), vec![], None, None);
+ let schema = tool.parameters_schema();
+ assert!(
+ schema["properties"].get("raw").is_some(),
+ "a caller must be able to opt out of conversion: {schema}"
+ );
+ assert!(
+ tool.description().contains("Markdown"),
+ "the model needs to know what it will get back: {}",
+ tool.description()
+ );
+}
+
+#[test]
+fn the_declared_cap_is_sized_for_extracted_markdown_not_raw_markup() {
+ let tool = WebFetchTool::new(Arc::new(SecurityPolicy::default()), vec![], None, None);
+ let cap = tool.max_result_size_chars().expect("web_fetch declares a cap");
+ assert!(
+ (8_000..=32_000).contains(&cap),
+ "cap should sit in the same range as Hermes (15k chars) and Codex \
+ (~10k tokens) budget for one result, got {cap}"
+ );
+}