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
fix(ranker): allow injecting a config loader for tests
Steven Enamakel5488a21c5aff
diff --git a/crates/openhuman-tinyhumans/src/jev/ranker.rs b/crates/openhuman-tinyhumans/src/jev/ranker.rsindex c6e309b0d5..891a91ccbe 100644--- a/crates/openhuman-tinyhumans/src/jev/ranker.rs+++ b/crates/openhuman-tinyhumans/src/jev/ranker.rs@@ -7,16 +7,26 @@ use std::{sync::Mutex,};+use std::{future::Future, pin::Pin, sync::Arc};+use openhuman_core::api::config::effective_backend_api_url;use openhuman_core::config::Config;use openhuman_core::security::credentials::session_support::resolve_backend_credential;use tinytools::{RankCandidate, RankContext, RankError, RankHit, ToolRanker};use tinytools_jev::{ClientConfig, JevRanker, JevRankerConfig};+/// How the ranker reads the config a search runs under. The default is the+/// core's own read path (the embedder's config when one is bound, else the+/// process-global load); a test hands in a fixed one.+pub type ConfigLoader = Arc<+ dyn Fn() -> Pin<Box<dyn Future<Output = Result<Config, String>> + Send>> + Send + Sync,+>;+/// A [`JevRanker`] bound to whichever credential and backend the process has/// at search time.pub struct TinyHumansJevRanker {config: JevRankerConfig,+ load_config: ConfigLoader,cached: Mutex<Option<Cached>>,}@@ -50,10 +60,19 @@ impl TinyHumansJevRanker {pub fn with_config(config: JevRankerConfig) -> Self {Self {config,+ load_config: Arc::new(|| {+ Box::pin(openhuman_core::config::ops::load_config_with_timeout())+ }),cached: Mutex::new(None),}}+ /// Reads the config through `loader` instead of the core's read path.+ pub fn with_config_loader(mut self, loader: ConfigLoader) -> Self {+ self.load_config = loader;+ self+ }+/// The `JevRanker` for the current credential and backend, built or/// reused.///@@ -62,10 +81,10 @@ impl TinyHumansJevRanker {/// dwarfs, and the benefit is that sign-in, sign-out and a backend URL/// change are all honoured by the next search.async fn current(&self) -> Result<JevRanker, RankError> {- let config = Config::load_or_init()+ let config = (self.load_config)().await.map_err(|error| RankError::Backend {- reason: format!("config unavailable: {error:#}"),+ reason: format!("config unavailable: {error}"),})?;let credential = resolve_backend_credential(&config).map_err(|reason| {// The message names what is missing, never a secret.diff --git a/crates/openhuman-tinyhumans/src/jev/ranker_tests.rs b/crates/openhuman-tinyhumans/src/jev/ranker_tests.rsindex 84622f3d7e..b3b7501e57 100644--- a/crates/openhuman-tinyhumans/src/jev/ranker_tests.rs+++ b/crates/openhuman-tinyhumans/src/jev/ranker_tests.rs@@ -25,8 +25,16 @@ fn fingerprint_changes_with_secret_or_base_url() {#[tokio::test]async fn no_credential_is_a_backend_error_naming_the_gap() {let tmp = tempfile::tempdir().expect("tempdir");- let _guard = openhuman_core::config::test_support::EnvGuard::set_home(tmp.path());- let ranker = TinyHumansJevRanker::new();+ let config = Config {+ workspace_dir: tmp.path().join("workspace"),+ action_dir: tmp.path().join("workspace"),+ config_path: tmp.path().join("config.toml"),+ ..Config::default()+ };+ let ranker = TinyHumansJevRanker::new().with_config_loader(Arc::new(move || {+ let config = config.clone();+ Box::pin(async move { Ok(config) })+ }));let err = ranker.rank("send a message",@@ -38,10 +46,7 @@ async fn no_credential_is_a_backend_error_naming_the_gap() {.expect_err("no credential must fail");match err {RankError::Backend { reason } => {- assert!(- reason.contains("no TinyHumans credential") || reason.contains("config"),- "{reason}"- );+ assert!(reason.contains("no TinyHumans credential"), "{reason}");}other => panic!("expected a backend error, got {other}"),}