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
chore(openhuman-embed): add test support module
Steven Enamakel27a9ee288261
diff --git a/crates/openhuman-embed/Cargo.toml b/crates/openhuman-embed/Cargo.tomlindex c9e0f366a3..d93d0e3b99 100644--- a/crates/openhuman-embed/Cargo.toml+++ b/crates/openhuman-embed/Cargo.toml@@ -82,6 +82,10 @@ async-trait = "0.1"tinymemory-api = { path = "../../vendor/tinymemory/crates/tinymemory-api", features = ["conformance"] }dirs = "6"env_logger = "0.11"+# The profile tests and example implement a stub `BackendTransport`, whose+# `http_client` hands out a `reqwest::Client`. Same features as the core's, so+# the dev graph adds no reqwest feature (see the unification note below).+reqwest = { version = "0.12", default-features = false, features = ["json", "blocking", "rustls-tls", "stream", "http2", "multipart", "socks"] }wiremock = "0.6"# Feature unification with openhuman-cli's dev-dependencies. Cargo builds the# core once per distinct feature set of its dependencies, and the tests ofdiff --git a/crates/openhuman-embed/tests/common/mod.rs b/crates/openhuman-embed/tests/common/mod.rsindex 4e7ceede55..ab79337f95 100644--- a/crates/openhuman-embed/tests/common/mod.rs+++ b/crates/openhuman-embed/tests/common/mod.rs@@ -219,3 +219,126 @@ pub async fn eventually<T>(what: &str, mut check: impl FnMut() -> Option<T>) ->}panic!("timed out waiting for {what}");}++/// A backend transport that sends managed inference to `base_url` (a mock)+/// and answers every control-plane call as "no backend". For suites that run+/// turns through the core's managed-inference path, such as SaaS profiles,+/// whose configs name no inference endpoint of their own.+pub struct PointedTransport {+ base_url: String,+}++impl PointedTransport {+ pub fn install(base_url: &str) {+ openhuman_embed::install_backend_transport(std::sync::Arc::new(Self {+ base_url: base_url.trim_end_matches('/').to_string(),+ }));+ }+}++#[async_trait::async_trait]+impl openhuman_embed::BackendTransport for PointedTransport {+ async fn send_json(+ &self,+ _req: openhuman_embed::BackendRequest<'_>,+ ) -> Result<serde_json::Value, openhuman_embed::BackendTransportError> {+ Err(openhuman_embed::BackendTransportError::Unavailable)+ }++ async fn send_multipart(+ &self,+ _req: openhuman_embed::BackendRequest<'_>,+ _form: reqwest::multipart::Form,+ ) -> Result<serde_json::Value, openhuman_embed::BackendTransportError> {+ Err(openhuman_embed::BackendTransportError::Unavailable)+ }++ fn http_client(&self, _profile: openhuman_embed::TransportProfile) -> reqwest::Client {+ reqwest::Client::new()+ }++ fn base_url(&self, _configured: Option<&str>, _purpose: openhuman_embed::BaseUrlPurpose) -> String {+ self.base_url.clone()+ }++ fn product_identity(&self) -> String {+ "openhuman-embed-test".to_string()+ }++ fn attribution_headers(&self) -> reqwest::header::HeaderMap {+ reqwest::header::HeaderMap::new()+ }++ fn name(&self) -> &'static str {+ "embed-test-pointed"+ }+}++/// A mock OpenAI-compatible endpoint that answers every chat completion with+/// `echo: <the last user message>`, streamed when the request asks for it,+/// and every other request with an empty success.+pub async fn echo_inference() -> MockServer {+ let server = MockServer::start().await;+ wiremock::Mock::given(wiremock::matchers::path_regex(r"chat/completions$"))+ .respond_with(EchoCompletion)+ .with_priority(1)+ .mount(&server)+ .await;+ wiremock::Mock::given(wiremock::matchers::any())+ .respond_with(+ wiremock::ResponseTemplate::new(200)+ .set_body_json(json!({ "success": true, "data": [] })),+ )+ .with_priority(10)+ .mount(&server)+ .await;+ server+}++/// The last user message of a chat-completion request body.+pub fn last_user_message(body: &serde_json::Value) -> String {+ body.get("messages")+ .and_then(|m| m.as_array())+ .and_then(|messages| {+ messages+ .iter()+ .rev()+ .find(|m| m.get("role").and_then(|r| r.as_str()) == Some("user"))+ })+ .and_then(|m| match m.get("content")? {+ serde_json::Value::String(s) => Some(s.clone()),+ other => Some(other.to_string()),+ })+ .unwrap_or_default()+}++struct EchoCompletion;++impl wiremock::Respond for EchoCompletion {+ fn respond(&self, request: &Request) -> wiremock::ResponseTemplate {+ let body: serde_json::Value = serde_json::from_slice(&request.body).unwrap_or_default();+ let reply = format!("echo: {}", last_user_message(&body));+ if body.get("stream").and_then(|s| s.as_bool()) == Some(true) {+ let chunk = json!({+ "id": "chatcmpl-embed-test",+ "object": "chat.completion.chunk",+ "created": 1_700_000_000_u64,+ "model": "embed-test-model",+ "choices": [{ "index": 0, "delta": { "role": "assistant", "content": reply }, "finish_reason": null }]+ });+ let done = json!({+ "id": "chatcmpl-embed-test",+ "object": "chat.completion.chunk",+ "created": 1_700_000_000_u64,+ "model": "embed-test-model",+ "choices": [{ "index": 0, "delta": {}, "finish_reason": "stop" }],+ "usage": { "prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2 }+ });+ wiremock::ResponseTemplate::new(200)+ .insert_header("content-type", "text/event-stream")+ .set_body_string(format!("data: {chunk}\n\ndata: {done}\n\ndata: [DONE]\n\n"))+ } else {+ wiremock::ResponseTemplate::new(200).set_body_json(chat_completion(&reply))+ }+ }+}