Skip to content

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

test(web_chat): add backend metadata classification to web tests

Steven Enamakelb5d928f171d4
diff --git a/crates/openhuman-core/src/web_chat/web_tests.rs b/crates/openhuman-core/src/web_chat/web_tests.rs
index 5ae4b82dd1..f84dd68e41 100644
--- a/crates/openhuman-core/src/web_chat/web_tests.rs
+++ b/crates/openhuman-core/src/web_chat/web_tests.rs
@@ -11,8 +11,12 @@ use super::{
TestRunChatTaskBlock, WebChatParams,
};
use crate::core::TypeSchema;
+use crate::inference::registry::{
+ register_backend_error_classifier, BackendErrorClassification, BackendErrorKind,
+};
use std::sync::atomic::{AtomicBool, Ordering};
-use std::sync::Arc;
+use std::sync::{Arc, Mutex, OnceLock};
+use std::collections::HashMap;
use tinyagents_harness::run_queue::QueueLane;
use tokio::time::{timeout, Duration};
@@ -49,6 +53,56 @@ fn managed_error(status: &str, body: &str) -> String {
format!("OpenHuman API error ({status}): {body}")
}
+/// Run a web-copy assertion with explicit provider-neutral metadata. Hosted
+/// token/envelope parsing belongs to TinyHumans; core tests inject the semantic
+/// classification that the host registry supplies at runtime.
+fn classify_with_backend_metadata(
+ message: &str,
+ kind: BackendErrorKind,
+ malformed_bad_request: bool,
+) -> ClassifiedError {
+ static FIXTURES: OnceLock<Arc<Mutex<HashMap<String, BackendErrorClassification>>>> =
+ OnceLock::new();
+ let fixtures = Arc::clone(FIXTURES.get_or_init(|| Arc::new(Mutex::new(HashMap::new()))));
+ register_backend_error_classifier(Arc::new(move |_provider, error| {
+ fixtures
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .get(error)
+ .cloned()
+ .unwrap_or(BackendErrorClassification {
+ provider_owned: false,
+ backend_owned: false,
+ reportable: true,
+ token: None,
+ kind: None,
+ malformed_bad_request: false,
+ })
+ }));
+ FIXTURES
+ .get()
+ .expect("fixture map initialized")
+ .lock()
+ .unwrap_or_else(|poisoned| poisoned.into_inner())
+ .insert(
+ message.to_string(),
+ BackendErrorClassification {
+ provider_owned: true,
+ backend_owned: true,
+ reportable: malformed_bad_request
+ || matches!(
+ kind,
+ BackendErrorKind::PayloadTooLarge
+ | BackendErrorKind::ContextLengthExceeded
+ ),
+ token: None,
+ kind: Some(kind),
+ malformed_bad_request,
+ },
+ );
+ classify_inference_error(message)
+}
+
// ── SessionCacheFingerprint (thread-session cache invalidation) ───────
use super::SessionCacheFingerprint;