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
test(session_host): reuse model fixture in builder tests
Steven Enamakel10c18986a030
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rsindex a892e5feb9..7b806de06f 100644--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests.rs@@ -22,12 +22,10 @@ fn spec(name: &str) -> ToolSpec {// ─────────────────────────────────────────────────────────────────────────────fn test_config(tmp: &tempfile::TempDir) -> crate::config::Config {- let config = crate::config::Config {- workspace_dir: tmp.path().join("workspace"),- action_dir: tmp.path().join("workspace"),- config_path: tmp.path().join("config.toml"),- ..crate::config::Config::default()- };+ let mut config = crate::agent::session_host::test_support::config_with_model_fixture();+ config.workspace_dir = tmp.path().join("workspace");+ config.action_dir = tmp.path().join("workspace");+ config.config_path = tmp.path().join("config.toml");std::fs::create_dir_all(&config.workspace_dir).unwrap();config}diff --git a/crates/openhuman-core/src/agent/session_host/test_support.rs b/crates/openhuman-core/src/agent/session_host/test_support.rsnew file mode 100644index 0000000000..3769093b2e--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/test_support.rs@@ -0,0 +1,81 @@+use super::*;++use crate::config::Config;+use crate::inference::provider::factory::PROVIDER_OPENHUMAN;+use crate::inference::registry::{ChatModelEntry, ChatModelRequest, ProviderModelHooks};+use std::sync::Arc;+use tinyinference_llm::model::{ChatModel, ModelProfile, ModelRequest, ModelResponse};++struct SessionFixtureModel;++#[async_trait::async_trait]+impl ChatModel<()> for SessionFixtureModel {+ fn profile(&self) -> Option<&ModelProfile> {+ None+ }++ async fn invoke(+ &self,+ _state: &(),+ _request: ModelRequest,+ ) -> tinyinference_llm::Result<ModelResponse> {+ Ok(ModelResponse::assistant("session fixture"))+ }+}++/// Installs an explicit generic model fixture for tests that construct a+/// session through the managed-provider factory. HookSlot test registrations+/// are thread-local, so each test opts in on the thread that builds its host.+pub(crate) fn install_model_fixture() {+ crate::inference::registry::register_chat_model(+ PROVIDER_OPENHUMAN,+ ChatModelEntry {+ build: Arc::new(|request: ChatModelRequest<'_>| {+ let model = request+ .model_override+ .or(request.default_model)+ .or(request.config.default_model.as_deref())+ .unwrap_or("test/session-fixture");+ Ok((Arc::new(SessionFixtureModel), model.to_string()))+ }),+ probe: None,+ models: Some(ProviderModelHooks {+ default_model: Arc::new(|| Some("test/session-fixture".into())),+ role_for_model: Arc::new(|model| {+ model+ .strip_prefix("hint:")+ .filter(|role| crate::config::WORKLOAD_ROLES.contains(role))+ .map(str::to_string)+ }),+ is_alias: Arc::new(|model| {+ model+ .strip_prefix("hint:")+ .is_some_and(|role| crate::config::WORKLOAD_ROLES.contains(&role))+ }),+ is_raw_model: Arc::new(|model| !model.starts_with("hint:")),+ supports_vision: Arc::new(|_| false),+ resolve_model: Arc::new(|_, config, model| match model {+ Some(model) if !model.starts_with("hint:") => Some(model.to_string()),+ Some(model) => model+ .strip_prefix("hint:")+ .filter(|role| crate::config::WORKLOAD_ROLES.contains(role))+ .map(|_| "test/session-fixture".to_string()),+ None => config+ .default_model+ .clone()+ .or_else(|| Some("test/session-fixture".into())),+ }),+ context_window: Arc::new(|_| None),+ default_pricing: Arc::new(|| None),+ without_reasoning: Arc::new(|request| request),+ }),+ },+ );+}++pub(crate) fn config_with_model_fixture() -> Config {+ install_model_fixture();+ let mut config = Config::default();+ config.default_model = Some("test/session-fixture".into());+ config+}