Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tests/tools/test_skills_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,27 @@ def test_bundle_content_hash_matches_installed_content_hash(self, tmp_path):

assert bundle_content_hash(bundle) == content_hash(skill_dir)

def test_bundle_content_hash_accepts_bytes_content(self, tmp_path):
from tools.skills_guard import content_hash

bundle = SkillBundle(
name="demo-skill",
files={
"SKILL.md": b"# Demo Skill\n",
"references/checklist.md": "- [ ] security\n",
},
source="github",
identifier="owner/repo/demo-skill",
trust_level="community",
)
skill_dir = tmp_path / "demo-skill"
skill_dir.mkdir()
(skill_dir / "SKILL.md").write_bytes(b"# Demo Skill\n")
(skill_dir / "references").mkdir()
(skill_dir / "references" / "checklist.md").write_text("- [ ] security\n")

assert bundle_content_hash(bundle) == content_hash(skill_dir)

def test_reports_update_when_remote_hash_differs(self):
lock = MagicMock()
lock.list_installed.return_value = [{
Expand Down
6 changes: 5 additions & 1 deletion tools/skills_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,11 @@ def bundle_content_hash(bundle: SkillBundle) -> str:
"""Compute a deterministic hash for an in-memory skill bundle."""
h = hashlib.sha256()
for rel_path in sorted(bundle.files):
h.update(bundle.files[rel_path].encode("utf-8"))
content = bundle.files[rel_path]
if isinstance(content, bytes):
h.update(content)
else:
h.update(content.encode("utf-8"))
return f"sha256:{h.hexdigest()[:16]}"


Expand Down