The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
test(embed): cover provider failure and timeout paths
Steven Enamakelf9b774583850
diff --git a/crates/openhuman-embed/src/complete.rs b/crates/openhuman-embed/src/complete.rsindex ec1df094ef..f9af1942a4 100644--- a/crates/openhuman-embed/src/complete.rs+++ b/crates/openhuman-embed/src/complete.rs@@ -373,7 +373,7 @@ fn parse_json_reply(text: &str) -> Option<Value> {#[derive(Debug)]pub struct CompletionTrace<'a> {/// The request as the host built it. The route's bearer is never part of- /// a request, so this is safe to export.+ /// a request; the message content is.pub request: &'a CompletionRequest,/// The response, or the error the call ended with.pub outcome: Result<&'a CompletionResponse, &'a CoreError>,diff --git a/crates/openhuman-embed/src/complete_tests.rs b/crates/openhuman-embed/src/complete_tests.rsindex b56512bd73..4aa8fb9ab3 100644--- a/crates/openhuman-embed/src/complete_tests.rs+++ b/crates/openhuman-embed/src/complete_tests.rs@@ -227,3 +227,49 @@ async fn raw_cost_survives_a_usage_block_without_tokens() {let usage = response.usage.expect("the provider reported a cost");assert_eq!(usage.cost_usd, Some(0.5));}++#[tokio::test]+async fn provider_failure_maps_to_an_rpc_error() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path("/v1/chat/completions"))+ .respond_with(ResponseTemplate::new(400).set_body_string("bad request"))+ .mount(&server)+ .await;+ let request = CompletionRequest::new("m", vec![ChatMessage::user("x")]);+ let err = completer(&server)+ .complete(request)+ .await+ .expect_err("a 400 must surface as an error");+ assert!(+ matches!(err, CoreError::Rpc { method, .. } if method == COMPLETE),+ "{err:?}"+ );+}++#[tokio::test]+async fn slow_provider_hits_the_timeout_branch() {+ let server = MockServer::start().await;+ Mock::given(method("POST"))+ .and(path("/v1/chat/completions"))+ .respond_with(+ ResponseTemplate::new(200)+ .set_body_json(body("late", "stop"))+ .set_delay(Duration::from_millis(2_000)),+ )+ .mount(&server)+ .await;+ let request = CompletionRequest::new("m", vec![ChatMessage::user("x")]);+ let err = completer(&server)+ .timeout(Duration::from_millis(50))+ .complete(request)+ .await+ .expect_err("the call must time out before the delayed reply");+ match err {+ CoreError::Rpc { method, message } => {+ assert_eq!(method, COMPLETE);+ assert_eq!(message, "timed out after 50ms");+ }+ other => panic!("expected a timeout Rpc error, got {other:?}"),+ }+}