Skip to content

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

test(search): add coverage for config and proxy modules

Steven Enamakel8b8bf85fb69d
diff --git a/crates/openhuman-core/src/modules/search/config_tests.rs b/crates/openhuman-core/src/modules/search/config_tests.rs
index bda4626071..cb0d7f1c40 100644
--- a/crates/openhuman-core/src/modules/search/config_tests.rs
+++ b/crates/openhuman-core/src/modules/search/config_tests.rs
@@ -188,3 +188,40 @@ fn search_off_disables_the_module_and_every_provider() {
assert!(payload.providers.values().all(|provider| !provider.enabled));
assert!(configured_tool_specs(&config).is_empty());
}
+
+#[test]
+fn a_pinned_key_reaches_the_module_config_with_its_endpoint() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = config_in(dir.path());
+ config.search.brave.api_key = Some("stored-brave".into());
+ config
+ .search
+ .pin_host_credential(
+ "brave",
+ crate::config::SearchHostCredential::new("pinned-brave")
+ .with_base_url("http://127.0.0.1:9"),
+ )
+ .unwrap();
+ let payload = module_config(&config);
+ let brave = &payload.providers["brave"];
+ assert!(brave.enabled);
+ assert_eq!(brave.route, ProviderRoute::Direct);
+ assert_eq!(brave.credential.as_deref(), Some("pinned-brave"));
+ assert_eq!(brave.base_url.as_deref(), Some("http://127.0.0.1:9"));
+ let names: Vec<String> = configured_tool_specs(&config)
+ .into_iter()
+ .map(|spec| spec.name)
+ .collect();
+ assert!(names.contains(&"web_search_tool".to_string()), "{names:?}");
+}
+
+#[test]
+fn a_stored_key_keeps_the_public_endpoint() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = config_in(dir.path());
+ select(&mut config, &[("brave", SearchProviderSettings::direct())]);
+ config.search.brave.api_key = Some("stored-brave".into());
+ let brave = &module_config(&config).providers["brave"];
+ assert_eq!(brave.credential.as_deref(), Some("stored-brave"));
+ assert_eq!(brave.base_url, None);
+}
diff --git a/crates/openhuman-core/src/modules/search/proxy_tests.rs b/crates/openhuman-core/src/modules/search/proxy_tests.rs
index 6caacbbb1b..13d289fa36 100644
--- a/crates/openhuman-core/src/modules/search/proxy_tests.rs
+++ b/crates/openhuman-core/src/modules/search/proxy_tests.rs
@@ -200,3 +200,51 @@ async fn released_search_artifact_serves_host_contract_and_rejects_disabled_exec
host.shutdown(std::time::Duration::from_secs(5)).await;
broker_task.abort();
}
+
+fn file_backed_config(dir: &std::path::Path) -> Config {
+ let mut config = Config::default();
+ config.config_path = dir.join("config.toml");
+ config.workspace_dir = dir.join("workspace");
+ config.secrets.encrypt = false;
+ config
+}
+
+#[tokio::test]
+async fn a_host_pinned_config_is_used_as_given_without_reading_config_path() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut config = file_backed_config(dir.path());
+ config
+ .search
+ .pin_host_credential(
+ "tavily",
+ crate::config::SearchHostCredential::new("agent-key"),
+ )
+ .unwrap();
+ // No config.toml exists; a reload would come back without the pin.
+ let current = current_config(&config).await.unwrap();
+ assert_eq!(current.search.direct_key("tavily"), Some("agent-key"));
+ assert!(current.search.is_host_pinned());
+ assert!(!config.config_path.exists(), "nothing was written");
+}
+
+#[tokio::test]
+async fn an_unpinned_config_is_reloaded_from_config_path() {
+ let dir = tempfile::tempdir().unwrap();
+ let mut on_disk = file_backed_config(dir.path());
+ on_disk.search.tavily.api_key = Some("file-key".into());
+ std::fs::create_dir_all(&on_disk.workspace_dir).unwrap();
+ std::fs::write(&on_disk.config_path, toml::to_string(&on_disk).unwrap()).unwrap();
+ // The caller's snapshot is stale: the file has since gained a key.
+ let stale = file_backed_config(dir.path());
+ let current = current_config(&stale).await.unwrap();
+ assert_eq!(current.search.direct_key("tavily"), Some("file-key"));
+}
+
+#[test]
+fn a_recorded_load_configuration_is_what_the_module_holds() {
+ let configuration = serde_json::json!({ "enabled": true, "providers": {} });
+ record_load_configuration(&configuration);
+ assert_eq!(held_fingerprint(), Some(fingerprint(&configuration)));
+ set_held(None);
+ assert_eq!(held_fingerprint(), None);
+}