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(web_chat): add coverage for ops, checkout, and queue accept paths
Steven Enamakelb31f33ba9cc8
diff --git a/crates/openhuman-core/src/web_chat/ops/state_tests.rs b/crates/openhuman-core/src/web_chat/ops/state_tests.rsindex d4c9bf6a51..a30f801a7a 100644--- a/crates/openhuman-core/src/web_chat/ops/state_tests.rs+++ b/crates/openhuman-core/src/web_chat/ops/state_tests.rs@@ -51,18 +51,27 @@ async fn two_profiles_on_the_same_thread_id_hold_two_keys() {)};let (alice, bob) = (profile("u-alice"), profile("u-bob"));- let key_a = CoreContext::scope(Arc::clone(&alice), async { key_for("t1") }).await;- let key_b = CoreContext::scope(Arc::clone(&bob), async { key_for("t1") }).await;- assert_ne!(key_a, key_b);- assert_eq!(- CoreContext::scope(Arc::clone(&alice), async { unscope(&key_a) }).await,- "t1"+ let (ctx_a, ctx_b) = (+ DispatchCtx::new(Arc::clone(&alice)),+ DispatchCtx::new(Arc::clone(&bob)),);+ let key_a = key_for(&ctx_a, "t1");+ let key_b = key_for(&ctx_b, "t1");+ assert_ne!(key_a, key_b);+ assert_eq!(unscope(&ctx_a, &key_a), "t1");assert_eq!(- CoreContext::scope(Arc::clone(&alice), async { unscope(&key_b) }).await,+ unscope(&ctx_a, &key_b),key_b,"another tenant's key is not unscoped");+ // The explicit context wins over whatever scope the caller happens to run+ // in, and concurrent callers do not cross.+ let (under_bob, under_alice) = tokio::join!(+ CoreContext::scope(Arc::clone(&bob), async { key_for(&ctx_a, "t1") }),+ CoreContext::scope(Arc::clone(&alice), async { key_for(&ctx_b, "t1") }),+ );+ assert_eq!(under_bob, key_a);+ assert_eq!(under_alice, key_b);assert_eq!(thread_id_of_key(&key_b), Some("t1"));// The desktop keeps the bare id.assert_eq!(key_in(&crate::core::runtime::Tenant::default(), "t1"), "t1");@@ -74,7 +83,12 @@ async fn a_user_cancel_under_the_fence_placeholder_id_keeps_the_callers_client()track_parallel_turn_for_test("fence-thread", "fence-req", token.clone()).await;let mut events = crate::web_chat::subscribe_web_channel_events();- crate::web_chat::ops::channel_ops::cancel_chat_scoped("profile-fence", "fence-thread", None)+ crate::web_chat::ops::channel_ops::cancel_chat_scoped(+ &DispatchCtx::ambient(),+ "profile-fence",+ "fence-thread",+ None,+ ).await.unwrap();diff --git a/crates/openhuman-core/src/web_chat/session_checkout_tests.rs b/crates/openhuman-core/src/web_chat/session_checkout_tests.rsindex d8b21522d5..954eb7d685 100644--- a/crates/openhuman-core/src/web_chat/session_checkout_tests.rs+++ b/crates/openhuman-core/src/web_chat/session_checkout_tests.rs@@ -103,7 +103,7 @@ async fn evict(thread_id: &str) {thread_sessions().lock_owned().await- .remove(&key_for(thread_id));+ .remove(&key_for(&DispatchCtx::ambient(), thread_id));}#[tokio::test]@@ -126,7 +126,7 @@ async fn checkout_cold_boots_from_the_thread_transcript_and_checkin_keeps_it_warmut agent,fingerprint,} = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,super::super::SYSTEM_CLIENT_ID,&thread_id,None,@@ -151,15 +151,15 @@ async fn checkout_cold_boots_from_the_thread_transcript_and_checkin_keeps_it_war"cold checkout must resume the thread's transcript, got {history:?}");- checkin_session_agent(&thread_id, agent, fingerprint).await;+ checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;assert!(thread_sessions().lock().await- .contains_key(&key_for(&thread_id)));+ .contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));// The next checkout — a user turn — reuses the warm agent with that history.let CheckedOutSession { agent, .. } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -179,7 +179,7 @@ async fn checkout_cold_boots_from_the_thread_transcript_and_checkin_keeps_it_warassert!(!thread_sessions().lock().await- .contains_key(&key_for(&thread_id)));+ .contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));evict(&thread_id).await;}@@ -194,15 +194,15 @@ async fn checkin_if_vacant_yields_to_a_turn_that_re_cached_meanwhile() {// A user turn finished while the system turn was running and cached its// agent unconditionally.let user_turn_agent = host_seeded_with(&config, "user-turn-history");- checkin_session_agent(&thread_id, user_turn_agent, fingerprint(&config)).await;+ checkin_session_agent(&DispatchCtx::ambient(), &thread_id, user_turn_agent, fingerprint(&config)).await;// The system turn must not clobber it.let system_turn_agent = host_seeded_with(&config, "system-turn-history");assert!(- !checkin_session_agent_if_vacant(&thread_id, system_turn_agent, fingerprint(&config)).await+ !checkin_session_agent_if_vacant(&DispatchCtx::ambient(), &thread_id, system_turn_agent, fingerprint(&config)).await);let CheckedOutSession { agent, .. } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -217,10 +217,10 @@ async fn checkin_if_vacant_yields_to_a_turn_that_re_cached_meanwhile() {// Into a vacant slot it goes in.let system_turn_agent = host_seeded_with(&config, "system-turn-history");assert!(- checkin_session_agent_if_vacant(&thread_id, system_turn_agent, fingerprint(&config)).await+ checkin_session_agent_if_vacant(&DispatchCtx::ambient(), &thread_id, system_turn_agent, fingerprint(&config)).await);let CheckedOutSession { agent, .. } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -242,14 +242,14 @@ async fn a_fork_never_takes_or_returns_the_cached_agent() {let fingerprint =super::build_session_fingerprint(&config, None, None, "orchestrator".into(), "chat");checkin_session_agent(- &thread_id,+ &DispatchCtx::ambient(), &thread_id,host_seeded_with(&config, "primary-history"),fingerprint,).await;let CheckedOutSession { agent, .. } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -265,7 +265,7 @@ async fn a_fork_never_takes_or_returns_the_cached_agent() {assert!(thread_sessions().lock().await- .contains_key(&key_for(&thread_id)));+ .contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));evict(&thread_id).await;}@@ -279,14 +279,14 @@ async fn a_system_turn_adopts_the_cached_agent_and_its_fingerprint() {let pinned =super::build_session_fingerprint(&config, None, Some(0.2), "orchestrator".into(), "chat");checkin_session_agent(- &thread_id,+ &DispatchCtx::ambient(), &thread_id,host_seeded_with(&config, "pinned-history"),pinned.clone(),).await;let CheckedOutSession { agent, fingerprint } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,super::super::SYSTEM_CLIENT_ID,&thread_id,None,@@ -300,9 +300,9 @@ async fn a_system_turn_adopts_the_cached_agent_and_its_fingerprint() {assert_eq!(fingerprint, pinned, "handed back under the user's settings");// An exact user checkout with the same settings then still hits warm.- checkin_session_agent_if_vacant(&thread_id, agent, fingerprint).await;+ checkin_session_agent_if_vacant(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;let CheckedOutSession { agent, .. } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -326,7 +326,7 @@ async fn a_thread_binds_one_stable_session_across_cold_boots() {let thread_id = unique_thread("stable");let first = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -338,7 +338,7 @@ async fn a_thread_binds_one_stable_session_across_cold_boots() {.unwrap();// Nothing is checked back in, so the next checkout is a genuine cold boot.let second = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -565,14 +565,14 @@ async fn a_system_turn_never_adopts_an_agent_from_another_workspace() {let built_for_a =super::build_session_fingerprint(&config_a, None, None, "orchestrator".into(), "chat");checkin_session_agent(- &thread_id,+ &DispatchCtx::ambient(), &thread_id,host_seeded_with(&config_a, "user-a-history"),built_for_a,).await;let CheckedOutSession { agent, fingerprint } = checkout_session_agent(- &config_b,+ &DispatchCtx::ambient(), &config_b,super::super::SYSTEM_CLIENT_ID,&thread_id,None,@@ -614,7 +614,7 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {let thread_id = thread_id.clone();async move {checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -633,7 +633,7 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {.reply_language_directive().expect("es arms a directive");assert!(directive.contains("Spanish"), "{directive}");- checkin_session_agent(&thread_id, agent, fingerprint).await;+ checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;// Reused cached agent, the user switched the UI to English: the Spanish// directives already in the history are superseded explicitly.@@ -641,7 +641,7 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {thread_sessions().lock().await- .contains_key(&key_for(&thread_id)),+ .contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)),"fixture: the next checkout must reuse the cached agent");let CheckedOutSession { agent, fingerprint } = checkout(Some("en")).await;@@ -649,13 +649,13 @@ async fn each_checkout_arms_the_reply_language_from_its_own_locale() {.reply_language_directive().expect("switching to English supersedes the Spanish directive");assert!(directive.contains("Respond in English"), "{directive}");- checkin_session_agent(&thread_id, agent, fingerprint).await;+ checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;// Reused again, now Hindi: re-armed with the new language.assert!(thread_sessions().lock().await- .contains_key(&key_for(&thread_id)));+ .contains_key(&key_for(&DispatchCtx::ambient(), &thread_id)));let CheckedOutSession { agent, .. } = checkout(Some("hi")).await;let directive = agent.reply_language_directive()@@ -674,7 +674,7 @@ async fn an_english_only_session_and_a_locale_less_turn_carry_no_directive() {let thread_id = unique_thread("english");for locale in [Some("en"), None] {let CheckedOutSession { agent, fingerprint } = checkout_session_agent(- &config,+ &DispatchCtx::ambient(), &config,"client-1",&thread_id,None,@@ -685,7 +685,7 @@ async fn an_english_only_session_and_a_locale_less_turn_carry_no_directive() {.await.unwrap();assert_eq!(agent.reply_language_directive(), None, "{locale:?}");- checkin_session_agent(&thread_id, agent, fingerprint).await;+ checkin_session_agent(&DispatchCtx::ambient(), &thread_id, agent, fingerprint).await;}evict(&thread_id).await;}diff --git a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rsindex 675c11f9d0..edec55856e 100644--- a/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs+++ b/crates/openhuman-core/src/web_chat/web_tests_queue_acceptance_tests.rs@@ -1,4 +1,5 @@use super::*;+use crate::core::runtime::DispatchCtx;use serde_json::json;@@ -39,7 +40,7 @@ async fn queue_message(thread_id: &str, text: &str, mode: &str) -> serde_json::V}async fn cancel_parked_turn(thread_id: &str, block: &TestRunChatTaskBlock) {- cancel_chat_scoped("queue-test-client", thread_id, None)+ cancel_chat_scoped(&DispatchCtx::ambient(), "queue-test-client", thread_id, None).await.expect("parked turn should cancel");wait_for_in_flight(|entries| !entries.iter().any(|(key, _)| key == thread_id)).await;