mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-07 02:51:50 +00:00
skills-hub: hash binary skill bundle files correctly
This commit is contained in:
parent
c90f25dd1f
commit
3072e5543b
2 changed files with 21 additions and 1 deletions
|
|
@ -901,6 +901,22 @@ class TestCheckForSkillUpdates:
|
||||||
|
|
||||||
assert bundle_content_hash(bundle) == content_hash(skill_dir)
|
assert bundle_content_hash(bundle) == content_hash(skill_dir)
|
||||||
|
|
||||||
|
def test_bundle_content_hash_accepts_binary_files(self):
|
||||||
|
bundle = SkillBundle(
|
||||||
|
name="demo-binary-skill",
|
||||||
|
files={
|
||||||
|
"SKILL.md": "# Demo\n",
|
||||||
|
"assets/logo.png": b"\x89PNG\r\n\x1a\nbinary",
|
||||||
|
},
|
||||||
|
source="github",
|
||||||
|
identifier="owner/repo/demo-binary-skill",
|
||||||
|
trust_level="community",
|
||||||
|
)
|
||||||
|
|
||||||
|
digest = bundle_content_hash(bundle)
|
||||||
|
|
||||||
|
assert digest.startswith("sha256:")
|
||||||
|
|
||||||
def test_reports_update_when_remote_hash_differs(self):
|
def test_reports_update_when_remote_hash_differs(self):
|
||||||
lock = MagicMock()
|
lock = MagicMock()
|
||||||
lock.list_installed.return_value = [{
|
lock.list_installed.return_value = [{
|
||||||
|
|
|
||||||
|
|
@ -2801,7 +2801,11 @@ def bundle_content_hash(bundle: SkillBundle) -> str:
|
||||||
"""Compute a deterministic hash for an in-memory skill bundle."""
|
"""Compute a deterministic hash for an in-memory skill bundle."""
|
||||||
h = hashlib.sha256()
|
h = hashlib.sha256()
|
||||||
for rel_path in sorted(bundle.files):
|
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]}"
|
return f"sha256:{h.hexdigest()[:16]}"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue