-
Notifications
You must be signed in to change notification settings - Fork 52.6k
fix(skills): prefer GitHub repo skill for owner/repo installs #52499
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
addelh
wants to merge
2
commits into
NousResearch:main
Choose a base branch
from
addelh:fix/github-repo-skill-install-resolution
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+252
−0
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| """Tests for CLI skill install source resolution.""" | ||
|
|
||
| from hermes_cli.skills_hub import _resolve_source_meta_and_bundle | ||
| from tools.skills_hub import SkillBundle, SkillMeta | ||
|
|
||
|
|
||
| class _FakeGitHubSource: | ||
| def __init__(self, tree_paths): | ||
| self.tree_paths = tree_paths | ||
| self.repo_tree_requests = [] | ||
| self.fetched = [] | ||
| self.inspected = [] | ||
|
|
||
| def source_id(self): | ||
| return "github" | ||
|
|
||
| def _get_repo_tree(self, repo): | ||
| self.repo_tree_requests.append(repo) | ||
| return ( | ||
| "main", | ||
| [{"type": "blob", "path": path} for path in self.tree_paths], | ||
| ) | ||
|
|
||
| def fetch(self, identifier): | ||
| self.fetched.append(identifier) | ||
| if identifier == "mvanhorn/last30days-skill/skills/last30days": | ||
| return SkillBundle( | ||
| name="last30days", | ||
| files={"SKILL.md": "---\nname: last30days\n---\n"}, | ||
| source="github", | ||
| identifier=identifier, | ||
| trust_level="community", | ||
| ) | ||
| return None | ||
|
|
||
| def inspect(self, identifier): | ||
| self.inspected.append(identifier) | ||
| if identifier == "mvanhorn/last30days-skill/skills/last30days": | ||
| return SkillMeta( | ||
| name="last30days", | ||
| description="Current GitHub runtime skill", | ||
| source="github", | ||
| identifier=identifier, | ||
| trust_level="community", | ||
| repo="mvanhorn/last30days-skill", | ||
| path="skills/last30days", | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| class _FakeClawHubSource: | ||
| def source_id(self): | ||
| return "clawhub" | ||
|
|
||
| def fetch(self, identifier): | ||
| if identifier == "mvanhorn/last30days-skill": | ||
| return SkillBundle( | ||
| name="last30days-skill", | ||
| files={"SKILL.md": "stale root package"}, | ||
| source="clawhub", | ||
| identifier="last30days-skill", | ||
| trust_level="community", | ||
| ) | ||
| return None | ||
|
|
||
| def inspect(self, identifier): | ||
| if identifier == "mvanhorn/last30days-skill": | ||
| return SkillMeta( | ||
| name="Last30days Skill", | ||
| description="Stale registry package", | ||
| source="clawhub", | ||
| identifier="last30days-skill", | ||
| trust_level="community", | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| class _FakeOfficialSource: | ||
| def source_id(self): | ||
| return "official" | ||
|
|
||
| def fetch(self, identifier): | ||
| if identifier == "official/last30days": | ||
| return SkillBundle( | ||
| name="last30days", | ||
| files={"SKILL.md": "official skill"}, | ||
| source="official", | ||
| identifier=identifier, | ||
| trust_level="builtin", | ||
| ) | ||
| return None | ||
|
|
||
| def inspect(self, identifier): | ||
| if identifier == "official/last30days": | ||
| return SkillMeta( | ||
| name="last30days", | ||
| description="Official skill", | ||
| source="official", | ||
| identifier=identifier, | ||
| trust_level="builtin", | ||
| ) | ||
| return None | ||
|
|
||
|
|
||
| def test_bare_github_repo_prefers_current_repo_skill_over_registry_alias(): | ||
| github = _FakeGitHubSource(["skills/last30days/SKILL.md"]) | ||
| clawhub = _FakeClawHubSource() | ||
|
|
||
| meta, bundle, matched = _resolve_source_meta_and_bundle( | ||
| "mvanhorn/last30days-skill", | ||
| # Put ClawHub first to prove explicit owner/repo still prefers GitHub. | ||
| [clawhub, github], | ||
| ) | ||
|
|
||
| assert matched is github | ||
| assert bundle is not None | ||
| assert bundle.source == "github" | ||
| assert bundle.identifier == "mvanhorn/last30days-skill/skills/last30days" | ||
| assert meta is not None | ||
| assert meta.path == "skills/last30days" | ||
| assert github.fetched == ["mvanhorn/last30days-skill/skills/last30days"] | ||
|
|
||
|
|
||
| def test_bare_github_repo_falls_back_to_sources_when_repo_skill_is_ambiguous(): | ||
| github = _FakeGitHubSource([ | ||
| "skills/alpha/SKILL.md", | ||
| "skills/beta/SKILL.md", | ||
| ]) | ||
| clawhub = _FakeClawHubSource() | ||
|
|
||
| meta, bundle, matched = _resolve_source_meta_and_bundle( | ||
| "mvanhorn/last30days-skill", | ||
| [github, clawhub], | ||
| ) | ||
|
|
||
| assert matched is clawhub | ||
| assert bundle is not None | ||
| assert bundle.source == "clawhub" | ||
| assert meta is not None | ||
| assert meta.source == "clawhub" | ||
|
|
||
|
|
||
| def test_registered_source_identifier_bypasses_bare_github_preflight(): | ||
| github = _FakeGitHubSource(["skills/last30days/SKILL.md"]) | ||
| official = _FakeOfficialSource() | ||
|
|
||
| meta, bundle, matched = _resolve_source_meta_and_bundle( | ||
| "official/last30days", | ||
| [github, official], | ||
| ) | ||
|
|
||
| assert github.repo_tree_requests == [] | ||
| assert matched is official | ||
| assert bundle is not None | ||
| assert bundle.source == "official" | ||
| assert meta is not None | ||
| assert meta.source == "official" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also matches explicit source-qualified identifiers such as
official/<skill>andclawhub/<skill>. Since the preflight runs before the normal router, those installs now probe GitHub first and can be hijacked by a matching GitHub repository. Exclude registered source prefixes here and add a regression test forofficial/<skill>.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 81c2cbf13. The bare owner/repo preflight now skips any identifier whose first segment matches a registered source ID, so explicit routes such as
official/<skill>andclawhub/<skill>stay with the normal source router. Added a regression test that assertsofficial/<skill>never calls GitHub_get_repo_treeand resolves through the official source. Rebased onto currentmain; focused resolver tests pass (6 passed) and Ruff/diff checks are clean.