Skip to content

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

fix(skills): do not trust a lone match in a truncated repo listing

M3gA-Mindf9630ddd34cb
diff --git a/crates/openhuman-core/src/skills/catalog/download.rs b/crates/openhuman-core/src/skills/catalog/download.rs
index 7b3d6ac2cc..d19f4d6434 100644
--- a/crates/openhuman-core/src/skills/catalog/download.rs
+++ b/crates/openhuman-core/src/skills/catalog/download.rs
@@ -146,7 +146,8 @@ impl<'a> SkillsShRef<'a> {
pub(super) enum TreeMiss {
/// The listing is complete and has no `<skill>/SKILL.md`.
Absent,
- /// GitHub truncated the listing and it has no match, so absence is unproven.
+ /// GitHub truncated the listing and it shows at most one match, so neither
+ /// absence nor uniqueness is proven.
Truncated,
/// Several directories are named for the skill; picking one would be a guess.
Ambiguous(Vec<String>),
@@ -166,10 +167,15 @@ pub(super) fn find_skill_md_in_tree(tree: &Value, skill: &str) -> Result<String,
.filter(|path| path.ends_with(&suffix) || *path == &suffix[1..])
.map(str::to_string)
.collect();
+ // A truncated listing can omit a match: it proves neither that the skill is
+ // absent nor that a lone visible match is the only one. Two visible matches
+ // are ambiguous either way.
let truncated = tree.get("truncated").and_then(Value::as_bool) == Some(true);
+ if truncated && matches.len() < 2 {
+ return Err(TreeMiss::Truncated);
+ }
match matches.len() {
1 => Ok(matches.remove(0)),
- 0 if truncated => Err(TreeMiss::Truncated),
0 => Err(TreeMiss::Absent),
_ => Err(TreeMiss::Ambiguous(matches)),
}
diff --git a/crates/openhuman-core/src/skills/catalog/download_tests.rs b/crates/openhuman-core/src/skills/catalog/download_tests.rs
index 0b445f4a24..fa78e513ee 100644
--- a/crates/openhuman-core/src/skills/catalog/download_tests.rs
+++ b/crates/openhuman-core/src/skills/catalog/download_tests.rs
@@ -83,7 +83,7 @@ fn find_skill_md_in_tree_refuses_to_guess_between_same_named_directories() {
}
#[test]
-fn find_skill_md_in_tree_does_not_call_a_truncated_listing_proof_of_absence() {
+fn find_skill_md_in_tree_does_not_trust_a_truncated_listing() {
let truncated = json!({
"truncated": true,
"tree": [{ "path": "other/SKILL.md", "type": "blob" }]
@@ -92,13 +92,26 @@ fn find_skill_md_in_tree_does_not_call_a_truncated_listing_proof_of_absence() {
find_skill_md_in_tree(&truncated, "my-skill"),
Err(TreeMiss::Truncated)
);
- // A match that did make it into a truncated listing is still usable.
- let found = json!({
+ // A lone visible match is not proof of uniqueness: the cut-off part of the
+ // listing can hold another directory with the same name.
+ let one_visible = json!({
"truncated": true,
"tree": [{ "path": "deep/my-skill/SKILL.md", "type": "blob" }]
});
assert_eq!(
- find_skill_md_in_tree(&found, "my-skill"),
- Ok("deep/my-skill/SKILL.md".to_string())
+ find_skill_md_in_tree(&one_visible, "my-skill"),
+ Err(TreeMiss::Truncated)
);
+ // Two visible matches are ambiguous whatever was cut off.
+ let two_visible = json!({
+ "truncated": true,
+ "tree": [
+ { "path": "a/my-skill/SKILL.md", "type": "blob" },
+ { "path": "b/my-skill/SKILL.md", "type": "blob" },
+ ]
+ });
+ assert!(matches!(
+ find_skill_md_in_tree(&two_visible, "my-skill"),
+ Err(TreeMiss::Ambiguous(_))
+ ));
}