Skip to content

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

test(skills): cover per-agent skill writes and discovery (#7032)

oxoxDev3cb40641016d
diff --git a/crates/openhuman-core/src/skills/write_root.rs b/crates/openhuman-core/src/skills/write_root.rs
index 1d996853cb..ddea36f4ef 100644
--- a/crates/openhuman-core/src/skills/write_root.rs
+++ b/crates/openhuman-core/src/skills/write_root.rs
@@ -54,3 +54,7 @@ pub fn user_workflow_root(workspace_dir: &Path, home: Option<&Path>) -> Option<P
None => home.map(|home| home.join(".openhuman").join("workflows")),
}
}
+
+#[cfg(test)]
+#[path = "write_root_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/skills/write_root_tests.rs b/crates/openhuman-core/src/skills/write_root_tests.rs
new file mode 100644
index 0000000000..7cab21392b
--- /dev/null
+++ b/crates/openhuman-core/src/skills/write_root_tests.rs
@@ -0,0 +1,94 @@
+use super::*;
+use crate::core::runtime::{context::CoreContext, ContextOverlay, DomainSet};
+use crate::skills::ops_create::{create_workflow_inner, CreateWorkflowParams};
+use crate::skills::ops_discover::discover_workflows;
+use crate::skills::ops_types::WorkflowScope;
+use crate::tools::toolpacks::ToolGroups;
+use std::sync::Arc;
+
+fn agent_on(workspace: &Path, agent: &str) -> Arc<CoreContext> {
+ let mut config = crate::config::Config::default();
+ config.workspace_dir = workspace.to_path_buf();
+ CoreContext::for_test_with_config(DomainSet::full(), config.clone()).derive_with(
+ ContextOverlay::new(config, DomainSet::full(), ToolGroups::none()).session_agent(agent),
+ )
+}
+
+fn user_workflow(name: &str) -> CreateWorkflowParams {
+ CreateWorkflowParams {
+ name: name.to_string(),
+ description: "An agent-owned workflow.".to_string(),
+ scope: WorkflowScope::User,
+ ..CreateWorkflowParams::default()
+ }
+}
+
+fn names(workflows: &[crate::skills::Workflow]) -> Vec<String> {
+ workflows
+ .iter()
+ .map(|workflow| workflow.name.clone())
+ .collect()
+}
+
+async fn seen_by(home: &Path, workspace: &Path, agent: Option<&str>) -> Vec<String> {
+ let discover = async { names(&discover_workflows(Some(home), Some(workspace), false)) };
+ match agent {
+ Some(agent) => CoreContext::scope(agent_on(workspace, agent), discover).await,
+ None => discover.await,
+ }
+}
+
+#[test]
+fn outside_an_agent_the_operator_home_is_the_write_root() {
+ let home = Path::new("/home/operator");
+ let workspace = Path::new("/ws");
+ assert_eq!(agent_skill_home(workspace), None);
+ assert_eq!(
+ user_skill_install_root(workspace, Some(home)),
+ Some(home.join(".openhuman/skills"))
+ );
+ assert_eq!(
+ user_workflow_root(workspace, Some(home)),
+ Some(home.join(".openhuman/workflows"))
+ );
+}
+
+#[tokio::test]
+async fn an_agents_created_skill_lands_in_its_directory_and_only_it_discovers_it() {
+ let home = tempfile::tempdir().expect("home");
+ let workspace = tempfile::tempdir().expect("workspace");
+ let home_path = home.path().to_path_buf();
+ let workspace_path = workspace.path().to_path_buf();
+
+ let created = CoreContext::scope(agent_on(workspace.path(), "alpha"), {
+ let (home_path, workspace_path) = (home_path.clone(), workspace_path.clone());
+ async move {
+ create_workflow_inner(
+ Some(&home_path),
+ &workspace_path,
+ user_workflow("Alpha Owned"),
+ )
+ .expect("alpha creates a workflow")
+ }
+ })
+ .await;
+
+ assert!(created
+ .location
+ .as_ref()
+ .is_some_and(|path| path.starts_with(workspace.path().join("agents/alpha/workflows"))));
+ assert!(
+ !home.path().join(".openhuman").exists(),
+ "home stays untouched"
+ );
+
+ assert!(seen_by(&home_path, &workspace_path, Some("alpha"))
+ .await
+ .contains(&"alpha-owned".to_string()));
+ assert!(!seen_by(&home_path, &workspace_path, Some("beta"))
+ .await
+ .contains(&"alpha-owned".to_string()));
+ assert!(!seen_by(&home_path, &workspace_path, None)
+ .await
+ .contains(&"alpha-owned".to_string()));
+}