Skip to content

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

test: verify collapsed tool exposure survives wildcard visibility reset

Steven Enamakelb5c6b125fdef
diff --git a/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_tool_exposure_tests.rs b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_tool_exposure_tests.rs
index c4bd929eff..6cf6f2c910 100644
--- a/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_tool_exposure_tests.rs
+++ b/crates/openhuman-core/src/agent/harness/session/builder/builder_tests_tool_exposure_tests.rs
@@ -1,10 +1,13 @@
use super::*;
fn visible_names(agent_id: &str) -> std::collections::HashSet<String> {
- crate::agent::harness::AgentDefinitionRegistry::init_global_builtins().unwrap();
let tmp = tempfile::TempDir::new().unwrap();
let config = test_config(&tmp);
- let agent = crate::agent::Agent::from_config_for_agent(&config, agent_id)
+ let definition = crate::agent::harness::AgentDefinitionRegistry::builtins_only()
+ .get(agent_id)
+ .cloned()
+ .unwrap_or_else(|| panic!("built-in agent definition not found: {agent_id}"));
+ let agent = crate::agent::Agent::from_config_with_definition(&config, &definition, None, None)
.unwrap_or_else(|e| panic!("{agent_id} session build: {e}"));
agent
.visible_tool_specs_arc()
@@ -13,6 +16,43 @@ fn visible_names(agent_id: &str) -> std::collections::HashSet<String> {
.collect()
}
+#[test]
+fn resetting_wildcard_visibility_keeps_collapsed_exposure() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let definition = crate::agent::harness::AgentDefinitionRegistry::builtins_only()
+ .get("tools_agent")
+ .cloned()
+ .expect("tools_agent built-in definition");
+ let mut agent = crate::agent::Agent::from_config_with_definition(&config, &definition, None, None)
+ .expect("build tools agent");
+
+ agent.set_visible_tool_names(std::collections::HashSet::new());
+
+ let visible = agent.visible_tool_specs_arc();
+ assert!(visible.iter().any(|spec| spec.name == crate::memory::tools::MEMORY_TOOL_NAME));
+ assert!(!visible.iter().any(|spec| spec.name == "memory_store"));
+}
+
+#[test]
+fn hiding_and_reseeding_wildcard_visibility_keeps_collapsed_exposure() {
+ let tmp = tempfile::TempDir::new().unwrap();
+ let config = test_config(&tmp);
+ let definition = crate::agent::harness::AgentDefinitionRegistry::builtins_only()
+ .get("tools_agent")
+ .cloned()
+ .expect("tools_agent built-in definition");
+ let mut agent = crate::agent::Agent::from_config_with_definition(&config, &definition, None, None)
+ .expect("build tools agent");
+
+ agent.set_visible_tool_names(std::collections::HashSet::new());
+ agent.hide_tools(&[crate::memory::tools::MEMORY_TOOL_NAME]);
+
+ let visible = agent.visible_tool_specs_arc();
+ assert!(!visible.iter().any(|spec| spec.name == crate::memory::tools::MEMORY_TOOL_NAME));
+ assert!(!visible.iter().any(|spec| spec.name == "memory_store"));
+}
+
/// A wildcard belt advertises the collapsed tool, never its `Hidden` members.
///
/// Both halves are asserted: the members gone AND the replacement present. A
diff --git a/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs b/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
index 547cbcc7c8..3706228ae7 100644
--- a/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
+++ b/crates/openhuman-core/src/agent/harness/session/runtime/accessors.rs
@@ -396,9 +396,30 @@ impl Agent {
/// still subject to the configured channel permission policy.
pub fn set_visible_tool_names(&mut self, names: HashSet<String>) {
self.visible_tool_names = names;
+ if self.visible_tool_names.is_empty() {
+ self.seed_wildcard_visible_tools();
+ }
self.rebuild_tool_policy_session();
}
+ /// Materialise the wildcard visibility sentinel while preserving the
+ /// exposure filters applied during the initial session build.
+ fn seed_wildcard_visible_tools(&mut self) {
+ self.visible_tool_names = self
+ .tool_specs
+ .iter()
+ .map(|spec| spec.name.clone())
+ .collect();
+ let _ = crate::tools::implementations::meta::strip_deferred_from_visible(
+ &mut self.visible_tool_names,
+ self.tools.as_slice(),
+ );
+ crate::tools::toolpacks::strip_packed_from_visible(
+ &mut self.visible_tool_names,
+ &self.agent_definition_name,
+ );
+ }
+
/// Remove `names` from the main agent's callable set for this session,
/// leaving every other currently-visible tool untouched.
///
@@ -418,31 +439,13 @@ impl Agent {
/// a handful of tools from a much larger belt, where that can't happen.
pub fn hide_tools(&mut self, names: &[&str]) {
if self.visible_tool_names.is_empty() {
- self.visible_tool_names = self
- .tool_specs
- .iter()
- .map(|spec| spec.name.clone())
- .collect();
- // Seeding a wildcard belt re-admits the durable Hidden/Deferred
- // tools the builder withheld; drop them again. Durable registry
- // only — the synthesised delegates report `Hidden` too and are
- // this belt's hand-off routes (see `AgentBuilder::build`). The
- // deferred specs were already indexed at build time.
- let _ = crate::tools::implementations::meta::strip_deferred_from_visible(
- &mut self.visible_tool_names,
- self.tools.as_slice(),
- );
+ // Durable registry only — synthesised delegates report `Hidden`
+ // too and are this belt's hand-off routes.
+ self.seed_wildcard_visible_tools();
}
for name in names {
self.visible_tool_names.remove(*name);
}
- // Seeding from `tool_specs` above materialises the "all visible"
- // sentinel into a concrete set, which would re-admit packed tools that
- // the builder withheld. Re-apply the withholding.
- crate::tools::toolpacks::strip_packed_from_visible(
- &mut self.visible_tool_names,
- &self.agent_definition_name,
- );
self.rebuild_tool_policy_session();
}
diff --git a/crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs b/crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs
index 95b8b7a956..c0c7c53a3d 100644
--- a/crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs
+++ b/crates/openhuman-core/src/tools/ops_tests_default_registry_tests.rs
@@ -47,6 +47,38 @@ fn all_tools_includes_spawn_subagent() {
);
}
+#[test]
+fn all_tools_registers_collapsed_memory_and_search_tools() {
+ let tmp = TempDir::new().unwrap();
+ let security = Arc::new(SecurityPolicy::default());
+ let cfg = test_config(&tmp);
+ let browser = BrowserConfig::default();
+ let http = crate::config::HttpRequestConfig::default();
+ let tools = all_tools(
+ Arc::new(Config::default()),
+ &security,
+ AuditLogger::disabled(),
+ &browser,
+ &http,
+ tmp.path(),
+ &HashMap::new(),
+ &cfg,
+ );
+
+ let memory = tools
+ .iter()
+ .find(|tool| tool.name() == crate::memory::tools::MEMORY_TOOL_NAME)
+ .expect("collapsed memory tool must be registered");
+ assert_eq!(tool_group(memory.name()), crate::core::all::DomainGroup::Memory);
+ assert_eq!(
+ tool_capability(memory.name()),
+ Some(tinymemory_api::capabilities::Capability::Core)
+ );
+ assert!(tools.iter().any(|tool| {
+ tool.name() == crate::tools::implementations::meta::TOOL_SEARCH_NAME
+ }));
+}
+
/// The three `whatsapp_data_*` agent tools are gone, in every build.
///
/// They queried a shell-side SQLite store whose only writer was the CDP