Skip to content

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

test(profiles): cover name-based tool admission

Steven Enamakelf17a8116dc02
diff --git a/crates/openhuman-core/src/profiles/tools_tests.rs b/crates/openhuman-core/src/profiles/tools_tests.rs
index 644d8aa601..0a114eccce 100644
--- a/crates/openhuman-core/src/profiles/tools_tests.rs
+++ b/crates/openhuman-core/src/profiles/tools_tests.rs
@@ -199,3 +199,28 @@ fn only_the_scheduler_and_clock_tools_are_operator_admittable() {
);
}
}
+
+#[test]
+fn only_an_admittable_tool_the_agent_names_passes_by_name() {
+ let named: std::collections::HashSet<String> = ["cron", "current_time", "shell", "memory"]
+ .into_iter()
+ .map(str::to_string)
+ .collect();
+ assert!(admitted_by_name("cron", Some(&named)));
+ assert!(admitted_by_name("current_time", Some(&named)));
+ assert!(
+ !admitted_by_name("resolve_time", Some(&named)),
+ "admittable but not named"
+ );
+ assert!(
+ !admitted_by_name("shell", Some(&named)),
+ "named but not admittable"
+ );
+ assert!(!admitted_by_name("cron", None), "no named scope at all");
+}
+
+#[test]
+fn outside_saas_without_a_context_only_the_domain_filter_applies() {
+ assert!(admits("shell", true));
+ assert!(!admits("cron", false));
+}
diff --git a/crates/openhuman-embed/tests/named_admitted_tools.rs b/crates/openhuman-embed/tests/named_admitted_tools.rs
new file mode 100644
index 0000000000..6d6429124c
--- /dev/null
+++ b/crates/openhuman-embed/tests/named_admitted_tools.rs
@@ -0,0 +1,66 @@
+//! An embedded agent on the harness domains gets the scheduler and clock tools
+//! it names, although their domain family is off, and nothing else from that
+//! family: not the shell or file tools, even when it names them too.
+//!
+//! One runtime per process, so one test in this binary.
+
+mod common;
+
+use std::sync::Arc;
+
+use common::{chat_requests, offline_config, provider, runtime, stub_backend, tool_names};
+use openhuman_embed::{
+ AgentDefinitionSpec, AgentSpec, DomainSet, HostTurnTools, InMemorySessionStores, Runtime,
+ ToolGroups, ToolScopeSpec, Workspace,
+};
+
+#[test]
+fn a_named_scope_admits_the_clock_and_scheduler_but_never_the_shell() {
+ runtime().block_on(async {
+ tokio::spawn(async {
+ let backend = stub_backend().await;
+ let model = provider("ok").await;
+ let runtime = Runtime::builder()
+ .config(offline_config())
+ .workspace(Workspace::Stateless)
+ .session_store(Arc::new(InMemorySessionStores::new()))
+ .backend_url(backend.uri())
+ .domains(DomainSet::harness())
+ .tool_groups(ToolGroups::advertised())
+ .build()
+ .await
+ .expect("runtime builds");
+ let named = ["cron", "current_time", "resolve_time", "shell", "file_read"];
+ let agent = runtime
+ .agent(
+ AgentSpec::new("teeny")
+ .provider(common::route(&model, "fixture"))
+ .definition(AgentDefinitionSpec::new().system_prompt("TEENY").tools(
+ ToolScopeSpec::Named(named.iter().map(|n| (*n).to_string()).collect()),
+ ))
+ .tools(|_| HostTurnTools::advertised(Vec::new())),
+ )
+ .expect("agent instantiates");
+ agent.run("hello").await.expect("the turn runs");
+
+ let requests = chat_requests(&model).await;
+ let offered = tool_names(&requests[0]);
+ for admitted in ["cron", "current_time", "resolve_time"] {
+ assert!(
+ offered.iter().any(|name| name == admitted),
+ "{admitted} missing: {offered:?}"
+ );
+ }
+ for refused in ["shell", "file_read"] {
+ assert!(
+ !offered.iter().any(|name| name == refused),
+ "{refused} offered: {offered:?}"
+ );
+ }
+ drop(agent);
+ drop(runtime);
+ })
+ .await
+ .expect("library host task did not panic");
+ });
+}