Skip to content

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

test(toolpacks): move pack registry tests into part_02 module

Steven Enamakel27a3cb7832a0
diff --git a/src/openhuman/tools/toolpacks/toolpacks_tests.rs b/src/openhuman/tools/toolpacks/toolpacks_tests.rs
index 990b71a527..1de3a75d4a 100644
--- a/src/openhuman/tools/toolpacks/toolpacks_tests.rs
+++ b/src/openhuman/tools/toolpacks/toolpacks_tests.rs
@@ -704,139 +704,6 @@ fn the_reactive_fleet_tools_are_never_packed() {
}
}
-#[test]
-fn rebinding_a_pack_handle_repoints_it_at_the_new_registry() {
- // `bind_pack_registry`'s own docs say to "call this after **every**
- // rebinding of the agent's tool `Arc`", but the handle used to hold a
- // `OnceLock`, so the second write was dropped on the floor. An agent that
- // rebuilt its tool vector kept a `Weak` into the old allocation; once that
- // allocation went away the upgrade failed and every `use_skill` call
- // reported the registry as unavailable for the rest of the session.
- // Last write must win.
- let name = pack("crypto").unwrap().tools[0];
-
- // The agent's first tool `Arc`, with the packed tool marked Dangerous.
- let first = registry_with(name, PermissionLevel::Dangerous);
- let use_skill = find(&first, USE_SKILL);
- let args = json!({"skill": "crypto", "tool": name});
- assert_eq!(
- use_skill.permission_level_with_args(&args),
- PermissionLevel::Dangerous,
- "sanity: the first binding resolves"
- );
-
- // The agent rebuilds its registry into a *different* allocation, where the
- // same packed tool is only ReadOnly.
- let mut rebuilt: Vec<Box<dyn Tool>> = vec![Box::new(FakeTool {
- name,
- level: PermissionLevel::ReadOnly,
- external: false,
- timeout: ToolTimeout::Inherit,
- })];
- append_pack_tools(&mut rebuilt);
- let rebuilt = Arc::new(rebuilt);
-
- // Re-point the ORIGINAL handle at it, which is what a rebuild does.
- crate::openhuman::tools::traits::pack_registry_handle(use_skill)
- .expect("use_skill exposes a pack registry handle")
- .bind(Arc::downgrade(&rebuilt));
-
- assert_eq!(
- use_skill.permission_level_with_args(&args),
- PermissionLevel::ReadOnly,
- "the rebound handle must resolve against the new registry, not the old one"
- );
-}
-
-// ── the listing must agree with the gate ────────────────────────────────────
-
-/// The bug, at the layer it lives on: a non-owner was shown `propose_workflow`
-/// and then refused when it called it.
-///
-/// `is_callable` here stands in for the session allowlist the middleware
-/// applies (`channel_permission_block` denies `propose_workflow` for every
-/// agent that is not `workflow_builder` / `flow_discovery`). The listing must
-/// not mention a tool that gate will refuse.
-#[test]
-fn a_non_owner_listing_omits_the_tools_the_gate_will_refuse() {
- let tools = registry_with_all(&["build_workflow", "propose_workflow"]);
- let handle = crate::openhuman::tools::traits::pack_registry_handle(find(&tools, USE_SKILL))
- .expect("use_skill carries the pack handle");
-
- let rendered = render_pack_filtered(
- "workflows",
- handle,
- &|name: &str| name != "propose_workflow",
- "",
- )
- .expect("the pack still has a callable tool");
-
- assert!(
- rendered.contains("build_workflow"),
- "a tool the session CAN call must still be listed: {rendered}"
- );
- assert!(
- !rendered.contains("propose_workflow"),
- "a tool the session will refuse must not be advertised: {rendered}"
- );
-}
-
-/// When the session can reach nothing in the pack, the failure has to carry the
-/// way out. A bare "no tools available" is the dead end the model retried into.
-#[test]
-fn a_listing_with_nothing_callable_names_the_route_out() {
- let tools = registry_with_all(&["build_workflow", "propose_workflow"]);
- let handle = crate::openhuman::tools::traits::pack_registry_handle(find(&tools, USE_SKILL))
- .expect("use_skill carries the pack handle");
-
- let route = route_sentence(&["build_workflow".to_string()], &["workflow_builder"]);
- let err = render_pack_filtered("workflows", handle, &|_| false, &route)
- .expect_err("nothing callable must not render a menu");
-
- assert!(
- err.contains("build_workflow"),
- "the denial must name the delegate to call instead: {err}"
- );
-}
-
-/// Naming the tool, not just the agent, is the difference between an
-/// instruction and a guess — and a model that guesses wrong retries.
-#[test]
-fn route_sentence_prefers_a_callable_tool_and_falls_back_to_owners() {
- let named = route_sentence(&["build_workflow".to_string()], &["workflow_builder"]);
- assert!(named.contains("`build_workflow`"), "{named}");
- assert!(
- !named.contains("`workflow_builder`"),
- "naming the agent as well is noise once the call is named: {named}"
- );
-
- let fallback = route_sentence(&[], &["workflow_builder", "flow_discovery"]);
- assert!(fallback.contains("`workflow_builder`"), "{fallback}");
- assert!(fallback.contains("`flow_discovery`"), "{fallback}");
-
- assert!(
- route_sentence(&[], &[]).is_empty(),
- "an ownerless pack has no route to offer and must stay silent"
- );
-}
-
-/// The route only exists because these owners do. If the `workflows` pack is
-/// ever re-owned, the hint silently stops naming `workflow_builder` — this
-/// pins the assumption the two tests above rest on.
-#[test]
-fn the_workflows_pack_is_still_owned_by_the_flow_agents() {
- let pack = pack("workflows").expect("the workflows pack exists");
- assert!(
- pack.owners.contains(&"workflow_builder"),
- "owners moved: {:?}",
- pack.owners
- );
- assert!(
- pack.tools.contains(&"propose_workflow"),
- "propose_workflow left the pack: {:?}",
- pack.tools
- );
-}
#[path = "toolpacks_tests_part_02_tests.rs"]
mod part_02_tests;
diff --git a/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs b/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs
index f5060bf94a..bb4087f5f6 100644
--- a/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs
+++ b/src/openhuman/tools/toolpacks/toolpacks_tests_part_02_tests.rs
@@ -176,3 +176,138 @@ fn a_hidden_tool_over_the_permission_ceiling_still_blocks_execution() {
"a hidden tool within the ceiling is the normal packed case and must stay callable"
);
}
+
+#[test]
+fn rebinding_a_pack_handle_repoints_it_at_the_new_registry() {
+ // `bind_pack_registry`'s own docs say to "call this after **every**
+ // rebinding of the agent's tool `Arc`", but the handle used to hold a
+ // `OnceLock`, so the second write was dropped on the floor. An agent that
+ // rebuilt its tool vector kept a `Weak` into the old allocation; once that
+ // allocation went away the upgrade failed and every `use_skill` call
+ // reported the registry as unavailable for the rest of the session.
+ // Last write must win.
+ let name = pack("crypto").unwrap().tools[0];
+
+ // The agent's first tool `Arc`, with the packed tool marked Dangerous.
+ let first = registry_with(name, PermissionLevel::Dangerous);
+ let use_skill = find(&first, USE_SKILL);
+ let args = json!({"skill": "crypto", "tool": name});
+ assert_eq!(
+ use_skill.permission_level_with_args(&args),
+ PermissionLevel::Dangerous,
+ "sanity: the first binding resolves"
+ );
+
+ // The agent rebuilds its registry into a *different* allocation, where the
+ // same packed tool is only ReadOnly.
+ let mut rebuilt: Vec<Box<dyn Tool>> = vec![Box::new(FakeTool {
+ name,
+ level: PermissionLevel::ReadOnly,
+ external: false,
+ timeout: ToolTimeout::Inherit,
+ })];
+ append_pack_tools(&mut rebuilt);
+ let rebuilt = Arc::new(rebuilt);
+
+ // Re-point the ORIGINAL handle at it, which is what a rebuild does.
+ crate::openhuman::tools::traits::pack_registry_handle(use_skill)
+ .expect("use_skill exposes a pack registry handle")
+ .bind(Arc::downgrade(&rebuilt));
+
+ assert_eq!(
+ use_skill.permission_level_with_args(&args),
+ PermissionLevel::ReadOnly,
+ "the rebound handle must resolve against the new registry, not the old one"
+ );
+}
+
+// ── the listing must agree with the gate ────────────────────────────────────
+
+/// The bug, at the layer it lives on: a non-owner was shown `propose_workflow`
+/// and then refused when it called it.
+///
+/// `is_callable` here stands in for the session allowlist the middleware
+/// applies (`channel_permission_block` denies `propose_workflow` for every
+/// agent that is not `workflow_builder` / `flow_discovery`). The listing must
+/// not mention a tool that gate will refuse.
+#[test]
+fn a_non_owner_listing_omits_the_tools_the_gate_will_refuse() {
+ let tools = registry_with_all(&["build_workflow", "propose_workflow"]);
+ let handle = crate::openhuman::tools::traits::pack_registry_handle(find(&tools, USE_SKILL))
+ .expect("use_skill carries the pack handle");
+
+ let rendered = render_pack_filtered(
+ "workflows",
+ handle,
+ &|name: &str| name != "propose_workflow",
+ "",
+ )
+ .expect("the pack still has a callable tool");
+
+ assert!(
+ rendered.contains("build_workflow"),
+ "a tool the session CAN call must still be listed: {rendered}"
+ );
+ assert!(
+ !rendered.contains("propose_workflow"),
+ "a tool the session will refuse must not be advertised: {rendered}"
+ );
+}
+
+/// When the session can reach nothing in the pack, the failure has to carry the
+/// way out. A bare "no tools available" is the dead end the model retried into.
+#[test]
+fn a_listing_with_nothing_callable_names_the_route_out() {
+ let tools = registry_with_all(&["build_workflow", "propose_workflow"]);
+ let handle = crate::openhuman::tools::traits::pack_registry_handle(find(&tools, USE_SKILL))
+ .expect("use_skill carries the pack handle");
+
+ let route = route_sentence(&["build_workflow".to_string()], &["workflow_builder"]);
+ let err = render_pack_filtered("workflows", handle, &|_| false, &route)
+ .expect_err("nothing callable must not render a menu");
+
+ assert!(
+ err.contains("build_workflow"),
+ "the denial must name the delegate to call instead: {err}"
+ );
+}
+
+/// Naming the tool, not just the agent, is the difference between an
+/// instruction and a guess — and a model that guesses wrong retries.
+#[test]
+fn route_sentence_prefers_a_callable_tool_and_falls_back_to_owners() {
+ let named = route_sentence(&["build_workflow".to_string()], &["workflow_builder"]);
+ assert!(named.contains("`build_workflow`"), "{named}");
+ assert!(
+ !named.contains("`workflow_builder`"),
+ "naming the agent as well is noise once the call is named: {named}"
+ );
+
+ let fallback = route_sentence(&[], &["workflow_builder", "flow_discovery"]);
+ assert!(fallback.contains("`workflow_builder`"), "{fallback}");
+ assert!(fallback.contains("`flow_discovery`"), "{fallback}");
+
+ assert!(
+ route_sentence(&[], &[]).is_empty(),
+ "an ownerless pack has no route to offer and must stay silent"
+ );
+}
+
+/// The route only exists because these owners do. If the `workflows` pack is
+/// ever re-owned, the hint silently stops naming `workflow_builder` — this
+/// pins the assumption the two tests above rest on.
+#[test]
+fn the_workflows_pack_is_still_owned_by_the_flow_agents() {
+ let pack = pack("workflows").expect("the workflows pack exists");
+ assert!(
+ pack.owners.contains(&"workflow_builder"),
+ "owners moved: {:?}",
+ pack.owners
+ );
+ assert!(
+ pack.tools.contains(&"propose_workflow"),
+ "propose_workflow left the pack: {:?}",
+ pack.tools
+ );
+}
+