Skip to content

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

test(memory): cover the office converter's name and its failed-task error

Ghost Scripter6fe9b9abb7ef
diff --git a/crates/openhuman-core/src/memory/convert.rs b/crates/openhuman-core/src/memory/convert.rs
index 03aac3cdb0..557cfb68e9 100644
--- a/crates/openhuman-core/src/memory/convert.rs
+++ b/crates/openhuman-core/src/memory/convert.rs
@@ -46,10 +46,17 @@ impl DocumentConverter for BlockingOffice {
let document = document.clone();
tokio::task::spawn_blocking(move || OfficeConverter.convert_blocking(&document))
.await
- .map_err(|error| Error::Converter {
- converter: "office".to_string(),
- message: format!("the conversion task did not finish: {error}"),
- })?
+ .map_err(task_failed)?
+ }
+}
+
+/// The error for a conversion task that never finished (it panicked or was
+/// cancelled): a converter failure, never a crash of the caller.
+#[cfg(feature = "documents")]
+fn task_failed(error: impl std::fmt::Display) -> Error {
+ Error::Converter {
+ converter: "office".to_string(),
+ message: format!("the conversion task did not finish: {error}"),
}
}
diff --git a/crates/openhuman-core/src/memory/convert_tests.rs b/crates/openhuman-core/src/memory/convert_tests.rs
index 6b11ca7db9..4f24435de9 100644
--- a/crates/openhuman-core/src/memory/convert_tests.rs
+++ b/crates/openhuman-core/src/memory/convert_tests.rs
@@ -112,3 +112,25 @@ async fn without_the_documents_feature_a_pdf_is_refused_cleanly() {
let error = converter().convert(&raw).await.unwrap_err();
assert!(matches!(error, Error::UnsupportedFormat(_)), "{error}");
}
+
+#[cfg(feature = "documents")]
+#[test]
+fn the_office_converter_names_itself_and_claims_only_office_formats() {
+ use tinymemory_integrations::documents::DocumentFormat;
+ assert_eq!(BlockingOffice.name(), "office");
+ assert!(BlockingOffice.supports(DocumentFormat::Pdf));
+ assert!(BlockingOffice.supports(DocumentFormat::Docx));
+ assert!(!BlockingOffice.supports(DocumentFormat::Markdown));
+}
+
+#[cfg(feature = "documents")]
+#[test]
+fn a_conversion_task_that_dies_is_a_converter_error_not_a_crash() {
+ match task_failed("task panicked") {
+ Error::Converter { converter, message } => {
+ assert_eq!(converter, "office");
+ assert!(message.contains("task panicked"), "{message}");
+ }
+ other => panic!("expected a converter error, got {other:?}"),
+ }
+}