From 4415dc4672a3c0b12d7f7fbb54ddc89d4284704b Mon Sep 17 00:00:00 2001 From: DocTator Date: Tue, 19 May 2026 06:03:33 -0400 Subject: [PATCH] test(retrieve): install rustls CryptoProvider in reranker tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR #6 installed a process-global rustls CryptoProvider in the api test setup_app() so the ~20 api tests stop panicking with "no process-level CryptoProvider available." That fix happened to also unblock the 3 retrieve::reranker tests that call reqwest::Client::new() — but only because api tests run before reranker tests in the same test binary, install the provider as a side effect, and the static Once is shared. Running `cargo test --lib retrieve::reranker::` in isolation still panics: no api test runs first, no provider is installed. That makes the green-CI claim from 3472c74 order-dependent. Mirror the PR #6 pattern here: own install_crypto_provider() helper guarded by its own Once, called at the top of each test that constructs a Reranker. Now `cargo test --lib retrieve::reranker::` passes 8/8 standalone. Co-Authored-By: Claude Opus 4.7 --- omem-server/src/retrieve/reranker.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/omem-server/src/retrieve/reranker.rs b/omem-server/src/retrieve/reranker.rs index 31f6e94..9b82663 100644 --- a/omem-server/src/retrieve/reranker.rs +++ b/omem-server/src/retrieve/reranker.rs @@ -128,6 +128,24 @@ impl Reranker { mod tests { use super::*; + // rustls 0.23 requires a process-global CryptoProvider to be installed + // before any TLS-aware reqwest::Client is constructed. The api tests + // install one in setup_app(), but retrieve::reranker tests don't go + // through that path — so under `cargo test --lib retrieve::reranker::` + // the tests panic with "no process-level CryptoProvider available." + // (They appear to pass under `cargo test --lib` because the api tests + // happen to run first in the same binary and install the provider as + // a side effect — order-dependent.) + // + // Guarded by Once so the multiple tests sharing this binary don't race. + fn install_crypto_provider() { + use std::sync::Once; + static INIT: Once = Once::new(); + INIT.call_once(|| { + let _ = rustls::crypto::ring::default_provider().install_default(); + }); + } + #[test] fn test_from_env_none_provider() { std::env::remove_var("OMEM_RERANK_PROVIDER"); @@ -145,6 +163,7 @@ mod tests { #[test] fn test_new_with_endpoint() { + install_crypto_provider(); let reranker = Reranker::new_with_endpoint("jina", "http://localhost:8080/rerank", "key"); assert_eq!(reranker.provider(), "jina"); assert_eq!(reranker.endpoint, "http://localhost:8080/rerank"); @@ -152,6 +171,7 @@ mod tests { #[tokio::test] async fn test_rerank_empty_documents() { + install_crypto_provider(); let reranker = Reranker::new_with_endpoint("jina", "http://localhost:1/rerank", "key"); let result = reranker.rerank("query", &[]).await; assert!(result.is_ok()); @@ -160,6 +180,7 @@ mod tests { #[tokio::test] async fn test_rerank_timeout_returns_error() { + install_crypto_provider(); let reranker = Reranker { provider: "jina".to_string(), endpoint: "http://192.0.2.1:1/rerank".to_string(),