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): isolate PTT ingress test with temp workspace and scoped context
Steven Enamakele8417f8c64d2
diff --git a/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs b/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rsindex 5ed8ed17f4..8acf3c7cd5 100644--- a/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs+++ b/crates/openhuman-core/src/web_chat/web_tests_start_chat_ingress_tests.rs@@ -8,122 +8,145 @@ async fn ptt_source_turn_completes_without_publishing_a_voice_event() {let _turn_lock = FORCED_ERROR_TEST_LOCK.lock().await;let _inference = crate::inference::inference_test_guard_async().await;- let _model = crate::inference::provider::factory::test_provider_override::install_model(- Arc::new(tinyagents_harness::testkit::ScriptedModel::replies(vec!["hello from mock"])),+ let _model =+ crate::inference::provider::factory::test_provider_override::install_model(Arc::new(+ tinyagents_harness::testkit::ScriptedModel::replies(vec!["hello from mock"]),+ ));+ let temp = tempfile::tempdir().expect("temporary test workspace");+ let workspace_dir = temp.path().join("workspace");+ let action_dir = temp.path().join("projects");+ let config_path = temp.path().join("config/config.toml");+ std::fs::create_dir_all(&workspace_dir).expect("create isolated workspace");+ std::fs::create_dir_all(&action_dir).expect("create isolated action directory");+ std::fs::create_dir_all(config_path.parent().unwrap()).expect("create isolated config dir");+ let mut config = crate::config::Config::default();+ config.workspace_dir = workspace_dir;+ config.action_dir = action_dir.clone();+ config.action_dir_override = Some(action_dir.clone());+ config.config_path = config_path;+ config.files_dir_override = Some(temp.path().join("files"));+ let core_context = crate::core::runtime::CoreContext::for_test_with_config(+ crate::core::runtime::DomainSet::full(),+ config,);+ let ctx = crate::core::runtime::DispatchCtx::new(Arc::clone(&core_context));- struct Events(tokio::sync::mpsc::UnboundedSender<crate::core::events::DomainEvent>);+ crate::core::runtime::CoreContext::scope(core_context, async {+ struct Events(tokio::sync::mpsc::UnboundedSender<crate::core::events::DomainEvent>);- #[async_trait::async_trait]- impl EventHandler<crate::core::events::DomainEvent> for Events {- fn name(&self) -> &str {- "web_chat::ptt_regression_test"- }+ #[async_trait::async_trait]+ impl EventHandler<crate::core::events::DomainEvent> for Events {+ fn name(&self) -> &str {+ "web_chat::ptt_regression_test"+ }- async fn handle(&self, event: &crate::core::events::DomainEvent) {- let _ = self.0.send(event.clone());+ async fn handle(&self, event: &crate::core::events::DomainEvent) {+ let _ = self.0.send(event.clone());+ }}- }- crate::core::bus::init().await.expect("event bus init");- let (events_tx, mut observed_events) = tokio::sync::mpsc::unbounded_channel();- let _subscription = crate::core::bus::BUS- .subscribe(Arc::new(Events(events_tx)))- .expect("voice event subscription");-- let bus_ready = "ptt-regression-bus-ready-403";- crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SystemStartup {- component: bus_ready.to_string(),- });- tokio::time::timeout(std::time::Duration::from_secs(5), async {- loop {- if matches!(observed_events.recv().await,+ crate::core::bus::init().await.expect("event bus init");+ let (events_tx, mut observed_events) = tokio::sync::mpsc::unbounded_channel();+ let _subscription = crate::core::bus::BUS+ .subscribe(Arc::new(Events(events_tx)))+ .expect("voice event subscription");++ let bus_ready = "ptt-regression-bus-ready-403";+ crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SystemStartup {+ component: bus_ready.to_string(),+ });+ tokio::time::timeout(std::time::Duration::from_secs(5), async {+ loop {+ if matches!(observed_events.recv().await,Some(crate::core::events::DomainEvent::SystemStartup { component })if component == bus_ready)- {- break;- }- }- })- .await- .expect("BUS subscriber should receive its control event");-- let mut web_events = subscribe_web_channel_events();- let thread_id = "ptt-event-regression-403-thread";- let session_id = 403_042;- let request_id = start_chat(- &crate::core::runtime::DispatchCtx::ambient(),- "ptt-test-client",- thread_id,- "recognized words",- None,- None,- None,- None,- ChatRequestMetadata {- source: Some("ptt".to_string()),- session_id: Some(session_id),- ..Default::default()- },- )- .await- .expect("PTT web chat turn should start");-- let done = tokio::time::timeout(std::time::Duration::from_secs(20), async {- loop {- let event = web_events.recv().await.expect("web event stream stays open");- if event.request_id == request_id && event.event == "chat_done" {- break event;+ {+ break;+ }}- assert_ne!(- (event.request_id.as_str(), event.event.as_str()),- (request_id.as_str(), "chat_error"),- "PTT turn should complete successfully: {event:?}"- );- }- })- .await- .expect("PTT turn should finish");- assert_eq!(done.full_response.as_deref(), Some("hello from mock"));-- // Subscriber dispatch is a single FIFO loop (`events/subscriber.rs`), so- // observing this marker proves it has handled every locally published- // event before the barrier, including any PTT event sent by the turn.- let barrier = "ptt-regression-bus-barrier-403";- crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SystemStartup {- component: barrier.to_string(),- });- let matching_voice_event_seen = tokio::time::timeout(- std::time::Duration::from_secs(5),- async {- let mut matching_voice_event_seen = false;+ })+ .await+ .expect("BUS subscriber should receive its control event");++ let mut web_events = subscribe_web_channel_events();+ let thread_id = "ptt-event-regression-403-thread";+ let session_id = 403_042;+ let request_id = start_chat(+ &ctx,+ "ptt-test-client",+ thread_id,+ "recognized words",+ None,+ None,+ None,+ None,+ ChatRequestMetadata {+ source: Some("ptt".to_string()),+ session_id: Some(session_id),+ ..Default::default()+ },+ )+ .await+ .expect("PTT web chat turn should start");++ let done = tokio::time::timeout(std::time::Duration::from_secs(20), async {loop {- let Some(event) = observed_events.recv().await else {- continue;- };- if matches!(- &event,- crate::core::events::DomainEvent::SystemStartup { component }- if component == barrier- ) {- break matching_voice_event_seen;- }- let debug = format!("{event:?}");- if event.domain() == "voice"- && debug.contains(thread_id)- && debug.contains(&session_id.to_string())- {- matching_voice_event_seen = true;+ let event = web_events+ .recv()+ .await+ .expect("web event stream stays open");+ if event.request_id == request_id && event.event == "chat_done" {+ break event;}+ assert_ne!(+ (event.request_id.as_str(), event.event.as_str()),+ (request_id.as_str(), "chat_error"),+ "PTT turn should complete successfully: {event:?}"+ );}- },- )- .await- .expect("BUS subscriber should reach the post-turn barrier");- assert!(- !matching_voice_event_seen,- "a successful source=ptt message must not publish a voice event"- );+ })+ .await+ .expect("PTT turn should finish");+ assert_eq!(done.full_response.as_deref(), Some("hello from mock"));++ // Subscriber dispatch is a single FIFO loop (`events/subscriber.rs`), so+ // observing this marker proves it has handled every locally published+ // event before the barrier, including any PTT event sent by the turn.+ let barrier = "ptt-regression-bus-barrier-403";+ crate::core::bus::BUS.publish(crate::core::events::DomainEvent::SystemStartup {+ component: barrier.to_string(),+ });+ let matching_voice_event_seen =+ tokio::time::timeout(std::time::Duration::from_secs(5), async {+ let mut matching_voice_event_seen = false;+ loop {+ let Some(event) = observed_events.recv().await else {+ continue;+ };+ if matches!(+ &event,+ crate::core::events::DomainEvent::SystemStartup { component }+ if component == barrier+ ) {+ break matching_voice_event_seen;+ }+ let debug = format!("{event:?}");+ if event.domain() == "voice"+ && debug.contains(thread_id)+ && debug.contains(&session_id.to_string())+ {+ matching_voice_event_seen = true;+ }+ }+ })+ .await+ .expect("BUS subscriber should reach the post-turn barrier");+ assert!(+ !matching_voice_event_seen,+ "a successful source=ptt message must not publish a voice event"+ );+ })+ .await;}#[tokio::test]