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
29 changes: 29 additions & 0 deletions tests/tools/test_skills_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,35 @@ def fake_get(url, *args, **kwargs):


class TestCheckForSkillUpdates:
def test_bundle_content_hash_handles_bytes_content(self):
"""Regression test for #2739: bundle_content_hash must handle bytes files."""
# SkillBundle.files can contain Union[str, bytes]
bundle = SkillBundle(
name="binary-skill",
files={
"SKILL.md": "---\nname: test\n---\n",
"assets/audio.wav": b"RIFF\x00\x01fakewav", # bytes content
},
source="github",
identifier="owner/repo/binary-skill",
trust_level="community",
)
# Should not crash with AttributeError: 'bytes' object has no attribute 'encode'
hash_result = bundle_content_hash(bundle)
assert hash_result.startswith("sha256:")
# Deterministic: same content = same hash
bundle2 = SkillBundle(
name="binary-skill",
files={
"SKILL.md": "---\nname: test\n---\n",
"assets/audio.wav": b"RIFF\x00\x01fakewav",
},
source="github",
identifier="owner/repo/binary-skill",
trust_level="community",
)
assert bundle_content_hash(bundle2) == hash_result

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

Expand Down
7 changes: 6 additions & 1 deletion tools/skills_hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -2630,7 +2630,12 @@ 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]
# files can contain str or bytes; handle both
if isinstance(content, bytes):
h.update(content)
else:
h.update(content.encode("utf-8"))
return f"sha256:{h.hexdigest()[:16]}"


Expand Down
Loading