Skip to content

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

test(orchestration): register running subagents projection test module

Steven Enamakelbaebe7d0be48
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_projection_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_projection_tests.rs
new file mode 100644
index 0000000000..f24aba1b33
--- /dev/null
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_projection_tests.rs
@@ -0,0 +1,123 @@
+use super::*;
+use crate::core::runtime::{ContextOverlay, CoreContext, DomainSet, DispatchCtx, Mode};
+use crate::tools::toolpacks::ToolGroups;
+use tinyagents_orchestration::subagent::list_subagent_records;
+
+const PARENT: &str = "projection-parent";
+
+fn profile(name: &str, workspace: &std::path::Path) -> Arc<CoreContext> {
+ CoreContext::for_test(DomainSet::full(), None).derive_with(
+ ContextOverlay::new(
+ crate::config::Config {
+ workspace_dir: workspace.to_path_buf(),
+ ..crate::config::Config::default()
+ },
+ DomainSet::kernel(),
+ ToolGroups::none(),
+ )
+ .profile(name)
+ .session_agent("projection-agent"),
+ )
+}
+
+fn records(ctx: &DispatchCtx, workspace: &std::path::Path) -> Vec<tinyagents_tasks::OrchestrationTaskRecord> {
+ let store = super::super::resolve::scoped_task_store(ctx, workspace)
+ .expect("profile-scoped task store");
+ list_subagent_records(store.as_ref())
+}
+
+#[tokio::test]
+async fn explicit_profile_projects_spawn_completion_and_cancel_without_ambient_scope() {
+ let name = "explicit_profile_projects_spawn_completion_and_cancel_without_ambient_scope";
+ let module = module_path!().split_once("::").expect("crate module").1;
+ let exact = format!("{module}::{name}");
+ if std::env::var("OPENHUMAN_SUBAGENT_PROJECTION_CHILD").as_deref() != Ok(exact.as_str()) {
+ let output = std::process::Command::new(std::env::current_exe().expect("test binary"))
+ .args(["--exact", &exact, "--nocapture", "--test-threads=1"])
+ .env("OPENHUMAN_SUBAGENT_PROJECTION_CHILD", &exact)
+ .output()
+ .expect("run isolated SaaS projection test");
+ assert!(
+ output.status.success() && String::from_utf8_lossy(&output.stdout).contains("1 passed"),
+ "isolated test {exact} failed:\n{}\n{}",
+ String::from_utf8_lossy(&output.stdout),
+ String::from_utf8_lossy(&output.stderr)
+ );
+ return;
+ }
+
+ crate::core::runtime::mode::lock_mode(Mode::Saas).expect("lock isolated SaaS mode");
+ assert!(CoreContext::scoped().is_none(), "test starts without ambient scope");
+ let _guard = test_guard_async().await;
+ let workspace = tempfile::tempdir().expect("workspace");
+ let alice = DispatchCtx::new(profile("projection-alice", workspace.path()));
+ let bob = DispatchCtx::new(profile("projection-bob", workspace.path()));
+ let alice_task = uuid::Uuid::new_v4().to_string();
+ let bob_task = uuid::Uuid::new_v4().to_string();
+
+ let (alice_tx, alice_rx) = status_channel();
+ let (bob_tx, bob_rx) = status_channel();
+ register(
+ &alice,
+ alice_task.clone(),
+ "researcher".into(),
+ PARENT.into(),
+ None,
+ None,
+ workspace.path().to_path_buf(),
+ None,
+ run_queue(),
+ dummy_abort(),
+ alice_rx,
+ )
+ .expect("Alice registration");
+ register(
+ &bob,
+ bob_task.clone(),
+ "researcher".into(),
+ PARENT.into(),
+ None,
+ None,
+ workspace.path().to_path_buf(),
+ None,
+ run_queue(),
+ dummy_abort(),
+ bob_rx,
+ )
+ .expect("Bob registration");
+
+ let alice_spawned = records(&alice, workspace.path());
+ let bob_spawned = records(&bob, workspace.path());
+ assert!(alice_spawned.iter().any(|row| row.spec.task_id.as_str() == alice_task));
+ assert!(alice_spawned.iter().all(|row| row.spec.task_id.as_str() != bob_task));
+ assert!(bob_spawned.iter().any(|row| row.spec.task_id.as_str() == bob_task));
+ assert!(bob_spawned.iter().all(|row| row.spec.task_id.as_str() != alice_task));
+
+ alice_tx
+ .send(DetachedSubagentStatus::Completed {
+ output: "finished".into(),
+ iterations: 1,
+ })
+ .expect("send terminal status");
+ tokio::time::timeout(std::time::Duration::from_secs(2), async {
+ loop {
+ if records(&alice, workspace.path())
+ .iter()
+ .any(|row| row.spec.task_id.as_str() == alice_task && row.is_terminal())
+ {
+ break;
+ }
+ tokio::task::yield_now().await;
+ }
+ })
+ .await
+ .expect("Alice terminal status projected");
+
+ assert!(cancel_by_task(&alice, &bob_task).is_none());
+ assert!(cancel_by_task(&alice, &alice_task).is_some());
+ let alice_after_cancel = records(&alice, workspace.path());
+ let bob_after_cancel = records(&bob, workspace.path());
+ assert!(alice_after_cancel.iter().any(|row| row.spec.task_id.as_str() == alice_task));
+ assert!(bob_after_cancel.iter().any(|row| row.spec.task_id.as_str() == bob_task));
+ let _ = bob_tx;
+}
diff --git a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
index 3b3b14b550..59b26c3bbc 100644
--- a/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/running_subagents_tests.rs
@@ -39,6 +39,9 @@ mod wire_tests;
#[path = "running_subagents_tenant_tests.rs"]
mod tenant_tests;
+#[path = "running_subagents_projection_tests.rs"]
+mod projection_tests;
+
/// Serializes every test that touches the global [`REGISTRY`]. We reuse the
/// crate-wide `TEST_ENV_LOCK` (rather than a module-local mutex) because the
/// destructive `cancel_all` path is also reachable from the `threads::ops`