Skip to content

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

chore: files changed src/openhuman/skills/search.rs,src/openhuman/skills/search_tests.rs

Steven Enamakel0a5c85166c62
diff --git a/src/openhuman/skills/search.rs b/src/openhuman/skills/search.rs
index 10c72c1f77..6ed098b14e 100644
--- a/src/openhuman/skills/search.rs
+++ b/src/openhuman/skills/search.rs
@@ -234,25 +234,38 @@ impl Tool for SkillSearchTool {
"[tool][skill_search] ranked"
);
- if matches.is_empty() {
- // An explicit miss, not an empty list. "No skill matched" and "you
- // have no skills" call for different next moves, and a bare `[]`
- // does not distinguish them.
- return Ok(ToolResult::success(serde_json::to_string(&json!({
- "matched": 0,
- "installed": workflows.len(),
- "skills": [],
- "hint": "No installed skill matched. Try `skill_registry_search` \
- to find one to install, or do the task directly.",
- }))?));
- }
+ Ok(ToolResult::success(serde_json::to_string(&render(
+ &matches,
+ workflows.len(),
+ ))?))
+ }
+}
- Ok(ToolResult::success(serde_json::to_string(&json!({
- "matched": matches.len(),
- "installed": workflows.len(),
- "skills": matches.iter().map(|w| project(w)).collect::<Vec<_>>(),
- }))?))
+/// Build the tool's reply.
+///
+/// Split out from `execute` so it is testable without a workspace: the tool
+/// itself discovers through `dirs::home_dir()`, so any test that went through
+/// `execute` would rank against whatever skills the developer running it
+/// happens to have installed. That is the same non-hermetic trap the prompt
+/// budget lane hit — a test whose corpus is the machine it runs on.
+fn render(matches: &[&Workflow], installed: usize) -> Value {
+ if matches.is_empty() {
+ // An explicit miss, not an empty list. "No skill matched" and "you have
+ // no skills installed" call for different next moves, and a bare `[]`
+ // does not distinguish them.
+ return json!({
+ "matched": 0,
+ "installed": installed,
+ "skills": [],
+ "hint": "No installed skill matched. Try `skill_registry_search` to \
+ find one to install, or just do the task directly.",
+ });
}
+ json!({
+ "matched": matches.len(),
+ "installed": installed,
+ "skills": matches.iter().map(|w| project(w)).collect::<Vec<_>>(),
+ })
}
#[cfg(test)]
diff --git a/src/openhuman/skills/search_tests.rs b/src/openhuman/skills/search_tests.rs
index 742efa23ca..37edaf9860 100644
--- a/src/openhuman/skills/search_tests.rs
+++ b/src/openhuman/skills/search_tests.rs
@@ -64,15 +64,20 @@ fn nothing_relevant_returns_nothing() {
// The property that makes a miss legible. A ranker that always returns
// `limit` entries would hand the model `ascii-art` for a database query
// and invite it to run the thing.
+ //
+ // This query is also the stopword regression: before `Bm25Index::significant`
+ // existed it matched `changelog`, on the strength of the word "a".
let all = corpus();
assert!(rank(&all, "provision a kubernetes cluster", 3).is_empty());
+ assert!(rank(&all, "photosynthesis", 3).is_empty());
}
#[test]
fn the_limit_caps_the_result_set() {
let all = corpus();
- assert_eq!(rank(&all, "a", 10).len(), rank(&all, "a", 10).len().min(3));
- assert!(rank(&all, "the", 1).len() <= 1);
+ let query = "changelog ascii tinyflows";
+ assert_eq!(rank(&all, query, 10).len(), 3, "all three must match unlimited");
+ assert_eq!(rank(&all, query, 1).len(), 1);
}
#[test]
@@ -113,27 +118,36 @@ async fn an_empty_query_is_an_error_rather_than_every_skill() {
assert!(result.is_error);
}
-#[tokio::test]
-async fn a_miss_says_so_instead_of_returning_a_bare_empty_list() {
- let tmp = tempfile::tempdir().expect("tempdir");
- let config = Config {
- workspace_dir: tmp.path().to_path_buf(),
- ..Default::default()
- };
- let tool = SkillSearchTool::new(Arc::new(config));
- let result = tool
- .execute(json!({ "query": "provision a kubernetes cluster" }))
- .await
- .expect("dispatch");
- assert!(!result.is_error);
- let text = format!("{result:?}");
- assert!(text.contains("\\\"matched\\\":0") || text.contains("matched"));
+#[test]
+fn a_miss_says_so_instead_of_returning_a_bare_empty_list() {
+ // Against `render`, not `execute`. The tool discovers through
+ // `dirs::home_dir()`, so an `execute`-level miss test ranks against the
+ // developer's own installed skills — this exact test failed that way,
+ // matching five real skills in a supposedly empty temp workspace.
+ let value = render(&[], 14);
+ assert_eq!(value["matched"], 0);
+ assert_eq!(value["installed"], 14);
assert!(
- text.contains("skill_registry_search"),
- "a miss must say what to do next: {text}"
+ value["hint"]
+ .as_str()
+ .expect("hint")
+ .contains("skill_registry_search"),
+ "a miss must say what to do next"
);
}
+#[test]
+fn a_hit_reports_how_many_were_searched() {
+ // `installed` is what lets the model tell "nothing matched" from "you have
+ // three skills and none is close" without a second call.
+ let all = corpus();
+ let hits = rank(&all, "changelog", 5);
+ let value = render(&hits, all.len());
+ assert_eq!(value["matched"], 1);
+ assert_eq!(value["installed"], 3);
+ assert!(value["hint"].is_null(), "a hit carries no miss hint");
+}
+
#[tokio::test]
async fn the_bundled_skill_is_findable_once_installed() {
// End to end over the real pipeline: materialise the compiled-in bundles