Skip to content

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

test(inference): add hosted cloud slug explicit auth policy test

Steven Enamakel4579bd8bff3b
diff --git a/crates/openhuman-core/src/inference/provider/factory_explicit_ctx_tests.rs b/crates/openhuman-core/src/inference/provider/factory_explicit_ctx_tests.rs
index 1b5505faf2..8767e5152a 100644
--- a/crates/openhuman-core/src/inference/provider/factory_explicit_ctx_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_explicit_ctx_tests.rs
@@ -107,6 +107,153 @@ async fn managed_factory_and_probe_use_the_explicit_provider_entry() {
assert!(!b_probed.load(Ordering::SeqCst));
}
+#[tokio::test]
+async fn hosted_cloud_slug_uses_explicit_auth_policy_and_model_entry() {
+ use crate::config::schema::cloud_providers::{
+ register_hosted_cloud_provider_policy_in, AuthStyle, CloudProviderCreds,
+ };
+ use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
+ use crate::core::slots::Extensions;
+ use crate::inference::registry::{ChatModelEntry, ProviderModelHooks};
+ use std::sync::Arc;
+ use tinyinference_llm::message::Message;
+ use tinyinference_llm::model::ModelRequest;
+
+ fn entry(name: &'static str) -> ChatModelEntry {
+ ChatModelEntry {
+ build: Arc::new(move |_| {
+ Ok((
+ Arc::new(tinyagents_harness::testkit::ScriptedModel::replies(vec![name])),
+ name.to_string(),
+ ))
+ }),
+ probe: None,
+ models: Some(ProviderModelHooks {
+ default_model: Arc::new(move || Some(name.to_string())),
+ role_for_model: Arc::new(|_| None),
+ is_alias: Arc::new(|_| false),
+ is_raw_model: Arc::new(|model| !model.trim().is_empty()),
+ supports_vision: Arc::new(|_| false),
+ resolve_model: Arc::new(move |_, _, _| Some(name.to_string())),
+ context_window: Arc::new(|_| None),
+ default_pricing: Arc::new(|| None),
+ without_reasoning: Arc::new(|request| request),
+ }),
+ }
+ }
+
+ async fn response(
+ model: Arc<dyn tinyinference_llm::model::ChatModel<()>>,
+ ) -> String {
+ model
+ .invoke(&(), ModelRequest::new(vec![Message::user("fixture")]))
+ .await
+ .expect("scripted hosted model response")
+ .text()
+ }
+
+ let _guard = crate::inference::inference_test_guard_async().await;
+ let provider = crate::inference::provider::factory::PROVIDER_OPENHUMAN;
+ let mut outcomes = Vec::new();
+ for ambient_owns_auth in [false, true] {
+ let a_extensions = Extensions::new();
+ crate::inference::registry::register_chat_model_in(
+ &a_extensions,
+ provider,
+ entry("context-a-hosted-slug"),
+ );
+ register_hosted_cloud_provider_policy_in(
+ &a_extensions,
+ Arc::new(|slug| slug == "p_hosted"),
+ Arc::new(|style| style == AuthStyle::OpenhumanJwt),
+ );
+ let context_a =
+ CoreContext::for_test_with_extensions(DomainSet::full(), None, a_extensions);
+
+ let b_extensions = Extensions::new();
+ crate::inference::registry::register_chat_model_in(
+ &b_extensions,
+ provider,
+ entry("context-b-hosted-slug"),
+ );
+ register_hosted_cloud_provider_policy_in(
+ &b_extensions,
+ Arc::new(move |slug| ambient_owns_auth && slug == "p_hosted"),
+ Arc::new(move |style| ambient_owns_auth && style == AuthStyle::OpenhumanJwt),
+ );
+ let context_b =
+ CoreContext::for_test_with_extensions(DomainSet::full(), None, b_extensions);
+
+ let dispatch = DispatchCtx::new(context_a);
+ let mut config = Config::default();
+ config.chat_provider = Some("p_hosted:chat-v1".to_string());
+ config.cloud_providers.push(CloudProviderCreds {
+ id: "p_hosted_fixture".to_string(),
+ slug: "p_hosted".to_string(),
+ label: "Hosted fixture".to_string(),
+ endpoint: "https://hosted.example.test/v1".to_string(),
+ auth_style: AuthStyle::OpenhumanJwt,
+ default_model: Some("chat-v1".to_string()),
+ });
+
+ let observed = CoreContext::scope(context_b, async {
+ let one_shot = create_chat_model_with_model_id_in(&dispatch, "chat", &config, 0.0)
+ .map(|(_, model)| model)
+ .unwrap_or_else(|error| format!("ERR: {error}"));
+ let role_turn = create_turn_chat_model_with_native_tools_and_route(
+ &dispatch,
+ "chat",
+ &config,
+ "hint:chat",
+ 0.0,
+ true,
+ &crate::security::egress::EgressLedger::none(),
+ )
+ .ok()
+ .map(|(model, _, _)| model);
+ let string_turn = create_turn_chat_model_from_string_with_native_tools_and_route(
+ &dispatch,
+ "chat",
+ "p_hosted:chat-v1",
+ &config,
+ "hint:chat",
+ 0.0,
+ true,
+ &crate::security::egress::EgressLedger::none(),
+ )
+ .ok()
+ .map(|(model, _, _)| model);
+ let role_turn = match role_turn {
+ Some(model) => response(model).await,
+ None => "ERR: role turn construction failed".to_string(),
+ };
+ let string_turn = match string_turn {
+ Some(model) => response(model).await,
+ None => "ERR: explicit turn construction failed".to_string(),
+ };
+ (one_shot, role_turn, string_turn)
+ })
+ .await;
+ outcomes.push(observed);
+ }
+
+ assert_eq!(
+ outcomes,
+ vec![
+ (
+ "context-a-hosted-slug".to_string(),
+ "context-a-hosted-slug".to_string(),
+ "context-a-hosted-slug".to_string()
+ ),
+ (
+ "context-a-hosted-slug".to_string(),
+ "context-a-hosted-slug".to_string(),
+ "context-a-hosted-slug".to_string()
+ )
+ ]
+ );
+}
+
/// A flow's LLM capability builds its model under the context it was handed,
/// not the calling task's: the host override of the explicit context wins over
/// an installed ambient model, and two contexts never see each other's model.