Skip to content

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

refactor(provider): clean up imports and simplify assertions in provider logic

Steven Enamakelc054fbe04d6d
diff --git a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
index 2149dcae5f..3aef45d5ac 100644
--- a/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/local_runtime.rs
@@ -40,7 +40,7 @@ pub(super) fn try_create_local_runtime_chat_model_from_string(
egress: &EgressLedger,
) -> OptionalChatModelResult {
use tinyinference_local::local_runtime::{
- LocalRuntimeAuth, LocalRuntimeInputs, resolve_local_runtime,
+ resolve_local_runtime, LocalRuntimeAuth, LocalRuntimeInputs,
};
// Use the same classifier as privacy and session policy. Canonicalize only
diff --git a/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs b/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
index a871a5d70e..109b68a11d 100644
--- a/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory/routing_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use crate::config::Config;
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+use crate::config::Config;
use crate::inference::provider::factory::resolves_to_managed_backend;
fn byok_openai_compatible_entry() -> CloudProviderCreds {
diff --git a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
index dadb1bbac5..6db1c76e6e 100644
--- a/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_crate_native_tests.rs
@@ -80,11 +80,9 @@ fn enforce_local_only_inference_errors_on_external_when_local_only() {
Err(error) => error,
Ok(_) => panic!("direct Claude Code model must preserve the privacy gate"),
};
- assert!(
- claude_code_error
- .to_string()
- .contains("Local-only privacy mode")
- );
+ assert!(claude_code_error
+ .to_string()
+ .contains("Local-only privacy mode"));
// Both the default factory and a thread-attached managed picker route must
// hit the managed resolver's privacy gate before any backend client exists.
@@ -437,11 +435,9 @@ fn create_chat_model_routes_anthropic_auth_cloud_slug_to_crate_native() {
identity.starts_with("anthropic:https://api.anthropic.com/v1:claude-sonnet-4-6"),
"expected the native Messages adapter, got identity {identity}"
);
- assert!(
- model
- .profile()
- .is_some_and(|p| p.tool_calling && p.streaming)
- );
+ assert!(model
+ .profile()
+ .is_some_and(|p| p.tool_calling && p.streaming));
}
/// Text mode (prompt-guided tools) is only implemented on the Chat Completions
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 89f3f8d016..21b3776433 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
@@ -5,8 +5,8 @@ async fn managed_factory_and_probe_use_the_explicit_provider_entry() {
use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
use crate::core::slots::Extensions;
use crate::inference::registry::{ChatModelEntry, ProviderModelHooks};
- use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
+ use std::sync::Arc;
use tinyinference_llm::message::Message;
use tinyinference_llm::model::ModelRequest;
@@ -121,12 +121,12 @@ async fn managed_factory_and_probe_use_the_explicit_provider_entry() {
#[tokio::test]
async fn hosted_cloud_slug_uses_explicit_auth_policy_and_model_entry() {
use crate::config::schema::cloud_providers::{
- AuthStyle, CloudProviderCreds, register_hosted_cloud_provider_policy_in,
+ register_hosted_cloud_provider_policy_in, AuthStyle, CloudProviderCreds,
};
use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
use crate::core::slots::Extensions;
use crate::inference::registry::{
- CatalogEntry, ChatModelEntry, ProviderModelHooks, register_catalog_in,
+ register_catalog_in, CatalogEntry, ChatModelEntry, ProviderModelHooks,
};
use std::sync::Arc;
use tinyinference_llm::message::Message;
diff --git a/crates/openhuman-core/src/inference/provider/factory_tests.rs b/crates/openhuman-core/src/inference/provider/factory_tests.rs
index 681dec5917..e03ae768c2 100644
--- a/crates/openhuman-core/src/inference/provider/factory_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/factory_tests.rs
@@ -1,6 +1,6 @@
use super::*;
-use crate::config::Config;
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+use crate::config::Config;
use crate::security::credentials::AuthService;
use tempfile::TempDir;
@@ -231,7 +231,7 @@ fn deepseek_entry(id: &str) -> CloudProviderCreds {
/// A config carrying a resolved model, as `agent_chat` leaves it after applying
/// `model_override` and before building the agent.
fn routed_config(endpoint: &str, api_key: &str, model: &str) -> Config {
- use crate::config::schema::ephemeral_route::{EphemeralRoute, apply};
+ use crate::config::schema::ephemeral_route::{apply, EphemeralRoute};
let mut config = Config {
default_model: Some(model.to_string()),
..Config::default()
diff --git a/crates/openhuman-core/src/inference/provider/http_error.rs b/crates/openhuman-core/src/inference/provider/http_error.rs
index cab64a883f..e74013b0d0 100644
--- a/crates/openhuman-core/src/inference/provider/http_error.rs
+++ b/crates/openhuman-core/src/inference/provider/http_error.rs
@@ -10,9 +10,9 @@ mod tests;
use crate::inference::registry::classify_backend_error;
use tinyinference_core::sanitize::sanitize_api_error;
-use tinyinference_llm::failure::demotion::{DemotionKind, demote_decision};
+use tinyinference_llm::failure::demotion::{demote_decision, DemotionKind};
use tinyinference_llm::failure::http::{
- ErrorReporter, ProviderHttpFailure, ProviderHttpFailureFacts, classify_and_report_http_failure,
+ classify_and_report_http_failure, ErrorReporter, ProviderHttpFailure, ProviderHttpFailureFacts,
};
use tinyinference_llm::failure::{
local_provider_no_model_loaded_user_message, ollama_cloud_internal_500_user_message,
diff --git a/crates/openhuman-core/src/inference/provider/http_error_tests.rs b/crates/openhuman-core/src/inference/provider/http_error_tests.rs
index 1f8343f0c1..42dab3b4fd 100644
--- a/crates/openhuman-core/src/inference/provider/http_error_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/http_error_tests.rs
@@ -15,7 +15,7 @@ const FIXTURE_BACKEND: &str = "fixture-managed-provider";
fn install_fixture_backend_classifier() {
use crate::inference::registry::{
- BackendErrorClassification, register_backend_error_classifier,
+ register_backend_error_classifier, BackendErrorClassification,
};
register_backend_error_classifier(std::sync::Arc::new(|provider, _message| {
BackendErrorClassification {
@@ -86,11 +86,10 @@ async fn api_error_replaces_no_model_loaded_body_with_guidance() {
),
)
.await;
- assert!(
- err.to_string()
- .to_ascii_lowercase()
- .contains("load a model")
- );
+ assert!(err
+ .to_string()
+ .to_ascii_lowercase()
+ .contains("load a model"));
}
#[tokio::test]
@@ -362,7 +361,7 @@ fn skips_sentry_report_for_transient_upstream_statuses() {
fn provider_http_policy_uses_registered_error_ownership_metadata() {
use crate::core::slots::Extensions;
use crate::inference::registry::{
- BackendErrorClassification, BackendErrorKind, register_backend_error_classifier_in,
+ register_backend_error_classifier_in, BackendErrorClassification, BackendErrorKind,
};
use std::sync::Arc;
@@ -402,7 +401,7 @@ fn provider_http_policy_uses_registered_error_ownership_metadata() {
fn quota_demotion_precedes_backend_owned_error_code_guard() {
use crate::core::slots::Extensions;
use crate::inference::registry::{
- BackendErrorClassification, register_backend_error_classifier_in,
+ register_backend_error_classifier_in, BackendErrorClassification,
};
use std::sync::Arc;
use tinyinference_llm::failure::demotion::DemotionKind;
@@ -456,7 +455,7 @@ fn quota_demotion_precedes_backend_owned_error_code_guard() {
#[test]
fn managed_unknown_model_remains_user_configuration_state() {
- use tinyinference_llm::failure::demotion::{DemotionKind, demote_decision};
+ use tinyinference_llm::failure::demotion::{demote_decision, DemotionKind};
let facts = tinyinference_llm::failure::http::classify_http_failure(
"openhuman",
StatusCode::BAD_REQUEST.as_u16(),
@@ -470,7 +469,7 @@ fn managed_unknown_model_remains_user_configuration_state() {
#[test]
fn managed_provider_config_phrase_remains_reportable_but_unknown_model_demotes() {
- use tinyinference_llm::failure::demotion::{DemotionKind, demote_decision};
+ use tinyinference_llm::failure::demotion::{demote_decision, DemotionKind};
let config_phrase = tinyinference_llm::failure::http::classify_http_failure(
"openhuman",
StatusCode::BAD_REQUEST.as_u16(),
@@ -491,7 +490,7 @@ fn managed_provider_config_phrase_remains_reportable_but_unknown_model_demotes()
#[test]
fn config_rejection_demotion_keeps_provider_status_and_polarity() {
- use tinyinference_llm::failure::demotion::{DemotionKind, demote_decision};
+ use tinyinference_llm::failure::demotion::{demote_decision, DemotionKind};
let cases = [
(
"custom_openai",
diff --git a/crates/openhuman-core/src/inference/provider/mod.rs b/crates/openhuman-core/src/inference/provider/mod.rs
index d87ab54b1f..546468f36c 100644
--- a/crates/openhuman-core/src/inference/provider/mod.rs
+++ b/crates/openhuman-core/src/inference/provider/mod.rs
@@ -11,9 +11,9 @@ pub mod http_error;
pub mod models;
pub use factory::{
- BYOK_INCOMPLETE_SENTINEL, create_chat_model_from_string,
- create_chat_model_from_string_with_model_id, create_chat_model_in,
- create_chat_model_with_model_id_in, probe_inference_readiness, provider_for_role,
+ create_chat_model_from_string, create_chat_model_from_string_with_model_id,
+ create_chat_model_in, create_chat_model_with_model_id_in, probe_inference_readiness,
+ provider_for_role, BYOK_INCOMPLETE_SENTINEL,
};
#[cfg(test)]
diff --git a/crates/openhuman-core/src/inference/provider/model_listing_test_support.rs b/crates/openhuman-core/src/inference/provider/model_listing_test_support.rs
index 757c81ee9a..ac18c4596e 100644
--- a/crates/openhuman-core/src/inference/provider/model_listing_test_support.rs
+++ b/crates/openhuman-core/src/inference/provider/model_listing_test_support.rs
@@ -1,17 +1,17 @@
-use crate::config::Config;
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+use crate::config::Config;
use crate::security::credentials::AuthService;
use axum::{
- Json, Router,
extract::State,
http::{HeaderMap, StatusCode},
response::{IntoResponse, Response},
routing::get,
+ Json, Router,
};
use std::collections::HashMap;
use std::sync::{
- Arc, Mutex,
atomic::{AtomicUsize, Ordering as AtomicOrdering},
+ Arc, Mutex,
};
use tempfile::TempDir;
diff --git a/crates/openhuman-core/src/inference/provider/models/catalog_listing_error_tests.rs b/crates/openhuman-core/src/inference/provider/models/catalog_listing_error_tests.rs
index d96e3b5331..138f9c5e8d 100644
--- a/crates/openhuman-core/src/inference/provider/models/catalog_listing_error_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/models/catalog_listing_error_tests.rs
@@ -6,7 +6,7 @@ use crate::inference::provider::model_listing_test_support::{
};
use axum::http::StatusCode;
use std::sync::atomic::Ordering as AtomicOrdering;
-use tinyinference_core::sanitize::{MAX_API_ERROR_CHARS, sanitize_api_error};
+use tinyinference_core::sanitize::{sanitize_api_error, MAX_API_ERROR_CHARS};
#[test]
fn list_configured_models_accepts_slug() {
@@ -14,8 +14,8 @@ fn list_configured_models_accepts_slug() {
// passes a slug instead of the opaque random id. This lets the frontend
// call the RPC before the provider config has been persisted (where only
// the slug is stable).
- use crate::config::Config;
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+ use crate::config::Config;
let mut config = Config::default();
config.cloud_providers.push(CloudProviderCreds {
diff --git a/crates/openhuman-core/src/inference/provider/models/catalog_listing_tests.rs b/crates/openhuman-core/src/inference/provider/models/catalog_listing_tests.rs
index 1591a19760..05754fc669 100644
--- a/crates/openhuman-core/src/inference/provider/models/catalog_listing_tests.rs
+++ b/crates/openhuman-core/src/inference/provider/models/catalog_listing_tests.rs
@@ -1,8 +1,8 @@
use super::*;
use super::local_runtime::synthesize_local_runtime_entry;
-use crate::config::Config;
use crate::config::schema::cloud_providers::{AuthStyle, CloudProviderCreds};
+use crate::config::Config;
use crate::inference::provider::model_listing_test_support::{
configure_generic_workspace, spawn_static_models_server,
};