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): split continuation and command route tests into new files
Steven Enamakel305ff6cc166d
diff --git a/crates/openhuman-cli/Cargo.toml b/crates/openhuman-cli/Cargo.tomlindex 29d7391331..fcdf7b34c1 100644--- a/crates/openhuman-cli/Cargo.toml+++ b/crates/openhuman-cli/Cargo.toml@@ -571,3 +571,8 @@ path = "../../tests/embeddings_opt_out.rs"name = "storage_backend_capabilities"path = "../../tests/storage_backend_capabilities.rs"required-features = ["storage-sqlite"]++[[test]]+name = "storage_delegation_e2e"+path = "../../tests/storage_delegation_e2e.rs"+required-features = ["storage-sqlite"]diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_continuation_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_continuation_tests.rsnew file mode 100644index 0000000000..ce4de03c3d--- /dev/null+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_continuation_tests.rs@@ -0,0 +1,234 @@+use super::*;++#[test]+fn a_cold_resumed_thread_can_send_again() {+ std::thread::Builder::new()+ .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)+ .spawn(|| {+ tokio::runtime::Builder::new_current_thread()+ .enable_all()+ .build()+ .expect("test runtime")+ .block_on(cold_resumed_thread_can_send_again());+ })+ .expect("test thread")+ .join()+ .expect("test thread panicked");+}++async fn cold_resumed_thread_can_send_again() {+ let root = tempfile::tempdir().expect("tempdir");+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(vec![+ tinyinference_llm::model::ModelResponse::assistant("first reply"),+ tinyinference_llm::model::ModelResponse::assistant("second reply"),+ ]));+ let new_host = || {+ crate::agent::SessionHostBuilder::new()+ .chat_model(model.clone())+ .model_name("test/session-fixture".to_string())+ .tools(Vec::new())+ .workspace_dir(root.path().join("workspace"))+ .action_dir(root.path().to_path_buf())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .build()+ .expect("session build")+ };+ let mut host = new_host();+ host.set_thread_id(Some("thread-resume-regression"));++ assert_eq!(host.turn("first message").await.unwrap(), "first reply");+ drop(host);+ let mut host = new_host();+ host.set_thread_id(Some("thread-resume-regression"));+ assert_eq!(host.turn("second message").await.unwrap(), "second reply");+}++/// The PRODUCTION turn path must wire an artifact store, rooted outside the+/// project the agent works in (#6408).+///+/// Two assertions, and both were dead code before this PR. The existing artifact+/// tests construct `TurnContextMiddleware` with `artifact_store: Some(..)`+/// themselves, so they prove the offload code works while saying nothing about+/// whether production ever reaches it — and it did not: the production+/// constructor hard-coded `None`, which is how a whole feature shipped dead.+///+/// The root matters as much as the wiring, and it is the workspace's+/// `artifacts/tool-results`, never a directory the agent works in. Rooted at+/// `action_dir` (or a descriptor's root) every oversized output was a stray file+/// in the user's project, swept into its diff. The pointer is absolute, so it+/// no longer has to match whichever root `file_read` resolves relative paths+/// against (#6483). This drives a real host with a descriptor whose root is not+/// `action_dir`, and pins that the store followed neither.+#[tokio::test]+async fn production_turn_path_wires_an_artifact_store_outside_the_project() {+ let workspace = tempfile::tempdir().expect("workspace");+ let action_dir = tempfile::tempdir().expect("tempdir");+ let turn_root = tempfile::tempdir().expect("turn root");+ assert_ne!(+ action_dir.path(),+ turn_root.path(),+ "the two roots must differ or this test cannot tell them apart"+ );++ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let mut host = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .model_name("test/session-fixture".to_string())+ .tools(Vec::new())+ .workspace_dir(workspace.path().to_path_buf())+ .action_dir(action_dir.path().to_path_buf())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .workspace_descriptor(Some(+ tinytools::WorkspaceDescriptor::new(turn_root.path().to_path_buf())+ .with_policy_id("turn-workspace"),+ ))+ .build()+ .expect("session build");++ host.ensure_runtime_session()+ .expect("ensure runtime session");++ let state = host+ .runtime_state+ .lock()+ .unwrap_or_else(|poisoned| poisoned.into_inner());+ let middleware = state+ .context_middleware+ .as_ref()+ .expect("the turn path must retain its context middleware");+ let store = middleware.artifact_store.as_ref().expect(+ "the production turn path must wire an artifact store, or oversized \+ tool results are truncated with their tail discarded (#6408)",+ );+ assert_eq!(+ store.materialize_root(),+ crate::security::policy::tool_result_artifacts_dir(workspace.path()),+ "the store must live under the workspace, not in the project the agent edits"+ );+ assert!(!store.materialize_root().starts_with(action_dir.path()));+ assert!(!store.materialize_root().starts_with(turn_root.path()));+}++/// Without a descriptor the answer is the same: the workspace, not+/// `action_dir`. The mirror of the test above, so neither branch can regress+/// back into the project.+#[tokio::test]+async fn artifact_store_stays_in_the_workspace_without_a_descriptor() {+ let workspace = tempfile::tempdir().expect("workspace");+ let action_dir = tempfile::tempdir().expect("tempdir");+ let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =+ Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));+ let mut host = crate::agent::SessionHostBuilder::new()+ .chat_model(model)+ .model_name("test/session-fixture".to_string())+ .tools(Vec::new())+ .workspace_dir(workspace.path().to_path_buf())+ .action_dir(action_dir.path().to_path_buf())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .build()+ .expect("session build");++ host.ensure_runtime_session()+ .expect("ensure runtime session");++ let state = host+ .runtime_state+ .lock()+ .unwrap_or_else(|poisoned| poisoned.into_inner());+ let store = state+ .context_middleware+ .as_ref()+ .expect("context middleware")+ .artifact_store+ .as_ref()+ .expect("artifact store");+ assert_eq!(+ store.materialize_root(),+ crate::security::policy::tool_result_artifacts_dir(workspace.path())+ );+}++/// The reply-language instruction reaches the MODEL, on the user message next+/// to the clock line, and clearing it removes it from the next turn. Before+/// this, the web channel computed the directive, logged "injecting", and+/// dropped it: no request ever carried it.+#[test]+fn reply_language_directive_rides_each_user_message_until_cleared() {+ std::thread::Builder::new()+ .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)+ .spawn(|| {+ tokio::runtime::Builder::new_current_thread()+ .enable_all()+ .build()+ .expect("test runtime")+ .block_on(reply_language_directive_rides_each_user_message_until_cleared_body());+ })+ .expect("test thread")+ .join()+ .expect("test thread panicked");+}++async fn reply_language_directive_rides_each_user_message_until_cleared_body() {+ const DIRECTIVE: &str = "User language: respond in Spanish (test directive).";+ let root = tempfile::tempdir().expect("tempdir");+ let model = Arc::new(tinyagents_harness::testkit::ScriptedModel::new(vec![+ tinyinference_llm::model::ModelResponse::assistant("hola"),+ tinyinference_llm::model::ModelResponse::assistant("hello"),+ ]));+ let mut host = crate::agent::SessionHostBuilder::new()+ .chat_model(model.clone() as Arc<dyn tinyinference_llm::model::ChatModel<()>>)+ .model_name("test/session-fixture".to_string())+ .tools(Vec::new())+ .workspace_dir(root.path().join("workspace"))+ .action_dir(root.path().to_path_buf())+ .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))+ .build()+ .expect("session build");+ host.set_thread_id(Some("thread-reply-language"));+ let last_user_text = |request: &tinyinference_llm::model::ModelRequest| {+ request+ .messages+ .iter()+ .rev()+ .find(|m| matches!(m, Message::User(_)))+ .map(|m| m.text())+ .expect("a user message reached the model")+ };++ host.set_reply_language_directive(Some(DIRECTIVE.to_string()));+ host.set_time_zone(Some("Pacific/Chatham".to_string()));+ assert_eq!(host.turn("¿qué tal?").await.unwrap(), "hola");+ host.set_reply_language_directive(None);+ assert_eq!(host.turn("and now?").await.unwrap(), "hello");++ let requests = model.requests();+ assert_eq!(requests.len(), 2, "one model call per turn");+ let first = last_user_text(&requests[0]);+ assert!(+ first.contains("Current Date & Time:"),+ "fixture: the clock line is there: {first}"+ );+ assert!(+ first.contains(DIRECTIVE),+ "the directive must reach the model: {first}"+ );+ assert!(+ first.contains(" Pacific/Chatham ("),+ "the clock reads in the user's zone: {first}"+ );+ assert!(+ first.find(DIRECTIVE) < first.find("¿qué tal?"),+ "the directive leads the user's own words: {first}"+ );+ let second = last_user_text(&requests[1]);+ assert!(+ second.contains("and now?"),+ "fixture: the second turn's text: {second}"+ );+ assert!(+ !second.contains(DIRECTIVE),+ "a cleared directive is gone next turn: {second}"+ );+}diff --git a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rsindex 84e804cdf3..a9ee8328f5 100644--- a/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs+++ b/crates/openhuman-core/src/agent/session_host/runtime_adapter_tests.rs@@ -520,235 +520,5 @@ fn a_subagent_thread_binding_claims_no_session_identity() {/// The resume hook and builder must name the same transcript locator instance./// A distinct locator for the same directory lets a new thread commit, then/// rejects a cold resumed thread before inference with InvalidSessionState (#6608).-#[test]-fn a_cold_resumed_thread_can_send_again() {- std::thread::Builder::new()- .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)- .spawn(|| {- tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .expect("test runtime")- .block_on(cold_resumed_thread_can_send_again());- })- .expect("test thread")- .join()- .expect("test thread panicked");-}--async fn cold_resumed_thread_can_send_again() {- let root = tempfile::tempdir().expect("tempdir");- let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =- Arc::new(tinyagents_harness::testkit::ScriptedModel::new(vec![- tinyinference_llm::model::ModelResponse::assistant("first reply"),- tinyinference_llm::model::ModelResponse::assistant("second reply"),- ]));- let new_host = || {- crate::agent::SessionHostBuilder::new()- .chat_model(model.clone())- .model_name("test/session-fixture".to_string())- .tools(Vec::new())- .workspace_dir(root.path().join("workspace"))- .action_dir(root.path().to_path_buf())- .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))- .build()- .expect("session build")- };- let mut host = new_host();- host.set_thread_id(Some("thread-resume-regression"));-- assert_eq!(host.turn("first message").await.unwrap(), "first reply");- drop(host);- let mut host = new_host();- host.set_thread_id(Some("thread-resume-regression"));- assert_eq!(host.turn("second message").await.unwrap(), "second reply");-}--/// The PRODUCTION turn path must wire an artifact store, rooted outside the-/// project the agent works in (#6408).-///-/// Two assertions, and both were dead code before this PR. The existing artifact-/// tests construct `TurnContextMiddleware` with `artifact_store: Some(..)`-/// themselves, so they prove the offload code works while saying nothing about-/// whether production ever reaches it — and it did not: the production-/// constructor hard-coded `None`, which is how a whole feature shipped dead.-///-/// The root matters as much as the wiring, and it is the workspace's-/// `artifacts/tool-results`, never a directory the agent works in. Rooted at-/// `action_dir` (or a descriptor's root) every oversized output was a stray file-/// in the user's project, swept into its diff. The pointer is absolute, so it-/// no longer has to match whichever root `file_read` resolves relative paths-/// against (#6483). This drives a real host with a descriptor whose root is not-/// `action_dir`, and pins that the store followed neither.-#[tokio::test]-async fn production_turn_path_wires_an_artifact_store_outside_the_project() {- let workspace = tempfile::tempdir().expect("workspace");- let action_dir = tempfile::tempdir().expect("tempdir");- let turn_root = tempfile::tempdir().expect("turn root");- assert_ne!(- action_dir.path(),- turn_root.path(),- "the two roots must differ or this test cannot tell them apart"- );-- let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =- Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));- let mut host = crate::agent::SessionHostBuilder::new()- .chat_model(model)- .model_name("test/session-fixture".to_string())- .tools(Vec::new())- .workspace_dir(workspace.path().to_path_buf())- .action_dir(action_dir.path().to_path_buf())- .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))- .workspace_descriptor(Some(- tinytools::WorkspaceDescriptor::new(turn_root.path().to_path_buf())- .with_policy_id("turn-workspace"),- ))- .build()- .expect("session build");-- host.ensure_runtime_session()- .expect("ensure runtime session");-- let state = host- .runtime_state- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner());- let middleware = state- .context_middleware- .as_ref()- .expect("the turn path must retain its context middleware");- let store = middleware.artifact_store.as_ref().expect(- "the production turn path must wire an artifact store, or oversized \- tool results are truncated with their tail discarded (#6408)",- );- assert_eq!(- store.materialize_root(),- crate::security::policy::tool_result_artifacts_dir(workspace.path()),- "the store must live under the workspace, not in the project the agent edits"- );- assert!(!store.materialize_root().starts_with(action_dir.path()));- assert!(!store.materialize_root().starts_with(turn_root.path()));-}--/// Without a descriptor the answer is the same: the workspace, not-/// `action_dir`. The mirror of the test above, so neither branch can regress-/// back into the project.-#[tokio::test]-async fn artifact_store_stays_in_the_workspace_without_a_descriptor() {- let workspace = tempfile::tempdir().expect("workspace");- let action_dir = tempfile::tempdir().expect("tempdir");- let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =- Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));- let mut host = crate::agent::SessionHostBuilder::new()- .chat_model(model)- .model_name("test/session-fixture".to_string())- .tools(Vec::new())- .workspace_dir(workspace.path().to_path_buf())- .action_dir(action_dir.path().to_path_buf())- .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))- .build()- .expect("session build");-- host.ensure_runtime_session()- .expect("ensure runtime session");-- let state = host- .runtime_state- .lock()- .unwrap_or_else(|poisoned| poisoned.into_inner());- let store = state- .context_middleware- .as_ref()- .expect("context middleware")- .artifact_store- .as_ref()- .expect("artifact store");- assert_eq!(- store.materialize_root(),- crate::security::policy::tool_result_artifacts_dir(workspace.path())- );-}--/// The reply-language instruction reaches the MODEL, on the user message next-/// to the clock line, and clearing it removes it from the next turn. Before-/// this, the web channel computed the directive, logged "injecting", and-/// dropped it: no request ever carried it.-#[test]-fn reply_language_directive_rides_each_user_message_until_cleared() {- std::thread::Builder::new()- .stack_size(crate::core::runtime::AGENT_WORKER_STACK_BYTES)- .spawn(|| {- tokio::runtime::Builder::new_current_thread()- .enable_all()- .build()- .expect("test runtime")- .block_on(reply_language_directive_rides_each_user_message_until_cleared_body());- })- .expect("test thread")- .join()- .expect("test thread panicked");-}--async fn reply_language_directive_rides_each_user_message_until_cleared_body() {- const DIRECTIVE: &str = "User language: respond in Spanish (test directive).";- let root = tempfile::tempdir().expect("tempdir");- let model = Arc::new(tinyagents_harness::testkit::ScriptedModel::new(vec![- tinyinference_llm::model::ModelResponse::assistant("hola"),- tinyinference_llm::model::ModelResponse::assistant("hello"),- ]));- let mut host = crate::agent::SessionHostBuilder::new()- .chat_model(model.clone() as Arc<dyn tinyinference_llm::model::ChatModel<()>>)- .model_name("test/session-fixture".to_string())- .tools(Vec::new())- .workspace_dir(root.path().join("workspace"))- .action_dir(root.path().to_path_buf())- .tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))- .build()- .expect("session build");- host.set_thread_id(Some("thread-reply-language"));- let last_user_text = |request: &tinyinference_llm::model::ModelRequest| {- request- .messages- .iter()- .rev()- .find(|m| matches!(m, Message::User(_)))- .map(|m| m.text())- .expect("a user message reached the model")- };-- host.set_reply_language_directive(Some(DIRECTIVE.to_string()));- host.set_time_zone(Some("Pacific/Chatham".to_string()));- assert_eq!(host.turn("¿qué tal?").await.unwrap(), "hola");- host.set_reply_language_directive(None);- assert_eq!(host.turn("and now?").await.unwrap(), "hello");-- let requests = model.requests();- assert_eq!(requests.len(), 2, "one model call per turn");- let first = last_user_text(&requests[0]);- assert!(- first.contains("Current Date & Time:"),- "fixture: the clock line is there: {first}"- );- assert!(- first.contains(DIRECTIVE),- "the directive must reach the model: {first}"- );- assert!(- first.contains(" Pacific/Chatham ("),- "the clock reads in the user's zone: {first}"- );- assert!(- first.find(DIRECTIVE) < first.find("¿qué tal?"),- "the directive leads the user's own words: {first}"- );- let second = last_user_text(&requests[1]);- assert!(- second.contains("and now?"),- "fixture: the second turn's text: {second}"- );- assert!(- !second.contains(DIRECTIVE),- "a cleared directive is gone next turn: {second}"- );-}+#[path = "runtime_adapter_continuation_tests.rs"]+mod continuation_tests;diff --git a/crates/openhuman-core/src/channels/routes_command_tests.rs b/crates/openhuman-core/src/channels/routes_command_tests.rsnew file mode 100644index 0000000000..ba1b7efd9d--- /dev/null+++ b/crates/openhuman-core/src/channels/routes_command_tests.rs@@ -0,0 +1,322 @@+use super::*;++#[tokio::test]+async fn handle_runtime_command_set_model_clears_sender_history_and_persists_route_override() {+ let ctx = runtime_context(PathBuf::from("/tmp"));+ let key = "telegram_alice_room";+ ctx.conversation_histories+ .lock()+ .unwrap()+ .insert(key.to_string(), vec![ChatMessage::user("old history")]);+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let msg = inbound(+ "1".into(),+ "alice".into(),+ "room".into(),+ "/model gpt-5-mini".into(),+ "telegram".into(),+ None,+ );++ let handled = handle_runtime_command_if_needed(+ &ctx,+ &msg,+ Some(&channel),+ &conversation_history_key(&msg),+ )+ .await;+ assert!(handled);++ assert!(ctx+ .conversation_histories+ .lock()+ .unwrap()+ .get(key)+ .is_none());+ assert_eq!(+ get_route_selection(&ctx, key),+ ChannelRouteSelection {+ provider: "openai".into(),+ model: "gpt-5-mini".into()+ }+ );++ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 1);+ assert!(sent_text(&sent[0]).contains("Model switched to `gpt-5-mini`"));+}++#[tokio::test]+async fn handle_runtime_command_telegram_status_replies_without_agent() {+ let ctx = runtime_context(PathBuf::from("/tmp"));+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/status".into(),+ "telegram".into(),+ Some("42".into()),+ );++ let handled = handle_runtime_command_if_needed(+ &ctx,+ &msg,+ Some(&channel),+ &conversation_history_key(&msg),+ )+ .await;+ assert!(handled);++ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 1);+ assert!(+ sent_text(&sent[0]).contains("**Status**"),+ "status command returned unexpected reply: {:?}",+ sent_text(&sent[0])+ );+ assert!(sent_text(&sent[0]).contains("Provider:"));+}++#[tokio::test]+async fn handle_runtime_command_without_target_channel_still_consumes_command() {+ let ctx = runtime_context(PathBuf::from("/tmp"));+ let msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/help".into(),+ "telegram".into(),+ None,+ );++ let handled =+ handle_runtime_command_if_needed(&ctx, &msg, None, &conversation_history_key(&msg)).await;+ assert!(handled);+}++#[tokio::test]+async fn handle_runtime_command_telegram_help_replies_with_remote_command_list() {+ let ctx = runtime_context(PathBuf::from("/tmp"));+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/help".into(),+ "telegram".into(),+ Some("42".into()),+ );++ let handled = handle_runtime_command_if_needed(+ &ctx,+ &msg,+ Some(&channel),+ &conversation_history_key(&msg),+ )+ .await;+ assert!(handled);++ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 1);+ assert!(sent_text(&sent[0]).contains("Remote control:"));+ assert!(sent_text(&sent[0]).contains("`/status`"));+ assert!(sent_text(&sent[0]).contains("`/sessions`"));+ assert!(sent_text(&sent[0]).contains("`/new`"));+ assert!(sent_text(&sent[0]).contains("Model routing: `/model`, `/models`"));+}++#[tokio::test]+async fn handle_runtime_command_telegram_sessions_reports_empty_store() {+ let tempdir = tempfile::tempdir().unwrap();+ let ctx = runtime_context(tempdir.path().to_path_buf());+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/sessions".into(),+ "telegram".into(),+ Some("42".into()),+ );++ let handled = handle_runtime_command_if_needed(+ &ctx,+ &msg,+ Some(&channel),+ &conversation_history_key(&msg),+ )+ .await;+ assert!(handled);++ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 1);+ assert!(sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one."));+ assert_eq!(sent[0].thread_id.as_deref(), Some("42"));+}++#[tokio::test]+#[ignore = "the linked tinychannels-module is given no storage backend here, so /new fails to persist the chat binding (host storage is unavailable); needs a storage fixture"]+async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {+ let tempdir = tempfile::tempdir().unwrap();+ let ctx = runtime_context(tempdir.path().to_path_buf());+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let sender_key = "telegram_alice_chat-remote";++ ctx.conversation_histories.lock().unwrap().insert(+ sender_key.to_string(),+ vec![ChatMessage::user("old history")],+ );++ let new_msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/new".into(),+ "telegram".into(),+ Some("42".into()),+ );+ assert!(+ handle_runtime_command_if_needed(+ &ctx,+ &new_msg,+ Some(&channel),+ &conversation_history_key(&new_msg)+ )+ .await+ );+ assert!(ctx+ .conversation_histories+ .lock()+ .unwrap()+ .get(sender_key)+ .is_none());++ ctx.conversation_histories+ .lock()+ .unwrap()+ .insert(sender_key.to_string(), vec![ChatMessage::user("after new")]);+ set_route_selection(+ &ctx,+ sender_key,+ ChannelRouteSelection {+ provider: "anthropic".into(),+ model: "claude-3".into(),+ },+ );++ let subscriber = ChannelTurnStateSubscriber::new(tempdir.path().to_path_buf());+ subscriber+ .handle(&DomainEvent::ChannelMessageReceived {+ channel: "telegram".into(),+ message_id: "2".into(),+ sender: "alice".into(),+ reply_target: "chat-remote".into(),+ content: "work".into(),+ thread_ts: Some("42".into()),+ inbound_envelope: None,+ workspace_dir: tempdir.path().to_path_buf(),+ })+ .await;++ let status_msg = inbound(+ "3".into(),+ "alice".into(),+ "chat-remote".into(),+ "/status".into(),+ "telegram".into(),+ Some("42".into()),+ );+ assert!(+ handle_runtime_command_if_needed(+ &ctx,+ &status_msg,+ Some(&channel),+ &conversation_history_key(&status_msg)+ )+ .await+ );++ let sessions_msg = inbound(+ "4".into(),+ "alice".into(),+ "chat-remote".into(),+ "/sessions".into(),+ "telegram".into(),+ Some("42".into()),+ );+ assert!(+ handle_runtime_command_if_needed(+ &ctx,+ &sessions_msg,+ Some(&channel),+ &conversation_history_key(&sessions_msg)+ )+ .await+ );++ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 3);+ assert!(sent_text(&sent[0]).contains("Started new session"));+ assert!(sent_text(&sent[0]).contains("In-memory channel history cleared for this chat."));++ assert!(sent_text(&sent[1]).contains("**Status**"));+ assert!(sent_text(&sent[1]).contains("Thread: `Telegram"));+ assert!(sent_text(&sent[1]).contains("Provider: `anthropic`"));+ assert!(sent_text(&sent[1]).contains("Model: `claude-3`"));+ assert!(sent_text(&sent[1]).contains("In-memory turns: 1"));+ assert!(sent_text(&sent[1]).contains("Turn: in progress"));++ assert!(sent_text(&sent[2]).contains("**Recent sessions**"));+ assert!(sent_text(&sent[2]).contains("→ `Telegram"));+ assert!(sent+ .iter()+ .all(|message| message.thread_id.as_deref() == Some("42")));+}++#[tokio::test]+async fn handle_runtime_command_telegram_new_reports_unavailable_storage() {+ let tempdir = tempfile::tempdir().unwrap();+ let ctx = runtime_context(tempdir.path().to_path_buf());+ let channel_impl = Arc::new(RecordingChannel::default());+ let channel: Arc<dyn Channel> = channel_impl.clone();+ let sender_key = "telegram_alice_chat-remote";++ ctx.conversation_histories.lock().unwrap().insert(+ sender_key.to_string(),+ vec![ChatMessage::user("old history")],+ );++ let msg = inbound(+ "1".into(),+ "alice".into(),+ "chat-remote".into(),+ "/new".into(),+ "telegram".into(),+ Some("42".into()),+ );+ assert!(+ handle_runtime_command_if_needed(+ &ctx,+ &msg,+ Some(&channel),+ &conversation_history_key(&msg)+ )+ .await+ );+ let sent = channel_impl.sent.lock().unwrap();+ assert_eq!(sent.len(), 1);+ assert!(+ sent_text(&sent[0]).contains("Created thread"),+ "{}",+ sent_text(&sent[0])+ );+ assert!(sent_text(&sent[0]).contains("failed to persist the chat binding"));+ assert!(sent_text(&sent[0]).contains("host storage is unavailable"));+ assert_eq!(sent[0].thread_id.as_deref(), Some("42"));+}diff --git a/crates/openhuman-core/src/channels/routes_tests.rs b/crates/openhuman-core/src/channels/routes_tests.rsindex c51f86e8ff..c2b6ba3a99 100644--- a/crates/openhuman-core/src/channels/routes_tests.rs+++ b/crates/openhuman-core/src/channels/routes_tests.rs@@ -452,323 +452,5 @@ async fn handle_runtime_command_unknown_provider_sends_helpful_error() {assert_eq!(sent[0].thread_id.as_deref(), Some("thread-1"));}-#[tokio::test]-async fn handle_runtime_command_set_model_clears_sender_history_and_persists_route_override() {- let ctx = runtime_context(PathBuf::from("/tmp"));- let key = "telegram_alice_room";- ctx.conversation_histories- .lock()- .unwrap()- .insert(key.to_string(), vec![ChatMessage::user("old history")]);- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let msg = inbound(- "1".into(),- "alice".into(),- "room".into(),- "/model gpt-5-mini".into(),- "telegram".into(),- None,- );-- let handled = handle_runtime_command_if_needed(- &ctx,- &msg,- Some(&channel),- &conversation_history_key(&msg),- )- .await;- assert!(handled);-- assert!(ctx- .conversation_histories- .lock()- .unwrap()- .get(key)- .is_none());- assert_eq!(- get_route_selection(&ctx, key),- ChannelRouteSelection {- provider: "openai".into(),- model: "gpt-5-mini".into()- }- );-- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 1);- assert!(sent_text(&sent[0]).contains("Model switched to `gpt-5-mini`"));-}--#[tokio::test]-async fn handle_runtime_command_telegram_status_replies_without_agent() {- let ctx = runtime_context(PathBuf::from("/tmp"));- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/status".into(),- "telegram".into(),- Some("42".into()),- );-- let handled = handle_runtime_command_if_needed(- &ctx,- &msg,- Some(&channel),- &conversation_history_key(&msg),- )- .await;- assert!(handled);-- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 1);- assert!(- sent_text(&sent[0]).contains("**Status**"),- "status command returned unexpected reply: {:?}",- sent_text(&sent[0])- );- assert!(sent_text(&sent[0]).contains("Provider:"));-}--#[tokio::test]-async fn handle_runtime_command_without_target_channel_still_consumes_command() {- let ctx = runtime_context(PathBuf::from("/tmp"));- let msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/help".into(),- "telegram".into(),- None,- );-- let handled =- handle_runtime_command_if_needed(&ctx, &msg, None, &conversation_history_key(&msg)).await;- assert!(handled);-}--#[tokio::test]-async fn handle_runtime_command_telegram_help_replies_with_remote_command_list() {- let ctx = runtime_context(PathBuf::from("/tmp"));- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/help".into(),- "telegram".into(),- Some("42".into()),- );-- let handled = handle_runtime_command_if_needed(- &ctx,- &msg,- Some(&channel),- &conversation_history_key(&msg),- )- .await;- assert!(handled);-- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 1);- assert!(sent_text(&sent[0]).contains("Remote control:"));- assert!(sent_text(&sent[0]).contains("`/status`"));- assert!(sent_text(&sent[0]).contains("`/sessions`"));- assert!(sent_text(&sent[0]).contains("`/new`"));- assert!(sent_text(&sent[0]).contains("Model routing: `/model`, `/models`"));-}--#[tokio::test]-async fn handle_runtime_command_telegram_sessions_reports_empty_store() {- let tempdir = tempfile::tempdir().unwrap();- let ctx = runtime_context(tempdir.path().to_path_buf());- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/sessions".into(),- "telegram".into(),- Some("42".into()),- );-- let handled = handle_runtime_command_if_needed(- &ctx,- &msg,- Some(&channel),- &conversation_history_key(&msg),- )- .await;- assert!(handled);-- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 1);- assert!(sent_text(&sent[0]).contains("No conversation threads yet. Send `/new` to create one."));- assert_eq!(sent[0].thread_id.as_deref(), Some("42"));-}--#[tokio::test]-#[ignore = "the linked tinychannels-module is given no storage backend here, so /new fails to persist the chat binding (host storage is unavailable); needs a storage fixture"]-async fn handle_runtime_command_telegram_new_status_and_sessions_round_trip() {- let tempdir = tempfile::tempdir().unwrap();- let ctx = runtime_context(tempdir.path().to_path_buf());- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let sender_key = "telegram_alice_chat-remote";-- ctx.conversation_histories.lock().unwrap().insert(- sender_key.to_string(),- vec![ChatMessage::user("old history")],- );-- let new_msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/new".into(),- "telegram".into(),- Some("42".into()),- );- assert!(- handle_runtime_command_if_needed(- &ctx,- &new_msg,- Some(&channel),- &conversation_history_key(&new_msg)- )- .await- );- assert!(ctx- .conversation_histories- .lock()- .unwrap()- .get(sender_key)- .is_none());-- ctx.conversation_histories- .lock()- .unwrap()- .insert(sender_key.to_string(), vec![ChatMessage::user("after new")]);- set_route_selection(- &ctx,- sender_key,- ChannelRouteSelection {- provider: "anthropic".into(),- model: "claude-3".into(),- },- );-- let subscriber = ChannelTurnStateSubscriber::new(tempdir.path().to_path_buf());- subscriber- .handle(&DomainEvent::ChannelMessageReceived {- channel: "telegram".into(),- message_id: "2".into(),- sender: "alice".into(),- reply_target: "chat-remote".into(),- content: "work".into(),- thread_ts: Some("42".into()),- inbound_envelope: None,- workspace_dir: tempdir.path().to_path_buf(),- })- .await;-- let status_msg = inbound(- "3".into(),- "alice".into(),- "chat-remote".into(),- "/status".into(),- "telegram".into(),- Some("42".into()),- );- assert!(- handle_runtime_command_if_needed(- &ctx,- &status_msg,- Some(&channel),- &conversation_history_key(&status_msg)- )- .await- );-- let sessions_msg = inbound(- "4".into(),- "alice".into(),- "chat-remote".into(),- "/sessions".into(),- "telegram".into(),- Some("42".into()),- );- assert!(- handle_runtime_command_if_needed(- &ctx,- &sessions_msg,- Some(&channel),- &conversation_history_key(&sessions_msg)- )- .await- );-- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 3);- assert!(sent_text(&sent[0]).contains("Started new session"));- assert!(sent_text(&sent[0]).contains("In-memory channel history cleared for this chat."));-- assert!(sent_text(&sent[1]).contains("**Status**"));- assert!(sent_text(&sent[1]).contains("Thread: `Telegram"));- assert!(sent_text(&sent[1]).contains("Provider: `anthropic`"));- assert!(sent_text(&sent[1]).contains("Model: `claude-3`"));- assert!(sent_text(&sent[1]).contains("In-memory turns: 1"));- assert!(sent_text(&sent[1]).contains("Turn: in progress"));-- assert!(sent_text(&sent[2]).contains("**Recent sessions**"));- assert!(sent_text(&sent[2]).contains("→ `Telegram"));- assert!(sent- .iter()- .all(|message| message.thread_id.as_deref() == Some("42")));-}--#[tokio::test]-async fn handle_runtime_command_telegram_new_reports_unavailable_storage() {- let tempdir = tempfile::tempdir().unwrap();- let ctx = runtime_context(tempdir.path().to_path_buf());- let channel_impl = Arc::new(RecordingChannel::default());- let channel: Arc<dyn Channel> = channel_impl.clone();- let sender_key = "telegram_alice_chat-remote";-- ctx.conversation_histories.lock().unwrap().insert(- sender_key.to_string(),- vec![ChatMessage::user("old history")],- );-- let msg = inbound(- "1".into(),- "alice".into(),- "chat-remote".into(),- "/new".into(),- "telegram".into(),- Some("42".into()),- );- assert!(- handle_runtime_command_if_needed(- &ctx,- &msg,- Some(&channel),- &conversation_history_key(&msg)- )- .await- );- let sent = channel_impl.sent.lock().unwrap();- assert_eq!(sent.len(), 1);- assert!(- sent_text(&sent[0]).contains("Created thread"),- "{}",- sent_text(&sent[0])- );- assert!(sent_text(&sent[0]).contains("failed to persist the chat binding"));- assert!(sent_text(&sent[0]).contains("host storage is unavailable"));- assert_eq!(sent[0].thread_id.as_deref(), Some("42"));-}+#[path = "routes_command_tests.rs"]+mod command_tests;diff --git a/scripts/ci/check-openhuman-rust-layout.mjs b/scripts/ci/check-openhuman-rust-layout.mjsindex 631fc12375..d8a64c3e2d 100644--- a/scripts/ci/check-openhuman-rust-layout.mjs+++ b/scripts/ci/check-openhuman-rust-layout.mjs@@ -26,16 +26,14 @@ const LEGACY_LIMIT_ENTRIES = [// parameter schema moved to `spawn_subagent_parameters.rs` and the file is// under the general 750 limit, so it needs no exception at all.["crates/openhuman-core/src/agent/subagent_host/ops/runner.rs", 878],- ["crates/openhuman-core/src/web_chat/progress_bridge.rs", 1061],// These established external test modules grew with upstream coverage. Pin// their current sizes while follow-up work separates their test concerns.// `core/` was pruned from the line limit by name until these pins; its// oversized files are pinned at the size they had when enforcement began.- ["crates/openhuman-core/src/core/all.rs", 1114],+ ["crates/openhuman-core/src/core/all.rs", 1080],["crates/openhuman-core/src/core/all_tests.rs", 1465],- ["crates/openhuman-core/src/core/events.rs", 1697],+ ["crates/openhuman-core/src/core/events.rs", 1649],["crates/openhuman-core/src/core/events_tests.rs", 988],- ["crates/openhuman-core/src/core/observability.rs", 3361],];const LEGACY_LIMITS = new Map(LEGACY_LIMIT_ENTRIES);