Skip to content

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

chore(tinyagents): split observability and provider tests into modules

Steven Enamakel83e7fe2929c8
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
index 2ad659f180..f010c03c76 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability/event_projection.rs
@@ -5,6 +5,7 @@
use std::sync::atomic::Ordering;
use tinyagents_harness::events::{AgentEvent, EventListener, EventRecord};
+use tinyagents_harness::cache::CacheLayoutEvent;
use crate::progress::AgentProgress;
use tinytools::humanize_tool_name;
diff --git a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
index 4208096fd9..ba87c03aff 100644
--- a/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/observability_tests.rs
@@ -432,133 +432,7 @@ fn emit_recovered_unknown_tool_call(sink: &EventSink, call_id: &str) {
});
}
-#[tokio::test]
-async fn unknown_tool_call_projects_exactly_one_failed_timeline_row() {
- // Production Langfuse showed two ERROR tool observations ~15ms apart for
- // every unknown-tool call: the bridge synthesised a Started/Completed pair
- // off `UnknownToolCall` (null output, NotFound copy) and the crate's own
- // recovered pair produced a second one carrying the error text. Exactly
- // one row per call, carrying the error text and the NotFound class.
- let (tx, mut rx) = tokio::sync::mpsc::channel(64);
- let bridge = OpenhumanEventBridge::new(Some(tx), "mock-model", 10);
- let sink = EventSink::new();
- sink.subscribe(bridge.clone());
-
- emit_recovered_unknown_tool_call(&sink, "c9");
-
- let mut started = Vec::new();
- let mut completed = Vec::new();
- while let Ok(p) = rx.try_recv() {
- match p {
- AgentProgress::ToolCallStarted {
- tool_name,
- display_label,
- ..
- } => started.push((tool_name, display_label)),
- AgentProgress::ToolCallCompleted {
- tool_name,
- success,
- failure,
- output,
- display_label,
- ..
- } => completed.push((tool_name, success, failure, output, display_label)),
- _ => {}
- }
- }
- assert_eq!(started.len(), 1, "exactly one started row: {started:?}");
- assert_eq!(completed.len(), 1, "exactly one completed row");
- assert_eq!(started[0].0, "search_files");
- assert_eq!(
- started[0].1.as_deref(),
- Some("Search Files (unavailable)"),
- "the timeline still says the tool was unavailable"
- );
- let (tool_name, success, failure, output, label) = completed.remove(0);
- assert_eq!(tool_name, "search_files");
- assert!(!success, "the attempted tool is projected as a failed call");
- assert_eq!(
- output, UNKNOWN_TOOL_ANSWER,
- "the row carries the error text"
- );
- assert_eq!(label.as_deref(), Some("Search Files (unavailable)"));
- // #6277: a tool the agent does not have fails identically on every retry,
- // so the timeline must not tell the user to "try again / run diagnostics".
- let failure = failure.expect("the failed row carries a classified failure");
- assert_eq!(
- failure.class,
- tinytools::status::ToolFailureClass::NotFound,
- "an unavailable tool must be classified NotFound, not Unknown"
- );
- assert!(!failure.recoverable);
-}
-
-#[tokio::test]
-async fn unknown_tool_call_alone_projects_no_tool_row() {
- // The typed event only annotates the call; the crate's recovered pair is
- // what opens and closes the row.
- let (tx, mut rx) = tokio::sync::mpsc::channel(64);
- let bridge = OpenhumanEventBridge::new(Some(tx), "mock-model", 10);
- let sink = EventSink::new();
- sink.subscribe(bridge.clone());
-
- sink.emit(AgentEvent::UnknownToolCall {
- call_id: "c9".into(),
- requested_name: "search_files".to_string(),
- arguments: serde_json::json!({}),
- recovery: "tool_error".to_string(),
- });
- while let Ok(p) = rx.try_recv() {
- assert!(
- !matches!(
- p,
- AgentProgress::ToolCallStarted { .. } | AgentProgress::ToolCallCompleted { .. }
- ),
- "UnknownToolCall must not synthesise its own tool row"
- );
- }
-}
-
-#[tokio::test]
-async fn unknown_tool_call_in_a_child_run_projects_one_subagent_row() {
- let (tx, mut rx) = tokio::sync::mpsc::channel(64);
- let bridge = OpenhumanEventBridge::with_scope(
- Some(tx),
- "mock-model",
- "managed",
- 10,
- Some(super::SubagentScope {
- agent_id: "researcher".to_string(),
- task_id: "task-1".to_string(),
- extended_policy: false,
- }),
- Arc::default(),
- Arc::default(),
- Arc::default(),
- Arc::default(),
- Vec::new(),
- crate::core::runtime::DispatchCtx::ambient(),
- );
- let sink = EventSink::new();
- sink.subscribe(bridge.clone());
-
- emit_recovered_unknown_tool_call(&sink, "c10");
-
- let (mut started, mut completed) = (0, 0);
- let mut class = None;
- while let Ok(p) = rx.try_recv() {
- match p {
- AgentProgress::SubagentToolCallStarted { .. } => started += 1,
- AgentProgress::SubagentToolCallCompleted { failure, .. } => {
- completed += 1;
- class = failure.map(|f| f.class);
- }
- _ => {}
- }
- }
- assert_eq!((started, completed), (1, 1));
- assert_eq!(class, Some(tinytools::status::ToolFailureClass::NotFound));
-}
+include!("observability_tests_tool_rows.rs");
#[path = "observability_projection_tests.rs"]
mod projection_tests;
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 9a25bc988a..f06826a4fd 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
@@ -379,139 +379,7 @@ fn try_create_local_runtime_returns_none_for_managed_and_cloud() {
assert!(try_create_local_runtime_chat_model("chat", &cloud, &EgressLedger::none()).is_none());
}
-#[test]
-fn create_chat_model_routes_plain_bearer_cloud_slug_to_crate_native() {
- let _guard = crate::inference::inference_test_guard();
- // DeepSeek is a built-in chat-completions-only Bearer provider: no
- // `/v1/responses` fallback and no codex-oauth, so it is wire-equivalent and
- // flips crate-native.
- let mut config = Config::default();
- config.cloud_providers.push(deepseek_entry("p_ds"));
- config.chat_provider = Some("deepseek:deepseek-reasoner".to_string());
- let (model, model_id) = create_chat_model_with_model_id_in(
- &crate::core::runtime::DispatchCtx::ambient(),
- "chat",
- &config,
- 0.7,
- )
- .expect("bearer cloud create_chat_model must build");
- assert_eq!(model_id, "deepseek-reasoner");
- let profile = model
- .profile()
- .expect("crate-native cloud model exposes a profile");
- assert_eq!(profile.provider.as_deref(), Some("deepseek"));
- // A generic cloud model keeps native tool calling + vision on (unlike the
- // local runtimes), so this is the crate `OpenAiModel` default profile.
- assert!(profile.tool_calling);
-}
-
-#[test]
-fn turn_model_route_metadata_uses_post_remap_cloud_model() {
- let _guard = crate::inference::inference_test_guard();
- let mut config = Config::default();
- config.cloud_providers.push(deepseek_entry("p_ds"));
- config.chat_provider = Some("deepseek:hint:chat".to_string());
-
- let (_model, provider, resolved_model) = create_turn_chat_model_with_native_tools_and_route(
- &crate::core::runtime::DispatchCtx::ambient(),
- "chat",
- &config,
- "hint:chat",
- 0.7,
- true,
- &EgressLedger::none(),
- )
- .expect("abstract BYOK tier must build");
-
- assert_eq!(provider, "deepseek");
- assert_eq!(resolved_model, "deepseek-chat");
-}
-
-#[test]
-fn explicit_cloud_provider_string_routes_to_crate_native_model() {
- let _guard = crate::inference::inference_test_guard();
- let mut config = Config::default();
- config.cloud_providers.push(deepseek_entry("p_ds"));
- let (model, model_id) = create_chat_model_from_string_with_model_id(
- "chat",
- "deepseek:deepseek-reasoner",
- &config,
- 0.7,
- )
- .expect("explicit cloud model must build");
- assert_eq!(model_id, "deepseek-reasoner");
- assert_eq!(
- model
- .profile()
- .and_then(|profile| profile.provider.as_deref()),
- Some("deepseek")
- );
-}
-
-#[test]
-fn create_chat_model_routes_anthropic_auth_cloud_slug_to_crate_native() {
- let _guard = crate::inference::inference_test_guard();
- // Anthropic-auth cloud slugs are always wire-equivalent (their endpoints have
- // no `/v1/responses`, so the host's dormant fallback is behavior-neutral).
- let mut config = Config::default();
- config
- .cloud_providers
- .push(anthropic_entry("p_anth", "anthropic"));
- config.chat_provider = Some("anthropic:claude-sonnet-4-6".to_string());
- let (model, model_id) = create_chat_model_with_model_id_in(
- &crate::core::runtime::DispatchCtx::ambient(),
- "chat",
- &config,
- 0.7,
- )
- .expect("anthropic cloud create_chat_model must build");
- assert_eq!(model_id, "claude-sonnet-4-6");
- assert_eq!(
- model.profile().and_then(|p| p.provider.as_deref()),
- Some("anthropic")
- );
- // The native Messages API adapter, not the OpenAI-compat flavour: its
- // cache identity is `anthropic:<base>:<model>`, while the compat client
- // would report the provider slug with an OpenAI-shaped identity. Only the
- // native adapter places `cache_control` breakpoints — Anthropic's compat
- // endpoint documents prompt caching as unsupported.
- let identity = model.cache_identity().expect("anthropic identifies itself");
- assert!(
- 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));
-}
-
-/// Text mode (prompt-guided tools) is only implemented on the Chat Completions
-/// adapter, so an Anthropic slug asked for `native_tools = false` keeps the
-/// compat client rather than a native adapter that would ignore the request.
-#[test]
-fn anthropic_auth_cloud_slug_in_text_mode_keeps_the_compat_client() {
- let _guard = crate::inference::inference_test_guard();
- let mut config = Config::default();
- config
- .cloud_providers
- .push(anthropic_entry("p_anth", "anthropic"));
- let (model, model_id) = try_create_cloud_slug_chat_model_from_string_with_native_tools(
- "chat",
- "anthropic:claude-sonnet-4-6",
- &config,
- false,
- &EgressLedger::none(),
- )
- .expect("anthropic slug resolves")
- .expect("build");
- assert_eq!(model_id, "claude-sonnet-4-6");
- let identity = model.cache_identity().unwrap_or_default();
- assert!(
- !identity.starts_with("anthropic:https://"),
- "text mode must not route to the native adapter, got {identity}"
- );
- assert!(model.profile().is_some_and(|p| !p.tool_calling));
-}
+include!("factory_crate_native_cloud_tests.rs");
#[path = "factory_crate_native_managed_slug_tests.rs"]
mod managed_slug_tests;