Skip to content

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

chore: files changed crates/openhuman-core/src/inference/provider/ops/models_tests.rs,crates/openhum

Steven Enamakel6e5c76cbb0c5
diff --git a/crates/openhuman-core/src/inference/provider/ops/models_tests.rs b/crates/openhuman-core/src/inference/provider/ops/models_tests.rs
index 42874e035a..eea79a9567 100644
--- a/crates/openhuman-core/src/inference/provider/ops/models_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/ops/models_tests.rs
@@ -1,7 +1,4 @@
-use super::{
- managed_401_means_signed_out, managed_session_attaches, resolve_local_runtime_key,
- synthesize_managed_entry, url_is_credential_safe,
-};
+use super::resolve_local_runtime_key;
use crate::config::Config;
#[test]
@@ -34,148 +31,6 @@ fn non_omlx_slug_does_not_fall_back() {
);
}
-/// A bearer credential must never ride a plaintext connection to a remote host.
-/// Loopback stays allowed so a locally-hosted backend still authenticates in
-/// development.
-#[test]
-fn credentials_ride_https_or_loopback_only() {
- for url in [
- "https://api.tinyhumans.ai/openai/v1/models",
- "https://staging-api.tinyhumans.ai/openai/v1/models?catalog=openrouter",
- "http://localhost:5005/openai/v1/models",
- "http://127.0.0.1:5005/openai/v1/models",
- ] {
- assert!(url_is_credential_safe(url), "{url}");
- }
-}
-
-#[test]
-fn credentials_are_withheld_from_remote_plaintext_and_junk_urls() {
- for url in [
- "http://api.tinyhumans.ai/openai/v1/models",
- "http://192.168.1.10:5005/openai/v1/models",
- "not a url",
- "",
- ] {
- assert!(!url_is_credential_safe(url), "{url}");
- }
-}
-
-/// The managed row is normally seeded by a migration, but a freshly created
-/// profile has none — which is what the app falls back to when a stored session
-/// is rejected. Managed is the product's own backend, so it must not depend on a
-/// user-config row; without this, being signed out surfaced
-/// "no cloud provider with id or slug 'openhuman' found".
-#[test]
-fn managed_entry_is_synthesized_when_the_config_row_is_missing() {
- use crate::config::schema::cloud_providers::AuthStyle;
- let entry = synthesize_managed_entry("openhuman").expect("managed entry");
- assert_eq!(entry.slug, "openhuman");
- assert_eq!(entry.auth_style, AuthStyle::OpenhumanJwt);
- assert!(!entry.endpoint.is_empty());
-}
-
-/// Only the managed slug synthesizes: anything else must keep reporting an
-/// unknown provider rather than being silently treated as managed.
-#[test]
-fn other_slugs_do_not_synthesize_a_managed_entry() {
- for slug in ["openai", "openrouter", "ollama", "", "openhuman-x"] {
- assert!(synthesize_managed_entry(slug).is_none(), "{slug}");
- }
-}
-
-/// A managed 401 is a signed-out state, not a provider failure: the stored
-/// session was rejected server-side while its local `exp` was still valid, so
-/// the picker rendered "could not load models" for a user whose only problem
-/// was a stale session.
-#[test]
-fn a_managed_401_reads_as_signed_out() {
- use crate::config::schema::cloud_providers::AuthStyle;
- assert!(managed_401_means_signed_out(
- 401,
- AuthStyle::OpenhumanJwt,
- true
- ));
-}
-
-/// When no session existed, the request went out with the provider-scoped
-/// fallback key — so a 401 means THAT key is wrong or revoked. Hiding it behind
-/// an empty catalog would strand a self-hosted entry with no clue why.
-#[test]
-fn a_401_against_the_fallback_key_still_surfaces() {
- use crate::config::schema::cloud_providers::AuthStyle;
- assert!(!managed_401_means_signed_out(
- 401,
- AuthStyle::OpenhumanJwt,
- false
- ));
-}
-
-/// A live session is not enough on its own: the credential-safety guard refuses
-/// to attach a bearer token to a non-https, non-loopback URL, so the request
-/// goes out unauthenticated. Reporting that 401 as signed-out would hide the
-/// misconfigured backend URL behind an empty catalog — the same failure this
-/// whole change exists to stop.
-#[test]
-fn a_session_is_not_attached_to_an_unsafe_url() {
- for url in [
- "http://api.example.com/openai/v1/models",
- "http://192.168.1.10:8080/openai/v1/models",
- ] {
- assert!(
- !managed_session_attaches("session-jwt", url),
- "a live session must not be attached to {url}"
- );
- }
- for url in [
- "https://api.tinyhumans.ai/openai/v1/models",
- "http://127.0.0.1:8787/openai/v1/models",
- ] {
- assert!(
- managed_session_attaches("session-jwt", url),
- "a live session must be attached to {url}"
- );
- }
- // No session: nothing to attach, whatever the URL.
- assert!(!managed_session_attaches(
- "",
- "https://api.tinyhumans.ai/openai/v1/models"
- ));
-}
-
-/// The two halves composed: a live session withheld by the safety guard reaches
-/// the 401 classifier as "not attached", so the error still surfaces.
-#[test]
-fn a_401_on_a_token_the_safety_guard_withheld_still_surfaces() {
- use crate::config::schema::cloud_providers::AuthStyle;
- let attached = managed_session_attaches("session-jwt", "http://api.example.com/v1/models");
- assert!(!managed_401_means_signed_out(
- 401,
- AuthStyle::OpenhumanJwt,
- attached
- ));
-}
-
-/// Everything else must keep surfacing the error. A BYOK 401 is the actionable
-/// case (wrong or revoked key) and must not be swallowed into an empty list,
-/// and a managed non-401 is a genuine provider failure.
-#[test]
-fn other_statuses_and_providers_still_surface_the_error() {
- use crate::config::schema::cloud_providers::AuthStyle;
- for style in [AuthStyle::Bearer, AuthStyle::Anthropic, AuthStyle::None] {
- assert!(
- !managed_401_means_signed_out(401, style, true),
- "{style:?} 401"
- );
- }
- for status in [400, 403, 404, 429, 500, 503] {
- assert!(
- !managed_401_means_signed_out(status, AuthStyle::OpenhumanJwt, true),
- "managed {status}"
- );
- }
-}
-
fn workspace_with_provider(
tmp: &tempfile::TempDir,
slug: &str,
@@ -248,3 +103,23 @@ async fn unsupported_scheme_endpoint_still_surfaces_an_error() {
let result = super::list_configured_models_from_config("custom-ftp", &config).await;
assert!(result.is_err(), "ftp:// must not read as an empty catalog");
}
+
+/// With no catalog provider registered, the managed provider (by id, and by an
+/// `OpenhumanJwt` entry) lists an empty catalog rather than failing.
+#[tokio::test]
+async fn unregistered_managed_catalog_lists_no_models() {
+ use crate::config::schema::cloud_providers::AuthStyle;
+ let tmp = tempfile::tempdir().expect("tempdir");
+ let config = workspace_with_provider(
+ &tmp,
+ "custom-managed",
+ "https://managed.example/v1",
+ AuthStyle::OpenhumanJwt,
+ );
+ for provider in ["openhuman", "custom-managed"] {
+ let outcome = super::list_configured_models_from_config(provider, &config)
+ .await
+ .expect("an unregistered managed catalog is empty, not an error");
+ assert_eq!(outcome.value["models"], serde_json::json!([]), "{provider}");
+ }
+}
diff --git a/crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs b/crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs
new file mode 100644
index 0000000000..8edb4fb6e5
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/inference/managed_catalog_tests.rs
@@ -0,0 +1,55 @@
+use super::*;
+
+#[test]
+fn a_managed_401_on_an_attached_session_reads_as_signed_out() {
+ assert!(managed_401_means_signed_out(401, true));
+}
+
+/// A 401 on a request that never carried the session token describes the
+/// request (a misconfigured URL), not the session, so the error surfaces.
+#[test]
+fn a_401_without_an_attached_session_still_surfaces() {
+ assert!(!managed_401_means_signed_out(401, false));
+}
+
+#[test]
+fn other_statuses_still_surface_the_error() {
+ for status in [400, 403, 404, 429, 500, 503] {
+ assert!(!managed_401_means_signed_out(status, true), "managed {status}");
+ }
+}
+
+#[test]
+fn the_catalog_url_targets_the_openrouter_catalog_on_the_control_plane() {
+ let config = Config {
+ api_url: Some("https://api.tinyhumans.ai".into()),
+ ..Config::default()
+ };
+ let url = catalog_url(&config);
+ assert!(url.ends_with("/openai/v1/models?catalog=openrouter"), "{url}");
+}
+
+#[test]
+fn limits_request_is_none_for_a_blank_model() {
+ assert!(limits_request(" ", &Config::default()).is_none());
+}
+
+#[test]
+fn limits_request_lists_the_catalog_keyed_by_the_inference_base() {
+ let config = Config {
+ api_url: Some("https://api.tinyhumans.ai".into()),
+ ..Config::default()
+ };
+ let request = limits_request("some/model", &config).expect("managed limits request");
+ assert_eq!(request.endpoint, "https://api.tinyhumans.ai/openai/v1");
+ assert!(request
+ .listing_url
+ .as_deref()
+ .is_some_and(|url| url.ends_with("/openai/v1/models?catalog=openrouter")));
+}
+
+#[test]
+fn truncate_caps_long_text_with_an_ellipsis() {
+ assert_eq!(truncate("abc", 5), "abc");
+ assert_eq!(truncate("abcdef", 3), "abc...");
+}